Skip to content

Commit 66a9006

Browse files
authored
Rollup merge of #107067 - tmiasko:custom-mir-storage-statements, r=oli-obk
Custom MIR: Support storage statements r? `@oli-obk` `@JakobDegen`
2 parents 3693399 + ca3d55e commit 66a9006

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ use super::{parse_by_kind, PResult, ParseCtxt};
1212
impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
1313
pub fn parse_statement(&self, expr_id: ExprId) -> PResult<StatementKind<'tcx>> {
1414
parse_by_kind!(self, expr_id, _, "statement",
15+
@call("mir_storage_live", args) => {
16+
Ok(StatementKind::StorageLive(self.parse_local(args[0])?))
17+
},
18+
@call("mir_storage_dead", args) => {
19+
Ok(StatementKind::StorageDead(self.parse_local(args[0])?))
20+
},
1521
@call("mir_retag", args) => {
1622
Ok(StatementKind::Retag(RetagKind::Default, Box::new(self.parse_place(args[0])?)))
1723
},

library/core/src/intrinsics/mir.rs

+2
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ define!("mir_unreachable", fn Unreachable() -> BasicBlock);
259259
define!("mir_drop", fn Drop<T>(place: T, goto: BasicBlock));
260260
define!("mir_drop_and_replace", fn DropAndReplace<T>(place: T, value: T, goto: BasicBlock));
261261
define!("mir_call", fn Call<T>(place: T, goto: BasicBlock, call: T));
262+
define!("mir_storage_live", fn StorageLive<T>(local: T));
263+
define!("mir_storage_dead", fn StorageDead<T>(local: T));
262264
define!("mir_retag", fn Retag<T>(place: T));
263265
define!("mir_move", fn Move<T>(place: T) -> T);
264266
define!("mir_static", fn Static<T>(s: T) -> &'static T);

tests/mir-opt/building/custom/simple_assign.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ pub fn simple(x: i32) -> i32 {
1111
let temp2: _;
1212

1313
{
14+
StorageLive(temp1);
1415
temp1 = x;
1516
Goto(exit)
1617
}
1718

1819
exit = {
1920
temp2 = Move(temp1);
21+
StorageDead(temp1);
2022
RET = temp2;
2123
Return()
2224
}

tests/mir-opt/building/custom/simple_assign.simple.built.after.mir

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ fn simple(_1: i32) -> i32 {
66
let mut _3: i32; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
77

88
bb0: {
9-
_2 = _1; // scope 0 at $DIR/simple_assign.rs:+6:13: +6:22
10-
goto -> bb1; // scope 0 at $DIR/simple_assign.rs:+7:13: +7:23
9+
StorageLive(_2); // scope 0 at $DIR/simple_assign.rs:+6:13: +6:31
10+
_2 = _1; // scope 0 at $DIR/simple_assign.rs:+7:13: +7:22
11+
goto -> bb1; // scope 0 at $DIR/simple_assign.rs:+8:13: +8:23
1112
}
1213

1314
bb1: {
14-
_3 = move _2; // scope 0 at $DIR/simple_assign.rs:+11:13: +11:32
15-
_0 = _3; // scope 0 at $DIR/simple_assign.rs:+12:13: +12:24
16-
return; // scope 0 at $DIR/simple_assign.rs:+13:13: +13:21
15+
_3 = move _2; // scope 0 at $DIR/simple_assign.rs:+12:13: +12:32
16+
StorageDead(_2); // scope 0 at $DIR/simple_assign.rs:+13:13: +13:31
17+
_0 = _3; // scope 0 at $DIR/simple_assign.rs:+14:13: +14:24
18+
return; // scope 0 at $DIR/simple_assign.rs:+15:13: +15:21
1719
}
1820
}

0 commit comments

Comments
 (0)