| @@ -31,8 +31,8 @@ lower → evidence → simplify ⇄ fuse ⇄ specialise → cpr → trmc → [na |
| 31 | 31 | ### The simplifier (issue #196) |
| 32 | 32 | To a fixed point, per function: |
| 33 | 33 | |
| 34 | | −- **Inlining:** a direct call of a small non-recursive function (a node-count threshold), or of a known lambda called once, becomes the body; a call in tail position stays in tail position. Wrappers (a function that only calls another) are always inlined. Recursive functions are never inlined. Inlining stays **within a module** (ADR 0029): a unit's C must not come to depend on another module's body, or an edit there would recompile it — cross-module calls are specialisation's and fusion's business (issues #197, #198), whose copies have a unit of their own. |
| 35 | | −- **Case-of-known-constructor:** a `switch` on a value built in the same function takes its branch at compile time; a projection of a known construction becomes the field. |
| 34 | +- **Inlining:** a direct call of a small non-recursive function (a node-count threshold), or of a known lambda called once, becomes the body; a call in tail position stays in tail position. Wrappers (a function that only calls another) are always inlined. Recursive functions are never inlined. Inlining stays **within a module** (ADR 0029): a unit's C must not come to depend on another module's body, or an edit there would recompile it — with two exceptions: generated code (dictionaries, the passes' copies) has no module and may inline anything, and **std's functions may be inlined anywhere** (std ships with the toolchain, so its units' stability is the toolchain's own). Other cross-module calls are specialisation's and fusion's business (issues #197, #198), whose copies have a unit of their own. |
| 35 | +- **Case-of-known-constructor:** a `switch` on a value built in the same function takes its branch at compile time; a projection of a known construction becomes the field. **Case-of-case:** a `switch` on a value that a nested block computed by a `switch` moves into the inner arms (the inner block pure and panic-free, the scrutinee used only there), where each arm's construction is then known — this is what dissolves a stream-fused pipeline's per-pull `Step` blocks (issue #199). |
| 36 | 36 | - **Dead lets and sinking:** a `let` of a pure value nothing uses is removed; a pure `let` sinks toward its single use — never across an effect, a `perform` or a `handle`. (Sinking pure code past a call is sound: pure code is unobservable, and its divergence is imprecise, below. The C backend's yield checks come later, on code whose effect order is fixed here.) |
| 37 | 37 | - **Copy propagation:** `let v = u` substitutes. |
| 38 | 38 | |
| @@ -69,7 +69,7 @@ A function whose exit paths all build the same tuple or single-constructor value |
| 69 | 69 | TRMC'd functions are never eligible (their returns go through contexts), and `@fip` functions keep their meaning: a worker builds nothing either. |
| 70 | 70 | |
| 71 | 71 | ### std/iter (issue #199) |
| 72 | | −Not a pass: a library the passes optimise well. `std/iter`'s `Iter<a>` is an existential state with a step function (ADR 0041), over `type Step<s, a> { Done, Skip(s), Yield(a, s) }`. A pipeline `range(1, n) |> map(f) |> filter(p) |> fold(0, add)` then compiles to one loop by specialisation, inlining and case-of-known-constructor on `Step` — stream fusion (Coutts, Leshchinskiy and Stewart, 2007) without rewrite rules. Effects are allowed and run in pull order: a stage's function runs when the element is pulled. Whether the step's effect row is a parameter of `Iter` or existential is an implementation detail (ADR 0041 has no row-kind indices). Done when the loop allocates nothing, by the leak oracle's allocation counts. |
| 72 | +Not a pass: a library the passes optimise well. `std/iter`'s `Iter<a, e>` is an existential state with a step function (ADR 0041), over `type Step<s, a> { Done, Skip(s), Yield(a, s) }`; the step's effect row is a parameter carried through unchanged (ADR 0041's Revision 1), so a stage's function may perform effects and runs when the element is pulled. A pipeline `range(1, n) |> map(f) |> filter(p) |> fold(0, add)` then compiles to one loop by specialisation, inlining, case-of-known-constructor and case-of-case on `Step` — stream fusion (Coutts, Leshchinskiy and Stewart, 2007) without rewrite rules. Done when the loop allocates nothing, by the leak oracle's allocation counts. |
| 73 | 73 | |
| 74 | 74 | ## Consequences |
| 75 | 75 | - The pipeline order changes: TRMC after optimisation, evidence before it (natively). ADR 0039 gains a note in the implementing PR. The optimiser never sees Perceus or TRMC nodes. |