Skip to content

delegation: fix cycles during delayed lowering#154368

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
aerooneqq:delegation-force-lowering-later
Apr 9, 2026
Merged

delegation: fix cycles during delayed lowering#154368
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
aerooneqq:delegation-force-lowering-later

Conversation

@aerooneqq
Copy link
Copy Markdown
Contributor

@aerooneqq aerooneqq commented Mar 25, 2026

View all comments

This PR forces lowering of delayed owners after hir_crate_items, as some diagnostics use hir_crate_items which results in query cycle which is then hangs calling def_path_str again and again. Fixes #154169. Part of #118212.

r? @petrochenkov

@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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 25, 2026
@aerooneqq aerooneqq changed the title delegation: invoke hir_crate_items before force_delayed_lowering delegation: invoke hir_crate_items before force_delayed_owners_lowering Mar 25, 2026
@petrochenkov petrochenkov added the F-fn_delegation `#![feature(fn_delegation)]` label Mar 25, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

What specific uses of def_path_str cause the infinite recursion?
Perhaps using something like with_reduced_queries will allow to break the recursion locally, and avoid global changes that this PR does.

@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 Mar 25, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

Relevant - #154387, #154389.

@jyn514
Copy link
Copy Markdown
Member

jyn514 commented Mar 26, 2026

This should really have a reviewer with a lot of query system experience.

r? @Zoxc

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 26, 2026

Failed to set assignee to zoxc: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@rust-bors

This comment has been minimized.

@aerooneqq aerooneqq force-pushed the delegation-force-lowering-later branch from f32739b to f50159f Compare March 27, 2026 09:41
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@aerooneqq aerooneqq force-pushed the delegation-force-lowering-later branch from f50159f to 5afd6e4 Compare March 27, 2026 09:50
@aerooneqq
Copy link
Copy Markdown
Contributor Author

So the reason of this cycle was that this function wants to iterate over all free items, however they were not available during delayed lowering as it was executed before hir_crate_items(()), now delayed lowering is executed after hir_crate_items(()), and we use available-without-lowering information to fill hir_crate_items with information about delayed owners.

for id in tcx.hir_free_items() {

Next, there is one more problem in this function, which is maybe not that actual now, but it will be during supporting inherent impls, as during function resolution we will do coherence check, and in cases like:

struct X<T> { t: T }

// No generics provided
impl X {
  pub fn foo() {}
}

reuse X::foo;

we would still come to for_each_def function, but this time this line will be a problem, as we would call delayed lowering during resolution of delegation, so I stored identifier which is needed by this loop in delayed owners, as it once again information that can be accessed without lowering.

let item = tcx.hir_item(id);

@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 Mar 27, 2026
@rust-log-analyzer

This comment has been minimized.

@aerooneqq aerooneqq changed the title delegation: invoke hir_crate_items before force_delayed_owners_lowering delegation: fix cycles during delayed lowering Mar 27, 2026
@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 Mar 27, 2026
@aerooneqq
Copy link
Copy Markdown
Contributor Author

aerooneqq commented Mar 27, 2026

@rustbot ready
For perf.

@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 Mar 27, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 8, 2026
@aerooneqq
Copy link
Copy Markdown
Contributor Author

aerooneqq commented Apr 8, 2026

@rustbot ready
Those 5 regressions happened because hir_crate was called during hir_module_items, now it should be ok.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 9, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

r=me after squashing commits.
@rustbot author

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

rustbot commented Apr 9, 2026

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

@aerooneqq aerooneqq force-pushed the delegation-force-lowering-later branch from 2314000 to dac2e3e Compare April 9, 2026 12:13
@aerooneqq
Copy link
Copy Markdown
Contributor Author

@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 Apr 9, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 9, 2026

📌 Commit dac2e3e 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 Apr 9, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 9, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 9, 2026

☀️ Test successful - CI
Approved by: petrochenkov
Duration: 3h 27m 53s
Pushing a87c9b9 to main...

@rust-bors rust-bors bot merged commit a87c9b9 into rust-lang:main Apr 9, 2026
12 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 4c42051 (parent) -> a87c9b9 (this PR)

Test differences

Show 28 test diffs

Stage 1

  • [ui] tests/ui/delegation/generics/query-cycle-oom-154169.rs: [missing] -> pass (J0)

Stage 2

  • [ui] tests/ui/delegation/generics/query-cycle-oom-154169.rs: [missing] -> pass (J1)

Additionally, 26 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard a87c9b96031d4d8698bb0cd6533e83bc6d77ddaa --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-android: 22m 2s -> 28m 50s (+30.9%)
  2. dist-x86_64-apple: 1h 43m -> 2h 10m (+26.5%)
  3. i686-gnu-nopt-1: 1h 55m -> 2h 24m (+24.6%)
  4. i686-gnu-2: 1h 26m -> 1h 42m (+18.0%)
  5. armhf-gnu: 1h 18m -> 1h 32m (+17.4%)
  6. pr-check-1: 27m 54s -> 32m 41s (+17.1%)
  7. aarch64-gnu-llvm-21-1: 54m 22s -> 1h 3m (+16.7%)
  8. i686-gnu-1: 2h 8m -> 2h 27m (+14.7%)
  9. optional-x86_64-gnu-parallel-frontend: 2h 22m -> 2h 42m (+14.3%)
  10. aarch64-gnu-debug: 1h 6m -> 1h 15m (+13.8%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (a87c9b9): comparison URL.

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

@rustbot label: -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.4% [0.4%, 0.4%] 1
Regressions ❌
(secondary)
0.6% [0.1%, 1.1%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.6% [-3.2%, -0.1%] 2
All ❌✅ (primary) 0.4% [0.4%, 0.4%] 1

Max RSS (memory usage)

Results (primary 6.5%, secondary 5.5%)

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

mean range count
Regressions ❌
(primary)
7.0% [0.6%, 25.1%] 20
Regressions ❌
(secondary)
5.5% [1.0%, 17.4%] 12
Improvements ✅
(primary)
-2.8% [-2.8%, -2.8%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 6.5% [-2.8%, 25.1%] 21

Cycles

Results (primary 1.5%)

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

Binary size

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

Bootstrap: 489.441s -> 489.938s (0.10%)
Artifact size: 395.61 MiB -> 395.59 MiB (-0.00%)

@rustbot rustbot removed the perf-regression Performance regression. label Apr 9, 2026
@aerooneqq aerooneqq deleted the delegation-force-lowering-later branch April 9, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-fn_delegation `#![feature(fn_delegation)]` merged-by-bors This PR was explicitly merged by bors. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

delegation: oom

6 participants