4444//! if you want your MIR to be modified by the full MIR pipeline, or `#![custom_mir(dialect =
4545//! "runtime", phase = "optimized")] if you don't.
4646//!
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
4849//!
4950//! The input to the [`mir!`] macro is:
5051//!
99100//! Return()
100101//! })
101102//! }
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+ //! }
102127//! ```
103128//!
104129//! We can also set off compilation failures that happen in sufficiently late stages of the
195220//!
196221//! #### Terminators
197222//!
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.
199228//! - `match some_int_operand` becomes a `SwitchInt`. Each arm should be `literal => basic_block`
200229//! - The exception is the last arm, which must be `_ => basic_block` and corresponds to the
201230//! 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)`.
202233//!
203234
204235#![ unstable(
@@ -223,6 +254,10 @@ macro_rules! define {
223254
224255define ! ( "mir_return" , fn Return ( ) -> BasicBlock ) ;
225256define ! ( "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 ) ) ;
226261define ! ( "mir_retag" , fn Retag <T >( place: T ) ) ;
227262define ! ( "mir_retag_raw" , fn RetagRaw <T >( place: T ) ) ;
228263define ! ( "mir_move" , fn Move <T >( place: T ) -> T ) ;
0 commit comments