Skip to content

Commit d0d0ccd

Browse files
authored
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`
2 parents f340e68 + 7c4c620 commit d0d0ccd

File tree

7 files changed

+16
-19
lines changed

7 files changed

+16
-19
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use rustc_middle::mir::visit::{PlaceContext, Visitor};
99
use rustc_middle::mir::{
1010
traversal, AggregateKind, BasicBlock, BinOp, Body, BorrowKind, CastKind, CopyNonOverlapping,
1111
Local, Location, MirPass, MirPhase, NonDivergingIntrinsic, Operand, Place, PlaceElem, PlaceRef,
12-
ProjectionElem, RuntimePhase, Rvalue, SourceScope, Statement, StatementKind, Terminator,
13-
TerminatorKind, UnOp, START_BLOCK,
12+
ProjectionElem, RetagKind, RuntimePhase, Rvalue, SourceScope, Statement, StatementKind,
13+
Terminator, TerminatorKind, UnOp, START_BLOCK,
1414
};
1515
use rustc_middle::ty::{self, InstanceDef, ParamEnv, Ty, TyCtxt, TypeVisitable};
1616
use rustc_mir_dataflow::impls::MaybeStorageLive;
@@ -667,10 +667,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
667667
self.fail(location, "`Deinit`is not allowed until deaggregation");
668668
}
669669
}
670-
StatementKind::Retag(_, _) => {
670+
StatementKind::Retag(kind, _) => {
671671
// FIXME(JakobDegen) The validator should check that `self.mir_phase <
672672
// DropsLowered`. However, this causes ICEs with generation of drop shims, which
673673
// seem to fail to set their `MirPhase` correctly.
674+
if *kind == RetagKind::Raw || *kind == RetagKind::TwoPhase {
675+
self.fail(location, format!("explicit `{:?}` is forbidden", kind));
676+
}
674677
}
675678
StatementKind::StorageLive(..)
676679
| StatementKind::StorageDead(..)

compiler/rustc_middle/src/mir/syntax.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,10 @@ pub enum StatementKind<'tcx> {
320320
/// <https://internals.rust-lang.org/t/stacked-borrows-an-aliasing-model-for-rust/8153/> for
321321
/// more details.
322322
///
323-
/// For code that is not specific to stacked borrows, you should consider retags to read
324-
/// and modify the place in an opaque way.
323+
/// For code that is not specific to stacked borrows, you should consider retags to read and
324+
/// modify the place in an opaque way.
325+
///
326+
/// Only `RetagKind::Default` and `RetagKind::FnEntry` are permitted.
325327
Retag(RetagKind, Box<Place<'tcx>>),
326328

327329
/// Encodes a user's type ascription. These need to be preserved

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
1515
@call("mir_retag", args) => {
1616
Ok(StatementKind::Retag(RetagKind::Default, Box::new(self.parse_place(args[0])?)))
1717
},
18-
@call("mir_retag_raw", args) => {
19-
Ok(StatementKind::Retag(RetagKind::Raw, Box::new(self.parse_place(args[0])?)))
20-
},
2118
@call("mir_set_discriminant", args) => {
2219
let place = self.parse_place(args[0])?;
2320
let var = self.parse_integer_literal(args[1])? as u32;

library/core/src/intrinsics/mir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ define!("mir_drop", fn Drop<T>(place: T, goto: BasicBlock));
259259
define!("mir_drop_and_replace", fn DropAndReplace<T>(place: T, value: T, goto: BasicBlock));
260260
define!("mir_call", fn Call<T>(place: T, goto: BasicBlock, call: T));
261261
define!("mir_retag", fn Retag<T>(place: T));
262-
define!("mir_retag_raw", fn RetagRaw<T>(place: T));
263262
define!("mir_move", fn Move<T>(place: T) -> T);
264263
define!("mir_static", fn Static<T>(s: T) -> &'static T);
265264
define!("mir_static_mut", fn StaticMut<T>(s: T) -> *mut T);

src/test/mir-opt/building/custom/references.immut_ref.built.after.mir

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ fn immut_ref(_1: &i32) -> &i32 {
66

77
bb0: {
88
_2 = &raw const (*_1); // scope 0 at $DIR/references.rs:+5:13: +5:29
9-
Retag([raw] _2); // scope 0 at $DIR/references.rs:+6:13: +6:24
10-
_0 = &(*_2); // scope 0 at $DIR/references.rs:+7:13: +7:23
11-
Retag(_0); // scope 0 at $DIR/references.rs:+8:13: +8:23
12-
return; // scope 0 at $DIR/references.rs:+9:13: +9:21
9+
_0 = &(*_2); // scope 0 at $DIR/references.rs:+6:13: +6:23
10+
Retag(_0); // scope 0 at $DIR/references.rs:+7:13: +7:23
11+
return; // scope 0 at $DIR/references.rs:+8:13: +8:21
1312
}
1413
}

src/test/mir-opt/building/custom/references.mut_ref.built.after.mir

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ fn mut_ref(_1: &mut i32) -> &mut i32 {
66

77
bb0: {
88
_2 = &raw mut (*_1); // scope 0 at $DIR/references.rs:+5:13: +5:33
9-
Retag([raw] _2); // scope 0 at $DIR/references.rs:+6:13: +6:24
10-
_0 = &mut (*_2); // scope 0 at $DIR/references.rs:+7:13: +7:26
11-
Retag(_0); // scope 0 at $DIR/references.rs:+8:13: +8:23
12-
return; // scope 0 at $DIR/references.rs:+9:13: +9:21
9+
_0 = &mut (*_2); // scope 0 at $DIR/references.rs:+6:13: +6:26
10+
Retag(_0); // scope 0 at $DIR/references.rs:+7:13: +7:23
11+
return; // scope 0 at $DIR/references.rs:+8:13: +8:21
1312
}
1413
}

src/test/mir-opt/building/custom/references.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub fn mut_ref(x: &mut i32) -> &mut i32 {
1212

1313
{
1414
t = addr_of_mut!(*x);
15-
RetagRaw(t);
1615
RET = &mut *t;
1716
Retag(RET);
1817
Return()
@@ -28,7 +27,6 @@ pub fn immut_ref(x: &i32) -> &i32 {
2827

2928
{
3029
t = addr_of!(*x);
31-
RetagRaw(t);
3230
RET = & *t;
3331
Retag(RET);
3432
Return()

0 commit comments

Comments
 (0)