Rollup merge of #106012 - JakobDegen:retag-raw, r=RalfJung
Clarify that raw retags are not permitted in Mir Not sure when this changed, but documentation and the validator needed to be updated. This also removes raw retags from custom mir. cc rust-lang/miri#2735 r? `@RalfJung`
This commit is contained in:
commit
d0d0ccdca2
7 changed files with 16 additions and 19 deletions
|
@ -9,8 +9,8 @@ use rustc_middle::mir::visit::{PlaceContext, Visitor};
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
traversal, AggregateKind, BasicBlock, BinOp, Body, BorrowKind, CastKind, CopyNonOverlapping,
|
traversal, AggregateKind, BasicBlock, BinOp, Body, BorrowKind, CastKind, CopyNonOverlapping,
|
||||||
Local, Location, MirPass, MirPhase, NonDivergingIntrinsic, Operand, Place, PlaceElem, PlaceRef,
|
Local, Location, MirPass, MirPhase, NonDivergingIntrinsic, Operand, Place, PlaceElem, PlaceRef,
|
||||||
ProjectionElem, RuntimePhase, Rvalue, SourceScope, Statement, StatementKind, Terminator,
|
ProjectionElem, RetagKind, RuntimePhase, Rvalue, SourceScope, Statement, StatementKind,
|
||||||
TerminatorKind, UnOp, START_BLOCK,
|
Terminator, TerminatorKind, UnOp, START_BLOCK,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::{self, InstanceDef, ParamEnv, Ty, TyCtxt, TypeVisitable};
|
use rustc_middle::ty::{self, InstanceDef, ParamEnv, Ty, TyCtxt, TypeVisitable};
|
||||||
use rustc_mir_dataflow::impls::MaybeStorageLive;
|
use rustc_mir_dataflow::impls::MaybeStorageLive;
|
||||||
|
@ -667,10 +667,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
||||||
self.fail(location, "`Deinit`is not allowed until deaggregation");
|
self.fail(location, "`Deinit`is not allowed until deaggregation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StatementKind::Retag(_, _) => {
|
StatementKind::Retag(kind, _) => {
|
||||||
// FIXME(JakobDegen) The validator should check that `self.mir_phase <
|
// FIXME(JakobDegen) The validator should check that `self.mir_phase <
|
||||||
// DropsLowered`. However, this causes ICEs with generation of drop shims, which
|
// DropsLowered`. However, this causes ICEs with generation of drop shims, which
|
||||||
// seem to fail to set their `MirPhase` correctly.
|
// seem to fail to set their `MirPhase` correctly.
|
||||||
|
if *kind == RetagKind::Raw || *kind == RetagKind::TwoPhase {
|
||||||
|
self.fail(location, format!("explicit `{:?}` is forbidden", kind));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
StatementKind::StorageLive(..)
|
StatementKind::StorageLive(..)
|
||||||
| StatementKind::StorageDead(..)
|
| StatementKind::StorageDead(..)
|
||||||
|
|
|
@ -320,8 +320,10 @@ pub enum StatementKind<'tcx> {
|
||||||
/// <https://internals.rust-lang.org/t/stacked-borrows-an-aliasing-model-for-rust/8153/> for
|
/// <https://internals.rust-lang.org/t/stacked-borrows-an-aliasing-model-for-rust/8153/> for
|
||||||
/// more details.
|
/// more details.
|
||||||
///
|
///
|
||||||
/// For code that is not specific to stacked borrows, you should consider retags to read
|
/// For code that is not specific to stacked borrows, you should consider retags to read and
|
||||||
/// and modify the place in an opaque way.
|
/// modify the place in an opaque way.
|
||||||
|
///
|
||||||
|
/// Only `RetagKind::Default` and `RetagKind::FnEntry` are permitted.
|
||||||
Retag(RetagKind, Box<Place<'tcx>>),
|
Retag(RetagKind, Box<Place<'tcx>>),
|
||||||
|
|
||||||
/// Encodes a user's type ascription. These need to be preserved
|
/// Encodes a user's type ascription. These need to be preserved
|
||||||
|
|
|
@ -15,9 +15,6 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
||||||
@call("mir_retag", args) => {
|
@call("mir_retag", args) => {
|
||||||
Ok(StatementKind::Retag(RetagKind::Default, Box::new(self.parse_place(args[0])?)))
|
Ok(StatementKind::Retag(RetagKind::Default, Box::new(self.parse_place(args[0])?)))
|
||||||
},
|
},
|
||||||
@call("mir_retag_raw", args) => {
|
|
||||||
Ok(StatementKind::Retag(RetagKind::Raw, Box::new(self.parse_place(args[0])?)))
|
|
||||||
},
|
|
||||||
@call("mir_set_discriminant", args) => {
|
@call("mir_set_discriminant", args) => {
|
||||||
let place = self.parse_place(args[0])?;
|
let place = self.parse_place(args[0])?;
|
||||||
let var = self.parse_integer_literal(args[1])? as u32;
|
let var = self.parse_integer_literal(args[1])? as u32;
|
||||||
|
|
|
@ -259,7 +259,6 @@ define!("mir_drop", fn Drop<T>(place: T, goto: BasicBlock));
|
||||||
define!("mir_drop_and_replace", fn DropAndReplace<T>(place: T, value: T, goto: BasicBlock));
|
define!("mir_drop_and_replace", fn DropAndReplace<T>(place: T, value: T, goto: BasicBlock));
|
||||||
define!("mir_call", fn Call<T>(place: T, goto: BasicBlock, call: T));
|
define!("mir_call", fn Call<T>(place: T, goto: BasicBlock, call: T));
|
||||||
define!("mir_retag", fn Retag<T>(place: T));
|
define!("mir_retag", fn Retag<T>(place: T));
|
||||||
define!("mir_retag_raw", fn RetagRaw<T>(place: T));
|
|
||||||
define!("mir_move", fn Move<T>(place: T) -> T);
|
define!("mir_move", fn Move<T>(place: T) -> T);
|
||||||
define!("mir_static", fn Static<T>(s: T) -> &'static T);
|
define!("mir_static", fn Static<T>(s: T) -> &'static T);
|
||||||
define!("mir_static_mut", fn StaticMut<T>(s: T) -> *mut T);
|
define!("mir_static_mut", fn StaticMut<T>(s: T) -> *mut T);
|
||||||
|
|
|
@ -6,9 +6,8 @@ fn immut_ref(_1: &i32) -> &i32 {
|
||||||
|
|
||||||
bb0: {
|
bb0: {
|
||||||
_2 = &raw const (*_1); // scope 0 at $DIR/references.rs:+5:13: +5:29
|
_2 = &raw const (*_1); // scope 0 at $DIR/references.rs:+5:13: +5:29
|
||||||
Retag([raw] _2); // scope 0 at $DIR/references.rs:+6:13: +6:24
|
_0 = &(*_2); // scope 0 at $DIR/references.rs:+6:13: +6:23
|
||||||
_0 = &(*_2); // scope 0 at $DIR/references.rs:+7:13: +7:23
|
Retag(_0); // scope 0 at $DIR/references.rs:+7:13: +7:23
|
||||||
Retag(_0); // scope 0 at $DIR/references.rs:+8:13: +8:23
|
return; // scope 0 at $DIR/references.rs:+8:13: +8:21
|
||||||
return; // scope 0 at $DIR/references.rs:+9:13: +9:21
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,8 @@ fn mut_ref(_1: &mut i32) -> &mut i32 {
|
||||||
|
|
||||||
bb0: {
|
bb0: {
|
||||||
_2 = &raw mut (*_1); // scope 0 at $DIR/references.rs:+5:13: +5:33
|
_2 = &raw mut (*_1); // scope 0 at $DIR/references.rs:+5:13: +5:33
|
||||||
Retag([raw] _2); // scope 0 at $DIR/references.rs:+6:13: +6:24
|
_0 = &mut (*_2); // scope 0 at $DIR/references.rs:+6:13: +6:26
|
||||||
_0 = &mut (*_2); // scope 0 at $DIR/references.rs:+7:13: +7:26
|
Retag(_0); // scope 0 at $DIR/references.rs:+7:13: +7:23
|
||||||
Retag(_0); // scope 0 at $DIR/references.rs:+8:13: +8:23
|
return; // scope 0 at $DIR/references.rs:+8:13: +8:21
|
||||||
return; // scope 0 at $DIR/references.rs:+9:13: +9:21
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ pub fn mut_ref(x: &mut i32) -> &mut i32 {
|
||||||
|
|
||||||
{
|
{
|
||||||
t = addr_of_mut!(*x);
|
t = addr_of_mut!(*x);
|
||||||
RetagRaw(t);
|
|
||||||
RET = &mut *t;
|
RET = &mut *t;
|
||||||
Retag(RET);
|
Retag(RET);
|
||||||
Return()
|
Return()
|
||||||
|
@ -28,7 +27,6 @@ pub fn immut_ref(x: &i32) -> &i32 {
|
||||||
|
|
||||||
{
|
{
|
||||||
t = addr_of!(*x);
|
t = addr_of!(*x);
|
||||||
RetagRaw(t);
|
|
||||||
RET = & *t;
|
RET = & *t;
|
||||||
Retag(RET);
|
Retag(RET);
|
||||||
Return()
|
Return()
|
||||||
|
|
Loading…
Add table
Reference in a new issue