Skip to content

Add rigid alias marker#156742

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

Add rigid alias marker#156742
adwinwhite wants to merge 14 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 AliasTy/AliasTerm/UnevaluatedConst.
It's used to skip renormalization of rigid aliases.

The difficulty is that rigid aliases are only valid in their own TypingEnv so we need to treat them as non-rigid when entering another TypingEnv.

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.

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

This comment has been minimized.

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

This comment has been minimized.

@adwinwhite adwinwhite marked this pull request as ready for review June 10, 2026 09:45
@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_sanitizers

cc @rcvalle

Some changes occurred in rustc_ty_utils::consts.rs

cc @BoxyUwU

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

HIR ty lowering was modified

cc @fmease

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

changes to the core type system

cc @lcnr

Some changes occurred to the core trait solver

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

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@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 Jun 10, 2026
ty,
// FIXME(rigid_aliases_marker): types coming out of `item_bounds`
// are marked as non-rigid while the visited ty can be rigid.
ty::set_aliases_to_non_rigid(tcx, ty),

@lcnr lcnr Jun 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

surprising. If args contain something that's rigid, shouldn't it be fine to keep that as rigid?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Relating of AliasTy now checks rigidness. And we have relating in test_type_match::extract_verify_if_eq.

Ah this reminds me that if the args contains rigid aliases, setting them to non-rigid would also cause discrepancy with the type instantiated from item bound.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as in, we relate non-rigid with rigid aliases here?

@lcnr lcnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel like longterm we should have ty::Aliasand ty::RigidAlias as separate variants on both Ty and Const as most code should only ever encounter one of them 🤔

would like to chat about this, but don't necessarily think it has to happen in this PR

View changes since this review

@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: ac2cd6c (ac2cd6c6bd6112f8ff087927638338b0d77a2756, parent: d56483a91d6cf5041351a3208b8d08f98f0c8b56)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (ac2cd6c): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.6% [0.1%, 1.3%] 32
Regressions ❌
(secondary)
0.5% [0.1%, 2.1%] 35
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.1% [-21.7%, -0.0%] 23
All ❌✅ (primary) 0.6% [0.1%, 1.3%] 32

Max RSS (memory usage)

Results (primary -0.3%, secondary 0.3%)

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

mean range count
Regressions ❌
(primary)
2.7% [2.5%, 2.8%] 2
Regressions ❌
(secondary)
4.3% [0.6%, 15.6%] 5
Improvements ✅
(primary)
-2.3% [-2.6%, -2.0%] 3
Improvements ✅
(secondary)
-2.9% [-7.2%, -1.0%] 6
All ❌✅ (primary) -0.3% [-2.6%, 2.8%] 5

Cycles

Results (secondary -8.8%)

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.7% [2.7%, 2.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-9.8% [-21.2%, -2.5%] 11
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.0%, secondary 0.0%)

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%] 24
Regressions ❌
(secondary)
0.1% [0.0%, 0.4%] 23
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 48
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.0%] 27
All ❌✅ (primary) -0.0% [-0.2%, 0.0%] 72

Bootstrap: 525.47s -> 527.211s (0.33%)
Artifact size: 400.80 MiB -> 401.22 MiB (0.11%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 10, 2026
@rust-log-analyzer

This comment has been minimized.

@adwinwhite adwinwhite changed the title [Experiment] Add rigid alias marker Add rigid alias marker Jun 11, 2026

@lcnr lcnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there are a few eager normalization changes in your PR which probably don't have to be here 🤔

I would really like to change the matches on ty::Alias which treat the alias as potentially normalizeable to explicitly check for "is_rigid" themselves. I dislike the way e.g. the normalization visitors currently just match on ty::Alias. For future PR

while there are a few things I kinda dislike about this PR as is, it is a large change and we can clean them up afterwards

View changes since this review

ty,
// FIXME(rigid_aliases_marker): types coming out of `item_bounds`
// are marked as non-rigid while the visited ty can be rigid.
ty::set_aliases_to_non_rigid(tcx, ty),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as in, we relate non-rigid with rigid aliases here?

}

/// Return whether we should consider the current place as a drop guard and skip reporting.
fn maybe_drop_guard<'tcx>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm, why does liveness use PostAnalysis at all?

It is running on mir_promoted and should just use the typing mode of its MIR body 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No idea, but it does use PostAnalysis 😢

Comment on lines +238 to +241
// FIXME(rigid_aliases_marker): ideally we set aliases to non_rigid right after
// the typing mode is set to `PostAnalysis`.
// But modifying local decls in MIR body is inconvenient. And we can't fold
// `PlaceRef` in `checked_places`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// FIXME(rigid_aliases_marker): ideally we set aliases to non_rigid right after
// the typing mode is set to `PostAnalysis`.
// But modifying local decls in MIR body is inconvenient. And we can't fold
// `PlaceRef` in `checked_places`.
// FIXME(rigid_aliases_marker): Liveness uses `TypingMode::PostAnalysis`
// even though its run on `mir_promoted` which is still
// in an earlier `TypingMode`. This is odd and we have to
// manually mark aliases as non-rigid here.

I think we just shouldn't use PostAnalysis here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can try with a different typing mode, perhaps PostBorrowckAnalysis? and we then don't need to change rigidness manually here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think changing rigidness and keeping this FIXME is fine. Should look into this in a separate PR though :>

{
if let Ok(c) = self.tcx.try_normalize_erasing_regions(
self.typing_env,
Unnormalized::new_wip(ty::set_aliases_to_non_rigid(self.tcx, constant.const_)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should set_aliases_to_non_rigid just return Unnormalized?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It could, but Unnormalized is kinda unwieldy as noted in its cons?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah, I think it results in a nicer temporary state to do this I think

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would prefer that I think

pub fn eager_resolve_vars_with_infcx<Infcx: InferCtxtLike, T: TypeFoldable<Infcx::Interner>>(
delegate: &Infcx,
value: T,
) -> T {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need both of these or could we just change the signature of eager_resolve_vars and that's good enough

"directory into which to write optimization remarks (if not specified, they will be \
written to standard error output)"),
renormalize_rigid_aliases: bool = (false, parse_bool, [TRACKED],
"do not skip rigid aliases in normalization"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"do not skip rigid aliases in normalization"),
"do not skip rigid aliases in normalization for internal debugging"),

Comment on lines +2805 to +2806
// FIXME: why don't we also instantiate const and region params with infer vars
// here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that fixme shouldn't be on the Alias branch 🤣

the reason we don't is "diagnostics code isn't soundness critical, wildly out of date, and poorly tested" 😁

Comment on lines +558 to +559
// FIXME: This can't handle `AliasTerm`. Unsure if this is a problem in practice.
// We can't assert about `AliasTerm` as well since it doesn't affect type flags.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that seems fine to me 😁

if you have an AliasTerm you should already know whether to treat it as rigid or not 😁


// Alias tend to mostly already be handled downstream due to normalization.
(ty::Alias(a), ty::Alias(b)) => {
(ty::Alias(a), ty::Alias(b)) if a.is_rigid == b.is_rigid => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

still relevant? 🤔

@adwinwhite

adwinwhite commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

I just saw the latest review comments right now. Will try to resolve them tomorrow.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-llvm-21 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- [mir-opt] tests/mir-opt/issue_99325.rs stdout ----
2 
3 | User Type Annotations
4 | 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
- | 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. }], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
+ | 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], is_rigid: No, .. }], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
6 |
7 fn main() -> () {
8     let mut _0: ();


thread '[mir-opt] tests/mir-opt/issue_99325.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:73:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/issue_99325.main.built.after.32bit.mir
stack backtrace:
   5: __rustc::rust_begin_unwind
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/panicking.rs:689:5
   6: core::panicking::panic_fmt
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/core/src/panicking.rs:80:14

@rust-bors

rust-bors Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #157794) made this pull request unmergeable. Please resolve the merge conflicts.

@lcnr lcnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just realized. SolverRelating should not emit alias relate goals if the aliases are rigid but instead just relate them structurally 🤔

View changes since this review

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-review Status: Awaiting review from the assignee but also interested parties. 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.

5 participants