Skip to content

Refactor proc_macro_decls_static#158119

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
aerooneqq:rustc-proc-macro-decls-refactoring
Jun 22, 2026
Merged

Refactor proc_macro_decls_static#158119
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
aerooneqq:rustc-proc-macro-decls-refactoring

Conversation

@aerooneqq

@aerooneqq aerooneqq commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

During experiments in #158024 I've noticed that we iterate over all hir_free_items and find RustcProcMacroDecls on each of them for rewrite of a single Option which is the result of the query.

In this PR:

  • The seach for RustcProcMacroDecls attribute is moved into hir_crate_items and result is cached in ModuleItems, now we do not find RustcProcMacroDecls for each free item, we stop when it is found,
  • self.crate_collector is replaced with generic const CRATE_COLLECTOR, maybe will give perf. improvements.

r? @petrochenkov

@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 Jun 19, 2026
@aerooneqq aerooneqq changed the title Refactor proc_macro_decls_static Refactor proc_macro_decls_static Jun 19, 2026
@aerooneqq aerooneqq marked this pull request as ready for review June 19, 2026 09:25
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 19, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 19, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 19, 2026
… r=<try>

Refactor `proc_macro_decls_static`
Comment thread compiler/rustc_interface/src/passes.rs Outdated
providers.queries.early_lint_checks = early_lint_checks;
providers.queries.env_var_os = env_var_os;
providers.queries.proc_macro_decls_static =
|tcx, _| tcx.hir_crate_items(()).rustc_proc_macro_decls();

@petrochenkov petrochenkov Jun 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it need to be a query now when it just reads a field in ModuleItems?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It can be seen as a projection query over hir_crate_items, so if anything else changes in hir_crate_items and we will use tcx.hir_crate_items(()).rustc_proc_macro_decls() instead of projection query then we would invalidate calling query as hir_crate_items will be red. proc_macro_decls_static it is not used in many places, but I can't predict how it will affect perf if we remove it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But all accessors (free_items, trait_items, ...) of hir_crate_items are regular methods, not queries, maybe they were queries in the past and were made regular methods for perf reasons, or maybe we can try to make them all queries and see what happens.

Comment thread compiler/rustc_middle/src/hir/mod.rs Outdated
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 19, 2026
@rust-bors

rust-bors Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 4efc489 (4efc48944e8dc10589dee0844efac3a8737040fe)
Base parent: 8e15021 (8e150217bafcaaaa0c45bf685c55fd56cec48598)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (4efc489): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@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)
1.4% [1.4%, 1.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.2%] 4
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 1.2%, secondary 5.1%)

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

mean range count
Regressions ❌
(primary)
1.2% [1.2%, 1.2%] 1
Regressions ❌
(secondary)
5.1% [2.2%, 7.2%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.2% [1.2%, 1.2%] 1

Cycles

Results (primary -0.0%, secondary 3.3%)

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

mean range count
Regressions ❌
(primary)
1.5% [1.5%, 1.5%] 1
Regressions ❌
(secondary)
3.3% [2.4%, 4.3%] 6
Improvements ✅
(primary)
-1.5% [-1.5%, -1.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.0% [-1.5%, 1.5%] 2

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 481.812s -> 481.916s (0.02%)
Artifact size: 390.71 MiB -> 390.73 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 19, 2026
@rust-bors

This comment has been minimized.

@aerooneqq aerooneqq force-pushed the rustc-proc-macro-decls-refactoring branch from 66723f1 to 3d19869 Compare June 22, 2026 07:23
@rustbot

rustbot commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@aerooneqq

Copy link
Copy Markdown
Contributor Author

Given insignificant perf changes I returned self.crate_collector.
@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 22, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 3d19869 has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Jun 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 22, 2026
…efactoring, r=petrochenkov

Refactor `proc_macro_decls_static`

During experiments in rust-lang#158024 I've noticed that we iterate over all `hir_free_items` and find `RustcProcMacroDecls` on each of them for rewrite of a single `Option` which is the result of the query.

In this PR:

- The seach for `RustcProcMacroDecls` attribute is moved into `hir_crate_items` and result is cached in `ModuleItems`, now we do not find `RustcProcMacroDecls` for each free item, we stop when it is found,
- ~`self.crate_collector` is replaced with generic const `CRATE_COLLECTOR`, maybe will give perf. improvements.~

r? @petrochenkov
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 22, 2026
…efactoring, r=petrochenkov

Refactor `proc_macro_decls_static`

During experiments in rust-lang#158024 I've noticed that we iterate over all `hir_free_items` and find `RustcProcMacroDecls` on each of them for rewrite of a single `Option` which is the result of the query.

In this PR:

- The seach for `RustcProcMacroDecls` attribute is moved into `hir_crate_items` and result is cached in `ModuleItems`, now we do not find `RustcProcMacroDecls` for each free item, we stop when it is found,
- ~`self.crate_collector` is replaced with generic const `CRATE_COLLECTOR`, maybe will give perf. improvements.~

r? @petrochenkov
rust-bors Bot pushed a commit that referenced this pull request Jun 22, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #155811 (Include AtomicU128/AtomicI128 in docs for any target)
 - #158242 (Fix linking for wasm with crate metadata included)
 - #158119 (Refactor `proc_macro_decls_static`)
 - #158230 (Include `Item::stability` info in rustdoc JSON.)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 22, 2026
…efactoring, r=petrochenkov

Refactor `proc_macro_decls_static`

During experiments in rust-lang#158024 I've noticed that we iterate over all `hir_free_items` and find `RustcProcMacroDecls` on each of them for rewrite of a single `Option` which is the result of the query.

In this PR:

- The seach for `RustcProcMacroDecls` attribute is moved into `hir_crate_items` and result is cached in `ModuleItems`, now we do not find `RustcProcMacroDecls` for each free item, we stop when it is found,
- ~`self.crate_collector` is replaced with generic const `CRATE_COLLECTOR`, maybe will give perf. improvements.~

r? @petrochenkov
rust-bors Bot pushed a commit that referenced this pull request Jun 22, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #155811 (Include AtomicU128/AtomicI128 in docs for any target)
 - #158242 (Fix linking for wasm with crate metadata included)
 - #158119 (Refactor `proc_macro_decls_static`)
 - #158172 (update `asm_experimental_reg` comments)
 - #158230 (Include `Item::stability` info in rustdoc JSON.)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 22, 2026
…efactoring, r=petrochenkov

Refactor `proc_macro_decls_static`

During experiments in rust-lang#158024 I've noticed that we iterate over all `hir_free_items` and find `RustcProcMacroDecls` on each of them for rewrite of a single `Option` which is the result of the query.

In this PR:

- The seach for `RustcProcMacroDecls` attribute is moved into `hir_crate_items` and result is cached in `ModuleItems`, now we do not find `RustcProcMacroDecls` for each free item, we stop when it is found,
- ~`self.crate_collector` is replaced with generic const `CRATE_COLLECTOR`, maybe will give perf. improvements.~

r? @petrochenkov
rust-bors Bot pushed a commit that referenced this pull request Jun 22, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158242 (Fix linking for wasm with crate metadata included)
 - #158119 (Refactor `proc_macro_decls_static`)
 - #158172 (update `asm_experimental_reg` comments)
 - #158230 (Include `Item::stability` info in rustdoc JSON.)
 - #158258 (Use an unexpanded span for actually written down opt out params)
 - #158262 (Change compiler leads in triagebot.toml)
rust-bors Bot pushed a commit that referenced this pull request Jun 22, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #158242 (Fix linking for wasm with crate metadata included)
 - #157978 (Avoid `&raw` recovery ICE after trailing comma)
 - #158119 (Refactor `proc_macro_decls_static`)
 - #158171 (rustdoc: Avoid ICE on unevaluated `type const` projections in array lengths)
 - #158172 (update `asm_experimental_reg` comments)
 - #158230 (Include `Item::stability` info in rustdoc JSON.)
 - #158258 (Use an unexpanded span for actually written down opt out params)
 - #158262 (Change compiler leads in triagebot.toml)
rust-bors Bot pushed a commit that referenced this pull request Jun 22, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #158242 (Fix linking for wasm with crate metadata included)
 - #157978 (Avoid `&raw` recovery ICE after trailing comma)
 - #158119 (Refactor `proc_macro_decls_static`)
 - #158171 (rustdoc: Avoid ICE on unevaluated `type const` projections in array lengths)
 - #158172 (update `asm_experimental_reg` comments)
 - #158230 (Include `Item::stability` info in rustdoc JSON.)
 - #158258 (Use an unexpanded span for actually written down opt out params)
 - #158262 (Change compiler leads in triagebot.toml)
rust-bors Bot pushed a commit that referenced this pull request Jun 22, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #158242 (Fix linking for wasm with crate metadata included)
 - #157978 (Avoid `&raw` recovery ICE after trailing comma)
 - #158119 (Refactor `proc_macro_decls_static`)
 - #158171 (rustdoc: Avoid ICE on unevaluated `type const` projections in array lengths)
 - #158172 (update `asm_experimental_reg` comments)
 - #158230 (Include `Item::stability` info in rustdoc JSON.)
 - #158258 (Use an unexpanded span for actually written down opt out params)
 - #158262 (Change compiler leads in triagebot.toml)
rust-bors Bot pushed a commit that referenced this pull request Jun 22, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #158242 (Fix linking for wasm with crate metadata included)
 - #157978 (Avoid `&raw` recovery ICE after trailing comma)
 - #158119 (Refactor `proc_macro_decls_static`)
 - #158171 (rustdoc: Avoid ICE on unevaluated `type const` projections in array lengths)
 - #158172 (update `asm_experimental_reg` comments)
 - #158230 (Include `Item::stability` info in rustdoc JSON.)
 - #158258 (Use an unexpanded span for actually written down opt out params)
 - #158262 (Change compiler leads in triagebot.toml)
@rust-bors rust-bors Bot merged commit c33e89f into rust-lang:main Jun 22, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 22, 2026
rust-timer added a commit that referenced this pull request Jun 22, 2026
Rollup merge of #158119 - aerooneqq:rustc-proc-macro-decls-refactoring, r=petrochenkov

Refactor `proc_macro_decls_static`

During experiments in #158024 I've noticed that we iterate over all `hir_free_items` and find `RustcProcMacroDecls` on each of them for rewrite of a single `Option` which is the result of the query.

In this PR:

- The seach for `RustcProcMacroDecls` attribute is moved into `hir_crate_items` and result is cached in `ModuleItems`, now we do not find `RustcProcMacroDecls` for each free item, we stop when it is found,
- ~`self.crate_collector` is replaced with generic const `CRATE_COLLECTOR`, maybe will give perf. improvements.~

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

Labels

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.

4 participants