Skip to content

Compiler Hang with High Memory Consumption during Compilation with Trait Implementation #117257

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

Open
iamanonymouscs opened this issue Oct 27, 2023 · 3 comments
Labels
C-bug Category: This is a bug. 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

@iamanonymouscs
Copy link

iamanonymouscs commented Oct 27, 2023

cat hang.rs

trait Trait {}
impl<T, U> Trait for (T, U)
where
    (U, T): Trait,
    (T, U): Trait {}
fn impls_constraint<T, U>()
where
    (T, U): ConstrainToU32<T>,
{
}
trait ConstrainToU32<T> {}
impl ConstrainToU32<u32> for () {}
fn impls_trait<T, U>()
where
    (T, U): Trait,
{
}
fn main() {
    impls_trait::<_, _>();
}

I expected to see this happen: The compiler compiles successfully or outputs an error message.

Instead, this happened: The code, as provided below, appears to encounter a hang. The code compilation consumes a lot of memory and eventually exits with return code 137.

Command

rustc hang.rs

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

The same problem is reproduced on the nightly version(1.75.0-nightly (aa1a71e9e 2023-10-26))

what's more, to get more information,I also tried '-Z time-passes' (using nighly version):

Output

$ rustc hang.rs -Z time-passes
time:   0.000; rss:   29MB ->   32MB (   +2MB)  parse_crate
time:   0.003; rss:   36MB ->   49MB (  +14MB)  expand_crate
time:   0.003; rss:   36MB ->   49MB (  +14MB)  macro_expand_crate
time:   0.000; rss:   49MB ->   52MB (   +3MB)  prepare_outputs
time:   0.000; rss:   52MB ->   56MB (   +4MB)  type_collecting

@iamanonymouscs iamanonymouscs added the C-bug Category: This is a bug. label Oct 27, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 27, 2023
@krtab
Copy link
Contributor

krtab commented Oct 27, 2023

Minimized (all I did was remove ConstrainToU32):

trait Trait {}
impl<T, U> Trait for (T, U)
where
    // Commenting one of these bounds displays a proper error message of overflow
   // when evaluating the trait bounds
    (U, T): Trait,
    (T, U): Trait,
{
}

fn impls_trait<T, U>()
where
    (T, U): Trait,
{
}

fn main() {
    impls_trait::<_, _>();
}

@krtab
Copy link
Contributor

krtab commented Oct 27, 2023

@rustbot assign @krtab

@saethlin saethlin added 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. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 28, 2023
@krtab krtab removed their assignment Nov 13, 2023
@krtab
Copy link
Contributor

krtab commented Nov 13, 2023

I couldn't find time to properly fix the issue. However, I tested and it is fixed with the new trait solver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. 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

No branches or pull requests

4 participants