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

Compiler (effectively) hangs, regression from overflow error #93774

Open
steffahn opened this issue Feb 8, 2022 · 4 comments
Open

Compiler (effectively) hangs, regression from overflow error #93774

steffahn opened this issue Feb 8, 2022 · 4 comments
Labels
A-lifetimes Area: lifetime related A-traits Area: Trait system C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. P-high High priority perf-regression Performance regression. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@steffahn
Copy link
Member

steffahn commented Feb 8, 2022

pub enum Either<L, R> {
    Left(L),
    Right(R),
}

pub trait HasItem<'a, _Constraint = &'a Self> {
    type Item;
}

pub type Item<'a, Self_> = <Self_ as HasItem<'a>>::Item;

pub trait LendingIterator: for<'a> HasItem<'a> {
    fn next(&mut self) -> Option<Item<'_, Self>>;
}

impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
where A: LendingIterator, B: LendingIterator,
 for<'b> B: HasItem<'b, Item = Item<'b, Self>>
{
    type Item = Item<'a, Self>;
}

impl<A, B> LendingIterator for Either<A, B>
where A: LendingIterator, B: LendingIterator,
 for<'b> B: HasItem<'b, Item = Item<'b, Self>>
{
    fn next(&mut self) -> Option<Item<'_, Self>> {
        match self {
            Either::Left(iter) => iter.next(),
            Either::Right(iter) => iter.next(),
        }
    }
}

hangs since 1.56
error on 1.55

error[E0275]: overflow evaluating the requirement `for<'b> <B as HasItem<'b>>::Item == <Either<A, B> as HasItem<'b>>::Item`
  --> <source>:16:24
   |
6  | pub trait HasItem<'a, _Constraint = &'a Self> {
   | --------------------------------------------- required by this bound in `HasItem`
...
16 | impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
   |                        ^^^^^^^^^^^
   |
note: required because of the requirements on the impl of `HasItem<'a>` for `Either<A, B>`
  --> <source>:16:24
   |
16 | impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
   |                        ^^^^^^^^^^^     ^^^^^^^^^^^^

error[E0275]: overflow evaluating the requirement `for<'b> <B as HasItem<'b>>::Item == <Either<A, B> as HasItem<'b>>::Item`
  --> <source>:23:12
   |
12 | pub trait LendingIterator: for<'a> HasItem<'a> {
   |                            ------------------- required by this bound in `LendingIterator`
...
23 | impl<A, B> LendingIterator for Either<A, B>
   |            ^^^^^^^^^^^^^^^
   |
note: required because of the requirements on the impl of `for<'a> HasItem<'a>` for `Either<A, B>`
  --> <source>:16:24
   |
16 | impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
   |                        ^^^^^^^^^^^     ^^^^^^^^^^^^

error[E0275]: overflow evaluating the requirement `for<'b> <B as HasItem<'b>>::Item == <Either<A, B> as HasItem<'b>>::Item`
  --> <source>:20:5
   |
20 |     type Item = Item<'a, Self>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: required because of the requirements on the impl of `HasItem<'a>` for `Either<A, B>`
  --> <source>:16:24
   |
16 | impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
   |                        ^^^^^^^^^^^     ^^^^^^^^^^^^

error[E0275]: overflow evaluating the requirement `for<'b> <B as HasItem<'b>>::Item == <Either<A, B> as HasItem<'b>>::Item`
  --> <source>:27:8
   |
27 |     fn next(&mut self) -> Option<Item<'_, Self>> {
   |        ^^^^
   |
note: required because of the requirements on the impl of `HasItem<'_>` for `Either<A, B>`
  --> <source>:16:24
   |
16 | impl<'a, A: 'a, B: 'a> HasItem<'a> for Either<A, B>
   |                        ^^^^^^^^^^^     ^^^^^^^^^^^^

error: aborting due to 4 previous errors

@rustbot label I-hang, regression-from-stable-to-stable, A-traits, A-lifetimes, E-needs-bisection, T-compiler


Edit:

“Hangs” means “runs for a wile on 100% CPU until I cancel it”. Who knows if it would ever terminate… actually, maybe I should test smaller recursion limits.

Note that this code example is not expected to compile successfully. Here’s a version that works / with the mistakes fixed. (The fixed version also works on some older Rust versions, including 1.55 and older.)


Edit2: Using smaller limits (like… around #![recursion_limit = "14"] it starts getting unbearably slow) reveals that this is apparently more like exponential-time slowdown rather than “actual” hanging.

@rustbot label -I-hang, +I-compiletime, +perf-regression

@steffahn steffahn added the C-bug Category: This is a bug. label Feb 8, 2022
@rustbot rustbot added A-lifetimes Area: lifetime related A-traits Area: Trait system E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 8, 2022
@steffahn steffahn changed the title Compiler hangs, regression from overflow error Compiler (effectively) hangs, regression from overflow error Feb 8, 2022
@rustbot rustbot added I-compiletime Issue: Problems and improvements with respect to compile times. perf-regression Performance regression. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. and removed I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. labels Feb 8, 2022
@apiraino
Copy link
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 10, 2022
@Badel2
Copy link
Contributor

Badel2 commented Feb 11, 2022

Run a bisect on this, 8d7707f is the first bad commit.

cargo-bisect-rustc was only able to narrow it down to nightly-2021-08-26, but I checked the remaining range using git bisect.

@steffahn
Copy link
Member Author

Let me remove the bisection label and mention the relevant PR #85499 (cc @jackh726)

@rustbot label -E-needs-bisection

@rustbot rustbot removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Aug 16, 2022
@pnkfelix
Copy link
Member

Discussed in T-compiler P-high review

Reassigning to T-types to determine what to do, if anything, in response to this.

@rustbot label -T-compiler +T-types

@rustbot rustbot added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: lifetime related A-traits Area: Trait system C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. P-high High priority perf-regression Performance regression. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants