-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: Infinite loop while elaborting predicates #20654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| ); | ||
| } | ||
|
|
||
| // FIXME(next-solver): does this test make sense with fast path? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this in accordance with #20422 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d keep this around and add an “expects a panic”. i think queries might be too expensive, but… i’d consider keeping it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding #[should_panic] I just updated the test output, as what was changed is just a single query name 😄
|
|
||
| let interner = DbInterner::new_with(db, Some(krate), None); | ||
| // FIXME: We should use `explicit_predicates_of` here, which hasn't been implemented to | ||
| // rust-analyzer yet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes a regression in the following test, though I think it's not a big deal for now, since having <Self> in type bounds is also reported as dyn-incompatible due to SelfRenferential but we should fix this eventually
| U: Dimension, | ||
| { | ||
| let t: <T as DimMax<U>>::Output = loop {}; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this will blow up your rust-analyzer like in #20504 😨
I feel getting better on minimizing hangs/panics on real world projects 😄
These were actually monstrously large traits like in https://docs.rs/ndarray/0.16.1/ndarray/trait.Dimension.html
davidbarsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving, modulo a nit.
| ); | ||
| } | ||
|
|
||
| // FIXME(next-solver): does this test make sense with fast path? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d keep this around and add an “expects a panic”. i think queries might be too expensive, but… i’d consider keeping it.
6d28a79 to
45e0f30
Compare
|
Merging this with David’s approval — without it, the issue might crop up quite often. I don’t think this should interfere with the ongoing coercion rewrite PR, but if it does, I’ll be ready to revert 😄 |
|
I actually rediscovered this issue from scratch in my coercion work just recently 😅 However, I stopped the merge due to one question - can't we just filter on |
|
That sounds reasonable as more queries means more memory usage 😅 I think if we gonna move this closer to rustc, we might need separated queries as we need more control over recursive lowering but given the current simple implementation, I'll give it a try |
3dd559b to
7cabe02
Compare
7cabe02 to
26b8b79
Compare
ChayimFriedman2
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for nudging you!
|
No worries at all |
|
changelog fixup #20329 |
| .iter() | ||
| .filter(|p| match p.kind().skip_binder() { | ||
| rustc_type_ir::ClauseKind::Trait(tr) => is_self_or_assoc(tr.self_ty()), | ||
| _ => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, that doesn't seem correct? E.g. if we got an AliasRelate we must filter it out if it's not constraining Self, otherwise trouble will happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I just found your comment by now. Yes, seems that I missed it.
To be clear, <T as Trait>::Assoc = Ty should be filtered out conditionally when T is not Self for both explicit_super_predicates_of and explicit_implied_predicates_of, unlike <T as Trait>::Assoc: Ty, which is always filtered out for explicit_super_predicates_of
https://github.com/rust-lang/rust/blob/52618eb338609df44978b0ca4451ab7941fd1c7a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs#L525-L608
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll open a followup for this once I'm back home from work 😅
Fixes #20582
If we gonna normalize projection types related to the above traits, the current implementation endlessly elaborates implied bounds like
<T as DimMax>::Output: Dimensionand we haveDimension: DimMax<<T as DimMax>::Output as DimMax>::Output: DimMax<<<T as DimMax>::Output as DimMax>::Output as DimMax>::Output: DimMax...😵Though this is not the best I can, I partially ported some implementation details from rustc to fix this infinite loop.
I think we should move overall lowering logic closer to that of rustc's, especially for those ones in here:
https://github.com/rust-lang/rust/blob/76c5ed2847cdb26ef2822a3a165d710f6b772217/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
but maybe after migrating remaining things to next-solver.