Skip to content

Commit

Permalink
Rollup merge of rust-lang#106012 - JakobDegen:retag-raw, r=RalfJung
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
matthiaskrgr committed Dec 22, 2022
2 parents f340e68 + 7c4c620 commit d0d0ccd
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 19 deletions.
9 changes: 6 additions & 3 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 || *kind == RetagKind::TwoPhase {
self.fail(location, format!("explicit `{:?}` is forbidden", kind));
}
}
StatementKind::StorageLive(..)
| StatementKind::StorageDead(..)
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,10 @@ 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.
///
/// Only `RetagKind::Default` and `RetagKind::FnEntry` are permitted.
Retag(RetagKind, Box<Place<'tcx>>),

/// Encodes a user's type ascription. These need to be preserved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion library/core/src/intrinsics/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 0 additions & 2 deletions src/test/mir-opt/building/custom/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -28,7 +27,6 @@ pub fn immut_ref(x: &i32) -> &i32 {

{
t = addr_of!(*x);
RetagRaw(t);
RET = & *t;
Retag(RET);
Return()
Expand Down

0 comments on commit d0d0ccd

Please sign in to comment.