Skip to content
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

Merged
merged 3 commits into from
Nov 23, 2022

Conversation

compiler-errors
Copy link
Member

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 #104225

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 11, 2022
Copy link
Contributor

@lcnr lcnr left a 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));
}

@compiler-errors
Copy link
Member Author

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.

@compiler-errors
Copy link
Member Author

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>

Oh, @lcnr, this is because of this check that the inference context is tainted.

if self.infcx.is_tainted_by_errors() {
return Err(OverflowError::Error(
ErrorGuaranteed::unchecked_claim_error_was_emitted(),
));
}
self.infcx.err_ctxt().report_overflow_error(error_obligation, true);

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() {}

@lcnr
Copy link
Contributor

lcnr commented Nov 16, 2022

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

@compiler-errors compiler-errors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 18, 2022
@compiler-errors compiler-errors force-pushed the hang-in-where-clause-sugg branch 2 times, most recently from 3d9097b to 65b3a30 Compare November 18, 2022 18:02
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Nov 18, 2022

📌 Commit 65b3a30 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 18, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 21, 2022
…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
@matthiaskrgr
Copy link
Member

@bors r- this needs to be reblessed it seems
#104671

ailures:

---- [ui] src/test/ui/typeck/hang-in-overflow.rs stdout ----
diff of stderr:

8	   = note: required for `...` to implement `...`
9	   = note: 127 redundant requirements hidden
10	   = note: required for `...` to implement `...`
+	   = note: the full type name has been written to '$TEST_BUILD_DIR/typeck/hang-in-overflow/hang-in-overflow.long-type-13273308321832961787.txt'
11	note: required by a bound in `foo`
12	  --> $DIR/hang-in-overflow.rs:14:28
13	   |


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/typeck/hang-in-overflow/hang-in-overflow.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args typeck/hang-in-overflow.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/typeck/hang-in-overflow.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/typeck/hang-in-overflow" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/typeck/hang-in-overflow/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0275]: overflow evaluating the requirement `&&[&&mut [&&[&[&_]]; _]]: PartialEq<&_>`
  --> /checkout/src/test/ui/typeck/hang-in-overflow.rs:8:5
   |
LL |     foo::<_>();
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
   |     ^^^^^^^^
   |
   = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`hang_in_overflow`)
   = note: required for `[&&[&&mut [&&[&[&_]]; _]]]` to implement `PartialEq<[&_]>`
   = note: 127 redundant requirements hidden
   = note: required for `Vec<[[[&[...; _]; 1]; 1]; 1]>` to implement `PartialEq<&[&mut [&mut [&mut [&&mut [&[&[&[&&[&[&[&[&[&[&[&[&&mut [&[&[[&&[&[&[&mut [&&[&[&[&mut [&&[&[&[&&mut [&&[&[&&mut [&&[&&[&[&&[&&[&&[&[&[&&[&&[&[&&mut [&[&&[&[&&[&&mut [&&[&[&&[&&mut [&&[&[&_]]; _]]]]]]]]; _]]]]]; _]]]]]]]]]]]]; _]]]; _]]]]]]]]; _]]]]]]]; _]]]]]]]]]]]]; _]>`
   = note: the full type name has been written to '/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/typeck/hang-in-overflow/hang-in-overflow.long-type-13273308321832961787.txt'
note: required by a bound in `foo`
  --> /checkout/src/test/ui/typeck/hang-in-overflow.rs:14:28
   |
LL | fn foo<B>()
   |    --- required by a bound in this
LL | where
LL |     Vec<[[[B; 1]; 1]; 1]>: PartialEq<B>,
   |                            ^^^^^^^^^^^^ required by this bound in `foo`

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 21, 2022
@compiler-errors compiler-errors force-pushed the hang-in-where-clause-sugg branch from 65b3a30 to 2657358 Compare November 23, 2022 04:49
@rust-log-analyzer

This comment has been minimized.

@compiler-errors compiler-errors force-pushed the hang-in-where-clause-sugg branch from 2657358 to 5e4265f Compare November 23, 2022 05:18
@rust-log-analyzer

This comment has been minimized.

@compiler-errors compiler-errors force-pushed the hang-in-where-clause-sugg branch from 5e4265f to 9decfff Compare November 23, 2022 05:36
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Nov 23, 2022

📌 Commit 9decfff has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 23, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2022
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
@bors bors merged commit bd91c94 into rust-lang:master Nov 23, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 23, 2022
@bors
Copy link
Contributor

bors commented Nov 23, 2022

☔ The latest upstream changes (presumably #104776) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 23, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 28, 2022
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`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 29, 2022
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``
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 29, 2022
…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
@compiler-errors compiler-errors deleted the hang-in-where-clause-sugg branch August 11, 2023 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hang with weird trait requirement
6 participants