Skip to content

Return a finite number of AllocIds per ConstAllocation in Miri#118336

Merged
bors merged 2 commits intorust-lang:masterfrom
saethlin:const-to-op-cache
Jan 24, 2024
Merged

Return a finite number of AllocIds per ConstAllocation in Miri#118336
bors merged 2 commits intorust-lang:masterfrom
saethlin:const-to-op-cache

Conversation

@saethlin
Copy link
Copy Markdown
Member

@saethlin saethlin commented Nov 26, 2023

Before this, every evaluation of a const slice would produce a new AllocId. So in Miri, this program used to have unbounded memory use:

fn main() {
    loop {
        helper();
    }
}

fn helper() {
    "ouch";
}

Every trip around the loop creates a new AllocId which we need to keep track of a base address for. And the provenance GC can never clean up that AllocId -> u64 mapping, because the AllocId is for a const allocation which will never be deallocated.

So this PR moves the logic of producing an AllocId for a ConstAllocation to the Machine trait, and the implementation that Miri provides will only produce 16 AllocIds for each allocation. The cache is also keyed on the Instance that the const is evaluated in, so that equal consts evaluated in two functions will have disjoint base addresses.

r? RalfJung

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants