Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2bca4b5

Browse files
authored
Rollup merge of rust-lang#115000 - RalfJung:custom-mir-call, r=compiler-errors,JakobDegen
custom_mir: change Call() terminator syntax to something more readable I find our current syntax very hard to read -- I cannot even remember the order of arguments, and having the "next block" *before* the actual function call is very counter-intuitive IMO. So I suggest we use `Call(ret_val = function(v), next_block)` instead. r? `@JakobDegen`
2 parents 4542711 + 7a63466 commit 2bca4b5

22 files changed

+62
-62
lines changed

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

Lines changed: 9 additions & 10 deletions
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

0 commit comments

Comments
 (0)