trait solver: account for universes from replace_bound_vars#158362
trait solver: account for universes from replace_bound_vars#158362Dnreikronos wants to merge 5 commits into
Conversation
|
rustbot has assigned @JonathanBrouwer. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
r? types |
9cc11df to
697770e
Compare
|
I'm not entirely sure if this is the right fix (I would actually expect that r? @BoxyUwU |
|
yeah, i think you're right that this probably is not the ideal long-term shape. what this pr does is more of a local bound: eager placeholder handling only walks universes the current solver region constraint can actually name. imo that part still makes sense to me. so yeah, idk if i would call this the best fix in the abstract. long term i'd expect us to have a cleaner invariant between created universes and placeholder assumptions, or maybe an explicit set of universes that eager handling should process. but for this pr, i still prefer this local fix over making missing assumptions silently mean ambiguity. if the constraint cannot name the universe, i don't think this pass should care about it. so this still lgtm to me as a short term fix, with the caveat that |
|
Offtopic: what does ltm mean? |
long term. |
|
this in theory makes sense as an optimization but it shouldn't make anything stop ICEing. We should not be entering binders inside of the trait solver without accounting for their assumptions 🤔
the set of universes it should handle is all of them (other than input universes). can you look into where/why we're entering a binder and not inserting assumptions for it |
yeah, you were right. i looked into where the unaccounted binder entry was happening, and it seems like the issue was in the bad path was basically: i changed the patch so eager handling keeps using all non-input universes. instead, when i also added the issue repro as a ui test. with this version it no longer ices and reports the overflow diagnostic instead. pushed this version for you to validate. idk if long-term we want |
| { | ||
| fn replace_bound_vars<T: TypeFoldable<I>>(&mut self, value: T) -> T { | ||
| let old_universes = self.universes.clone(); | ||
| let value = self.ecx.replace_bound_vars(value, &mut self.universes); |
There was a problem hiding this comment.
I think slightly more generally than FindParamInClause, any part of the new solver which calls replace_bound_vars is just wrong under -Zassumptions-on-binders 🤔
I think ideally we would update replace_bound_vars to, when it creates new universes, also insert empty assumptions (and add an associated fixme to fix that in the long term :3)
There was a problem hiding this comment.
yeah, makes sense. i changed this to be less FindParamInClause-specific.
replace_bound_vars now snapshots the universe slots before calling BoundVarReplacer, then inserts Assumptions::empty() for any slot that got materialized. FindParamInClause is back to just calling ecx.replace_bound_vars, so btw this should cover the other new-solver callers of that helper too.
imo this is a better shape than the previous patch. idk if empty assumptions is what we want irl, since replace_bound_vars still does not know enough to compute the real assumptions, so i left a FIXME there as you requested. ltm if you'd rather push this closer to BoundVarReplacer, but i think this is the right small step for this PR.
fyi i also updated the title/description so they no longer talk about limiting eager placeholder handling.
This comment has been minimized.
This comment has been minimized.
ad0815f to
25bd5cc
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. |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Fixes #157840.
The ICE was not really because eager placeholder handling looked at too many universes. Boxy was right: with
-Zassumptions-on-binders, if the new solver creates a placeholder universe, that universe needs an assumptions entry.The bad path is
FindParamInClauseentering a binder throughreplace_bound_vars.BoundVarReplacermaterializes a placeholder universe for the escaping bound vars, but nothing records placeholder assumptions for it. Later eager placeholder handling walks all non-input universes, which imo is the right behavior, andget_placeholder_assumptionshits the missing entry.This moves the empty-assumptions bookkeeping into
EvalCtxt::replace_bound_varsinstead of keeping it local toFindParamInClause. The helper snapshots the universe slots before replacement and insertsAssumptions::empty()for any slot that got filled.There is still a FIXME there because idk that empty assumptions is the final shape irl.
replace_bound_varsdoes not have the param-env context to compute proper assumptions. But for this PR, imo this is the least weird local fix: it keeps the eager pass looking at all non-input universes and fixes the missing bookkeeping where the universe is created.The repro is covered by a UI test. It reports the overflow diagnostic instead of ICEing.