[Experiment] Add rigid alias marker#156742
Conversation
|
Unfinished. Let's have a look at the perf impact nonetheless. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
[Experiment] Add rigid alias marker
This comment has been minimized.
This comment has been minimized.
|
💔 Test for 73eccb5 failed: CI. Failed job:
|
This comment has been minimized.
This comment has been minimized.
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
[Experiment] Add rigid alias marker
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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 @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
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.
CyclesResults (primary 2.5%, secondary 17.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 510.83s -> 514.725s (0.76%) |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
[Experiment] Add rigid alias marker
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (9ad2ace): 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 @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.2%, secondary -4.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.6%, secondary -4.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.1%, secondary 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 513.065s -> 515.25s (0.43%) |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
[Experiment] Add rigid alias marker
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
I am slightly unhappy about the way you currently handle instantiate_identity 🤔
The easiest solution for now would be for EarlyBinder::new to replace all rigid aliases with non rigid ones 🤔 while that does cause us to sometimes renormalize aliases even though that shouldn't be necessary, I expect that to be rather rare and wouldn't worry about that unless for now?
| INSTANTIATE_RHS_WITH_INFER, | ||
| >; | ||
| pub type DeepRejectCtxt<'tcx, const HANDLE_LHS: u8, const HANDLE_RHS: u8> = | ||
| rustc_type_ir::fast_reject::DeepRejectCtxt<TyCtxt<'tcx>, HANDLE_LHS, HANDLE_RHS>; |
There was a problem hiding this comment.
surprising change 🤔 I feel like this should be unnecessary if we now use rigid aliases instead
There was a problem hiding this comment.
This is from your commit? Or u clicked the wrong lines?
| && alias.is_rigid == ty::IsRigid::Yes | ||
| && !(ty.has_opaque_types() | ||
| && matches!(self.infcx.typing_mode_raw(), TypingMode::PostAnalysis)) |
There was a problem hiding this comment.
so the way you currently handle TypingEnv changes is by never treating affected things as rigid in post analysis?
This is unfortunately insufficient 🤔 imagine having the where-clauses T: Trait<u32> and T: Trait<TaitNotInDefiningScope, Assoc = u32>. With this <T as Trait<u32>>::Assoc is now rigid during analysis, but if we TaitNotInDefiningScope is defined to u32 we can now normalize it to u32 at this point.
I don't know expect this to ever cause problems in practice, do feel like it is quite brittle though and would prefer to not have to even consider that as a theoretical concern
There was a problem hiding this comment.
Great example. Never thought that opaques in param env can affect other rigid aliases indirectly.
Items with where-clauses T: Trait<u32> and T: Trait<TaitNotInDefiningScope> are unusable as the coherence check is bound to fail if we have the two required impls.
I don't know how to detect all typing mode changes and be defensive about them 🤔.
It seems the opaque_types && PostAnalysis check is unnecessary if we handle EarlyBinder well.
MIR instantiation will go through EarlyBinder. Another notable typing mode change is layout_of.
I didn't find other places that leak rigid opaques into PostAnalysis, by turning the check into an assert. Though the assert can't detect your example.
| // FIXME: how to best detect rigid? Follow `compute_alias_relate` for now. | ||
| // Can we have infer vars in rigid aliases? | ||
| if let ty::Alias(alias_ty) = normalized_ty.kind() { | ||
| I::Ty::new_alias(self.cx(), alias_ty.to_rigid()) | ||
| } else { | ||
| normalized_ty | ||
| } |
There was a problem hiding this comment.
I would expect the only place to create rigid aliases to be NormalizesTo. More specifically, all uses of structurally_instantiate_normalizes_to_term
rust/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs
Lines 108 to 112 in b7e97a9
| } else { | ||
| None | ||
| } | ||
| } |
There was a problem hiding this comment.
this feels like sth we could/definitely should split out into a separate PR?
It is unfortunately also not correct for AliasRelate as you could have <T as Trait<?normalizing_the_lhs_constrains_this>>::Assoc eq <?normalizing_the_lhs_constrains_this as Whatever>::Assoc`.
I think we rigid aliases we don't need alias relate anymore. When type relations encounter non-rigid aliases, they can replace the alias with an infer var, add a nested Projection goal and then just continue to recur with that infer var instead
| ty::Alias(alias_ty) if alias_ty.is_rigid == ty::IsRigid::Yes => { | ||
| let alias_ty = alias_ty.fold_with(self); | ||
| I::Ty::new_alias(self.cx(), alias_ty.to_non_rigid()) | ||
| } |
There was a problem hiding this comment.
instantiate also needs to make aliases non-rigid even if tehy don't contain any params. The !t.has_param fast path also needs to check for rigid aliases so that we replace all of them.
Otherwise instantiating some_opaque in a typing env that can define some_opaque incorrectly treats it as rigid
|
Finished benchmarking commit (65383a4): 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 @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.6%, secondary -4.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 3.7%, secondary -4.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 511.751s -> 516.392s (0.91%) |
This comment has been minimized.
This comment has been minimized.
This is not easy for several reasons:
In the alternative approach where we replace all rigid aliases with non-rigid in |
View all comments
still WIP but push before leaving the computer.
r? lcnr