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

Compiling this code caused the compiler to block #125428

Open
umoho opened this issue May 23, 2024 · 2 comments
Open

Compiling this code caused the compiler to block #125428

umoho opened this issue May 23, 2024 · 2 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

@umoho
Copy link

umoho commented May 23, 2024

I tried this code:

pub trait Trait<T> {
    fn f(&self) -> T;
}

pub struct S1<'a>(pub &'a Box<S3<'a>>);

pub struct S2<'a>(pub Vec<S1<'a>>);

pub struct S3<'a>(pub Vec<S2<'a>>);

impl<T> Trait<T> for S1<'_>
where
    for<'a> S1<'a>: Trait<T>,
    for<'a> S3<'a>: Trait<T>,
{
    fn f(&self) -> T {
        self.0.f()
    }
}

impl<T> Trait<T> for S2<'_>
where
    for<'a> S1<'a>: Trait<T>,
{
    fn f(&self) -> T {
        _ = self.0.iter().map(|s| s.f());
        todo!()
    }
}

impl<T> Trait<T> for S3<'_>
where
    for<'a> S2<'a>: Trait<T>,
{
    fn f(&self) -> T {
        _ = self.0.iter().map(|s| s.f());
        todo!()
    }
}

fn main() {
    S3(vec![]).f();
}

I expected to see this happen: Compilation completed to obtain binary file, or compiler returns an error.

Instead, this happened: Increased CPU and memory usage, unable to compile or exit for a long time.

Meta

rustc --version --verbose:

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: aarch64-apple-darwin
release: 1.78.0
LLVM version: 18.1.2

rustc +nightly --version --verbose:

rustc 1.80.0-nightly (791adf759 2024-05-21)
binary: rustc
commit-hash: 791adf759cc065316f054961875052d5bc03e16c
commit-date: 2024-05-21
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6
Backtrace

RUST_BACKTRACE=1 cargo build:

   Compiling rs_block_compile v0.1.0 (/Users/umoho/Devs/rs_block_compile)
    Building [                             ] 0/1: rs_block_compile(bin) 

@umoho umoho added the C-bug Category: This is a bug. label May 23, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 23, 2024
@jieyouxu jieyouxu added the I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. label May 23, 2024
@bjorn3
Copy link
Member

bjorn3 commented May 24, 2024

ctrl-c not working is likely #124212. Since #111769 we catch ctrl-c and only check if it happens during const eval. If you get stuck in a loop that doesn't contain any const eval, you can't exit anymore.

@saethlin
Copy link
Member

saethlin commented May 24, 2024

unable to compile or exit

Hunh. I expected that people would instinctively send SIGINT again if the compiler stays running. Are you using some system that prevents you from doing this, like an editor? On the command line, rustc will eat your first ctrl+c then instantly exit if you press ctrl+c again.

@saethlin saethlin added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 31, 2024
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

5 participants