Rollup merge of #107067 - tmiasko:custom-mir-storage-statements, r=oli-obk

Custom MIR: Support storage statements

r? `@oli-obk` `@JakobDegen`
This commit is contained in:
Matthias Krüger 2023-01-20 07:16:11 +01:00 committed by GitHub
commit 66a9006759
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 5 deletions

View file

@ -12,6 +12,12 @@ use super::{parse_by_kind, PResult, ParseCtxt};
impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
pub fn parse_statement(&self, expr_id: ExprId) -> PResult<StatementKind<'tcx>> { pub fn parse_statement(&self, expr_id: ExprId) -> PResult<StatementKind<'tcx>> {
parse_by_kind!(self, expr_id, _, "statement", parse_by_kind!(self, expr_id, _, "statement",
@call("mir_storage_live", args) => {
Ok(StatementKind::StorageLive(self.parse_local(args[0])?))
},
@call("mir_storage_dead", args) => {
Ok(StatementKind::StorageDead(self.parse_local(args[0])?))
},
@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])?)))
}, },

View file

@ -259,6 +259,8 @@ define!("mir_unreachable", fn Unreachable() -> BasicBlock);
define!("mir_drop", fn Drop<T>(place: T, goto: BasicBlock)); 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_storage_live", fn StorageLive<T>(local: T));
define!("mir_storage_dead", fn StorageDead<T>(local: T));
define!("mir_retag", fn Retag<T>(place: T)); define!("mir_retag", fn Retag<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);

View file

@ -11,12 +11,14 @@ pub fn simple(x: i32) -> i32 {
let temp2: _; let temp2: _;
{ {
StorageLive(temp1);
temp1 = x; temp1 = x;
Goto(exit) Goto(exit)
} }
exit = { exit = {
temp2 = Move(temp1); temp2 = Move(temp1);
StorageDead(temp1);
RET = temp2; RET = temp2;
Return() Return()
} }

View file

@ -6,13 +6,15 @@ fn simple(_1: i32) -> i32 {
let mut _3: i32; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL let mut _3: i32; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
bb0: { bb0: {
_2 = _1; // scope 0 at $DIR/simple_assign.rs:+6:13: +6:22 StorageLive(_2); // scope 0 at $DIR/simple_assign.rs:+6:13: +6:31
goto -> bb1; // scope 0 at $DIR/simple_assign.rs:+7:13: +7:23 _2 = _1; // scope 0 at $DIR/simple_assign.rs:+7:13: +7:22
goto -> bb1; // scope 0 at $DIR/simple_assign.rs:+8:13: +8:23
} }
bb1: { bb1: {
_3 = move _2; // scope 0 at $DIR/simple_assign.rs:+11:13: +11:32 _3 = move _2; // scope 0 at $DIR/simple_assign.rs:+12:13: +12:32
_0 = _3; // scope 0 at $DIR/simple_assign.rs:+12:13: +12:24 StorageDead(_2); // scope 0 at $DIR/simple_assign.rs:+13:13: +13:31
return; // scope 0 at $DIR/simple_assign.rs:+13:13: +13:21 _0 = _3; // scope 0 at $DIR/simple_assign.rs:+14:13: +14:24
return; // scope 0 at $DIR/simple_assign.rs:+15:13: +15:21
} }
} }