44
44
//! if you want your MIR to be modified by the full MIR pipeline, or `#![custom_mir(dialect =
45
45
//! "runtime", phase = "optimized")] if you don't.
46
46
//!
47
- //! [dialect docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.MirPhase.html
47
+ //! [dialect docs]:
48
+ //! https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.MirPhase.html
48
49
//!
49
50
//! The input to the [`mir!`] macro is:
50
51
//!
99
100
//! Return()
100
101
//! })
101
102
//! }
103
+ //!
104
+ //! #[custom_mir(dialect = "runtime", phase = "optimized")]
105
+ //! fn push_and_pop<T>(v: &mut Vec<T>, value: T) {
106
+ //! mir!(
107
+ //! let unused;
108
+ //! let popped;
109
+ //!
110
+ //! {
111
+ //! Call(unused, pop, Vec::push(v, value))
112
+ //! }
113
+ //!
114
+ //! pop = {
115
+ //! Call(popped, drop, Vec::pop(v))
116
+ //! }
117
+ //!
118
+ //! drop = {
119
+ //! Drop(popped, ret)
120
+ //! }
121
+ //!
122
+ //! ret = {
123
+ //! Return()
124
+ //! }
125
+ //! )
126
+ //! }
102
127
//! ```
103
128
//!
104
129
//! We can also set off compilation failures that happen in sufficiently late stages of the
195
220
//!
196
221
//! #### Terminators
197
222
//!
198
- //! - [`Goto`] and [`Return`] have associated functions.
223
+ //! Custom MIR does not currently support cleanup blocks or non-trivial unwind paths. As such, there
224
+ //! are no resume and abort terminators, and terminators that might unwind do not have any way to
225
+ //! indicate the unwind block.
226
+ //!
227
+ //! - [`Goto`], [`Return`], [`Unreachable`], [`Drop`](Drop()), and [`DropAndReplace`] have associated functions.
199
228
//! - `match some_int_operand` becomes a `SwitchInt`. Each arm should be `literal => basic_block`
200
229
//! - The exception is the last arm, which must be `_ => basic_block` and corresponds to the
201
230
//! otherwise branch.
231
+ //! - [`Call`] has an associated function as well. The third argument of this function is a normal
232
+ //! function call expresion, for example `my_other_function(a, 5)`.
202
233
//!
203
234
204
235
#![ unstable(
@@ -223,6 +254,10 @@ macro_rules! define {
223
254
224
255
define ! ( "mir_return" , fn Return ( ) -> BasicBlock ) ;
225
256
define ! ( "mir_goto" , fn Goto ( destination: BasicBlock ) -> BasicBlock ) ;
257
+ define ! ( "mir_unreachable" , fn Unreachable ( ) -> BasicBlock ) ;
258
+ define ! ( "mir_drop" , fn Drop <T >( place: T , goto: BasicBlock ) ) ;
259
+ define ! ( "mir_drop_and_replace" , fn DropAndReplace <T >( place: T , value: T , goto: BasicBlock ) ) ;
260
+ define ! ( "mir_call" , fn Call <T >( place: T , goto: BasicBlock , call: T ) ) ;
226
261
define ! ( "mir_retag" , fn Retag <T >( place: T ) ) ;
227
262
define ! ( "mir_retag_raw" , fn RetagRaw <T >( place: T ) ) ;
228
263
define ! ( "mir_move" , fn Move <T >( place: T ) -> T ) ;
0 commit comments