Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix anon const def-creation when macros are involved take 2 #130337

Merged
merged 1 commit into from
Sep 22, 2024

Conversation

BoxyUwU
Copy link
Member

@BoxyUwU BoxyUwU commented Sep 14, 2024

Fixes #130321

There were two cases that #129137 did not handle correctly:

  • Given a const argument Foo<{ bar!() }> in which bar!() expands to N, we would visit the anon const and then visit the { bar() } expression instead of visiting the macro call. This meant that we would build a def for the anon const as { bar!() } is not a trivial const argument as bar!() is not a path.
  • Given a const argument Foo<{ bar!() }> is which bar!() expands to { qux!() } in which qux!() expands to N, it should not be considered a trivial const argument as {{ N }} has two pairs of braces. If we only looked at qux's expansion it would look like a trivial const argument even though it is not. We have to track whether we have "unwrapped" a brace already when recursing into the expansions of bar/qux/any macro

r? @camelid

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 14, 2024
self.is_const_arg_trivial_macro_expansion(&*constant.value, Some(&constant))
{
self.pending_anon_const_info = Some(pending_anon);
return self.visit_macro_invoc(macro_invoc);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change to call visit_macro_invoc instead of walk_anon_const is what fixes #130321. Everything else in this PR is changes made to track if we've already unwrapped a brace or not (and related code deduplication since it would be pretty messy otherwise)

@@ -1199,14 +1199,15 @@ impl Expr {
}
}

pub fn maybe_unwrap_block(&self) -> &Expr {
/// Returns an expression with (when possible) *one* outter brace removed
pub fn maybe_unwrap_block(&self) -> (bool, &Expr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if it would be clearer to return Option<&Expr> (also matching the function's name)? Then it could be used as expr.maybe_unwrap_block().unwrap_or(expr) e.g. Maybe that'd be worse, but it just came to mind.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this is probably just worse for every caller unfortunately because this is not the nicest name/signature combo 😅

compiler/rustc_resolve/src/def_collector.rs Outdated Show resolved Hide resolved
@BoxyUwU BoxyUwU force-pushed the anon_const_macro_call branch from 90ff601 to 248dfe7 Compare September 15, 2024 20:22
Copy link
Member

@camelid camelid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with these comments addressed. Thanks!

compiler/rustc_resolve/src/def_collector.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/def_collector.rs Outdated Show resolved Hide resolved
@BoxyUwU BoxyUwU force-pushed the anon_const_macro_call branch from 248dfe7 to 781ec11 Compare September 21, 2024 21:18
@BoxyUwU
Copy link
Member Author

BoxyUwU commented Sep 22, 2024

@bors r=camelid rollup=never

@bors
Copy link
Contributor

bors commented Sep 22, 2024

📌 Commit 781ec11 has been approved by camelid

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 22, 2024
@bors
Copy link
Contributor

bors commented Sep 22, 2024

⌛ Testing commit 781ec11 with merge 55043f0...

@bors
Copy link
Contributor

bors commented Sep 22, 2024

☀️ Test successful - checks-actions
Approved by: camelid
Pushing 55043f0 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 22, 2024
@bors bors merged commit 55043f0 into rust-lang:master Sep 22, 2024
7 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 22, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (55043f0): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -0.7%, secondary -1.7%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.4% [0.4%, 0.4%] 1
Regressions ❌
(secondary)
3.7% [3.7%, 3.7%] 1
Improvements ✅
(primary)
-1.8% [-1.8%, -1.8%] 1
Improvements ✅
(secondary)
-4.4% [-5.2%, -3.5%] 2
All ❌✅ (primary) -0.7% [-1.8%, 0.4%] 2

Cycles

Results (primary 0.7%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.7% [0.7%, 0.7%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.7% [0.7%, 0.7%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 769.615s -> 769.437s (-0.02%)
Artifact size: 341.55 MiB -> 341.48 MiB (-0.02%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: adding a def'n for node-id NodeId(17) and def kind AnonConst but a previous def'n exists
5 participants