-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Fix hang in where-clause suggestion with predicate_can_apply
#104269
Fix hang in where-clause suggestion with predicate_can_apply
#104269
Conversation
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.
generally this seems fine, but why does this not result in an infinite hang if we manually try to check Vec<[[[?0; 1]; 1]; 1]>: PartialEq<?0>
🤔 something like
#![recursion_limit = "128"]
fn f<B>(x: (B,)) -> Vec<[[[B; 1]; 1]; 1]> {
vec![]
}
fn is_eq<T: PartialEq<B>, B>(_: (B,), _: T) {}
fn main() {
let b = loop {};
is_eq(b, f(b));
}
I actually tested something similar while investigating this issue -- I actually don't know why this doesn't hang but instead quickly reports an error when registered as an obligation during typeck'ing. I'll have to investigate. |
Oh, @lcnr, this is because of this check that the inference context is tainted. rust/compiler/rustc_trait_selection/src/traits/select/mod.rs Lines 1098 to 1103 in 6d651a2
If it's not tainted, we fatally abort on an overflow, but if it is tainted, then we'll keep evaluating a bunch of nonsense predicates leading to the hang. Notice how this code hangs when the commented line is uncommented (which causes infcx to become tainted): fn f() {
// 1i32.cos();
foo::<_>();
}
fn foo<B>() where Vec<[[[B; 1]; 1]; 1]>: PartialEq<B> {}
fn main() {} |
can you still add the example where the infcx is not tainted as a test? It looks like this hang is something we will have to deal with for non-fatal overflow. r=me after that |
3d9097b
to
65b3a30
Compare
@bors r=lcnr |
…se-sugg, r=lcnr Fix hang in where-clause suggestion with `predicate_can_apply` Using `predicate_may_hold` during error reporting causes an evaluation overflow, which (because we use `evaluate_obligation_no_overflow`) then causes the predicate to need to be re-evaluated locally, which results in a hang. ... but since the "add a where clause" suggestion is best-effort, just throw any overflow errors. No need for 100% accuracy. r? `@lcnr` who has been thinking about overflows... Let me know if you want more context about this issue, and as always, feel free to reassign. Fixes rust-lang#104225
@bors r- this needs to be reblessed it seems
|
65b3a30
to
2657358
Compare
This comment has been minimized.
This comment has been minimized.
2657358
to
5e4265f
Compare
This comment has been minimized.
This comment has been minimized.
5e4265f
to
9decfff
Compare
@bors r=lcnr |
Rollup of 6 pull requests Successful merges: - rust-lang#104269 (Fix hang in where-clause suggestion with `predicate_can_apply`) - rust-lang#104286 (copy doc output files by format) - rust-lang#104509 (Use obligation ctxt instead of dyn TraitEngine) - rust-lang#104721 (Remove more `ref` patterns from the compiler) - rust-lang#104744 (rustdoc: give struct fields CSS `display: block`) - rust-lang#104751 (Fix an ICE parsing a malformed attribute.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
☔ The latest upstream changes (presumably #104776) made this pull request unmergeable. Please resolve the merge conflicts. |
Revert rust-lang#104269 (to avoid spurious hang/test failure in CI) Causes hangs/memory overflows in the test suite apparently 😢 Reopens rust-lang#104225 Fixes rust-lang#104957 r? `@lcnr`
Revert rust-lang#104269 (to avoid spurious hang/test failure in CI) Causes hangs/memory overflows in the test suite apparently 😢 Reopens rust-lang#104225 Fixes rust-lang#104957 r? ``@lcnr``
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#104465 (Document more settings for building rustc for Fuchsia) - rust-lang#104951 (Simplify checking for `GeneratorKind::Async`) - rust-lang#104959 (Revert rust-lang#104269 (to avoid spurious hang/test failure in CI)) - rust-lang#104978 (notify the rust-analyzer team on changes to the rust-analyzer subtree) - rust-lang#105010 (Fix documentation of asymptotic complexity for rustc_data_structures::SortedMap) - rust-lang#105016 (Add sentence when rustdoc search is running) - rust-lang#105020 (rustdoc: merge background-image rules in rustdoc-toggle CSS) - rust-lang#105024 (rustdoc: remove `fnname` CSS class that's styled exactly like `fn`) - rust-lang#105027 (Rustdoc-Json: Add tests for linking to foreign variants.) - rust-lang#105038 (Clean up pr 104954) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Using
predicate_may_hold
during error reporting causes an evaluation overflow, which (because we useevaluate_obligation_no_overflow
) then causes the predicate to need to be re-evaluated locally, which results in a hang.... but since the "add a where clause" suggestion is best-effort, just throw any overflow errors. No need for 100% accuracy.
r? @lcnr who has been thinking about overflows... Let me know if you want more context about this issue, and as always, feel free to reassign.
Fixes #104225