Skip to content

Commit

Permalink
Auto merge of #116564 - oli-obk:evaluated_static_in_metadata, r=RalfJ…
Browse files Browse the repository at this point in the history
…ung,cjgillot

Store static initializers in metadata instead of the MIR of statics.

This means that adding generic statics would be even more difficult, as we can't evaluate statics from other crates anymore, but the subtle issue I have encountered make me think that having this be an explicit problem is better.

The issue is that

```rust
static mut FOO: &mut u32 = &mut 42;
static mut BAR = unsafe { FOO };
```

gets different allocations, instead of referring to the same one. This is also true for non-static mut, but promotion makes `static FOO: &u32 = &42;` annoying to demo.

Fixes rust-lang/rust#61345

## Why is this being done?

In order to ensure all crates see the same nested allocations (which is the last issue that needs fixing before we can stabilize [`const_mut_refs`](rust-lang/rust#57349)), I am working on creating anonymous (from the Rust side, to LLVM it's like a regular static item) static items for the nested allocations in a static. If we evaluate the static item in a downstream crate again, we will end up duplicating its nested allocations (and in some cases, like the `match` case, even duplicate the main allocation).
  • Loading branch information
bors committed Feb 15, 2024
2 parents 4232e7f + fda1555 commit 1b459c4
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/shims/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
"volatile_load" => {
let [place] = check_arg_count(args)?;
let place = this.deref_pointer(place)?;
this.copy_op(&place, dest, /*allow_transmute*/ false)?;
this.copy_op(&place, dest)?;
}
"volatile_store" => {
let [place, dest] = check_arg_count(args)?;
let place = this.deref_pointer(place)?;
this.copy_op(dest, &place, /*allow_transmute*/ false)?;
this.copy_op(dest, &place)?;
}

"write_bytes" | "volatile_set_memory" => {
Expand Down
3 changes: 0 additions & 3 deletions src/shims/x86/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ fn bin_op_simd_float_first<'tcx, F: rustc_apfloat::Float>(
this.copy_op(
&this.project_index(&left, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}

Expand Down Expand Up @@ -424,7 +423,6 @@ fn unary_op_ss<'tcx>(
this.copy_op(
&this.project_index(&op, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}

Expand Down Expand Up @@ -484,7 +482,6 @@ fn round_first<'tcx, F: rustc_apfloat::Float>(
this.copy_op(
&this.project_index(&left, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}

Expand Down
1 change: 0 additions & 1 deletion src/shims/x86/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
this.copy_op(
&this.project_index(&left, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/shims/x86/sse2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
this.copy_op(
&this.project_index(&op, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}
}
Expand Down Expand Up @@ -584,7 +583,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
this.copy_op(
&this.project_index(&left, i)?,
&this.project_index(&dest, i)?,
/*allow_transmute*/ false,
)?;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/shims/x86/sse41.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
this.copy_op(
&this.project_index(&left, i)?,
&dest,
/*allow_transmute*/ false,
)?;
}
}
Expand Down

0 comments on commit 1b459c4

Please sign in to comment.