Prove nested goals before const evaluation - #160466
Conversation
This comment has been minimized.
This comment has been minimized.
Const evaluation instantiates the item's body with its arguments, so an argument whose type does not match its parameter produced ill-formed MIR and ICEd the interpreter instead of the ConstArgHasType goal reporting the mismatch.
cb9b162 to
942fe2a
Compare
|
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. |
|
This feels like a weaker form of what @BoxyUwU has been planning long term where we only evaluate constants with fully concrete arguments whose where-clauses hold in an empty environment. I also think mapping errors to anything but an error is very weird and we generally shouldn't change trait solver semantics for the sake of diagnostics. Would you be up to start a conversation about this PR in https://rust-lang.zulipchat.com/#narrow/channel/260443-project-const-generics @rustbot author r? BoxyUwU |
|
Reminder, once the PR becomes ready for a review, use |
|
|
|
Fair enough. Opened #project-const-generics > gating const evaluation on where-clauses (#156780) @ 💬. I'll mark this as draft for now. |
Fixes #156780.
Tracking issue: #132980.
evaluate_const_and_instantiate_projection_termhanded the constant to CTFE before proving the nested goals already registered for it. Evaluation instantiates the item's body with its arguments, so an argument whose type does not match its parameter produced ill-formed MIR and ICEd the interpreter instead of theConstArgHasTypegoal reporting the mismatch.const IGNORE<const N: usize>: usize = 0;reports the mismatch today because its body never readsN.const ADD1<const N: usize>: usize = N + 1;ICEs.This is not specific to literals.
const F: f64 = 1.0;withADD1::<F>ICEs the same way, so checking the literal during lowering, as #156944 attempted, would not have covered it.I'm not completely sure about the call to
self.inspect.make_canonical_response.evaluate_added_goals_and_make_canonical_responserecords the response before evaluating nested goals so a failure still leaves an attributable proof tree. Without it every case reports:This adds a
try_evaluate_added_goalscall before each const evaluated during normalization. The tailevaluate_added_goals_and_make_canonical_responsecalls it again, so goals which come back ambiguous are evaluated twice.r? @lcnr