You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ICE with unleash-miri: mutable allocation in constant #71316
I tried this code with -Zunleash-the-miri-inside-of-you:
// compile-flags: -Zunleash-the-miri-inside-of-you#![feature(const_raw_ptr_deref)]#![feature(const_mut_refs)]#![allow(const_err)]use std::cell::UnsafeCell;// make sure we do not just intern this as mutableconstMUTABLE_BEHIND_RAW:*muti32 = &UnsafeCell::new(42)as*const_as*mut_;fnmain(){}
This is a variant of the mutable_const test.
I am getting an ICE:
error: internal compiler error: mutable allocation in constant
--> ice.rs:10:1
|
10 | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366:17
I thought that was the intent 😆 The miri-engine doesn't need to gracefully error in situations that can only occur in unleash mode. There's no way a user will ever see it unless we have a bug in either our knowledge of the engine or the static checks.
That doesn't match what we do elsewhere though; CTFE doesn't ICE when it hits a box on inline assembly or a non-const fn-call.
This error is slightly different though... it is entirely unclear (to me at least) what the intended behavior is here. On the one hand the user asked for interior mutability, on the other hand it's a const. Any of the following three behaviors seems reasonable:
Just make this a mutable allocation and let the const point to it (as if it was an "anonymous static" or so).
Just make this an immutable allocation, so if the user writes to it later that's UB. This is potentially surprising though since they did use UnsafeCell.
Curiously, mutable_references_ice ICEs in a different way. The issues seem related though. It would be nice if they could all go through the same error path.
In other words, the current const check in the leftover_allocations phase has nothing to do with mutability. These allocations will all be mutable, because all allocations start as mutable and then get frozen when initialization is done. We are right now just rejecting all leftover (untyped) allocations in consts because we cannot sanity-check them. That's not unreasonable, but it is not what the error message says.
This seems like one of the cases where we'd need to overwrite the mutability of the allocation. This is one of the promotion-without-promotable cases. The MIR is
As you can see, there's no StorageDead for _3, making it live forever. But miri needs to make it a mutable allocation in order to write the return value of the Vec::new() call into it.
Activity
RalfJung commentedon Apr 19, 2020
Hm okay in another case it looks like we are actually expecting an ICE with miri-unleash? That seems rather extreme though.
oli-obk commentedon Apr 22, 2020
I thought that was the intent 😆 The miri-engine doesn't need to gracefully error in situations that can only occur in unleash mode. There's no way a user will ever see it unless we have a bug in either our knowledge of the engine or the static checks.
RalfJung commentedon Apr 22, 2020
That doesn't match what we do elsewhere though; CTFE doesn't ICE when it hits a
boxon inline assembly or a non-const fn-call.This error is slightly different though... it is entirely unclear (to me at least) what the intended behavior is here. On the one hand the user asked for interior mutability, on the other hand it's a
const. Any of the following three behaviors seems reasonable:UnsafeCell.RalfJung commentedon Apr 22, 2020
Curiously,
mutable_references_iceICEs in a different way. The issues seem related though. It would be nice if they could all go through the same error path.oli-obk commentedon Apr 22, 2020
of these three options I'd choose the nice error. I'd rather bail out than introduce mutability to constants.
RalfJung commentedon Apr 28, 2020
I am getting the feeling that that check is overzealous... we also get an ICE for this constant, which arguably is fine:
RalfJung commentedon Apr 28, 2020
In other words, the current const check in the
leftover_allocationsphase has nothing to do with mutability. These allocations will all be mutable, because all allocations start as mutable and then get frozen when initialization is done. We are right now just rejecting all leftover (untyped) allocations in consts because we cannot sanity-check them. That's not unreasonable, but it is not what the error message says.RalfJung commentedon Apr 28, 2020
In fact, this ICEs on stable:
oli-obk commentedon May 2, 2020
This seems like one of the cases where we'd need to overwrite the mutability of the allocation. This is one of the promotion-without-promotable cases. The MIR is
As you can see, there's no
StorageDeadfor_3, making it live forever. But miri needs to make it a mutable allocation in order to write the return value of theVec::new()call into it.RalfJung commentedon May 2, 2020
Yeah and interning already makes these immutable:
rust/src/librustc_mir/interpret/intern.rs
Line 386 in 08dfbfb
It just also ICEs currently, but that is fixed by #71665 (which makes it a hard error instead).
Rollup merge of rust-lang#71665 - RalfJung:miri-intern-no-ice, r=oli-obk
Rollup merge of rust-lang#71665 - RalfJung:miri-intern-no-ice, r=oli-obk
Auto merge of rust-lang#71665 - RalfJung:miri-intern-no-ice, r=oli-obk