rust/compiler/rustc_const_eval/src
bors 6a4222b511 Auto merge of #116564 - oli-obk:evaluated_static_in_metadata, r=RalfJung,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 https://github.com/rust-lang/rust/issues/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`](https://github.com/rust-lang/rust/issues/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).
2024-02-15 10:28:31 +00:00
..
const_eval Do not allocate a second "background" alloc id for the main allocation of a static. 2024-02-15 10:25:18 +00:00
interpret Do not allocate a second "background" alloc id for the main allocation of a static. 2024-02-15 10:25:18 +00:00
transform Enforce coroutine-closure layouts are identical 2024-02-15 01:18:09 +00:00
util unstably allow constants to refer to statics and read from immutable statics 2024-02-10 16:12:55 +01:00
errors.rs Remove dcx arg from ReportErrorExt::add_args. 2024-02-12 18:39:18 +11:00
lib.rs Return ConstAllocation from eval_static_initializer query directly 2024-02-15 10:25:18 +00:00