Skip to content

Merge several HIR-level queries into one#155678

Open
aerooneqq wants to merge 2 commits into
rust-lang:mainfrom
aerooneqq:single-owners-query-exp
Open

Merge several HIR-level queries into one#155678
aerooneqq wants to merge 2 commits into
rust-lang:mainfrom
aerooneqq:single-owners-query-exp

Conversation

@aerooneqq
Copy link
Copy Markdown
Contributor

@aerooneqq aerooneqq commented Apr 23, 2026

View all comments

Now four queries (local_def_id_to_hir_id, opt_hir_owner_nodes, opt_ast_lowering_delayed_lints, in_scope_traits_map) were replaced with regular methods which acts like getters.
An owner query was added that returns a ProjectedMaybeOwner that contains all those fields. hir_attr_map remains a separate query as adding attributes to ProjectedMaybeOwner led to perf regressions.
There is a similar issue with in_scopes_trait_map, but according to the comments from rust-lang/rustc-perf#2436 it is a rare case.
Most of the changes in incremental tests are renames from opt_hir_owner_nodes -> owner, but there are few cases when new dirty queries were added.

r? @petrochenkov
r? @oli-obk

@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 Apr 23, 2026
@rust-log-analyzer

This comment has been minimized.

@aerooneqq aerooneqq force-pushed the single-owners-query-exp branch from 7b9e758 to 67a6a79 Compare April 23, 2026 09:24
@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 Apr 23, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 23, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 23, 2026

☀️ Try build successful (CI)
Build commit: a7e17f9 (a7e17f9dcdebc727f983dd75b86950023250e23a, parent: 92c7010294007f9bb819f0ddd9d9e9b5ccd5714a)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (a7e17f9): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@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)
42.5% [0.3%, 107.3%] 7
Regressions ❌
(secondary)
27.3% [0.0%, 106.5%] 10
Improvements ✅
(primary)
-1.1% [-2.6%, -0.2%] 111
Improvements ✅
(secondary)
-1.6% [-5.3%, -0.2%] 68
All ❌✅ (primary) 1.4% [-2.6%, 107.3%] 118

Max RSS (memory usage)

Results (primary 1.5%, secondary -0.4%)

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

mean range count
Regressions ❌
(primary)
17.4% [9.5%, 28.4%] 6
Regressions ❌
(secondary)
4.6% [2.3%, 7.3%] 10
Improvements ✅
(primary)
-1.2% [-2.2%, -0.6%] 36
Improvements ✅
(secondary)
-4.1% [-6.8%, -1.8%] 14
All ❌✅ (primary) 1.5% [-2.2%, 28.4%] 42

Cycles

Results (primary 40.1%, secondary 5.3%)

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

mean range count
Regressions ❌
(primary)
61.3% [9.7%, 117.9%] 6
Regressions ❌
(secondary)
19.9% [1.8%, 63.2%] 10
Improvements ✅
(primary)
-2.3% [-2.6%, -2.1%] 3
Improvements ✅
(secondary)
-3.8% [-5.3%, -1.5%] 16
All ❌✅ (primary) 40.1% [-2.6%, 117.9%] 9

Binary size

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

Bootstrap: 500.795s -> 487.693s (-2.62%)
Artifact size: 394.31 MiB -> 394.27 MiB (-0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 23, 2026
@aerooneqq aerooneqq force-pushed the single-owners-query-exp branch 2 times, most recently from 69beb66 to 464a7a0 Compare April 24, 2026 11:17
@petrochenkov
Copy link
Copy Markdown
Contributor

@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 Apr 24, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 24, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 24, 2026

☀️ Try build successful (CI)
Build commit: 7769c1a (7769c1a185b3989b2a2bf22894bf03f2b0505c4c, parent: cf79d034aa3d8f396d407aafce6f1ccd818e710e)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (7769c1a): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@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.0%, 0.6%] 4
Improvements ✅
(primary)
-0.8% [-1.7%, -0.2%] 99
Improvements ✅
(secondary)
-1.0% [-2.8%, -0.0%] 56
All ❌✅ (primary) -0.8% [-1.7%, -0.2%] 99

Max RSS (memory usage)

Results (primary -0.0%, secondary 2.0%)

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

mean range count
Regressions ❌
(primary)
2.2% [1.0%, 3.5%] 2
Regressions ❌
(secondary)
3.9% [2.3%, 7.4%] 6
Improvements ✅
(primary)
-0.8% [-0.9%, -0.6%] 6
Improvements ✅
(secondary)
-2.0% [-2.3%, -1.5%] 3
All ❌✅ (primary) -0.0% [-0.9%, 3.5%] 8

Cycles

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

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)
3.5% [1.3%, 6.8%] 4
Improvements ✅
(primary)
-2.9% [-2.9%, -2.9%] 1
Improvements ✅
(secondary)
-2.8% [-3.5%, -1.3%] 8
All ❌✅ (primary) -2.9% [-2.9%, -2.9%] 1

Binary size

Results (primary -0.0%, secondary -0.1%)

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.0% [-0.0%, -0.0%] 11
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.0%] 4
All ❌✅ (primary) -0.0% [-0.0%, -0.0%] 11

Bootstrap: 493.065s -> 491.562s (-0.30%)
Artifact size: 394.27 MiB -> 394.23 MiB (-0.01%)

@rustbot rustbot removed perf-regression Performance regression. S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 24, 2026
@rust-bors

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (fd2440f): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@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.1% [0.0%, 0.1%] 4
Improvements ✅
(primary)
-0.7% [-1.7%, -0.2%] 109
Improvements ✅
(secondary)
-1.0% [-3.0%, -0.0%] 65
All ❌✅ (primary) -0.7% [-1.7%, -0.2%] 109

Max RSS (memory usage)

Results (primary -1.1%, secondary 1.4%)

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

mean range count
Regressions ❌
(primary)
0.9% [0.9%, 0.9%] 1
Regressions ❌
(secondary)
3.6% [0.7%, 5.0%] 7
Improvements ✅
(primary)
-1.3% [-3.8%, -0.6%] 9
Improvements ✅
(secondary)
-3.6% [-7.5%, -0.6%] 3
All ❌✅ (primary) -1.1% [-3.8%, 0.9%] 10

Cycles

Results (primary -2.6%, secondary 1.1%)

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)
7.5% [5.8%, 10.0%] 3
Improvements ✅
(primary)
-2.6% [-3.5%, -2.2%] 5
Improvements ✅
(secondary)
-3.7% [-7.0%, -2.2%] 4
All ❌✅ (primary) -2.6% [-3.5%, -2.2%] 5

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.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 510.527s -> 514.955s (0.87%)
Artifact size: 400.06 MiB -> 397.95 MiB (-0.53%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 12, 2026
@aerooneqq aerooneqq force-pushed the single-owners-query-exp branch 3 times, most recently from 556806c to 1ebbd9b Compare May 15, 2026 07:12
@aerooneqq aerooneqq changed the title experiment: single owner query Merge several HIR-level queries into one May 15, 2026
@aerooneqq aerooneqq marked this pull request as ready for review May 15, 2026 07:17
@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 May 15, 2026
@rustbot rustbot assigned oli-obk and unassigned petrochenkov May 15, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 15, 2026

Requested reviewer is already assigned to this pull request.

Please choose another assignee.

@aerooneqq aerooneqq force-pushed the single-owners-query-exp branch from 1ebbd9b to 5f6b026 Compare May 15, 2026 08:17
Copy link
Copy Markdown
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

Oh nice you got it performant!

r=me with comments addressed or explained why

View changes since this review

}
}

/// This function is used only inside eval-always query analysis
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.

Assert (or debug assert that it's invoked from an eval-always query

Comment thread compiler/rustc_middle/src/queries.rs Outdated
}

query delayed_owner(def_id: LocalDefId) -> hir::MaybeOwner<'tcx> {
query owner(def_id: LocalDefId) -> &'tcx rustc_middle::hir::ProjectedMaybeOwner<'tcx> {
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.

Is arena-caching this useful considering all fields are references, too?

@rustbot rustbot 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 May 15, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 15, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Comment thread compiler/rustc_middle/src/hir/mod.rs Outdated
}

impl<'tcx> ProjectedMaybeOwner<'tcx> {
pub fn create_from(value: &'tcx MaybeOwner<'tcx>, def_id: LocalDefId) -> Self {
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov May 15, 2026

Choose a reason for hiding this comment

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

Suggested change
pub fn create_from(value: &'tcx MaybeOwner<'tcx>, def_id: LocalDefId) -> Self {
pub fn new(value: &'tcx MaybeOwner<'tcx>, def_id: LocalDefId) -> Self {

View changes since the review


#[inline]
pub fn opt_hir_owner_nodes(self, def_id: LocalDefId) -> Option<&'tcx OwnerNodes<'tcx>> {
self.owner(def_id).as_owner().map(|i| i.nodes)
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov May 15, 2026

Choose a reason for hiding this comment

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

Style nit: 3 owner maps and 3 different names for the same thing (o, i, owner_info) 😄

View changes since the review

@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 May 15, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 15, 2026
Merge several HIR-level queries into one
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 15, 2026

☀️ Try build successful (CI)
Build commit: 8859956 (885995683a54fec9f53bdca583ee62263c6fb7d3, parent: 88ba7fbe0a6eda36e0adbfd0482856f3784031b9)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (8859956): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@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.1% [0.0%, 0.1%] 2
Improvements ✅
(primary)
-0.7% [-1.6%, -0.2%] 117
Improvements ✅
(secondary)
-0.9% [-2.9%, -0.0%] 66
All ❌✅ (primary) -0.7% [-1.6%, -0.2%] 117

Max RSS (memory usage)

Results (primary -0.8%, 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.8% [0.8%, 0.8%] 1
Regressions ❌
(secondary)
4.4% [1.3%, 9.8%] 6
Improvements ✅
(primary)
-1.0% [-1.2%, -0.7%] 8
Improvements ✅
(secondary)
-2.3% [-2.9%, -1.4%] 6
All ❌✅ (primary) -0.8% [-1.2%, 0.8%] 9

Cycles

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)
4.2% [2.9%, 5.5%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.8% [-2.9%, -2.7%] 3
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 510.626s -> 510.588s (-0.01%)
Artifact size: 398.07 MiB -> 398.12 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 15, 2026
Comment thread compiler/rustc_hir/src/hir.rs Outdated

/// Attributes owned by a HIR owner.
#[derive(Debug)]
#[derive(Debug, Clone)]
Copy link
Copy Markdown
Contributor

@cjgillot cjgillot Apr 25, 2026

Choose a reason for hiding this comment

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

Where do we clone this ?

View changes since the review

Comment thread compiler/rustc_middle/src/queries.rs Outdated
}

query delayed_owner(def_id: LocalDefId) -> hir::MaybeOwner<'tcx> {
query owner(def_id: LocalDefId) -> &'tcx rustc_middle::hir::ProjectedMaybeOwner<'tcx> {
Copy link
Copy Markdown
Contributor

@cjgillot cjgillot Apr 25, 2026

Choose a reason for hiding this comment

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

Could you keep a name starting with hir_ ?

View changes since the review

Comment thread compiler/rustc_middle/src/queries.rs Outdated
}

query delayed_owner(def_id: LocalDefId) -> hir::MaybeOwner<'tcx> {
query owner(def_id: LocalDefId) -> &'tcx rustc_middle::hir::ProjectedMaybeOwner<'tcx> {
Copy link
Copy Markdown
Contributor

@cjgillot cjgillot Apr 25, 2026

Choose a reason for hiding this comment

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

Why can't we just return a MaybeOwner ?

View changes since the review

// This query has to be `no_hash` and `eval_always`,
// because it accesses `delayed_lints` which is not hashed as part of the HIR
no_hash
eval_always
Copy link
Copy Markdown
Contributor

@cjgillot cjgillot Apr 25, 2026

Choose a reason for hiding this comment

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

How do we ensure that we are not leaking untracked state ?

View changes since the review

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants