Skip to content

generic const items: polymorphically recursive consts lead to compiler stack overflow #114192

Closed
@fmease

Description

@fmease

I expected the following code to lead to an error (overflow, const eval, or cycle):

#![feature(generic_const_items)]

const RECUR<T>: () = RECUR::<(T,)>;

fn main() {}

Instead, the memory & CPU usage of the compiler quickly grew until the OOM killer terminated the process (I presume this to be a stack overflow turned into an OOM situation due to the use of ensure_sufficient_stack somewhere which causes stacks to be allocated on the heap).

Debug builds of the compiler crash immediately with a segmentation fault.
Running rustc with GDB yields (which merely looks like a symptom):

Thread 2 "rustc" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe8bff6c0 (LWP 433325)]
rustc_middle::ty::print::pretty::PrettyPrinter::pretty_print_type<rustc_middle::ty::print::pretty::FmtPrinter> (self=..., ty=...) at compiler/rustc_middle/src/ty/print/pretty.rs:909
909             ty::Slice(ty) => p!("[", print(ty), "]"),

(14,000 line backtrace not included in this issue ^^)

Corresponding UI test: tests/ui/generic-const-items/recursive.rs (known-bug, ignore-test).

Meta

rustc -Vv
rustc 1.73.0-nightly (04abc370b 2023-07-28)
binary: rustc
commit-hash: 04abc370b9f3855b28172b65a7f7d5a433f41412
commit-date: 2023-07-28
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

@rustbot label C-bug T-compiler I-crash requires-incomplete-features F-generic_const_items
@rustbot claim

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-generic_const_items`#![feature(generic_const_items)]`I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-incomplete-featuresThis issue requires the use of incomplete features.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions