kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit 54fdf61dc669598af59c54ec278002f1686ea817
parent d03eb4c8a8580486122ee065c08a6e391489e6f5
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Mon,  1 Jun 2026 20:04:25 -0700

plan: record Track 6.2 (fold.{c,h} extraction) as landed

Diffstat:
Mdoc/plan/CODEGEN.md | 32++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/doc/plan/CODEGEN.md b/doc/plan/CODEGEN.md @@ -53,8 +53,9 @@ Between them sits the translation layer (`src/cg/value.c`, `arith.c`, `memory.c` | `5e1335d` | **4 (FP_REM)** | Removed the `CFREE_CG_FP_REM` façade (always-panic; only dead callers). FP remainder is a libcall the frontend emits. | | `917ffe9` | **2 (AsmDir)** | Deleted internal `AsmDir` + `api_map_asm_dir`; `AsmConstraint.dir` and backends use public `CfreeCgAsmDir`. | | `a2f6367` | **2 (Atomic/Order)** | Deleted internal `AtomicOp`/`MemOrder` + `api_map_atomic_op`/`api_map_mem_order`; **both** the semantic `CgTarget` and physical `NativeTarget` atomic hooks, the recorder+opt IR aux, and the interpreter now carry public `CfreeCgAtomicOp`/`CfreeCgMemOrder`. | +| `d03eb4c` | **6.2** | Isolated the `-O0` semantic peephole into `src/cg/fold.{c,h}`: integer constant folding, the `SV_CMP` delayed-compare lifecycle, the (gated-off) `SV_ARITH` delayed-arith lifecycle, and const-local store-to-load forwarding with its invalidation boundaries. `fold.h` is the documented contract, re-exported via `internal.h`; `value.c` keeps stack discipline, `api_lvalue_addr`, and the enum-mapping helpers. Pure relocation, no behavior change. `doc/CODEGEN.md` updated. | -So **Tracks 1a/1d, 5, 3a are done; Track 2 is 2/3 done** (the 3 identical enums); **Track 4** +So **Tracks 1a/1d, 5, 3a, 6.2 are done; Track 2 is 2/3 done** (the 3 identical enums); **Track 4** has FP_REM removed. ### Caveats / follow-ups discovered while doing the above @@ -222,18 +223,21 @@ The semantic layer is also a `-O0` peephole optimizer — a **kept feature** (Pr - **Live:** scalar store-to-load forwarding (`api_local_const_*`). ### Action -1. **6.2 — Extract the live peephole into `src/cg/fold.c` + `fold.h`** with a documented - contract: integer fold helpers, the `SV_CMP` lifecycle, and const-local forwarding with - its invalidation boundaries (`api_local_const_memory_boundary`/`_control_boundary`/ - `_address_taken`). Op families call into `fold.h` instead of reaching into `value.c` - internals. **This settles `ApiSValue`'s shape — do it before Track 7, and it eases the - Track 2 binop/cmp split (the fold layer is the entangled part there).** +1. **6.2 — Extract the live peephole into `src/cg/fold.c` + `fold.h`** — **DONE** (`d03eb4c`). + The documented contract covers the integer fold helpers, the `SV_CMP` lifecycle, and + const-local forwarding with its invalidation boundaries + (`api_local_const_memory_boundary`/`_control_boundary`/`_address_taken`). The (gated-off) + `SV_ARITH` machinery was moved alongside it so 6.3 is a gate flip, not a code move. Op + families call into `fold.h`; `value.c` keeps the stack discipline. `ApiSValue`'s shape is + now settled for Track 7, and the Track 2 binop/cmp split has the fold layer isolated. 2. **6.3 — Re-enable delayed arith *after* Track 7.** Restore the gate - (`g && !flags && api_foldable_int_type(...)`); bring `api_make_arith_*`/ - `api_materialize_arith_to`/`api_release_arith`/the fold-chain + identity-collapse helpers - under `fold.c`; verify they compose with the place/value model. -3. **Fix [doc/CODEGEN.md](../CODEGEN.md)** to match the restored, isolated peephole (it - currently documents delayed arith as live). + (`g && !flags && api_foldable_int_type(...)`) in `api_can_delay_int_arith` (now in + `fold.c`); the `api_make_arith_*`/`api_materialize_arith_to`/`api_release_arith`/the + fold-chain + identity-collapse helpers already live under `fold.c` — verify they compose + with the place/value model. +3. **Fix [doc/CODEGEN.md](../CODEGEN.md)** to match the restored, isolated peephole. 6.2 + already corrected it to introduce `fold.c` and mark delayed arith gated-off; 6.3 should + flip that note to "live" once re-enabled. --- @@ -307,8 +311,8 @@ red-green per op on the toy corpus + C frontend; `-O0` quality is not a gate (de ## Recommended sequencing (remaining) 1. **Track 1c** completeness audit + tests (small, no behavior change). -2. **Track 6.2** — isolate the live fold layer into `fold.c`. Settles `ApiSValue` and is a - clean dependency for both the Track 2 binop/cmp split and Track 7. +2. **Track 6.2** — isolate the live fold layer into `fold.c`. **DONE (`d03eb4c`).** Settles + `ApiSValue` and is a clean dependency for both the Track 2 binop/cmp split and Track 7. 3. **Track 2 binop/cmp split** — independent of 6.2 but cleaner after it (shares the fold layer). Also fixes the lossy FP compare. 4. **Track 7** (place/value) — the centerpiece; removes the EA rider; do it red-green.