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

recursive opaque type results in stack overflow #139402

Closed
matthiaskrgr opened this issue Apr 5, 2025 · 3 comments · Fixed by #139501
Closed

recursive opaque type results in stack overflow #139402

matthiaskrgr opened this issue Apr 5, 2025 · 3 comments · Fixed by #139501
Labels
C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

original:

struct FileSystem;

impl FileSystem {
    fn build<'a>(
        &mut self,
        commands: impl Iterator<Item = &'a str> + 'a,
    ) -> Option<impl Iterator<Item = &'a str> + 'a> {
        let further_commands = self.build(commands);
        self.build(further_commands?)
    }
}

fn main() {}

Version information

rustc 1.88.0-nightly (1e008dd5d 2025-04-05)
binary: rustc
commit-hash: 1e008dd5d83e782ad37fc9cf6824733f824cc8cd
commit-date: 2025-04-05
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error: rustc interrupted by SIGSEGV, printing backtrace

/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x391f4bf) [0x75640411f4bf]
/usr/lib/libc.so.6(+0x3dcd0) [0x75640064bcd0]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x426cee4) [0x756404a6cee4]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x4260681) [0x756404a60681]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x426d087) [0x756404a6d087]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x4260681) [0x756404a60681]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x426d087) [0x756404a6d087]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6b1f2cb) [0x75640731f2cb]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x653cb8b) [0x756406d3cb8b]

### cycle encountered after 9 frames with period 10
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
### recursed 24 times

/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-67dafa3979729d17.so(+0x6807409) [0x756407007409]

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
[1]    2393986 segmentation fault  rustc a.rs

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 5, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 5, 2025
@matthiaskrgr matthiaskrgr added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Apr 5, 2025
@matthiaskrgr
Copy link
Member Author

this is caused by #138785 cc @lcnr @compiler-errors

@matthiaskrgr matthiaskrgr added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Apr 5, 2025
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 5, 2025
@theemathas
Copy link
Contributor

Minimized:

fn build<T>(commands: T) -> impl Sized {
    let further_commands = (build(commands),);
    build(further_commands.0)
}

@lcnr lcnr changed the title stack overflow recursive opaque type results in stack overflow Apr 6, 2025
@lcnr lcnr added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Apr 7, 2025
@lcnr
Copy link
Contributor

lcnr commented Apr 7, 2025

This was never intended to compile, see #139406. We intend to change this to an explicit error in #139419

Zalathar added a commit to Zalathar/rust that referenced this issue Apr 8, 2025
…rflow, r=lcnr

Fix stack overflow in exhaustiveness due to recursive HIR opaque hidden types

This fixes several spicy non-trivial recursive opaque definitions inferred from HIR typeck, ensuring that they don't cause stack overflows in exhaustiveness code, which currently reveals opaques manually in a way that is not overflow aware (as opposed to something like the normalizer folders).

These should eventually be outright rejected, but today (some) non-trivial recursive opaque definitions are accepted, and changing that requires an FCP, so for now just make sure we don't stack overflow :^)

Fixes rust-lang#139402

r? lcnr
@bors bors closed this as completed in 9ea9339 Apr 9, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 9, 2025
Rollup merge of rust-lang#139501 - compiler-errors:suppress-stack-overflow, r=lcnr

Fix stack overflow in exhaustiveness due to recursive HIR opaque hidden types

This fixes several spicy non-trivial recursive opaque definitions inferred from HIR typeck, ensuring that they don't cause stack overflows in exhaustiveness code, which currently reveals opaques manually in a way that is not overflow aware (as opposed to something like the normalizer folders).

These should eventually be outright rejected, but today (some) non-trivial recursive opaque definitions are accepted, and changing that requires an FCP, so for now just make sure we don't stack overflow :^)

Fixes rust-lang#139402

r? lcnr
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 10, 2025
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-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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