Handle recursive TAIT item bounds - #160711
Conversation
|
r? @khyperia rustbot has assigned @khyperia. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
sorry, I'm not quite confident enough with t-types yet to know if this is the right approach or not r? types |
|
I don't know enough about the next solver's opaque type handling yet to review this properly. My gut feeling on reading the diff is that the changes are solving the problem in a very brute force way, which may be the required way, but I'd basically need to debug this from scratch to understand it. Can you explain a bit about how you got to this solution? Just looking at logs and checking where things start going wrong? The fast path should probably be a separate commit and ideally have some (local is fine) benchmarks showing it's necessary at all r? @lcnr |
yeah, I am very worried about adding special cases or different paths to the behavior of the trait solver without a clear reason for why it is necessary and correct. I don't think this issue is particularly important to fix right now as to my knowledge it does not block stabilization and does not cause breakage to stable code in the wild here. You could look into why exactly your PR changes things. I would expect this to be a larger underlying issue related to cyclic reasoning and maybe it should actually not be a productive cycle |
38da246 to
e05f08f
Compare
The SolverRelating change has nothing to do with #288. the eval_ctxt change alone fixes the original reproducer. remaining question is whether preventing this normalization while checking an opaque's own item bounds is the right layer for the fix. |
I personally feel hesitant about something being an "unnecessary cycle". We should generally be free to normalize things whereever we are, so either this cycle should actually be productive, or the cycle does actually matter somewhere. That's what I am unsure about, why exactly this cycle should or should not be accepted. It's hard to explain, but your change to normalization is something that "does not easily fit into a more theoretical model of what Rust is". Explaining what exactly this means is hard, but I want the behavior of the core type system to be as close to the its |
e05f08f to
88d16ec
Compare
This comment has been minimized.
This comment has been minimized.
|
The path that matters here is the one where we are checking the opaque’s own item bounds I don’t think the interesting part here is just overflows and the overflow comes from normalizing the same opaque again while we are already proving its own bounds Bar: PartialEq<(Foo, i32)>if we normalize the recursive Foo inside that obligation we just reenter opaque normalization and create the cycle again and this also lines up with the existing comment in add_item_bounds_for_hidden_type recursive references to the opaque whose item bounds we are currently proving should be preserved because normalizing them may recursively normalize the same opaque while proving its own bounds the broader opaque cycle-semantics question still exists but this case does not seem to need a more general cycle mechanism to make progress |
"keep an alias as rigid even though it can be normalized" also falls under
If you change the |
Yes, this works. Would it make sense to introduce a more specific goal source for the opaque item-bound case instead of making all |
This comment has been minimized.
This comment has been minimized.
88d16ec to
d5791af
Compare
|
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
|
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. |
Fixes rust-lang/trait-system-refactor-initiative#288.
While checking an opaque's item bounds we may legitimately need to normalize the same opaque again and use its provisional hidden type
the actual problem is that re-entering opaque normalization also schedules the same item bounds again and the proof recurses through another copy of obligations that are already part of the current proof and keeps those two things separate which having the opaque equation available and already having its item bounds scheduled in the current proof