Skip to content

change HIR typeck region uniquification handling approach #145706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2025

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Aug 21, 2025

#144405 causes structural lookup of opaque types to not work during HIR typeck, so instead avoid uniquifying goals and instead only reprove them if MIR borrowck actually encounters an error.

This doesn't perfectly maintain the property that HIR typeck succeeding implies that MIR typeck succeeds, instead weakening this check to only guarantee that HIR typeck implies that MIR typeck succeeds modulo region uniquification. This means we still get the actually desirable ICEs if we MIR building is broken or we forget to check some property in HIR typeck, without having to deal with the fallout of uniquification in HIR typeck itself.

We report errors using the original obligation sources of HIR typeck so diagnostics aren't that negatively impacted either.

Here's the history of region uniquification while working on the new trait solver:

r? @BoxyUwU

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Aug 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 21, 2025

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@lcnr
Copy link
Contributor Author

lcnr commented Aug 21, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 21, 2025
change HIR typeck unification handling approach
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 21, 2025
@@ -94,6 +97,8 @@ where
let errors = ocx.select_all_or_error();
if errors.is_empty() {
Ok(value)
} else if let Err(guar) = infcx.tcx.check_potentially_region_dependent_goals(root_def_id) {
Err(guar)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the relevant change.

We store potentially region dependent goals in the TypeckResults and then reprove them in case MIR type check failed to prove something

@rustbot

This comment has been minimized.

@lcnr lcnr changed the title change HIR typeck unification handling approach change HIR typeck region uniquification handling approach Aug 21, 2025
@rust-bors
Copy link

rust-bors bot commented Aug 21, 2025

☀️ Try build successful (CI)
Build commit: 792614a (792614acc44e937dc26ebf049538b29ac45fabe3, parent: 57e620e56b718abaf47f18e1e20a3cc3480b258b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (792614a): comparison URL.

Overall result: ✅ improvements - no action needed

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.

@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
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.7% [-2.5%, -1.0%] 6
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 3.2%, secondary 3.1%)

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

mean range count
Regressions ❌
(primary)
3.2% [1.2%, 5.4%] 3
Regressions ❌
(secondary)
3.1% [2.3%, 3.8%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.2% [1.2%, 5.4%] 3

Cycles

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

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 469.9s -> 472.215s (0.49%)
Artifact size: 378.22 MiB -> 378.38 MiB (0.04%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 21, 2025
Copy link
Member

@BoxyUwU BoxyUwU left a comment

Choose a reason for hiding this comment

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

the code generally seems reasonable to me. I want to think more about whether this is what we actually want to do big picture wise though

View changes since this review

@BoxyUwU BoxyUwU 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 Aug 21, 2025
@@ -23,6 +24,7 @@ use crate::universal_regions::UniversalRegions;
#[instrument(skip(infcx, constraints, op), level = "trace")]
pub(crate) fn fully_perform_op_raw<'tcx, R: fmt::Debug, Op>(
infcx: &BorrowckInferCtxt<'tcx>,
root_def_id: LocalDefId,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to thread root_def_id everywhere? Could we use tcx.typeck_root_def_id(body.source.def_id()) where we use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, that feels like it would slightly worsen perf though/just feels weird given that we've already got that value anyways 🤔 we use fully_perform_op_raw frequently. I personally don't mind passing this additional arg everywhere, so I would keep it as is for now

@rustbot
Copy link
Collaborator

rustbot commented Aug 22, 2025

This PR was rebased onto a different master 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.

@BoxyUwU
Copy link
Member

BoxyUwU commented Aug 22, 2025

@bors r+ rollup=never

I don't feel too strongly about the root_def_id thing, we can always change it after the fact

@bors
Copy link
Collaborator

bors commented Aug 22, 2025

📌 Commit 17ac2fc has been approved by BoxyUwU

It is now in the queue for this repository.

@bors bors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 22, 2025
@jhpratt
Copy link
Member

jhpratt commented Aug 23, 2025

@bors p=1

putting ahead of rollup=iffy PR

@bors
Copy link
Collaborator

bors commented Aug 23, 2025

⌛ Testing commit 17ac2fc with merge 69b76df...

@bors
Copy link
Collaborator

bors commented Aug 23, 2025

☀️ Test successful - checks-actions
Approved by: BoxyUwU
Pushing 69b76df to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 23, 2025
@bors bors merged commit 69b76df into rust-lang:master Aug 23, 2025
11 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 23, 2025
Copy link
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 c5a6a7b (parent) -> 69b76df (this PR)

Test differences

Show 94 test diffs

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

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 69b76df90c7ea63b5350d1865f92902a0b27c9a2 --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-aarch64-apple: 5957.3s -> 7095.1s (19.1%)
  2. tidy: 212.1s -> 187.3s (-11.7%)
  3. dist-aarch64-msvc: 5272.3s -> 5820.8s (10.4%)
  4. aarch64-gnu-llvm-19-2: 2657.9s -> 2394.9s (-9.9%)
  5. x86_64-gnu-llvm-20-1: 3830.3s -> 3471.0s (-9.4%)
  6. x86_64-gnu-llvm-19: 2731.0s -> 2973.7s (8.9%)
  7. dist-x86_64-apple: 6774.3s -> 7344.0s (8.4%)
  8. dist-apple-various: 5106.3s -> 4740.3s (-7.2%)
  9. dist-arm-linux-musl: 5957.4s -> 5545.5s (-6.9%)
  10. x86_64-gnu-tools: 3997.7s -> 3735.2s (-6.6%)
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
Collaborator

Finished benchmarking commit (69b76df): comparison URL.

Overall result: ✅ 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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.7% [-2.5%, -0.9%] 6
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 2.2%)

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

Cycles

Results (secondary 3.9%)

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

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 467.196s -> 466.542s (-0.14%)
Artifact size: 378.17 MiB -> 378.32 MiB (0.04%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants