Skip to content

Conversation

@petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Jan 23, 2026

This is a continuation of #150741 and #150982 based on the ideas from #151491 (comment).

Before this PR Macros20NormalizedIdent was used as a key in various "identifier -> its resolution" maps in rustc_resolve.
Macros20NormalizedIdent is a newtype around Ident in which SyntaxContext (packed inside Span) is guaranteed to be normalized using normalize_to_macros_2_0.
This type is also used in a number of functions looking up identifiers in those maps.
Macros20NormalizedIdent still contains span locations, which are useless and ignored during hash map lookups and comparisons due to Ident's special PartialEq and Hash impls.

This PR replaces Macros20NormalizedIdent with a new type called IdentKey, which contains only a symbol and a normalized unpacked syntax context. (E.g. IdentKey == Macros20NormalizedIdent minus span locations.)
So we avoid keeping additional data and doing some syntax context packing/unpacking.

Along with IdentKey you can often see orig_ident_span: Span being passed around.
This is an unnormalized span of the original Ident from which IdentKey was obtained.
It is not used in map keys, but it is used in a number of other scenarios:

  • diagnostics
  • edition checks
  • allow_unstable checks

This is because normalize_to_macros_2_0 normalization is lossy and the normalized spans / syntax contexts no longer contain parts of macro backtraces, while the original span contains everything.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 23, 2026
@petrochenkov
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 23, 2026
rust-bors bot pushed a commit that referenced this pull request Jan 23, 2026
resolve: Replace `Macros20NormalizedIdent` with `IdentKey`
@petrochenkov petrochenkov removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 23, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 23, 2026

☀️ Try build successful (CI)
Build commit: 0b62e28 (0b62e28b1ffadafe2f62aaba7d06486bcdb96f83, parent: d222ddc4d90743dfc1e53b610be8fc9d95893d2c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0b62e28): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.1%, 0.3%] 2
Improvements ✅
(primary)
-0.2% [-0.3%, -0.2%] 21
Improvements ✅
(secondary)
-0.5% [-1.4%, -0.1%] 24
All ❌✅ (primary) -0.2% [-0.3%, -0.2%] 21

Max RSS (memory usage)

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

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.6% [1.7%, 3.6%] 3
Improvements ✅
(primary)
-1.7% [-1.8%, -1.7%] 2
Improvements ✅
(secondary)
-3.2% [-6.4%, -2.3%] 5
All ❌✅ (primary) -1.7% [-1.8%, -1.7%] 2

Cycles

Results (primary 0.7%, secondary 5.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Binary size

Results (secondary -0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Bootstrap: 470.684s -> 470.503s (-0.04%)
Artifact size: 383.48 MiB -> 383.42 MiB (-0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jan 23, 2026
@petrochenkov petrochenkov added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 23, 2026
@petrochenkov petrochenkov marked this pull request as ready for review January 23, 2026 22:30
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 23, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 23, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 23, 2026

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@petrochenkov
Copy link
Contributor Author

r? @nnethercote

@rustbot rustbot assigned nnethercote and unassigned fee1-dead Jan 23, 2026
@petrochenkov
Copy link
Contributor Author

(I also want to try passing the ident: IdentKey, orig_ident_span: Span pair to resolve_ident_in_scope_set, but it may have some negative performance effects, so I'll try it separately.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants