Skip to content

Temporaries used for indirectly-passed const arguments should get lifetime markers #98156

Closed
@erikdesjardins

Description

@erikdesjardins

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

Metadata

Metadata

Assignees

Labels

I-heavyIssue: Problems and improvements with respect to binary size of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions