trait_selection: fix type-const eval ICE#152040
trait_selection: fix type-const eval ICE#152040JohnTitor wants to merge 2 commits intorust-lang:mainfrom
Conversation
|
|
| if !type_const_stack.insert(uv.def) { | ||
| let guar = tcx.dcx().span_err( | ||
| tcx.def_span(uv.def), | ||
| "cycle detected when evaluating type-level constant", |
There was a problem hiding this comment.
I'm not sure if we should detect a cyclic error in this place though, maybe we can handle it better?
There was a problem hiding this comment.
I'm don't know how/where/when we invoke try_evaluate_const (during normalization of course, but …) but ideally (?) either the query system would detect cycles / overflows for us (but I guess no queries are involved here) or we have a simple depth param similar to what type normalization does instead of storing visited definitions. idk, imma wait for Boxy
|
Does this code compiles under your impl? |
3fc70e5 to
e853189
Compare
This comment has been minimized.
This comment has been minimized.
|
@Human9000-bit Yeah, it should. Added a rev so that we can make sure it. |
This comment has been minimized.
This comment has been minimized.
| } | ||
| }; | ||
|
|
||
| if tcx.is_type_const(uv.def) { |
There was a problem hiding this comment.
I don't know if this change makes sense, I'm not an expert in mGCA. Therefore I'll assign @BoxyUwU instead.
| trait Owner { | ||
| #[type_const] | ||
| const C<const N: u32>: u32; | ||
| //~^ ERROR cycle detected when evaluating type-level constant |
There was a problem hiding this comment.
Ideally this error would point to the C in the trait impl.
| if !type_const_stack.insert(uv.def) { | ||
| let guar = tcx.dcx().span_err( | ||
| tcx.def_span(uv.def), | ||
| "cycle detected when evaluating type-level constant", |
There was a problem hiding this comment.
I'm don't know how/where/when we invoke try_evaluate_const (during normalization of course, but …) but ideally (?) either the query system would detect cycles / overflows for us (but I guess no queries are involved here) or we have a simple depth param similar to what type normalization does instead of storing visited definitions. idk, imma wait for Boxy
e853189 to
1641602
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. |
| } | ||
| }; | ||
|
|
||
| if tcx.is_type_const(uv.def) { |
There was a problem hiding this comment.
We're not supposed to be calling try_evaluate_const on a type const in the first place 🤔 Whatever code is causing this to be reachable is the problematic place.
Can you look into that a bit and then explain to me what's going on there?
There was a problem hiding this comment.
I see!
Can you look into that a bit and then explain to me what's going on there?
IIUC:
- we generate
ConstEvaluatableobligation inconst_evaluatable_predicates_of, including type consts. - the next solver handles that in
compute_const_evaluatable_goalby callingdelegate.evaluate_const, which forwards totry_evaluate_const.
Do you have any idea for proper fix?
There was a problem hiding this comment.
Ah interesting, follow up question: Where does the ConstEvaluatable obligation come from? I'm not sure why const_evaluatable_predicates_of would be returning anything here
There was a problem hiding this comment.
Sorry, I misunderstood.
WfPredicates::visit_const emits ClauseKind::ConstEvaluatable(c) for ConstKind::Unevaluated:
rust/compiler/rustc_trait_selection/src/traits/wf.rs
Lines 1019 to 1021 in fbd6934
There, IIUC we don't have a check for type const.
And delegate calls unnormalized_obligations:
This place should register ConstEvaluatable obligations as goals (right? sorry if I'm wrong).
Then compute_const_evaluatable_goal calls evaluate_const -> try_evaluate_const
|
@rustbot author |
Fixes #151631, fixes #151477
r? @fmease
I'd recommend reviewing commit-by-commit, the diff is less-readable to address a cyclic issue.