Compiling drop(Box<large array>)
causes runaway compiler memory usage
#109004
Labels
C-bug
Category: This is a bug.
I-compilemem
Issue: Problems and improvements with respect to memory usage during compilation.
Attempting to compile this code causes extremely large memory usage by rustc.
By experimentation, the important features of the code are: large
LIMIT
, the element type needs to have drop glue, and the drop can't be skipped withforget
or some other mechanism. It also must be a program, not a library function.src/main.rs
Cargo.toml
The problematic compiler invocation:
cargo build
.I expected to see this happen: The compiler memory usage shouldn't run away due to large
LIMIT
; in fact the compiler memory usage should be almost entirely independent ofLIMIT
for this program.Instead, this happened: When
LIMIT
is large,rustc
uses a lot of memory and takes a long time. I have not successfully compiled the above program with the givenLIMIT
of 64M.Meta
I repro'd this on
1.65.0
,1.68.0
, and finally:(I did not capture a compiler backtrace.)
Thoughts
I surmise that there's a correlation between
LIMIT
and compiler behavior but I haven't explored it beyond verifying a smallLIMIT
doesn't repro the bad behavior.I thought perhaps this program tries to use the stack for the slice->array cast, and somehow the compiler is getting stuck on such a large stack frame. Thankfully, this is ruled out by checking that
src/alloc/boxed.rs:boxed_slice_as_array_unchecked
does indeed do the slice->array cast entirely using pointers. So the compiler shouldn't "see" how big the array is; it's behind a pointer.Appending
std::mem::forget(_arr);
tomain
bypasses the issue, so it appears to be drop glue for the box which causes the problem. I don't see a particular reason why the drop glue for this type should be problematic; it should be no different than dropping the initialized part of a largeVec<String>
.The text was updated successfully, but these errors were encountered: