1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Phase 6 MIR optimization passes.
//!
//! Each pass is a pure function `MirProgram → MirProgram`, so the
//! pipeline composes through plain function chaining
//! (`branch_collapse(bool_match_to_if(const_fold(program)))`).
//! The VM compiler wires them up in
//! `vm::compiler::compile_program_with_mir_fallback`.
//!
//! ## Pass directory
//!
//! - [`const_fold`] (wave 5) — evaluate `BinOp` / `Neg` over
//! literal operands at compile time.
//! - [`dead_code`] (wave 6) — drop `Let { value: <pure>, body }`
//! bindings that `body` never reads.
//! - [`inline`] (wave 7) — replace nullary literal-only fn
//! calls with the callee's literal.
//! - [`algebraic`] (wave 8) — rewrite Int identity shapes
//! (`x + 0`, `x * 1`, `Neg(Neg(x))`).
//! - [`bool_match`] (wave 9) — lift two-arm `Bool` `Match`
//! into `MirExpr::IfThenElse`.
//! - [`branch_collapse`] (wave 10) — drop the dead branch of
//! an `IfThenElse` whose `cond` folded to a literal `Bool`.
//!
//! ## Cascades
//!
//! Two passes that look orthogonal compose in interesting ways
//! end-to-end:
//!
//! - `const_fold` → `algebraic` → `dead_code`: `let x = 1 + 0; 7`
//! folds the value, the symbolic identity drops the BinOp,
//! DCE drops the unused binding.
//! - `const_fold` → `bool_match` → `branch_collapse`:
//! `match (5 == 5) { true → A; false → B }` folds the
//! subject to `true`, lifts the match to `if true { A }
//! else { B }`, collapses to `A`.
//!
//! ## What this layer doesn't transform (deferred)
//!
//! - General inlining with param substitution.
//! - String concatenation folding (would need intern-side
//! allocation policy; the VM does it efficiently at runtime
//! already).
//! - Match arms (would require pattern → literal
//! classification plumbing; defer until there's a real perf
//! signal).
//! - CSE / loop-invariant hoisting — future waves.
pub
pub use algebraic_simplify;
pub use ;
pub use bool_match_to_if;
pub use branch_collapse;
pub use const_fold;
pub use dead_code;
pub use inline_nullary_literals;
pub use own_param_refine;
/// The canonical Core-MIR optimization pipeline: the passes applied
/// in dependency order
/// (`inline → const_fold → algebraic → bool_match → branch_collapse →
/// dead_code → own_param`). Every backend that runs the optimizer calls
/// this single entry, so the pass set and their order live in one place
/// instead of being re-nested per call site. `lower_program` produces
/// the input.
///
/// `own_param_refine` runs LAST: it reads the final slot↔`LocalId`
/// mapping (after any inlining that mints fresh locals) so its
/// interprocedural Vector/Map-param un-flagging keys off slots that
/// won't shift under a later pass — avoiding the
/// `aliased_slots`-vs-`LocalId` desync class.