-Znext-solver=coherence: stack overflow #119905
Copy link
Copy link
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)The Rustc Trait System Refactor Initiative (-Znext-solver)
Description
Code
#![recursion_limit="1024"]
#![allow(dead_code)]
use std::mem;
pub struct S0<T>(T,T);
pub struct S1<T>(Option<Box<S0<S0<T>>>>,Option<Box<S0<S0<S1<S1<T>>>>>>);
pub struct S2<T>(Option<Box<T>>,Option<S3<T>>);
pub struct S3<T>(S5<T>,Option<Box<S2<S2<T>>>>);
pub struct S4<T>(Option<Box<S3<S3<T>>>>,Option<Box<S3<S3<T>>>>);
pub struct S5<T>(Option<Box<S4<S4<T>>>>,Option<Box<S4<S4<T>>>>,Option<T>);
trait Foo { fn xxx(&self); }
/// some local of #[fundamental] trait
trait Bar {}
impl<T> Foo for T where T: Sync, T: Bar {
fn xxx(&self) {}
}
impl Foo for S5<u8> { fn xxx(&self) {} }
fn main() {
let s = S5(None,None,None);
s.xxx();
assert_eq!(mem::size_of_val(&s.2), mem::size_of::<Option<u8>>());
}Meta
rustc --version --verbose:
rustc 1.77.0-nightly (ce1f2ccf5 2024-01-12)
binary: rustc
commit-hash: ce1f2ccf5a5ac9343623bd115a05e4151d93af0d
commit-date: 2024-01-12
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6
Error output
<output>
Backtrace
error: rustc interrupted by SIGSEGV, printing backtrace
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-b35442033d0dc6f2.so(+0x2d6cc16)[0x7f1df876cc16]
/usr/lib/libc.so.6(+0x3e710)[0x7f1df585c710]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-b35442033d0dc6f2.so(+0x37dff57)[0x7f1df91dff57]
### cycle encountered after 3 frames with period 6
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-b35442033d0dc6f2.so(+0x378a11c)[0x7f1df918a11c]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-b35442033d0dc6f2.so(+0x379b388)[0x7f1df919b388]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-b35442033d0dc6f2.so(+0x37e05ec)[0x7f1df91e05ec]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-b35442033d0dc6f2.so(+0x378a11c)[0x7f1df918a11c]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-b35442033d0dc6f2.so(+0x379b388)[0x7f1df919b388]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-b35442033d0dc6f2.so(+0x37e05ec)[0x7f1df91e05ec]
### recursed 42 times
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-b35442033d0dc6f2.so(+0x378a11c)[0x7f1df918a11c]
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
[1] 3560606 segmentation fault rustc ff1f66b05db64ab43484975ddfc23cfa38b36db7.rs -Znext-solver=coherence
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)The Rustc Trait System Refactor Initiative (-Znext-solver)
Activity
matthiaskrgr commentedon Jan 12, 2024
compiler-errors commentedon Mar 1, 2024
This code isn't stack-overflowing for me; it's hanging. However, I don't believe we have any guarantees that if the user pushes the recursion limit very very highly above the default that the compiler mustn't hang.
lcnr commentedon Mar 14, 2024
this hits the recursion limit in the old solver, the hang is expected fallout from using non-fatal overflow
lcnr commentedon Jan 28, 2026
this no longer hangs, it now terminates after 33s on my machine.
We already have related tests here which also involve overflow and complex trait solver cycles, so I don't really want to add it to the test suite.
matthiaskrgr commentedon Jan 31, 2026
@lcnr in case it helps, this does still stack-overflow with
-Znext-solver=globally😅