Skip to content

Hang with weird trait requirement #104225

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
jruderman opened this issue Nov 10, 2022 · 4 comments · Fixed by #104269
Open

Hang with weird trait requirement #104225

jruderman opened this issue Nov 10, 2022 · 4 comments · Fixed by #104269
Assignees
Labels
C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

Found with a modified fuzz-rustc.

Code

This input effectively hangs the compiler during item_types_checking / trait selection.

fn f<B>(x: Vec<[[[B; 1]; 1]; 1]>) -> impl PartialEq<B> {
    x
}

fn main() {}

Time complexity

The time spent increases exponentially(?) with the complexity of type x and with the recursion_limit setting.

Setting Time to reject
#![recursion_limit = "16"] 0.6 sec
#![recursion_limit = "32"] 3.5 sec
#![recursion_limit = "48"] 107 sec
#![recursion_limit = "128"] (default) Impatience prevailed

Regression

Regression in nightly-2022-05-28, from #96046. At the same time, the error message changed from E0275 to E0277.

Error before 2022-05-28

E0275: An evaluation of a trait requirement overflowed

error[E0275]: overflow evaluating the requirement `[&&[Vec<&&[&&[_]], _>]]: PartialEq<[_]>`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "96"]` attribute to your crate (`main`)
  = note: required because of the requirements on the impl of `PartialEq<&[_]>` for `&[&&[Vec<&&[&&[_]], _>]]`
  = note: 47 redundant requirements hidden
  = note: required because of the requirements on the impl of `PartialEq<Vec<&[&[&[Vec<&[&[&[Vec<&[&[&&[Vec<&[&[&&[Vec<&[&&[&&[Vec<&[&&[&&[Vec<&&[&&[_]], _>]]; _], _>]]], _>]; _]], _>]]], _>; _]]], _>]]], _>>` for `Vec<[[[Vec<&[&[&[Vec<&[&[&[Vec<&[&[&&[Vec<&[&[&&[Vec<&[&&[&&[Vec<&[&&[&&[Vec<&&[&&[_]], _>]]; _], _>]]], _>]; _]], _>]]], _>; _]]], _>]]], _>; 1]; 1]; 1]>`
Current error

E0277: trait requirement not satisfied

error[E0277]: can't compare `Vec<[[[B; 1]; 1]; 1]>` with `B`
 --> input.rs:3:38
  |
3 | fn f<B>(x: Vec<[[[B; 1]; 1]; 1]>) -> impl PartialEq<B> {
  |                                      ^^^^^^^^^^^^^^^^^ no implementation for `Vec<[[[B; 1]; 1]; 1]> == B`
4 |     x
  |     - return type was inferred to be `Vec<[[[B; 1]; 1]; 1]>` here
  |
  = help: the trait `PartialEq<B>` is not implemented for `Vec<[[[B; 1]; 1]; 1]>`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
  |
3 | fn f<B>(x: Vec<[[[B; 1]; 1]; 1]>) -> impl PartialEq<B> where Vec<[[[B; 1]; 1]; 1]>: PartialEq<B> {
  |                                                        +++++++++++++++++++++++++++++++++++++++++

Version

rustc --version --verbose:

rustc 1.67.0-nightly (85f4f41de 2022-11-08)
binary: rustc
commit-hash: 85f4f41deb1557ca8ab228319d33003dd2f20f45
commit-date: 2022-11-08
host: x86_64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4

@rustbot label +I-compiletime +I-hang

@jruderman jruderman added the C-bug Category: This is a bug. label Nov 10, 2022
@rustbot rustbot added I-compiletime Issue: Problems and improvements with respect to compile times. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. labels Nov 10, 2022
@estebank
Copy link
Contributor

cc @compiler-errors I believe this might related to what you were looking at recently

@estebank estebank added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 11, 2022
@compiler-errors
Copy link
Member

Hm, don't think so? This doesn't have to with opaques that have higher-ranked (lifetime) vars in their substs.

@estebank
Copy link
Contributor

Ah! Fair enough, I misremembered what you were working on :)

@compiler-errors
Copy link
Member

compiler-errors commented Nov 11, 2022

This doesn't even have to do with impl Trait -- requiring the bound Vec<[[[B; 1]; 1]; 1]>: PartialEq<B> anywhere causes the hanging, e.g.:

#![recursion_limit = "48"]

fn f<B>(x: Vec<[[[B; 1]; 1]; 1]>) {
    is_eq::<_, B>(x);
}

fn is_eq<T: PartialEq<B>, B>(_: T) {}

fn main() {}

I'll look into it regardless.

@compiler-errors compiler-errors self-assigned this Nov 11, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue 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
@bors bors closed this as completed in bd91c94 Nov 23, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue 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 issue 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``
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants