You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
lazy_normalization_consts breaks unsize coercion in rare cases #78369
We currently look at all substs while we should only look at the generic params which are actually mentioned by the constant.
The correct solution would be to instead walk the AbstractConst in case it exists, but for that we would have to move that to rustc_middle and also need to access the TyCtxt everywhere which seems difficult.
I am currently thinking about moving AbstractConsts directly into ConstKind as the current ConstKind::Unevaluated is really unhelpful when dealing with anonymous constants. That would simplify dealing with them as we can then just treat them pretty much exactly like other projections, 🤔 would be a big change though, so it might make sense allocate some time to discuss this before doing anything stupid here...
I don't think we can remove Unevaluated. There are cases where we can neither build an abstract const nor evaluate it to a concrete constant. And once we have an abstract const, we can't turn that abstract const into a concrete one, so we'd need to keep the information about the uneavluated source around anyway. Can you elaborate on the changes you were thinking about?
I am not too sure how to actually do this yet... probably by adding an optional reference to &'tcx [Node<'tcx>] to Unevaluated 🤔
we might not be able to just evaluate mir_abstract_const eagerly as that can cause query cycles though. I forgot what actually causes the cycles without lazy normalization
At that point you're just talking about caching, so one thing that we could also do is change the Unevaluated variant to be a tuple variant around an UnevaluatedConst which has methods for evaluating or converting to an abstract const, without exposing the internal fields anymore. The evaluation is already cached via the query system, and I think the abstract const building, too? So this would just be an API change to make it less painful to use.
Activity
lcnr commentedon Nov 16, 2020
The issue is here
rust/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Lines 846 to 854 in f5230fb
in combination with
rust/compiler/rustc_middle/src/ty/walk.rs
Line 199 in f5230fb
We currently look at all substs while we should only look at the generic params which are actually mentioned by the constant.
The correct solution would be to instead walk the
AbstractConstin case it exists, but for that we would have to move that torustc_middleand also need to access theTyCtxteverywhere which seems difficult.I am currently thinking about moving
AbstractConsts directly intoConstKindas the currentConstKind::Unevaluatedis really unhelpful when dealing with anonymous constants. That would simplify dealing with them as we can then just treat them pretty much exactly like other projections, 🤔 would be a big change though, so it might make sense allocate some time to discuss this before doing anything stupid here...cc @oli-obk
oli-obk commentedon Nov 16, 2020
I don't think we can remove
Unevaluated. There are cases where we can neither build an abstract const nor evaluate it to a concrete constant. And once we have an abstract const, we can't turn that abstract const into a concrete one, so we'd need to keep the information about the uneavluated source around anyway. Can you elaborate on the changes you were thinking about?lcnr commentedon Nov 16, 2020
I am not too sure how to actually do this yet... probably by adding an optional reference to
&'tcx [Node<'tcx>]toUnevaluated🤔we might not be able to just evaluate
mir_abstract_consteagerly as that can cause query cycles though. I forgot what actually causes the cycles without lazy normalizationoli-obk commentedon Nov 16, 2020
At that point you're just talking about caching, so one thing that we could also do is change the
Unevaluatedvariant to be a tuple variant around anUnevaluatedConstwhich has methods for evaluating or converting to an abstract const, without exposing the internal fields anymore. The evaluation is already cached via the query system, and I think the abstract const building, too? So this would just be an API change to make it less painful to use.lcnr commentedon Nov 11, 2025
will be replaced by MGCA cc @BoxyUwU