Skip to content

Commit 02deaac

Browse files
committed
custom mir: make it clear what the return block is
1 parent 6bd0ab4 commit 02deaac

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

core/src/intrinsics/mir.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,22 @@
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!(
109110
//! let _unused;
110111
//! let popped;
111112
//!
112113
//! {
113-
//! Call(_unused = Vec::push(v, value), pop, UnwindContinue())
114+
//! Call(_unused = Vec::push(v, value), ReturnTo(pop), UnwindContinue())
114115
//! }
115116
//!
116117
//! pop = {
117-
//! Call(popped = Vec::pop(v), drop, UnwindContinue())
118+
//! Call(popped = Vec::pop(v), ReturnTo(drop), UnwindContinue())
118119
//! }
119120
//!
120121
//! drop = {
121-
//! Drop(popped, ret, UnwindContinue())
122+
//! Drop(popped, ReturnTo(ret), UnwindContinue())
122123
//! }
123124
//!
124125
//! ret = {
@@ -242,9 +243,8 @@
242243
//! - `match some_int_operand` becomes a `SwitchInt`. Each arm should be `literal => basic_block`
243244
//! - The exception is the last arm, which must be `_ => basic_block` and corresponds to the
244245
//! otherwise branch.
245-
//! - [`Call`] has an associated function as well. The third argument of this function is a normal
246-
//! function call expression, for example `my_other_function(a, 5)`.
247-
//!
246+
//! - [`Call`] has an associated function as well, with special syntax:
247+
//! `Call(ret_val = function(arg1, arg2, ...), ReturnTo(next_block), UnwindContinue())`.
248248
249249
#![unstable(
250250
feature = "custom_mir",
@@ -295,7 +295,7 @@ define!(
295295
define!(
296296
"mir_unwind_unreachable",
297297
/// An unwind action that triggers undefined behaviour.
298-
fn UnwindUnreachable() -> BasicBlock
298+
fn UnwindUnreachable()
299299
);
300300
define!(
301301
"mir_unwind_terminate",
@@ -310,12 +310,43 @@ define!(
310310
fn UnwindCleanup(goto: BasicBlock)
311311
);
312312

313+
// Return destination for `Call`
314+
define!("mir_return_to", fn ReturnTo(goto: BasicBlock));
315+
313316
// Terminators
314317
define!("mir_return", fn Return() -> BasicBlock);
315318
define!("mir_goto", fn Goto(destination: BasicBlock) -> BasicBlock);
316319
define!("mir_unreachable", fn Unreachable() -> BasicBlock);
317-
define!("mir_drop", fn Drop<T, U>(place: T, goto: BasicBlock, unwind_action: U));
318-
define!("mir_call", fn Call<U>(call: (), goto: BasicBlock, unwind_action: U));
320+
define!("mir_drop",
321+
/// Drop the contents of a place.
322+
///
323+
/// The first argument must be a place.
324+
///
325+
/// The second argument must be of the form `ReturnTo(bb)`, where `bb` is the basic block that
326+
/// will be jumped to after the destructor returns.
327+
///
328+
/// The third argument describes what happens on unwind. It can be one of:
329+
/// - [`UnwindContinue`]
330+
/// - [`UnwindUnreachable`]
331+
/// - [`UnwindTerminate`]
332+
/// - [`UnwindCleanup`]
333+
fn Drop<T>(place: T, goto: (), unwind_action: ())
334+
);
335+
define!("mir_call",
336+
/// Call a function.
337+
///
338+
/// The first argument must be of the form `ret_val = fun(arg1, arg2, ...)`.
339+
///
340+
/// The second argument must be of the form `ReturnTo(bb)`, where `bb` is the basic block that
341+
/// will be jumped to after the function returns.
342+
///
343+
/// The third argument describes what happens on unwind. It can be one of:
344+
/// - [`UnwindContinue`]
345+
/// - [`UnwindUnreachable`]
346+
/// - [`UnwindTerminate`]
347+
/// - [`UnwindCleanup`]
348+
fn Call(call: (), goto: (), unwind_action: ())
349+
);
319350
define!("mir_unwind_resume",
320351
/// A terminator that resumes the unwinding.
321352
fn UnwindResume()

0 commit comments

Comments
 (0)