Skip to content

Commit 7a63466

Browse files
committed
custom_mir: change Call() terminator syntax to something more readable
1 parent d06ca0f commit 7a63466

22 files changed

+62
-62
lines changed

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

+9-10
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
6161
})
6262
},
6363
@call("mir_call", args) => {
64-
let destination = self.parse_place(args[0])?;
65-
let target = self.parse_block(args[1])?;
66-
self.parse_call(args[2], destination, target)
64+
self.parse_call(args)
6765
},
6866
ExprKind::Match { scrutinee, arms, .. } => {
6967
let discr = self.parse_operand(*scrutinee)?;
@@ -109,13 +107,14 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
109107
Ok(SwitchTargets::new(values.into_iter().zip(targets), otherwise))
110108
}
111109

112-
fn parse_call(
113-
&self,
114-
expr_id: ExprId,
115-
destination: Place<'tcx>,
116-
target: BasicBlock,
117-
) -> PResult<TerminatorKind<'tcx>> {
118-
parse_by_kind!(self, expr_id, _, "function call",
110+
fn parse_call(&self, args: &[ExprId]) -> PResult<TerminatorKind<'tcx>> {
111+
let (destination, call) = parse_by_kind!(self, args[0], _, "function call",
112+
ExprKind::Assign { lhs, rhs } => (*lhs, *rhs),
113+
);
114+
let destination = self.parse_place(destination)?;
115+
let target = self.parse_block(args[1])?;
116+
117+
parse_by_kind!(self, call, _, "function call",
119118
ExprKind::Call { fun, args, from_hir_call, fn_span, .. } => {
120119
let fun = self.parse_operand(*fun)?;
121120
let args = args

library/core/src/intrinsics/mir.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,18 @@
104104
//! }
105105
//!
106106
//! #[custom_mir(dialect = "runtime", phase = "optimized")]
107+
#![cfg_attr(bootstrap, doc = "#[cfg(any())]")] // disable the following function in doctests when `bootstrap` is set
107108
//! fn push_and_pop<T>(v: &mut Vec<T>, value: T) {
108109
//! mir!(
109-
//! let unused;
110+
//! let _unused;
110111
//! let popped;
111112
//!
112113
//! {
113-
//! Call(unused, pop, Vec::push(v, value))
114+
//! Call(_unused = Vec::push(v, value), pop)
114115
//! }
115116
//!
116117
//! pop = {
117-
//! Call(popped, drop, Vec::pop(v))
118+
//! Call(popped = Vec::pop(v), drop)
118119
//! }
119120
//!
120121
//! drop = {
@@ -275,7 +276,7 @@ define!("mir_return", fn Return() -> BasicBlock);
275276
define!("mir_goto", fn Goto(destination: BasicBlock) -> BasicBlock);
276277
define!("mir_unreachable", fn Unreachable() -> BasicBlock);
277278
define!("mir_drop", fn Drop<T>(place: T, goto: BasicBlock));
278-
define!("mir_call", fn Call<T>(place: T, goto: BasicBlock, call: T));
279+
define!("mir_call", fn Call(call: (), goto: BasicBlock));
279280
define!("mir_storage_live", fn StorageLive<T>(local: T));
280281
define!("mir_storage_dead", fn StorageDead<T>(local: T));
281282
define!("mir_deinit", fn Deinit<T>(place: T));

src/tools/miri/tests/fail/function_calls/arg_inplace_mutate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ pub struct S(i32);
88
#[custom_mir(dialect = "runtime", phase = "optimized")]
99
fn main() {
1010
mir! {
11-
let unit: ();
11+
let _unit: ();
1212
{
1313
let non_copy = S(42);
1414
let ptr = std::ptr::addr_of_mut!(non_copy);
1515
// Inside `callee`, the first argument and `*ptr` are basically
1616
// aliasing places!
17-
Call(unit, after_call, callee(Move(*ptr), ptr))
17+
Call(_unit = callee(Move(*ptr), ptr), after_call)
1818
}
1919
after_call = {
2020
Return()

src/tools/miri/tests/fail/function_calls/arg_inplace_mutate.stack.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
1010
--> $DIR/arg_inplace_mutate.rs:LL:CC
1111
|
1212
LL | / mir! {
13-
LL | | let unit: ();
13+
LL | | let _unit: ();
1414
LL | | {
1515
LL | | let non_copy = S(42);
1616
... |
@@ -27,8 +27,8 @@ LL | unsafe { ptr.write(S(0)) };
2727
note: inside `main`
2828
--> $DIR/arg_inplace_mutate.rs:LL:CC
2929
|
30-
LL | Call(unit, after_call, callee(Move(*ptr), ptr))
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
LL | Call(_unit = callee(Move(*ptr), ptr), after_call)
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232
= 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)
3333

3434
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

src/tools/miri/tests/fail/function_calls/arg_inplace_mutate.tree.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ help: the accessed tag <TAG> was created here
1212
--> $DIR/arg_inplace_mutate.rs:LL:CC
1313
|
1414
LL | / mir! {
15-
LL | | let unit: ();
15+
LL | | let _unit: ();
1616
LL | | {
1717
LL | | let non_copy = S(42);
1818
... |
@@ -29,8 +29,8 @@ LL | unsafe { ptr.write(S(0)) };
2929
note: inside `main`
3030
--> $DIR/arg_inplace_mutate.rs:LL:CC
3131
|
32-
LL | Call(unit, after_call, callee(Move(*ptr), ptr))
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
LL | Call(_unit = callee(Move(*ptr), ptr), after_call)
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
= 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)
3535

3636
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

src/tools/miri/tests/fail/function_calls/arg_inplace_observe_after.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ pub struct S(i32);
66
#[custom_mir(dialect = "runtime", phase = "optimized")]
77
fn main() {
88
mir! {
9-
let unit: ();
9+
let _unit: ();
1010
let _observe: i32;
1111
{
1212
let non_copy = S(42);
1313
// This could change `non_copy` in-place
14-
Call(unit, after_call, change_arg(Move(non_copy)))
14+
Call(_unit = change_arg(Move(non_copy)), after_call)
1515
}
1616
after_call = {
1717
// So now we must not be allowed to observe non-copy again.

src/tools/miri/tests/fail/function_calls/arg_inplace_observe_during.none.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ LL | unsafe { ptr.read() };
1111
note: inside `main`
1212
--> $DIR/arg_inplace_observe_during.rs:LL:CC
1313
|
14-
LL | Call(unit, after_call, change_arg(Move(*ptr), ptr))
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call)
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616

1717
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1818

src/tools/miri/tests/fail/function_calls/arg_inplace_observe_during.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ pub struct S(i32);
99
#[custom_mir(dialect = "runtime", phase = "optimized")]
1010
fn main() {
1111
mir! {
12-
let unit: ();
12+
let _unit: ();
1313
{
1414
let non_copy = S(42);
1515
let ptr = std::ptr::addr_of_mut!(non_copy);
1616
// This could change `non_copy` in-place
17-
Call(unit, after_call, change_arg(Move(*ptr), ptr))
17+
Call(_unit = change_arg(Move(*ptr), ptr), after_call)
1818
}
1919
after_call = {
2020
Return()

src/tools/miri/tests/fail/function_calls/arg_inplace_observe_during.stack.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
1010
--> $DIR/arg_inplace_observe_during.rs:LL:CC
1111
|
1212
LL | / mir! {
13-
LL | | let unit: ();
13+
LL | | let _unit: ();
1414
LL | | {
1515
LL | | let non_copy = S(42);
1616
... |
@@ -27,8 +27,8 @@ LL | x.0 = 0;
2727
note: inside `main`
2828
--> $DIR/arg_inplace_observe_during.rs:LL:CC
2929
|
30-
LL | Call(unit, after_call, change_arg(Move(*ptr), ptr))
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call)
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232
= 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)
3333

3434
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

src/tools/miri/tests/fail/function_calls/arg_inplace_observe_during.tree.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ help: the accessed tag <TAG> was created here
1212
--> $DIR/arg_inplace_observe_during.rs:LL:CC
1313
|
1414
LL | / mir! {
15-
LL | | let unit: ();
15+
LL | | let _unit: ();
1616
LL | | {
1717
LL | | let non_copy = S(42);
1818
... |
@@ -29,8 +29,8 @@ LL | x.0 = 0;
2929
note: inside `main`
3030
--> $DIR/arg_inplace_observe_during.rs:LL:CC
3131
|
32-
LL | Call(unit, after_call, change_arg(Move(*ptr), ptr))
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call)
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
= 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)
3535

3636
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

src/tools/miri/tests/fail/function_calls/return_pointer_aliasing.none.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ LL | unsafe { ptr.read() };
1111
note: inside `main`
1212
--> $DIR/return_pointer_aliasing.rs:LL:CC
1313
|
14-
LL | Call(*ptr, after_call, myfun(ptr))
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
LL | Call(*ptr = myfun(ptr), after_call)
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616

1717
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1818

src/tools/miri/tests/fail/function_calls/return_pointer_aliasing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn main() {
1515
let ptr = &raw mut x;
1616
// We arrange for `myfun` to have a pointer that aliases
1717
// its return place. Even just reading from that pointer is UB.
18-
Call(*ptr, after_call, myfun(ptr))
18+
Call(*ptr = myfun(ptr), after_call)
1919
}
2020

2121
after_call = {

src/tools/miri/tests/fail/function_calls/return_pointer_aliasing.stack.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ LL | unsafe { ptr.read() };
2727
note: inside `main`
2828
--> $DIR/return_pointer_aliasing.rs:LL:CC
2929
|
30-
LL | Call(*ptr, after_call, myfun(ptr))
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
LL | Call(*ptr = myfun(ptr), after_call)
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232
= 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)
3333

3434
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

src/tools/miri/tests/fail/function_calls/return_pointer_aliasing.tree.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ LL | unsafe { ptr.read() };
2929
note: inside `main`
3030
--> $DIR/return_pointer_aliasing.rs:LL:CC
3131
|
32-
LL | Call(*ptr, after_call, myfun(ptr))
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
LL | Call(*ptr = myfun(ptr), after_call)
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
= 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)
3535

3636
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

src/tools/miri/tests/fail/function_calls/return_pointer_aliasing2.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use std::intrinsics::mir::*;
99
pub fn main() {
1010
mir! {
1111
{
12-
let x = 0;
13-
let ptr = &raw mut x;
12+
let _x = 0;
13+
let ptr = &raw mut _x;
1414
// We arrange for `myfun` to have a pointer that aliases
1515
// its return place. Even just reading from that pointer is UB.
16-
Call(x, after_call, myfun(ptr))
16+
Call(_x = myfun(ptr), after_call)
1717
}
1818

1919
after_call = {

src/tools/miri/tests/fail/function_calls/return_pointer_aliasing2.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ help: the accessed tag <TAG> was created here
1313
|
1414
LL | / mir! {
1515
LL | | {
16-
LL | | let x = 0;
17-
LL | | let ptr = &raw mut x;
16+
LL | | let _x = 0;
17+
LL | | let ptr = &raw mut _x;
1818
... |
1919
LL | | }
2020
LL | | }
@@ -29,8 +29,8 @@ LL | unsafe { ptr.write(0) };
2929
note: inside `main`
3030
--> $DIR/return_pointer_aliasing2.rs:LL:CC
3131
|
32-
LL | Call(x, after_call, myfun(ptr))
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
LL | Call(_x = myfun(ptr), after_call)
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
= 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)
3535

3636
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

src/tools/miri/tests/pass/function_calls/return_place_on_heap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn main() {
1111
{
1212
let x = 0;
1313
let ptr = &raw mut x;
14-
Call(*ptr, after_call, myfun())
14+
Call(*ptr = myfun(), after_call)
1515
}
1616

1717
after_call = {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn ident<T>(t: T) -> T {
1212
fn direct_call(x: i32) -> i32 {
1313
mir!(
1414
{
15-
Call(RET, retblock, ident(x))
15+
Call(RET = ident(x), retblock)
1616
}
1717

1818
retblock = {
@@ -26,7 +26,7 @@ fn direct_call(x: i32) -> i32 {
2626
fn indirect_call(x: i32, f: fn(i32) -> i32) -> i32 {
2727
mir!(
2828
{
29-
Call(RET, retblock, f(x))
29+
Call(RET = f(x), retblock)
3030
}
3131

3232
retblock = {

tests/mir-opt/copy-prop/borrowed_local.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ fn f() -> bool {
2121
let b = a;
2222
// We cannot propagate the place `a`.
2323
let r2 = &b;
24-
Call(RET, next, cmp_ref(r1, r2))
24+
Call(RET = cmp_ref(r1, r2), next)
2525
}
2626
next = {
2727
// But we can propagate the value `a`.
28-
Call(RET, ret, opaque(b))
28+
Call(RET = opaque(b), ret)
2929
}
3030
ret = {
3131
Return()

tests/mir-opt/copy-prop/custom_move_arg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ struct NotCopy(bool);
1313
fn f(_1: NotCopy) {
1414
mir!({
1515
let _2 = _1;
16-
Call(RET, bb1, opaque(Move(_1)))
16+
Call(RET = opaque(Move(_1)), bb1)
1717
}
1818
bb1 = {
1919
let _3 = Move(_2);
20-
Call(RET, bb2, opaque(_3))
20+
Call(RET = opaque(_3), bb2)
2121
}
2222
bb2 = {
2323
Return()

tests/mir-opt/copy-prop/move_projection.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ fn f(a: Foo) -> bool {
1717
let b = a;
1818
// This is a move out of a copy, so must become a copy of `a.0`.
1919
let c = Move(b.0);
20-
Call(RET, bb1, opaque(Move(a)))
20+
Call(RET = opaque(Move(a)), bb1)
2121
}
2222
bb1 = {
23-
Call(RET, ret, opaque(Move(c)))
23+
Call(RET = opaque(Move(c)), ret)
2424
}
2525
ret = {
2626
Return()

tests/mir-opt/reference_prop.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ fn multiple_storage() {
426426
// As there are multiple `StorageLive` statements for `x`, we cannot know if this `z`'s
427427
// pointer address is the address of `x`, so do nothing.
428428
let y = *z;
429-
Call(RET, retblock, opaque(y))
429+
Call(RET = opaque(y), retblock)
430430
}
431431

432432
retblock = {
@@ -452,7 +452,7 @@ fn dominate_storage() {
452452
}
453453
bb1 = {
454454
let c = *r;
455-
Call(RET, bb2, opaque(c))
455+
Call(RET = opaque(c), bb2)
456456
}
457457
bb2 = {
458458
StorageDead(x);
@@ -486,18 +486,18 @@ fn maybe_dead(m: bool) {
486486
bb1 = {
487487
StorageDead(x);
488488
StorageDead(y);
489-
Call(RET, bb2, opaque(u))
489+
Call(RET = opaque(u), bb2)
490490
}
491491
bb2 = {
492492
// As `x` may be `StorageDead`, `a` may be dangling, so we do nothing.
493493
let z = *a;
494-
Call(RET, bb3, opaque(z))
494+
Call(RET = opaque(z), bb3)
495495
}
496496
bb3 = {
497497
// As `y` may be `StorageDead`, `b` may be dangling, so we do nothing.
498498
// This implies that we also do not substitute `b` in `bb0`.
499499
let t = *b;
500-
Call(RET, retblock, opaque(t))
500+
Call(RET = opaque(t), retblock)
501501
}
502502
retblock = {
503503
Return()

0 commit comments

Comments
 (0)