Skip to content

compute_trait_goal structural equality fast path #144258

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Jul 21, 2025

Fixes the hang in rayon and rust-lang/trait-system-refactor-initiative#210.

This changes means we now have a far stronger reliance on structural identity making rust-lang/trait-system-refactor-initiative#127 a significantly larger problem. However, I've come to believe that fast paths based on structural equality are just too desirable. Solves that issue by uniquifying root goals only during HIR typeck. Fixes github.com/rust-lang/trait-system-refactor-initiative/issues/27

Fixes #139409.

r? @compiler-errors

@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 Jul 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 21, 2025

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@lcnr
Copy link
Contributor Author

lcnr commented Jul 21, 2025

@ors2 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 Jul 21, 2025
.any(|p| p == goal.predicate)
{
let candidate = self
.probe_trait_candidate(CandidateSource::ParamEnv(ParamEnvSource::NonGlobal))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: this incorrect marks param_env candidates as global :<

//@[next] compile-flags: -Znext-solver
//@[next] known-bug: #92505
//@[current] check-pass
//@ check-pass
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: I don't fully get why this one compiles now 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we've got the proof tree

  • T: Trait
    • via env: AliasRelate(T::Assoc, T) no solution
      • NormalizesTo(T::Assoc)
        • compute proven_via for T: Trait
          • via AliasRelate(T::Assoc, T) unproductive cycle
          • via impl -> T

we currently never try to actually normalize T::Assoc outside of applying the param env candidate. Doing this has the following proof tree

  • NormalizesTo(T::Assoc)
    • compute proven_via for T: Trait
      • via AliasRelate(T::Assoc, T) err
        • NormalizesTo(T::Assoc) unproductive cycle no solution
      • via impl -> T
  • cycle rerun (provisional result: normalizes-to T)
    • compute proven_via for T: Trait
      • via AliasRelate(T::Assoc, T) ok
        • NormalizesTo(T::Assoc) cycle provisional result T
    • alias is rigid
  • cycle rerun (provisional result: normalizes-to T::Assoc)
    • compute proven_via for T: Trait
      • via AliasRelate(T::Assoc, T) err
        • NormalizesTo(T::Assoc) cycle provisional result T::Assoc
    • via impl -> T
  • ...fail to reach fixpoint

This should start failing again with #140558 and changes it's behavior as this PR simply causes checking whether the <T as Trait>::Assoc: Trait to use the fast path instead of normalizing the self type

@lcnr
Copy link
Contributor Author

lcnr commented Jul 21, 2025

@bors2 try

rust-bors bot added a commit that referenced this pull request Jul 21, 2025
`compute_trait_goal` structural equality fast path

Fixes the hang in rayon and rust-lang/trait-system-refactor-initiative#210.

This changes means we now have a far stronger reliance on structural equality making rust-lang/trait-system-refactor-initiative#127 a significantly larger problem. However, I've come to believe that fast paths based on structural equality are just too desirable.

Fixes #139409.

r? `@compiler-errors`
@rust-bors
Copy link

rust-bors bot commented Jul 21, 2025

⌛ Trying commit 8c737ce with merge 2f05b1f

To cancel the try build, run the command @bors2 try cancel.

@rust-bors
Copy link

rust-bors bot commented Jul 21, 2025

☀️ Try build successful (CI)
Build commit: 2f05b1f (2f05b1f742a5c897ad5434184c44474f4107be5e, parent: 67819923ac8ea353aaa775303f4c3aacbf41d010)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2f05b1f): 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)
-2.1% [-5.5%, -0.3%] 8
All ❌✅ (primary) - - 0

Max RSS (memory usage)

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)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.9% [-11.4%, -3.1%] 3
All ❌✅ (primary) - - 0

Cycles

Results (primary -2.2%, 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)
- - 0
Regressions ❌
(secondary)
1.7% [1.7%, 1.7%] 1
Improvements ✅
(primary)
-2.2% [-2.2%, -2.2%] 1
Improvements ✅
(secondary)
-4.3% [-5.7%, -2.4%] 5
All ❌✅ (primary) -2.2% [-2.2%, -2.2%] 1

Binary size

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

Bootstrap: 465.321s -> 462.652s (-0.57%)
Artifact size: 374.50 MiB -> 374.44 MiB (-0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: next solver: errors selecting obligation during MIR typeck: [Ambiguity]
4 participants