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

Nested recursive enum with ManuallyDrop causes thread 'rustc' to overflow its stack #135093

Open
w-utter opened this issue Jan 4, 2025 · 5 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. 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

@w-utter
Copy link
Contributor

w-utter commented Jan 4, 2025

There seemed to be an issue with the type Composition<Conditional> adding drop-check rules, so I added ManuallyDrop to get the program to compile. I also added the unpin impl as there was also an error regarding its implementation.

I tried this code:

use std::mem::ManuallyDrop;

pub enum Composition<T> {
    Conditional(ManuallyDrop<Conditional<T>>),
    Item(T),
}

impl <T> Unpin for Composition<T> {}

#[derive(Default)]
pub struct Conditional<T> {
    _condition: Vec<Composition<Condition<T>>>,
    _warrant: Vec<Composition<T>>,
}

pub enum Condition<T> {
    T(T),
}

fn main() {
    let _ = Conditional::<()>::default();
}

I expected wither for the program to run, or for the compiler to give the a similar error to when ManuallyDrop is removed: "overflow while adding drop-check rules for Vec<Composition<T>>"

Instead, the rustc thread overflowed its stack.

Meta

rustc --version --verbose:

rustc 1.86.0-nightly (3f43b1a63 2025-01-03)
binary: rustc
commit-hash: 3f43b1a636738f41c48df073c5bcb97a97bf8459
commit-date: 2025-01-03
host: aarch64-apple-darwin
release: 1.86.0-nightly
LLVM version: 19.1.6
Backtrace

   Compiling overflow-issue v0.1.0 (/Users/wutter/dev/overflow-issue)

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
error: could not compile `overflow-issue` (bin "overflow-issue")

Caused by:
  process didn't exit successfully: `/Users/wutter/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/rustc --crate-name overflow_issue --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=80 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=2a6ba930726f09c1 -C extra-filename=-15d023de81aec2c9 --out-dir /Users/wutter/dev/overflow-issue/target/debug/deps -C incremental=/Users/wutter/dev/overflow-issue/target/debug/incremental -L dependency=/Users/wutter/dev/overflow-issue/target/debug/deps` (signal: 6, SIGABRT: process abort signal)```

@w-utter w-utter added the C-bug Category: This is a bug. label Jan 4, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 4, 2025
@w-utter
Copy link
Contributor Author

w-utter commented Jan 4, 2025

trying to do something similar with the example in E0320:

use core::mem::ManuallyDrop;

enum A<T> {
    B,
    C(T, Vec<ManuallyDrop<A<T>>>)
}

fn main() {
    let _ = A::<()>::B;
}

both runs and compiles.

@theemathas
Copy link
Contributor

theemathas commented Jan 4, 2025

Minimized:

pub struct Wrap<T>(T);

pub enum Recursive<T> {
    Recurse(*const Recursive<Wrap<T>>),
    Item(T),
}

pub struct Conditional<T>(Option<Recursive<T>>);

fn main() {
    let _x = Conditional::<()>(None);
}

Playground

@cyrgani
Copy link
Contributor

cyrgani commented Jan 4, 2025

a bit more reduced:

struct Wrap<T>(T);

enum Recursive<T> {
    Recurse(*const Recursive<Wrap<T>>),
    Item(T),
}

fn main() {
    let _x: Recursive<()>;
}

playground
@rustbot label:I-crash

@rustbot rustbot added the I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. label Jan 4, 2025
@matthiaskrgr matthiaskrgr added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Jan 4, 2025
@matthiaskrgr
Copy link
Member

error: rustc interrupted by SIGSEGV, printing backtrace

/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x3670773) [0x790753670773]
/usr/lib/libc.so.6(+0x3d1d0) [0x79074fe4c1d0]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(_RNvNtNtCsltYj7KdNTVr_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x14) [0x790754c120d4]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(_RNvNtNtCsltYj7KdNTVr_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x1b3) [0x790754c12273]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511b505) [0x79075511b505]

### cycle encountered after 5 frames with period 6
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511ac49) [0x79075511ac49]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511ac49) [0x79075511ac49]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511ac49) [0x79075511ac49]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511ac49) [0x79075511ac49]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511ac49) [0x79075511ac49]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511ac49) [0x79075511ac49]
### recursed 41 times

/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511ac49) [0x79075511ac49]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511ac49) [0x79075511ac49]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511ac49) [0x79075511ac49]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511ac49) [0x79075511ac49]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-78e18ca94582029e.so(+0x511ac49) [0x79075511ac49]

note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
note: backtrace dumped due to SIGSEGV! resuming signal
[2]    944011 segmentation fault  rustc /tmp/crash.rs --edition=2024 -C debuginfo=2

@matthiaskrgr
Copy link
Member

This is probably a duplicate of #121538

@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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 Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. 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

No branches or pull requests

6 participants