Closed
Description
See https://godbolt.org/z/Kn7b7nTnd.
Basically, this function:
const A: [u8; 1024] = [0; 1024];
pub fn copy_const() {
f(A);
f(A);
}
uses twice as much stack space as this function:
const A: [u8; 1024] = [0; 1024];
pub fn copy_local() {
let a = A;
f(a);
let b = A;
f(b);
}
This happens because:
In copy_local
, locals get lifetime markers (@llvm.lifetime.start
/@llvm.lifetime.end
, or StorageLive
/StorageDead
in MIR), so a
and b
can reuse the same stack slot.
In copy_const
, the temporaries created to copy A
to the stack before the call do not get lifetime markers, so the two calls use two separate stack slots.
@rustbot label T-compiler I-heavy