Clarify that raw retags are not permitted in Mir

This commit is contained in:
Jakob Degen 2022-12-21 10:30:38 -08:00
parent d6da428f34
commit cb2c7bb833
7 changed files with 17 additions and 19 deletions

View File

@ -9,8 +9,8 @@ use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::{
traversal, AggregateKind, BasicBlock, BinOp, Body, BorrowKind, CastKind, CopyNonOverlapping,
Local, Location, MirPass, MirPhase, NonDivergingIntrinsic, Operand, Place, PlaceElem, PlaceRef,
ProjectionElem, RuntimePhase, Rvalue, SourceScope, Statement, StatementKind, Terminator,
TerminatorKind, UnOp, START_BLOCK,
ProjectionElem, RetagKind, RuntimePhase, Rvalue, SourceScope, Statement, StatementKind,
Terminator, TerminatorKind, UnOp, START_BLOCK,
};
use rustc_middle::ty::{self, InstanceDef, ParamEnv, Ty, TyCtxt, TypeVisitable};
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");
}
}
StatementKind::Retag(_, _) => {
StatementKind::Retag(kind, _) => {
// FIXME(JakobDegen) The validator should check that `self.mir_phase <
// DropsLowered`. However, this causes ICEs with generation of drop shims, which
// seem to fail to set their `MirPhase` correctly.
if *kind == RetagKind::Raw {
self.fail(location, "explicit `RetagKind::Raw` is forbidden");
}
}
StatementKind::StorageLive(..)
| StatementKind::StorageDead(..)

View File

@ -320,8 +320,11 @@ pub enum StatementKind<'tcx> {
/// <https://internals.rust-lang.org/t/stacked-borrows-an-aliasing-model-for-rust/8153/> for
/// more details.
///
/// For code that is not specific to stacked borrows, you should consider retags to read
/// and modify the place in an opaque way.
/// For code that is not specific to stacked borrows, you should consider retags to read and
/// modify the place in an opaque way.
///
/// Explicit `RetagKind::Raw` is not permitted - it is implicit as a part of
/// `Rvalue::AddressOf`.
Retag(RetagKind, Box<Place<'tcx>>),
/// Encodes a user's type ascription. These need to be preserved

View File

@ -15,9 +15,6 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
@call("mir_retag", args) => {
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) => {
let place = self.parse_place(args[0])?;
let var = self.parse_integer_literal(args[1])? as u32;

View File

@ -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_call", fn Call<T>(place: T, goto: BasicBlock, call: 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_static", fn Static<T>(s: T) -> &'static T);
define!("mir_static_mut", fn StaticMut<T>(s: T) -> *mut T);

View File

@ -6,9 +6,8 @@ fn immut_ref(_1: &i32) -> &i32 {
bb0: {
_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:+7:13: +7:23
Retag(_0); // scope 0 at $DIR/references.rs:+8:13: +8:23
return; // scope 0 at $DIR/references.rs:+9:13: +9:21
_0 = &(*_2); // scope 0 at $DIR/references.rs:+6:13: +6:23
Retag(_0); // scope 0 at $DIR/references.rs:+7:13: +7:23
return; // scope 0 at $DIR/references.rs:+8:13: +8:21
}
}

View File

@ -6,9 +6,8 @@ fn mut_ref(_1: &mut i32) -> &mut i32 {
bb0: {
_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:+7:13: +7:26
Retag(_0); // scope 0 at $DIR/references.rs:+8:13: +8:23
return; // scope 0 at $DIR/references.rs:+9:13: +9:21
_0 = &mut (*_2); // scope 0 at $DIR/references.rs:+6:13: +6:26
Retag(_0); // scope 0 at $DIR/references.rs:+7:13: +7:23
return; // scope 0 at $DIR/references.rs:+8:13: +8:21
}
}

View File

@ -12,7 +12,6 @@ pub fn mut_ref(x: &mut i32) -> &mut i32 {
{
t = addr_of_mut!(*x);
RetagRaw(t);
RET = &mut *t;
Retag(RET);
Return()
@ -28,7 +27,6 @@ pub fn immut_ref(x: &i32) -> &i32 {
{
t = addr_of!(*x);
RetagRaw(t);
RET = & *t;
Retag(RET);
Return()