') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); delegation: fix cycles during delayed lowering by aerooneqq · Pull Request #154368 · rust-lang/rust · GitHub
Skip to content

delegation: fix cycles during delayed lowering - #154368

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

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

Conversation

@aerooneqq

@aerooneqqaerooneqq commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

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

@rustbotrustbot 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
@aerooneqqaerooneqq changed the title delegation: invoke hir_crate_items before force_delayed_loweringdelegation: invoke hir_crate_items before force_delayed_owners_loweringMar 25, 2026
@petrochenkovpetrochenkov 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.

@petrochenkovpetrochenkov 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

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

r? @Zoxc

@rustbot

Copy link
Copy Markdown
Collaborator

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
aerooneqqforce-pushed the delegation-force-lowering-later branch from f32739b to f50159fCompareMarch 27, 2026 09:41
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@aerooneqq
aerooneqqforce-pushed the delegation-force-lowering-later branch from f50159f to 5afd6e4CompareMarch 27, 2026 09:50
@aerooneqq

Copy link
Copy Markdown
ContributorAuthor

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:

structX<T>{t:T}// No generics providedimplX{pubfnfoo(){}}
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

@rustbotrustbot 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.

@aerooneqqaerooneqq changed the title delegation: invoke hir_crate_items before force_delayed_owners_loweringdelegation: fix cycles during delayed loweringMar 27, 2026
Comment threadcompiler/rustc_hir/src/hir.rs Outdated
Comment threadcompiler/rustc_hir/src/hir.rs Outdated
Comment threadcompiler/rustc_middle/src/hir/mod.rs Outdated
Comment threadcompiler/rustc_middle/src/hir/map.rs Outdated
Comment threadcompiler/rustc_middle/src/hir/map.rs Outdated
@petrochenkovpetrochenkov 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

aerooneqq commented Mar 27, 2026

Copy link
Copy Markdown
ContributorAuthor

@rustbot ready
For perf.

@rustbotrustbot 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

@aerooneqq

Copy link
Copy Markdown
ContributorAuthor

@rustbot ready

@rustbotrustbot 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

rust-borsBot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

📌 Commit dac2e3e has been approved by petrochenkov

It is now in the queue for this repository.

@rust-borsrust-borsBot 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-borsrust-borsBot 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

rust-borsBot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

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

@rust-bors
rust-borsBot merged commit a87c9b9 into rust-lang:mainApr 9, 2026
12 checks passed
@rustbotrustbot added this to the 1.96.0 milestone Apr 9, 2026
@github-actions

Copy link
Copy Markdown
Contributor
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.

meanrangecount
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.

meanrangecount
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.

meanrangecount
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%)

@rustbotrustbot removed the perf-regression Performance regression. label Apr 9, 2026
@aerooneqq
aerooneqq deleted the delegation-force-lowering-later branch April 9, 2026 17:38
@matthiaskrgr

Copy link
Copy Markdown
Member

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 13, 2026
…ms-revert, r=petrochenkov
delegation: revert execution of hir_crate_items before delayed lowering
This PR reverts rust-lang#154368, as after weekend consideration I don't think that it is a correct way of fixing cycles during delayed lowering:
- The number of ICEs were reported, fixing them would require to develop solution from rust-lang#154368 but I am afraid that it would lead to cancer code growing,
- The [memory regression](rust-lang#154368 (comment)) for rustdoc was reported, it can be fixed with moving `tcx.force_delayed_owners_lowering` call earlier, but it is already bad that this is call is now required everywhere, before rust-lang#154368 AST was dropped before `hir_crate_items` automatically and users of `rustc` API did not have to think about it.
I will try to come up with a more robust solution leaving rust-lang#154368 as a last resort if nothing else will work.
Re-opens rust-lang#154169.
Fixesrust-lang#155125. Fixesrust-lang#155127. Fixesrust-lang#155128. Fixesrust-lang#155164. Fixesrust-lang#155202.
Part of rust-lang#118212.
r? @petrochenkov
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 13, 2026
…ms-revert, r=petrochenkov
delegation: revert execution of hir_crate_items before delayed lowering
This PR reverts rust-lang#154368, as after weekend consideration I don't think that it is a correct way of fixing cycles during delayed lowering:
- The number of ICEs were reported, fixing them would require to develop solution from rust-lang#154368 but I am afraid that it would lead to cancer code growing,
- The [memory regression](rust-lang#154368 (comment)) for rustdoc was reported, it can be fixed with moving `tcx.force_delayed_owners_lowering` call earlier, but it is already bad that this is call is now required everywhere, before rust-lang#154368 AST was dropped before `hir_crate_items` automatically and users of `rustc` API did not have to think about it.
I will try to come up with a more robust solution leaving rust-lang#154368 as a last resort if nothing else will work.
Re-opens rust-lang#154169.
Fixesrust-lang#155125. Fixesrust-lang#155127. Fixesrust-lang#155128. Fixesrust-lang#155164. Fixesrust-lang#155202.
Part of rust-lang#118212.
r? @petrochenkov
rust-timer added a commit that referenced this pull request Apr 13, 2026
Rollup merge of #155226 - aerooneqq:delegation-hir-crate-items-revert, r=petrochenkov
delegation: revert execution of hir_crate_items before delayed lowering
This PR reverts #154368, as after weekend consideration I don't think that it is a correct way of fixing cycles during delayed lowering:
- The number of ICEs were reported, fixing them would require to develop solution from #154368 but I am afraid that it would lead to cancer code growing,
- The [memory regression](#154368 (comment)) for rustdoc was reported, it can be fixed with moving `tcx.force_delayed_owners_lowering` call earlier, but it is already bad that this is call is now required everywhere, before #154368 AST was dropped before `hir_crate_items` automatically and users of `rustc` API did not have to think about it.
I will try to come up with a more robust solution leaving #154368 as a last resort if nothing else will work.
Re-opens #154169.
Fixes#155125. Fixes#155127. Fixes#155128. Fixes#155164. Fixes#155202.
Part of #118212.
r? @petrochenkov
github-actionsBot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Apr 13, 2026
…, r=petrochenkov
delegation: revert execution of hir_crate_items before delayed lowering
This PR reverts rust-lang/rust#154368, as after weekend consideration I don't think that it is a correct way of fixing cycles during delayed lowering:
- The number of ICEs were reported, fixing them would require to develop solution from rust-lang/rust#154368 but I am afraid that it would lead to cancer code growing,
- The [memory regression](rust-lang/rust#154368 (comment)) for rustdoc was reported, it can be fixed with moving `tcx.force_delayed_owners_lowering` call earlier, but it is already bad that this is call is now required everywhere, before rust-lang/rust#154368 AST was dropped before `hir_crate_items` automatically and users of `rustc` API did not have to think about it.
I will try to come up with a more robust solution leaving rust-lang/rust#154368 as a last resort if nothing else will work.
Re-opens rust-lang/rust#154169.
Fixesrust-lang/rust#155125. Fixesrust-lang/rust#155127. Fixesrust-lang/rust#155128. Fixesrust-lang/rust#155164. Fixesrust-lang/rust#155202.
Part of rust-lang/rust#118212.
r? @petrochenkov
github-actionsBot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Apr 16, 2026
…, r=petrochenkov
delegation: revert execution of hir_crate_items before delayed lowering
This PR reverts rust-lang/rust#154368, as after weekend consideration I don't think that it is a correct way of fixing cycles during delayed lowering:
- The number of ICEs were reported, fixing them would require to develop solution from rust-lang/rust#154368 but I am afraid that it would lead to cancer code growing,
- The [memory regression](rust-lang/rust#154368 (comment)) for rustdoc was reported, it can be fixed with moving `tcx.force_delayed_owners_lowering` call earlier, but it is already bad that this is call is now required everywhere, before rust-lang/rust#154368 AST was dropped before `hir_crate_items` automatically and users of `rustc` API did not have to think about it.
I will try to come up with a more robust solution leaving rust-lang/rust#154368 as a last resort if nothing else will work.
Re-opens rust-lang/rust#154169.
Fixesrust-lang/rust#155125. Fixesrust-lang/rust#155127. Fixesrust-lang/rust#155128. Fixesrust-lang/rust#155164. Fixesrust-lang/rust#155202.
Part of rust-lang/rust#118212.
r? @petrochenkov
ghaaj pushed a commit to ghaaj/polygrammar that referenced this pull request Aug 7, 2026
…, r=petrochenkov
delegation: revert execution of hir_crate_items before delayed lowering
This PR reverts rust-lang/rust#154368, as after weekend consideration I don't think that it is a correct way of fixing cycles during delayed lowering:
- The number of ICEs were reported, fixing them would require to develop solution from rust-lang/rust#154368 but I am afraid that it would lead to cancer code growing,
- The [memory regression](rust-lang/rust#154368 (comment)) for rustdoc was reported, it can be fixed with moving `tcx.force_delayed_owners_lowering` call earlier, but it is already bad that this is call is now required everywhere, before rust-lang/rust#154368 AST was dropped before `hir_crate_items` automatically and users of `rustc` API did not have to think about it.
I will try to come up with a more robust solution leaving rust-lang/rust#154368 as a last resort if nothing else will work.
Re-opens rust-lang/rust#154169.
Fixesrust-lang/rust#155125. Fixesrust-lang/rust#155127. Fixesrust-lang/rust#155128. Fixesrust-lang/rust#155164. Fixesrust-lang/rust#155202.
Part of rust-lang/rust#118212.
r? @petrochenkov
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-fn_delegation`#![feature(fn_delegation)]`merged-by-borsThis PR was explicitly merged by bors.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-rustdocRelevant 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

7 participants

@aerooneqq@petrochenkov@jyn514@rustbot@rust-log-analyzer@rust-timer@matthiaskrgr