Exponentially expanding type causes monomorphization in compiler to panic or run "forever" #132558
Labels
A-monomorphization
Area: Monomorphization
C-bug
Category: This is a bug.
I-ICE
Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
I-monomorphization
Issue: An error at monomorphization time.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
The below code causes the compiler to panic or run forever, depending on how large the compiler
recursion_limit
setting is.Here's a summary of code below: I have a trait
S
with associated typeS::Child: S
, and I define a structA: S
withA::Child = (A,A)
, and I define(X,X)::Child = (X::Child, X::Child)
. I define a functionuhoh<T: S>(x:T)
that recurses onuhoh::<T::Child>
, and so trying to calluhoh::<A>
results in the compiler needing to monomorphize at typeA
,A::Child = (A,A)
,A::Child::Child = ((A,A),(A,A))
etc, ad infinitum. Instead of giving an error as I would expect, the compiler panics or runs forever, depending on how largerecursion_limit
is.The below code is a minimal reproduction of a real problem I ran into into a private code base.
Code
Single file reproduction, just run with
cargo run
:Meta
I encountered the real problem on 1.80.1, and tested the minimal reproduction above on 1.80.1, 1.82.0, and 1.84.0-nightly. I.e.
rustc --version --verbose
:and
and
Error output
Here's the output of
cargo build
on 1.84.0-nightly, with backtrace and huge type elided:Panic message asked me to attach this:
rustc-ice-2024-11-03T12_59_37-2130395.txt
Backtrace
The text was updated successfully, but these errors were encountered: