Skip to content

Add rigid alias marker#156742

Open
adwinwhite wants to merge 2 commits into
rust-lang:mainfrom
adwinwhite:rigid-alias
Open

Add rigid alias marker#156742
adwinwhite wants to merge 2 commits into
rust-lang:mainfrom
adwinwhite:rigid-alias

Conversation

@adwinwhite

@adwinwhite adwinwhite commented May 19, 2026

Copy link
Copy Markdown
Contributor

View all comments

This PR adds a rigidness marker to TyKind::Alias and ConstKind::Unevaluated. It's used to skip renormalization of rigid aliases. The tracking issue for this is #155345.

The difficulty is that rigid aliases are only valid in their own TypingEnv so we need to force them back to non-rigid when entering another TypingEnv, either because a change to the ParamEnv or because we enter another TypingMode.

Changes to the ParamEnv currently only happen by moving into a new context. We now make sure that EarlyBinder new contains any rigid aliases, this way we have to normalize all aliases contained in it after instantiating.

Changes to the TypingMode are rare, and have to be manually handled.


The main changes in this PR are as follows:

  • we add enum IsRigid { Yes, No } as a field to TyKind::Alias and ConstKind::Unevaluated. It is always No with the old solver, this makes some of the code less nice than it will be with the old solver removed.
  • if we keep an alias as rigid when proving Projection goals we equate the expected term with that alias with IsRigid::Yes
  • EarlyBinder::bind now takes the tcx and eagerly sets all IsRigid to No, this is necessary as moving aliases into a different TypingEnv may cause them to no longer be rigid
  • EarlyBinder::bind_iter asserts that there are no rigid aliases instead of replacing them
  • type relations and generalization always structurally recurse into rigid aliases
  • a lot of places in the new solver can ICE when matching on TyKind::Alias with IsRigid::No

There's a lot of future work here:

  • coherence don't actually rely on lazy norm :<
  • remove eq_structurally_relating_aliases, have a special type folder for canonical responses
  • yeet AliasRelate, lazily replace non-rigid aliases with infer var + projection goal
  • ParamEnv normalization hack to incorrectly mark things as rigid
  • eagerly normalize when adding stuff to the fulfillment ctxt :>
  • change TypeOutlives goal handling to only expect rigid aliases
  • properly expect IsRigid::Yesin region handling (or yes_if_next_solver)
  • probably change EarlyBinder::bind to also assert that there are no rigid aliases and manually replacing rigid aliases before then where necessary

This PR also adds a flag -Zrenormalize-rigid-aliases to test whether we properly handle typing mode change.

Currently only tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-4.rs fails this check.

r? lcnr

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. PG-exploit-mitigations Project group: Exploit mitigations 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 19, 2026
@adwinwhite

Copy link
Copy Markdown
Contributor Author

Unfinished. Let's have a look at the perf impact nonetheless.

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

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 19, 2026
[Experiment] Add rigid alias marker
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 73eccb5 failed: CI. Failed job:

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label May 20, 2026
@adwinwhite

Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 20, 2026
[Experiment] Add rigid alias marker
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 42e2939 (42e2939c892f3c5e872d5751bb653ed74736a040, parent: 4b9792692fbb675174d4d2082e7c37b2bc930e71)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (42e2939): comparison URL.

Overall result: ❌ regressions - 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)
0.8% [0.2%, 2.2%] 15
Regressions ❌
(secondary)
11.3% [0.1%, 95.1%] 29
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 2
All ❌✅ (primary) 0.8% [0.2%, 2.2%] 15

Max RSS (memory usage)

Results (primary 1.6%, secondary -1.7%)

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

mean range count
Regressions ❌
(primary)
2.1% [1.7%, 2.7%] 7
Regressions ❌
(secondary)
2.4% [0.8%, 3.6%] 6
Improvements ✅
(primary)
-2.4% [-2.4%, -2.4%] 1
Improvements ✅
(secondary)
-4.1% [-13.8%, -1.1%] 10
All ❌✅ (primary) 1.6% [-2.4%, 2.7%] 8

Cycles

Results (primary 2.5%, secondary 17.8%)

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

mean range count
Regressions ❌
(primary)
2.5% [2.4%, 2.6%] 2
Regressions ❌
(secondary)
19.3% [3.5%, 91.9%] 15
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.7% [-4.7%, -4.7%] 1
All ❌✅ (primary) 2.5% [2.4%, 2.6%] 2

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

Bootstrap: 510.83s -> 514.725s (0.76%)
Artifact size: 400.58 MiB -> 401.07 MiB (0.12%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels May 20, 2026
@adwinwhite

Copy link
Copy Markdown
Contributor Author

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

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@lcnr

lcnr commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@bors r+ rollup=never p=1

@rust-bors

rust-bors Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 1af8ca5 has been approved by lcnr

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 Jun 23, 2026
@lcnr

lcnr commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@bors r- will conflict with the currently happening rollup

@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 23, 2026
@rust-bors

rust-bors Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

View changes since this unapproval

@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 23, 2026
@lcnr

lcnr commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@bors delegate+ p=1

This is both important and very prone to merge conflicts. @adwinwhite please rebase and then feel free to merge this after looking over it yourself again. I'll do that first thing in the morning otherwise :>

@rust-bors

rust-bors Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Invalid command: Key-value argument p is not supported. Run @bors help or go to https://bors.rust-lang.org/help to see available commands.

@rustbot

rustbot commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

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

@adwinwhite

Copy link
Copy Markdown
Contributor Author

@bors r=lcnr

@rust-bors

rust-bors Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 2b8fa4f has been approved by lcnr

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 5. This pull request will be tested once the tree is reopened.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 24, 2026
@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 24, 2026
@rust-bors

rust-bors Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

⚠️ A new commit 2368b4b70b41e8f35a73bfb329f7847699b39e16 was pushed.

This pull request was unapproved.

@adwinwhite

Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

Copy link
Copy Markdown
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 24, 2026
@rust-bors

rust-bors Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

⌛ Trying commit 2368b4b with merge cc59b8e

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

Workflow: https://github.com/rust-lang/rust/actions/runs/28080269494

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) perf-regression Performance regression. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-perf Status: Waiting on a perf run to be completed. T-clippy Relevant to the Clippy team. 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.

6 participants