1
Fork 0

custom_mir: change Call() terminator syntax to something more readable

This commit is contained in:
Ralf Jung 2023-08-19 18:08:23 +02:00
parent d06ca0ffaf
commit 7a6346660e
22 changed files with 62 additions and 62 deletions

View file

@ -61,9 +61,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
}) })
}, },
@call("mir_call", args) => { @call("mir_call", args) => {
let destination = self.parse_place(args[0])?; self.parse_call(args)
let target = self.parse_block(args[1])?;
self.parse_call(args[2], destination, target)
}, },
ExprKind::Match { scrutinee, arms, .. } => { ExprKind::Match { scrutinee, arms, .. } => {
let discr = self.parse_operand(*scrutinee)?; let discr = self.parse_operand(*scrutinee)?;
@ -109,13 +107,14 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
Ok(SwitchTargets::new(values.into_iter().zip(targets), otherwise)) Ok(SwitchTargets::new(values.into_iter().zip(targets), otherwise))
} }
fn parse_call( fn parse_call(&self, args: &[ExprId]) -> PResult<TerminatorKind<'tcx>> {
&self, let (destination, call) = parse_by_kind!(self, args[0], _, "function call",
expr_id: ExprId, ExprKind::Assign { lhs, rhs } => (*lhs, *rhs),
destination: Place<'tcx>, );
target: BasicBlock, let destination = self.parse_place(destination)?;
) -> PResult<TerminatorKind<'tcx>> { let target = self.parse_block(args[1])?;
parse_by_kind!(self, expr_id, _, "function call",
parse_by_kind!(self, call, _, "function call",
ExprKind::Call { fun, args, from_hir_call, fn_span, .. } => { ExprKind::Call { fun, args, from_hir_call, fn_span, .. } => {
let fun = self.parse_operand(*fun)?; let fun = self.parse_operand(*fun)?;
let args = args let args = args

View file

@ -104,17 +104,18 @@
//! } //! }
//! //!
//! #[custom_mir(dialect = "runtime", phase = "optimized")] //! #[custom_mir(dialect = "runtime", phase = "optimized")]
#![cfg_attr(bootstrap, doc = "#[cfg(any())]")] // disable the following function in doctests when `bootstrap` is set
//! fn push_and_pop<T>(v: &mut Vec<T>, value: T) { //! fn push_and_pop<T>(v: &mut Vec<T>, value: T) {
//! mir!( //! mir!(
//! let unused; //! let _unused;
//! let popped; //! let popped;
//! //!
//! { //! {
//! Call(unused, pop, Vec::push(v, value)) //! Call(_unused = Vec::push(v, value), pop)
//! } //! }
//! //!
//! pop = { //! pop = {
//! Call(popped, drop, Vec::pop(v)) //! Call(popped = Vec::pop(v), drop)
//! } //! }
//! //!
//! drop = { //! drop = {
@ -275,7 +276,7 @@ define!("mir_return", fn Return() -> BasicBlock);
define!("mir_goto", fn Goto(destination: BasicBlock) -> BasicBlock); define!("mir_goto", fn Goto(destination: BasicBlock) -> BasicBlock);
define!("mir_unreachable", fn Unreachable() -> BasicBlock); 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_call", fn Call<T>(place: T, goto: BasicBlock, call: T)); define!("mir_call", fn Call(call: (), goto: BasicBlock));
define!("mir_storage_live", fn StorageLive<T>(local: T)); define!("mir_storage_live", fn StorageLive<T>(local: T));
define!("mir_storage_dead", fn StorageDead<T>(local: T)); define!("mir_storage_dead", fn StorageDead<T>(local: T));
define!("mir_deinit", fn Deinit<T>(place: T)); define!("mir_deinit", fn Deinit<T>(place: T));

View file

@ -8,13 +8,13 @@ pub struct S(i32);
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
fn main() { fn main() {
mir! { mir! {
let unit: (); let _unit: ();
{ {
let non_copy = S(42); let non_copy = S(42);
let ptr = std::ptr::addr_of_mut!(non_copy); let ptr = std::ptr::addr_of_mut!(non_copy);
// Inside `callee`, the first argument and `*ptr` are basically // Inside `callee`, the first argument and `*ptr` are basically
// aliasing places! // aliasing places!
Call(unit, after_call, callee(Move(*ptr), ptr)) Call(_unit = callee(Move(*ptr), ptr), after_call)
} }
after_call = { after_call = {
Return() Return()

View file

@ -10,7 +10,7 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
--> $DIR/arg_inplace_mutate.rs:LL:CC --> $DIR/arg_inplace_mutate.rs:LL:CC
| |
LL | / mir! { LL | / mir! {
LL | | let unit: (); LL | | let _unit: ();
LL | | { LL | | {
LL | | let non_copy = S(42); LL | | let non_copy = S(42);
... | ... |
@ -27,8 +27,8 @@ LL | unsafe { ptr.write(S(0)) };
note: inside `main` note: inside `main`
--> $DIR/arg_inplace_mutate.rs:LL:CC --> $DIR/arg_inplace_mutate.rs:LL:CC
| |
LL | Call(unit, after_call, callee(Move(*ptr), ptr)) LL | Call(_unit = callee(Move(*ptr), ptr), after_call)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info)
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View file

@ -12,7 +12,7 @@ help: the accessed tag <TAG> was created here
--> $DIR/arg_inplace_mutate.rs:LL:CC --> $DIR/arg_inplace_mutate.rs:LL:CC
| |
LL | / mir! { LL | / mir! {
LL | | let unit: (); LL | | let _unit: ();
LL | | { LL | | {
LL | | let non_copy = S(42); LL | | let non_copy = S(42);
... | ... |
@ -29,8 +29,8 @@ LL | unsafe { ptr.write(S(0)) };
note: inside `main` note: inside `main`
--> $DIR/arg_inplace_mutate.rs:LL:CC --> $DIR/arg_inplace_mutate.rs:LL:CC
| |
LL | Call(unit, after_call, callee(Move(*ptr), ptr)) LL | Call(_unit = callee(Move(*ptr), ptr), after_call)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info)
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View file

@ -6,12 +6,12 @@ pub struct S(i32);
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
fn main() { fn main() {
mir! { mir! {
let unit: (); let _unit: ();
let _observe: i32; let _observe: i32;
{ {
let non_copy = S(42); let non_copy = S(42);
// This could change `non_copy` in-place // This could change `non_copy` in-place
Call(unit, after_call, change_arg(Move(non_copy))) Call(_unit = change_arg(Move(non_copy)), after_call)
} }
after_call = { after_call = {
// So now we must not be allowed to observe non-copy again. // So now we must not be allowed to observe non-copy again.

View file

@ -11,8 +11,8 @@ LL | unsafe { ptr.read() };
note: inside `main` note: inside `main`
--> $DIR/arg_inplace_observe_during.rs:LL:CC --> $DIR/arg_inplace_observe_during.rs:LL:CC
| |
LL | Call(unit, after_call, change_arg(Move(*ptr), ptr)) LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View file

@ -9,12 +9,12 @@ pub struct S(i32);
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
fn main() { fn main() {
mir! { mir! {
let unit: (); let _unit: ();
{ {
let non_copy = S(42); let non_copy = S(42);
let ptr = std::ptr::addr_of_mut!(non_copy); let ptr = std::ptr::addr_of_mut!(non_copy);
// This could change `non_copy` in-place // This could change `non_copy` in-place
Call(unit, after_call, change_arg(Move(*ptr), ptr)) Call(_unit = change_arg(Move(*ptr), ptr), after_call)
} }
after_call = { after_call = {
Return() Return()

View file

@ -10,7 +10,7 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
--> $DIR/arg_inplace_observe_during.rs:LL:CC --> $DIR/arg_inplace_observe_during.rs:LL:CC
| |
LL | / mir! { LL | / mir! {
LL | | let unit: (); LL | | let _unit: ();
LL | | { LL | | {
LL | | let non_copy = S(42); LL | | let non_copy = S(42);
... | ... |
@ -27,8 +27,8 @@ LL | x.0 = 0;
note: inside `main` note: inside `main`
--> $DIR/arg_inplace_observe_during.rs:LL:CC --> $DIR/arg_inplace_observe_during.rs:LL:CC
| |
LL | Call(unit, after_call, change_arg(Move(*ptr), ptr)) LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info)
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View file

@ -12,7 +12,7 @@ help: the accessed tag <TAG> was created here
--> $DIR/arg_inplace_observe_during.rs:LL:CC --> $DIR/arg_inplace_observe_during.rs:LL:CC
| |
LL | / mir! { LL | / mir! {
LL | | let unit: (); LL | | let _unit: ();
LL | | { LL | | {
LL | | let non_copy = S(42); LL | | let non_copy = S(42);
... | ... |
@ -29,8 +29,8 @@ LL | x.0 = 0;
note: inside `main` note: inside `main`
--> $DIR/arg_inplace_observe_during.rs:LL:CC --> $DIR/arg_inplace_observe_during.rs:LL:CC
| |
LL | Call(unit, after_call, change_arg(Move(*ptr), ptr)) LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info)
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View file

@ -11,8 +11,8 @@ LL | unsafe { ptr.read() };
note: inside `main` note: inside `main`
--> $DIR/return_pointer_aliasing.rs:LL:CC --> $DIR/return_pointer_aliasing.rs:LL:CC
| |
LL | Call(*ptr, after_call, myfun(ptr)) LL | Call(*ptr = myfun(ptr), after_call)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View file

@ -15,7 +15,7 @@ pub fn main() {
let ptr = &raw mut x; let ptr = &raw mut x;
// We arrange for `myfun` to have a pointer that aliases // We arrange for `myfun` to have a pointer that aliases
// its return place. Even just reading from that pointer is UB. // its return place. Even just reading from that pointer is UB.
Call(*ptr, after_call, myfun(ptr)) Call(*ptr = myfun(ptr), after_call)
} }
after_call = { after_call = {

View file

@ -27,8 +27,8 @@ LL | unsafe { ptr.read() };
note: inside `main` note: inside `main`
--> $DIR/return_pointer_aliasing.rs:LL:CC --> $DIR/return_pointer_aliasing.rs:LL:CC
| |
LL | Call(*ptr, after_call, myfun(ptr)) LL | Call(*ptr = myfun(ptr), after_call)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info)
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View file

@ -29,8 +29,8 @@ LL | unsafe { ptr.read() };
note: inside `main` note: inside `main`
--> $DIR/return_pointer_aliasing.rs:LL:CC --> $DIR/return_pointer_aliasing.rs:LL:CC
| |
LL | Call(*ptr, after_call, myfun(ptr)) LL | Call(*ptr = myfun(ptr), after_call)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info)
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View file

@ -9,11 +9,11 @@ use std::intrinsics::mir::*;
pub fn main() { pub fn main() {
mir! { mir! {
{ {
let x = 0; let _x = 0;
let ptr = &raw mut x; let ptr = &raw mut _x;
// We arrange for `myfun` to have a pointer that aliases // We arrange for `myfun` to have a pointer that aliases
// its return place. Even just reading from that pointer is UB. // its return place. Even just reading from that pointer is UB.
Call(x, after_call, myfun(ptr)) Call(_x = myfun(ptr), after_call)
} }
after_call = { after_call = {

View file

@ -13,8 +13,8 @@ help: the accessed tag <TAG> was created here
| |
LL | / mir! { LL | / mir! {
LL | | { LL | | {
LL | | let x = 0; LL | | let _x = 0;
LL | | let ptr = &raw mut x; LL | | let ptr = &raw mut _x;
... | ... |
LL | | } LL | | }
LL | | } LL | | }
@ -29,8 +29,8 @@ LL | unsafe { ptr.write(0) };
note: inside `main` note: inside `main`
--> $DIR/return_pointer_aliasing2.rs:LL:CC --> $DIR/return_pointer_aliasing2.rs:LL:CC
| |
LL | Call(x, after_call, myfun(ptr)) LL | Call(_x = myfun(ptr), after_call)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info)
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View file

@ -11,7 +11,7 @@ pub fn main() {
{ {
let x = 0; let x = 0;
let ptr = &raw mut x; let ptr = &raw mut x;
Call(*ptr, after_call, myfun()) Call(*ptr = myfun(), after_call)
} }
after_call = { after_call = {

View file

@ -12,7 +12,7 @@ fn ident<T>(t: T) -> T {
fn direct_call(x: i32) -> i32 { fn direct_call(x: i32) -> i32 {
mir!( mir!(
{ {
Call(RET, retblock, ident(x)) Call(RET = ident(x), retblock)
} }
retblock = { retblock = {
@ -26,7 +26,7 @@ fn direct_call(x: i32) -> i32 {
fn indirect_call(x: i32, f: fn(i32) -> i32) -> i32 { fn indirect_call(x: i32, f: fn(i32) -> i32) -> i32 {
mir!( mir!(
{ {
Call(RET, retblock, f(x)) Call(RET = f(x), retblock)
} }
retblock = { retblock = {

View file

@ -21,11 +21,11 @@ fn f() -> bool {
let b = a; let b = a;
// We cannot propagate the place `a`. // We cannot propagate the place `a`.
let r2 = &b; let r2 = &b;
Call(RET, next, cmp_ref(r1, r2)) Call(RET = cmp_ref(r1, r2), next)
} }
next = { next = {
// But we can propagate the value `a`. // But we can propagate the value `a`.
Call(RET, ret, opaque(b)) Call(RET = opaque(b), ret)
} }
ret = { ret = {
Return() Return()

View file

@ -13,11 +13,11 @@ struct NotCopy(bool);
fn f(_1: NotCopy) { fn f(_1: NotCopy) {
mir!({ mir!({
let _2 = _1; let _2 = _1;
Call(RET, bb1, opaque(Move(_1))) Call(RET = opaque(Move(_1)), bb1)
} }
bb1 = { bb1 = {
let _3 = Move(_2); let _3 = Move(_2);
Call(RET, bb2, opaque(_3)) Call(RET = opaque(_3), bb2)
} }
bb2 = { bb2 = {
Return() Return()

View file

@ -17,10 +17,10 @@ fn f(a: Foo) -> bool {
let b = a; let b = a;
// This is a move out of a copy, so must become a copy of `a.0`. // This is a move out of a copy, so must become a copy of `a.0`.
let c = Move(b.0); let c = Move(b.0);
Call(RET, bb1, opaque(Move(a))) Call(RET = opaque(Move(a)), bb1)
} }
bb1 = { bb1 = {
Call(RET, ret, opaque(Move(c))) Call(RET = opaque(Move(c)), ret)
} }
ret = { ret = {
Return() Return()

View file

@ -426,7 +426,7 @@ fn multiple_storage() {
// As there are multiple `StorageLive` statements for `x`, we cannot know if this `z`'s // As there are multiple `StorageLive` statements for `x`, we cannot know if this `z`'s
// pointer address is the address of `x`, so do nothing. // pointer address is the address of `x`, so do nothing.
let y = *z; let y = *z;
Call(RET, retblock, opaque(y)) Call(RET = opaque(y), retblock)
} }
retblock = { retblock = {
@ -452,7 +452,7 @@ fn dominate_storage() {
} }
bb1 = { bb1 = {
let c = *r; let c = *r;
Call(RET, bb2, opaque(c)) Call(RET = opaque(c), bb2)
} }
bb2 = { bb2 = {
StorageDead(x); StorageDead(x);
@ -486,18 +486,18 @@ fn maybe_dead(m: bool) {
bb1 = { bb1 = {
StorageDead(x); StorageDead(x);
StorageDead(y); StorageDead(y);
Call(RET, bb2, opaque(u)) Call(RET = opaque(u), bb2)
} }
bb2 = { bb2 = {
// As `x` may be `StorageDead`, `a` may be dangling, so we do nothing. // As `x` may be `StorageDead`, `a` may be dangling, so we do nothing.
let z = *a; let z = *a;
Call(RET, bb3, opaque(z)) Call(RET = opaque(z), bb3)
} }
bb3 = { bb3 = {
// As `y` may be `StorageDead`, `b` may be dangling, so we do nothing. // As `y` may be `StorageDead`, `b` may be dangling, so we do nothing.
// This implies that we also do not substitute `b` in `bb0`. // This implies that we also do not substitute `b` in `bb0`.
let t = *b; let t = *b;
Call(RET, retblock, opaque(t)) Call(RET = opaque(t), retblock)
} }
retblock = { retblock = {
Return() Return()