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

circular set of associated types cause cargo build to hang #123448

Closed
martinjrobins opened this issue Apr 4, 2024 · 3 comments · Fixed by #123471
Closed

circular set of associated types cause cargo build to hang #123448

martinjrobins opened this issue Apr 4, 2024 · 3 comments · Fixed by #123471
Labels
A-traits Area: Trait system C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@martinjrobins
Copy link

I have a linear algebra based project (https://github.com/martinjrobins/diffsol) which has a set of Scalar, Vector and Matrix traits that refer to each other via associated traits. On stable (rustc 1.77.1) this builds fine, but on beta (1.78.0) and nightly (1.79.0) the build hangs (martinjrobins/diffsol#3). A MRE is:

use std::ops::{Add, Sub};

pub trait Scalar {}

pub trait VectorCommon: Sized {
    type T: Scalar;
}

pub trait VectorOpsByValue<Rhs = Self, Output = Self>:
    VectorCommon + Add<Rhs, Output = Output> + Sub<Rhs, Output = Output>
{
}

pub trait VectorView<'a>:
    VectorOpsByValue<Self, Self::Owned> + VectorOpsByValue<Self::Owned, Self::Owned>
{
    type Owned;
}

pub trait Vector: VectorOpsByValue<Self> + for<'a> VectorOpsByValue<Self::View<'a>> {
    type View<'a>: VectorView<'a, T = Self::T, Owned = Self>
    where
        Self: 'a;
}

pub trait MatrixCommon {
    type V: Vector;
}

If I look at the compiler log with RUSTC_LOG=TRACE I see an endless repitition of text like:

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=128, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?127], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) })], def_id: DefId(2:3151 ~ core[191c]::ops::arith::Sub::Output) }

rustc_trait_selection::traits::project::project obligation=Obligation(predicate=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?127], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) }, depth=128)

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=129, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?128], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) })], def_id: DefId(2:3151 ~ core[191c]::ops::arith::Sub::Output) }

Note that if I remove the MatrixCommon trait everything builds fine.

Meta

The bug does not exist in stable:
rustup run stable rustc --version:

rustc 1.77.1 (7cf61ebde 2024-03-27)

The bug exists in beta and nightly:
rustup run beta rustc --version:

rustc 1.78.0-beta.4 (c1195518c 2024-03-29)

rustup run nightly rustc --version:

rustc 1.79.0-nightly (1684a753d 2024-04-01)
Backtrace

here is some more of the logs:

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=129, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), true], def_id: DefId(2:3146 ~ core[191c]::ops::arith::Add::Output) }

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=129, value=<<Self as MatrixCommon>::V as Vector>

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=128, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) })], def_id: DefId(2:3151 ~ core[191c]::ops::arith::Sub::Output) }

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=128, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), true], def_id: DefId(2:3146 ~ core[191c]::ops::arith::Add::Output) }

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=128, value=<<Self as MatrixCommon>::V as Vector>

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=127, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?126], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) }), true], def_id: DefId(2:3146 ~ core[191c]::ops::arith::Add::Output) }

rustc_trait_selection::traits::project::project obligation=Obligation(predicate=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?126], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) }, depth=127)

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=128, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?127], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) })], def_id: DefId(2:3151 ~ core[191c]::ops::arith::Sub::Output) }

rustc_trait_selection::traits::project::project obligation=Obligation(predicate=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?127], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) }, depth=128)

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=129, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?128], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) })], def_id: DefId(2:3151 ~ core[191c]::ops::arith::Sub::Output) }

rustc_trait_selection::traits::project::project obligation=Obligation(predicate=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?128], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) }, depth=129)

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=129, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?128], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) }), true], def_id: DefId(2:3146 ~ core[191c]::ops::arith::Add::Output) }

rustc_trait_selection::traits::project::project obligation=Obligation(predicate=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?128], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) }, depth=129)

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=129, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) })], def_id: DefId(2:3151 ~ core[191c]::ops::arith::Sub::Output) }

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=129, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), true], def_id: DefId(2:3146 ~ core[191c]::ops::arith::Add::Output) }

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=129, value=<<Self as MatrixCommon>::V as Vector>

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=128, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?127], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) }), true], def_id: DefId(2:3146 ~ core[191c]::ops::arith::Add::Output) }

rustc_trait_selection::traits::project::project obligation=Obligation(predicate=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?127], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) }, depth=128)

rustc_trait_selection::traits::normalize::normalize_with_depth_to depth=129, value=AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), Alias(Projection, AliasTy { args: [Alias(Projection, AliasTy { args: [Self/#0], def_id: DefId(0:20 ~ nightly_bug[62a3]::MatrixCommon::V) }), '?128], def_id: DefId(0:17 ~ nightly_bug[62a3]::Vector::View) })], def_id: DefId(2:3151 ~ core[191c]::ops::arith::Sub::Output) }

@martinjrobins martinjrobins added the C-bug Category: This is a bug. label Apr 4, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 4, 2024
@lqd
Copy link
Member

lqd commented Apr 4, 2024

IIUC that's from #120584 cc @compiler-errors (it also only happens with the old solver ofc)

@jieyouxu jieyouxu added A-traits Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 4, 2024
@compiler-errors
Copy link
Member

I'm fascinated that this wasn't fixed by #121123. Perhaps there's somewhere else we need to be calling item_super_predicates instead of item_bounds in the solver...

@compiler-errors
Copy link
Member

Oh lol, I found the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

5 participants