| @@ -1,43 +1,43 @@ |
| 1 | 1 | # Code health audit (issue #62) |
| 2 | 2 | |
| 3 | | −> **Status.** This audit was written against `main` at `f2b02b7`, before the v1 feature stack (packages, FFI callbacks and bindgen, multi-parameter traits, HKT, derives, arrays, bigint, HTTP limits, `defer`, multi-shot) landed. Line numbers refer to that commit. Each finding's checkbox is ticked as the cleanliness PRs land; a finding or part of one that is deliberately not done carries a note saying why. Each finding a PR worked on carries a **Status** line saying what it did, per PR. PR 2 (core, Perceus, codegen) was checked against the v1 base after PR 1: generated C is byte-identical for every program of `tests/run`, `tests/stress`, `tests/bench` and `examples/http_demo` (one and three translation units), and `tilc core` prints the same Core, except for the intended changes its H1 and L3 entries name. PR 4 (driver, LSP, std, scripts) was checked against the base after PR 3, with the old and new `tilc` side by side: `check`, `core` and `build` (`TILC_C_UNITS=3`) print and generate the same thing (224 outputs, 56 C files) for every program of `tests/run`, `tests/stress`, `tests/bench` and both example programs, and `test` (interpreted and native) prints the same results for the four packages in the repository; the exceptions are the intended changes its M5, L1 and L4 entries name. |
| 3 | +> **Status.** This audit was written against `main` at `f2b02b7`, before the v1 feature stack (packages, FFI callbacks and bindgen, multi-parameter traits, HKT, derives, arrays, bigint, HTTP limits, `defer`, multi-shot) landed. Line numbers refer to that commit. Each finding's checkbox is ticked as the cleanliness PRs land; a finding or part of one that is deliberately not done carries a note saying why. Each finding a PR worked on carries a **Status** line saying what it did, per PR. PR 2 (core, Perceus, codegen) was checked against the v1 base after PR 1: generated C is byte-identical for every program of `tests/run`, `tests/stress`, `tests/bench` and `examples/http_demo` (one and three translation units), and `louise core` prints the same Core, except for the intended changes its H1 and L3 entries name. PR 4 (driver, LSP, std, scripts) was checked against the base after PR 3, with the old and new `louise` side by side: `check`, `core` and `build` (`LOUISE_C_UNITS=3`) print and generate the same thing (224 outputs, 56 C files) for every program of `tests/run`, `tests/stress`, `tests/bench` and both example programs, and `test` (interpreted and native) prints the same results for the four packages in the repository; the exceptions are the intended changes its M5, L1 and L4 entries name. |
| 4 | 4 | |
| 5 | 5 | ## After the four cleanliness PRs (issue #62) |
| 6 | 6 | |
| 7 | 7 | **What they did.** Every High and Medium finding is done, each part either fixed or left with a reason below. |
| 8 | | −- **One source of truth where the code had several:** one table of the runtime's externs, checked against std, the interpreter, `tilrt` and `tilrt.h` (H1); one crate of pure kernels and constants shared by the runtime, the interpreter and codegen (M3); one resolved table of the std items the back ends know, with a test of every constructor tag they build (M4); typed attributes, with diagnostics instead of crashes (H2); one decision of what a path names, for every command and the language server (M5). |
| 9 | | −- **Layering:** codegen no longer depends on `tilc_db`; the C build is `tilc_build`, which depends on the packages crate, `tilc_package`, not on the front end (M1); the interpreter is its own crate (M2). |
| 8 | +- **One source of truth where the code had several:** one table of the runtime's externs, checked against std, the interpreter, `louise_rt` and `louise_rt.h` (H1); one crate of pure kernels and constants shared by the runtime, the interpreter and codegen (M3); one resolved table of the std items the back ends know, with a test of every constructor tag they build (M4); typed attributes, with diagnostics instead of crashes (H2); one decision of what a path names, for every command and the language server (M5). |
| 9 | +- **Layering:** codegen no longer depends on `louise_db`; the C build is `louise_build`, which depends on the packages crate, `louise_package`, not on the front end (M1); the interpreter is its own crate (M2). |
| 10 | 10 | - **Size:** four of the five files over 1,200 lines, and the driver's `main.rs` (one module per command), are split along their sections, verbatim (M6; PR 4 for `main.rs`); one test kit and one pipeline instead of seven copies (M8). |
| 11 | | −- **Outside the audit, in PR 4:** `--offline` and `--locked` reach the package resolver as a value, not through a global `OnceLock`; `scripts/lib.sh` holds what `bench.sh`, `bench-compile.sh` and `stress.sh` repeated (the results table, the `//>` extraction), and `ci.sh` names its repeated `cargo run -p tilc` and sanitizer settings. |
| 11 | +- **Outside the audit, in PR 4:** `--offline` and `--locked` reach the package resolver as a value, not through a global `OnceLock`; `scripts/lib.sh` holds what `bench.sh`, `bench-compile.sh` and `stress.sh` repeated (the results table, the `//>` extraction), and `ci.sh` names its repeated `cargo run -p louise` and sanitizer settings. |
| 12 | 12 | - **Tests:** HTTP framing has unit and end-to-end tests of its rejecting paths (H3); every diagnostic code is asserted; the unifier and decision trees have direct tests; Perceus is verified on every debug build (M9). |
| 13 | 13 | - **Docs:** `runtime-abi.md` is the current ABI plus its history, and every ADR section has one status, which the index lists (M10). |
| 14 | 14 | - **Behaviour:** preserved, generated C byte-identical, except where an entry says otherwise: the bugs fixed (the module a path names in M5, a crashing native test passing `@should_panic` in L4, `random.int`'s bias in M3, N4), and diagnostics that replace crashes (H2) or silence (the language server's E0801, M5). |
| 15 | 15 | |
| 16 | | −**Left, deliberately** (each entry says why): engineering review of the `unsafe` boundary and the leak counter's inlining (M7); `tilrt/src/sched.rs` unsplit while its revisions are under review (M6); constructor tags written as numbers, now guarded by a test (M4); `tilc_core::entry`, `runnable` and `tilc_perceus::verify` returning `String` (L4); the interpreter's scheduler `request` as one `match` (M6). |
| 16 | +**Left, deliberately** (each entry says why): engineering review of the `unsafe` boundary and the leak counter's inlining (M7); `louise_rt/src/sched.rs` unsplit while its revisions are under review (M6); constructor tags written as numbers, now guarded by a test (M4); `louise_core::entry`, `runnable` and `louise_perceus::verify` returning `String` (L4); the interpreter's scheduler `request` as one `match` (M6). |
| 17 | 17 | |
| 18 | | −**Open findings** (below): N1 (`@derive(module.Trait)` does not parse), N2 (trait method bodies ignored; needs a language decision), N3 (match compilation repeats tests; needs review), N5 (the language server never reloads a package), N6 (`tilc check` skips `test/`), N7 (`tilc test` runs the dependencies' tests). Each changes behaviour, so none is in these PRs. |
| 18 | +**Open findings** (below): N1 (`@derive(module.Trait)` does not parse), N2 (trait method bodies ignored; needs a language decision), N3 (match compilation repeats tests; needs review), N5 (the language server never reloads a package), N6 (`louise check` skips `test/`), N7 (`louise test` runs the dependencies' tests). Each changes behaviour, so none is in these PRs. |
| 19 | 19 | |
| 20 | | −Audit of `main` at `f2b02b7` (2026-10-09). It covers the compiler crates, `runtime/tilrt`, `runtime/tilcayo-ffi`, `std/`, `scripts/` and the test harnesses. Every finding was checked against the code. Two findings (H2, M5) were reproduced by running `tilc` on small programs, written outside the repository. |
| 20 | +Audit of `main` at `f2b02b7` (2026-10-09). It covers the compiler crates, `runtime/louise_rt`, `runtime/louise-ffi`, `std/`, `scripts/` and the test harnesses. Every finding was checked against the code. Two findings (H2, M5) were reproduced by running `louise` on small programs, written outside the repository. |
| 21 | 21 | |
| 22 | 22 | ## Summary |
| 23 | 23 | |
| 24 | 24 | The codebase is in good shape for a three-day-old v0. Several things are already better than usual: |
| 25 | | −- **Lints:** clippy is clean with `-D warnings`, and `clippy::undocumented_unsafe_blocks` is enforced, so every `unsafe` block in `tilrt` has a `SAFETY` comment. |
| 25 | +- **Lints:** clippy is clean with `-D warnings`, and `clippy::undocumented_unsafe_blocks` is enforced, so every `unsafe` block in `louise_rt` has a `SAFETY` comment. |
| 26 | 26 | - **Module docs:** every source file starts with a module doc (`//!`). |
| 27 | 27 | - **Diagnostics:** all 51 codes are listed in `docs/reference/diagnostics.md`. |
| 28 | 28 | - **Testing:** differential testing (interpreter against native code, with a leak oracle), loom models of the scheduler hand-offs, and ASan/UBSan runs in CI. |
| 29 | 29 | |
| 30 | 30 | The debt is structural and concentrated in a few places: |
| 31 | 31 | |
| 32 | | −1. **The runtime contract has no single source of truth.** One std extern, one `proc` operation or one std constructor is described by hand in up to seven places: `std/*.til`, `tilrt`, `tilrt.h`, two hand-kept lists in codegen, the interpreter, and the docs. Nothing checks that these agree. One of the lists, `PANICKING`, decides whether generated code checks for unwinding after a call. Forgetting to update it compiles silently into wrong code (H1). |
| 33 | | −2. **The checker accepts programs that lowering cannot handle.** Attributes are unvalidated strings. A function without a body passes `tilc check`, then crashes `tilc run` (H2). |
| 34 | | −3. **Security-relevant runtime code has no tests.** HTTP request framing has no unit tests and no test of any path that rejects a request (H3). More broadly, `tilrt` has 9 unit tests for 5.8k lines; most of it is covered only end to end. |
| 35 | | −4. **Layering and size.** Codegen depends on the whole front end through `tilc_db`. `tilc_core` mixes the IR, lowering and the interpreter. Five files are over 1,200 lines. |
| 32 | +1. **The runtime contract has no single source of truth.** One std extern, one `proc` operation or one std constructor is described by hand in up to seven places: `std/*.lse`, `louise_rt`, `louise_rt.h`, two hand-kept lists in codegen, the interpreter, and the docs. Nothing checks that these agree. One of the lists, `PANICKING`, decides whether generated code checks for unwinding after a call. Forgetting to update it compiles silently into wrong code (H1). |
| 33 | +2. **The checker accepts programs that lowering cannot handle.** Attributes are unvalidated strings. A function without a body passes `louise check`, then crashes `louise run` (H2). |
| 34 | +3. **Security-relevant runtime code has no tests.** HTTP request framing has no unit tests and no test of any path that rejects a request (H3). More broadly, `louise_rt` has 9 unit tests for 5.8k lines; most of it is covered only end to end. |
| 35 | +4. **Layering and size.** Codegen depends on the whole front end through `louise_db`. `louise_core` mixes the IR, lowering and the interpreter. Five files are over 1,200 lines. |
| 36 | 36 | |
| 37 | 37 | The reference interpreter duplicates the runtime's semantics on purpose: it is the test oracle. That is not a defect (see "Deliberate choices"). The pure leaf helpers both copies share are a different matter: they are duplicated by accident, and they have already drifted apart (M3). |
| 38 | 38 | |
| 39 | 39 | **Sizes:** S is half a day or less; M is 1 to 3 days; L is more than 3 days. |
| 40 | | −**PRs:** (1) front end: syntax, hir, types; (2) core, perceus, codegen; (3) runtime `tilrt`; (4) driver, LSP, std, scripts, docs index. |
| 40 | +**PRs:** (1) front end: syntax, hir, types; (2) core, perceus, codegen; (3) runtime `louise_rt`; (4) driver, LSP, std, scripts, docs index. |
| 41 | 41 | |
| 42 | 42 | --- |
| 43 | 43 | |
| @@ -47,129 +47,129 @@ The reference interpreter duplicates the runtime's semantics on purpose: it is t |
| 47 | 47 | |
| 48 | 48 | - [x] **H1. Adding a std extern means hand-syncing up to 7 places, and one omission compiles silently into wrong code.** Size **M**, PRs **(2)** and **(3)**. |
| 49 | 49 | - **The touch points for a new `tl_foo`:** |
| 50 | | − 1. `std/<module>.til`: `@extern(c, "tl_foo")`. |
| 51 | | − 2. `runtime/tilrt/src/<module>.rs`: the `#[unsafe(no_mangle)] extern "C" fn tl_foo`. Int and float arithmetic are instead `static inline` functions in `tilrt.h`. |
| 52 | | − 3. `runtime/tilrt/include/tilrt.h`: the prototype. Today this step is optional, and 16 exported functions have none: all of `tl_bytes_*`, `tl_hash_bytes` and `tl_string_join`. |
| 53 | | − 4. `crates/tilc_codegen_c/src/emit.rs:90` `DECLARED`, if the header declares it. |
| 54 | | − 5. `crates/tilc_codegen_c/src/emit.rs:74` `PANICKING`, if it may panic or park the actor. |
| 55 | | − 6. `crates/tilc_core/src/interp.rs:580` `call_extern`, or `:753` `bytes_extern`. |
| 50 | + 1. `std/<module>.lse`: `@extern(c, "tl_foo")`. |
| 51 | + 2. `runtime/louise_rt/src/<module>.rs`: the `#[unsafe(no_mangle)] extern "C" fn tl_foo`. Int and float arithmetic are instead `static inline` functions in `louise_rt.h`. |
| 52 | + 3. `runtime/louise_rt/include/louise_rt.h`: the prototype. Today this step is optional, and 16 exported functions have none: all of `tl_bytes_*`, `tl_hash_bytes` and `tl_string_join`. |
| 53 | + 4. `crates/louise_codegen_c/src/emit.rs:90` `DECLARED`, if the header declares it. |
| 54 | + 5. `crates/louise_codegen_c/src/emit.rs:74` `PANICKING`, if it may panic or park the actor. |
| 55 | + 6. `crates/louise_core/src/interp.rs:580` `call_extern`, or `:753` `bytes_extern`. |
| 56 | 56 | 7. `docs/runtime-abi.md`. |
| 57 | 57 | |
| 58 | | − A new `proc` operation has its own set: `std/process.til`, `tilc_core/src/sched.rs:336` `request`, `tilrt/src/process.rs:30` `PROC_OPS` and `:49` `CLAUSES`, and a second `PROC_OPS` in `tilc_codegen_c/src/lib.rs:149`. |
| 58 | + A new `proc` operation has its own set: `std/process.lse`, `louise_core/src/sched.rs:336` `request`, `louise_rt/src/process.rs:30` `PROC_OPS` and `:49` `CLAUSES`, and a second `PROC_OPS` in `louise_codegen_c/src/lib.rs:149`. |
| 59 | 59 | - **The problem:** nothing checks that these places agree. |
| 60 | 60 | - **Missing step 6:** the interpreter fails only at run time, with "unknown extern", and only when a program calls the extern. |
| 61 | 61 | - **Missing step 5 (the hazard):** `may_unwind` (`emit.rs:810-822`) returns false, so the generated code has no `TL_YIELDING` check after the call (`emit.rs:648-650`). After a panic or a park, the caller keeps running with a meaningless result. The only thing that catches this is a test that panics through that exact extern. All current externs are listed correctly; I checked every runtime function that calls `panic_with`, `tl_panic_str` or `park`. The risk is to future additions. |
| 62 | | − - **The same hole exists for user FFI.** `tl_panic_str` is in the public `tilrt.h:171`, but ADR 0005 (Revision 1) forbids panics only in `blocking` externs. A non-blocking binding that panics gets no yield check. |
| 62 | + - **The same hole exists for user FFI.** `tl_panic_str` is in the public `louise_rt.h:171`, but ADR 0005 (Revision 1) forbids panics only in `blocking` externs. A non-blocking binding that panics gets no yield check. |
| 63 | 63 | - **A misplaced comment:** the doc comment meant for `DECLARED` sits on `PANICKING` (`emit.rs:72-73`). |
| 64 | 64 | - **The fix:** |
| 65 | | − 1. **One table of std externs.** Put it in `tilc_core` (e.g. `externs.rs`) or a leaf crate: `struct Extern { sym, arity, may_unwind, in_header }`. Codegen derives `PANICKING` and `DECLARED` from it. The interpreter's dispatch is keyed on it. `PROC_OPS` moves next to it, so codegen and `tilrt` share one list. |
| 66 | | − 2. **A consistency test.** Parse every `@extern` in `std/*.til` and assert that each one: |
| 65 | + 1. **One table of std externs.** Put it in `louise_core` (e.g. `externs.rs`) or a leaf crate: `struct Extern { sym, arity, may_unwind, in_header }`. Codegen derives `PANICKING` and `DECLARED` from it. The interpreter's dispatch is keyed on it. `PROC_OPS` moves next to it, so codegen and `louise_rt` share one list. |
| 66 | + 2. **A consistency test.** Parse every `@extern` in `std/*.lse` and assert that each one: |
| 67 | 67 | - is in the table with the right arity; |
| 68 | 68 | - is handled by the interpreter; |
| 69 | | − - is exported by `tilrt` (against an `EXPORTS` list, or `nm libtilrt.a`); |
| 70 | | − - is declared in `tilrt.h`. |
| 71 | | − 3. **Foreign externs:** either treat them as may-unwind (one predictable branch per call), or add a `panics` option next to `blocking`. Document the rule in ADR 0005 and `tilrt.h`. |
| 69 | + - is exported by `louise_rt` (against an `EXPORTS` list, or `nm liblouise_rt.a`); |
| 70 | + - is declared in `louise_rt.h`. |
| 71 | + 3. **Foreign externs:** either treat them as may-unwind (one predictable branch per call), or add a `panics` option next to `blocking`. Document the rule in ADR 0005 and `louise_rt.h`. |
| 72 | 72 | 4. Until this lands, add an "Adding a std extern" checklist to `docs/runtime-abi.md`. |
| 73 | 73 | - **Status (PR 2, done; the runtime side needed no restructuring):** |
| 74 | | − - **One table.** `tilc_core::externs::RUNTIME_EXTERNS` lists every runtime extern (the 82 std declares, and `tl_string_concat`, which lowering calls for `++`) with `may_unwind`, `blocking` and `owned`. Codegen's `PANICKING` and `DECLARED` are gone. `externs::may_unwind(symbol, blocking)` is the single rule for both the yield check after a call (`emit`) and the never-unwinds analysis (`unwind.rs`): a runtime extern unwinds if the table says so, a `blocking` one always, and any other extern (a binding's) always, as ADR 0015 decided. One behaviour change, deliberate: a `tl_` symbol missing from the table used to be treated as never unwinding; it is now treated like a binding's. |
| 75 | | − - **`tilrt.h` declares every runtime extern.** It lacked 29 (the `Bytes`, builder and `Array` functions, `tl_hash_bytes`, `tl_string_join`). Codegen now declares only a binding's externs, so the generated C lost those prototypes; nothing else in it changed. |
| 76 | | − - **The consistency test** is `tilc_codegen_c/tests/externs.rs`. It reads std's `@extern`s from the analysed HIR (not by parsing text) and checks that each is in the table with the same `blocking` and `owned`; that every `tl_` extern the Core of `tests/run` calls is in the table, and every entry is declared by std or called by lowering; that the interpreter implements each (`tilc_interp::implements_extern`); that `libtilrt.a` exports each (`nm`) or `tilrt.h` defines it `static inline`; and that `tilrt.h` declares each. It found one gap: the interpreter did not know `tl_http_parse_chunk` (it now fails like the other networking externs, which need the native backend). |
| 74 | + - **One table.** `louise_core::externs::RUNTIME_EXTERNS` lists every runtime extern (the 82 std declares, and `tl_string_concat`, which lowering calls for `++`) with `may_unwind`, `blocking` and `owned`. Codegen's `PANICKING` and `DECLARED` are gone. `externs::may_unwind(symbol, blocking)` is the single rule for both the yield check after a call (`emit`) and the never-unwinds analysis (`unwind.rs`): a runtime extern unwinds if the table says so, a `blocking` one always, and any other extern (a binding's) always, as ADR 0015 decided. One behaviour change, deliberate: a `tl_` symbol missing from the table used to be treated as never unwinding; it is now treated like a binding's. |
| 75 | + - **`louise_rt.h` declares every runtime extern.** It lacked 29 (the `Bytes`, builder and `Array` functions, `tl_hash_bytes`, `tl_string_join`). Codegen now declares only a binding's externs, so the generated C lost those prototypes; nothing else in it changed. |
| 76 | + - **The consistency test** is `louise_codegen_c/tests/externs.rs`. It reads std's `@extern`s from the analysed HIR (not by parsing text) and checks that each is in the table with the same `blocking` and `owned`; that every `tl_` extern the Core of `tests/run` calls is in the table, and every entry is declared by std or called by lowering; that the interpreter implements each (`louise_interp::implements_extern`); that `liblouise_rt.a` exports each (`nm`) or `louise_rt.h` defines it `static inline`; and that `louise_rt.h` declares each. It found one gap: the interpreter did not know `tl_http_parse_chunk` (it now fails like the other networking externs, which need the native backend). |
| 77 | 77 | - **How the interpreter test works:** `implements_extern` calls the built-in with no arguments on an empty interpreter. Every built-in reads its arguments before doing anything, so the call fails at once, but not with the "unknown extern" error. Rewriting the interpreter's dispatch as a table of functions would make this exact, at the cost of rewriting 300 lines of working code; the probe is 20 lines. |
| 78 | | − - **Not in the table, deliberately:** arity (the prototypes in `tilrt.h` make the C compiler check it). `blocking` and `owned` stay declared in std, where Perceus and codegen read them through the same attributes as a binding's; the table records the runtime's side and the test requires both to agree. |
| 78 | + - **Not in the table, deliberately:** arity (the prototypes in `louise_rt.h` make the C compiler check it). `blocking` and `owned` stay declared in std, where Perceus and codegen read them through the same attributes as a binding's; the table records the runtime's side and the test requires both to agree. |
| 79 | 79 | - **Not checkable:** whether `may_unwind` is right. The test cannot see that a function reaches `tl_panic_str` or parks. The table's documentation and `runtime-abi.md` ("Adding a runtime extern", the checklist of fix 4) say so. All current entries were re-checked against the runtime's calls of `panic_with`, `tl_panic_str` and `park`. |
| 80 | | − - **`PROC_OPS`** has one copy, in `tilrt-prims` (see M3), read by codegen's check and by the runtime, whose clause table is now sized by it (`[Code; PROC_OPS.len()]`), so a missing clause does not compile. |
| 80 | + - **`PROC_OPS`** has one copy, in `louise_rt_prims` (see M3), read by codegen's check and by the runtime, whose clause table is now sized by it (`[Code; PROC_OPS.len()]`), so a missing clause does not compile. |
| 81 | 81 | - **Foreign externs (fix 3)** were settled by the FFI work: every extern of a binding may unwind (ADR 0015). |
| 82 | 82 | |
| 83 | | −- [x] **H2. Attributes are unvalidated strings: functions without a body pass `tilc check` and crash `tilc run`.** Size **S**, PR **(1)** (with the readers in (2)). |
| 83 | +- [x] **H2. Attributes are unvalidated strings: functions without a body pass `louise check` and crash `louise run`.** Size **S**, PR **(1)** (with the readers in (2)). |
| 84 | 84 | - **The paths:** |
| 85 | | − - attributes are read by string at `tilc_hir/src/lower.rs:86`, `tilc_types/src/env.rs:662`, `tilc_types/src/send.rs:115` and `tilc_core/src/lower.rs:347-368`; |
| 86 | | − - the crash is the `self.fn_ids[&def]` lookup at `tilc_core/src/lower.rs:1552`. |
| 85 | + - attributes are read by string at `louise_hir/src/lower.rs:86`, `louise_types/src/env.rs:662`, `louise_types/src/send.rs:115` and `louise_core/src/lower.rs:347-368`; |
| 86 | + - the crash is the `self.fn_ids[&def]` lookup at `louise_core/src/lower.rs:1552`. |
| 87 | 87 | - **Reproduced (in a scratch directory):** |
| 88 | | − - `fn p(x: Int) -> Int` with no body and no attribute: `tilc check` exits 0, then `tilc run` panics with `no entry found for key` at `lower.rs:1552:32`. |
| 88 | + - `fn p(x: Int) -> Int` with no body and no attribute: `louise check` exits 0, then `louise run` panics with `no entry found for key` at `lower.rs:1552:32`. |
| 89 | 89 | - A typo, `@extrn(c, "tl_println")`, and `@extern(c)` without a symbol: both crash the same way. |
| 90 | 90 | - `@extern(c, "tl_println", blockng)` is accepted and silently not blocking. `note_blocking` matches the string `"blocking"` (`lower.rs:365`). |
| 91 | | − - `@builtin`, used in `std/prelude.til:8`, `std/process.til:8,61` and `std/ffi.til:8`, is not read by any compiler code. It looks semantic, but it is a comment. |
| 92 | | − - **The problem:** lowering assumes "the input is free of errors" (`tilc_core/src/lower.rs:24`), but the checker never establishes these invariants. |
| 91 | + - `@builtin`, used in `std/prelude.lse:8`, `std/process.lse:8,61` and `std/ffi.lse:8`, is not read by any compiler code. It looks semantic, but it is a comment. |
| 92 | + - **The problem:** lowering assumes "the input is free of errors" (`louise_core/src/lower.rs:24`), but the checker never establishes these invariants. |
| 93 | 93 | - **The fix:** |
| 94 | | − - Parse attributes once in `tilc_hir` into a typed enum: `Extern { abi, symbol, blocking }`, `Derive(..)`, `ThreadSafe`, `Test { should_panic }`, `Builtin`. |
| 94 | + - Parse attributes once in `louise_hir` into a typed enum: `Extern { abi, symbol, blocking }`, `Derive(..)`, `ThreadSafe`, `Test { should_panic }`, `Builtin`. |
| 95 | 95 | - Report these as diagnostics: an unknown attribute or option, a malformed `@extern`, and a function without a body that is not `@extern`. Add the new codes to `diagnostics.md`, with `tests/ui` cases. |
| 96 | 96 | - Lowering then reads typed fields instead of strings. |
| 97 | 97 | - Either give `@builtin` a meaning, or remove it. |
| 98 | 98 | - **Status (PR 1, done):** |
| 99 | | − - `tilc_hir::attrs` parses each item's attributes once into `Attrs` (`Extern { symbol, blocking, owned }`, `test`, `should_panic`, `derive`, `Derivable`, `thread_safe`, `builtin`). Every reader, in HIR, types and Core lowering, uses the typed fields; no attribute name is matched as a string elsewhere. The ABI is not a field: `c` is the only one, and any other is reported. |
| 99 | + - `louise_hir::attrs` parses each item's attributes once into `Attrs` (`Extern { symbol, blocking, owned }`, `test`, `should_panic`, `derive`, `Derivable`, `thread_safe`, `builtin`). Every reader, in HIR, types and Core lowering, uses the typed fields; no attribute name is matched as a string elsewhere. The ABI is not a field: `c` is the only one, and any other is reported. |
| 100 | 100 | - `E0114` reports an unknown attribute, ABI or `@extern` option, malformed arguments, a repeated attribute, and one on an item it does not apply to. A known attribute with bad arguments is still applied as far as possible, so a typo in an option is one error. |
| 101 | | − - `E0115` reports a function or impl method without a body that is not `@extern`, and an `@extern` function with a body. Tests: `tests/ui/attributes.til`, `crates/tilc/tests/cli.rs` (`run` reports instead of crashing), `crates/tilc_hir/tests/lower.rs`. |
| 101 | + - `E0115` reports a function or impl method without a body that is not `@extern`, and an `@extern` function with a body. Tests: `tests/ui/attributes.lse`, `crates/louise/tests/cli.rs` (`run` reports instead of crashing), `crates/louise_hir/tests/lower.rs`. |
| 102 | 102 | - `@builtin` keeps a checked meaning: it is allowed only on an opaque type in a `std/` module, and documents that the runtime implements it. No phase reads it. |
| 103 | 103 | - Attributes now belong to their item only. Before, constructors, trait methods and effect operations got copies of their parent's; nothing read them. Attributes written on methods were silently dropped; they are now reported. |
| 104 | 104 | |
| 105 | 105 | - [x] **H3. HTTP framing and the runtime's pure functions have no tests of their rejecting paths.** Size **S**, PRs **(3)** and **(4)**. |
| 106 | 106 | - **The code at stake:** |
| 107 | | − - `tilrt/src/net.rs:347` `tl_http_parse_request` rejects a non-decimal `Content-Length` and conflicting duplicates. That is the defence against request smuggling on kept-alive connections, as its own doc says. |
| 107 | + - `louise_rt/src/net.rs:347` `tl_http_parse_request` rejects a non-decimal `Content-Length` and conflicting duplicates. That is the defence against request smuggling on kept-alive connections, as its own doc says. |
| 108 | 108 | - `net.rs:407` `tl_http_parse_chunk` handles chunked bodies. |
| 109 | | − - `std/http.til:239-249` answers `Content-Length` together with `Transfer-Encoding` with 400, and an unsupported `Transfer-Encoding` with 501. |
| 109 | + - `std/http.lse:239-249` answers `Content-Length` together with `Transfer-Encoding` with 400, and an unsupported `Transfer-Encoding` with 501. |
| 110 | 110 | - **The problem:** |
| 111 | | − - None of these rejecting paths is tested anywhere. `crates/tilc/tests/cli.rs` sends only valid requests: one `Content-Length: 5` request and one chunked body. |
| 112 | | − - More broadly, `tilrt` has 9 `#[test]`s for 5,848 lines. `prims.rs`, `bytes.rs`, `net.rs`, `heap.rs`, `process.rs`, `sched.rs` and `handlers.rs` have none. Differential tests cover most of this end to end, but the parsers and `url_decode` (`prims.rs:694`) have no direct tests. |
| 111 | + - None of these rejecting paths is tested anywhere. `crates/louise/tests/cli.rs` sends only valid requests: one `Content-Length: 5` request and one chunked body. |
| 112 | + - More broadly, `louise_rt` has 9 `#[test]`s for 5,848 lines. `prims.rs`, `bytes.rs`, `net.rs`, `heap.rs`, `process.rs`, `sched.rs` and `handlers.rs` have none. Differential tests cover most of this end to end, but the parsers and `url_decode` (`prims.rs:694`) have no direct tests. |
| 113 | 113 | - **The fix:** |
| 114 | 114 | 1. Factor the pure parsing out of the two externs into Rust functions over `&[u8]` that return Rust enums. The externs only build the cells. |
| 115 | 115 | 2. Unit-test those functions: partial input, invalid input, duplicate and conflicting `Content-Length`, an oversized chunk, and offsets past the end. |
| 116 | 116 | 3. Add `cli.rs` cases that send malformed and smuggling-shaped requests, and expect 400 or 501 with the connection closed. |
| 117 | 117 | - **Status (PR 3, done):** |
| 118 | | − - **The parsers** moved from `net.rs` (sockets) to `tilrt/src/http.rs`. `parse_head` and `parse_chunk` are plain Rust over `&[u8]` returning Rust enums; the externs only build `std/http`'s `Head` and `Chunk`, whose tags are named constants. Their bounds use `tilrt-prims`' `SMALL_INT` (the two `1 << 62` M3 left). Behaviour is unchanged. |
| 118 | + - **The parsers** moved from `net.rs` (sockets) to `louise_rt/src/http.rs`. `parse_head` and `parse_chunk` are plain Rust over `&[u8]` returning Rust enums; the externs only build `std/http`'s `Head` and `Chunk`, whose tags are named constants. Their bounds use `louise_rt_prims`' `SMALL_INT` (the two `1 << 62` M3 left). Behaviour is unchanged. |
| 119 | 119 | - **Unit tests** (12 in `http.rs`): partial input; offsets at and past the end, and negative ones; malformed request lines and headers; whitespace before a colon; more than 64 headers; `Content-Length` that is empty, signed, hexadecimal, non-ASCII, not UTF-8, 2^62 or more, or repeated with a different value (and accepted when repeated with the same one); both framings reported as they are; header values kept byte for byte; chunk sizes with extensions, invalid, cut, overflowing or 2^62 and more; the last chunk and its trailers; and, in a test actor under the leak oracle, the `Head` and `Chunk` values the externs build. |
| 120 | | − - **End to end:** `crates/tilc/tests/cli.rs` `http_rejects_malformed_requests` (fixture `tests/fixtures/http/malformed.til`) sends conflicting and non-decimal lengths, both framings (400), `Transfer-Encoding: gzip, chunked` (501), whitespace before a colon, an invalid, an unterminated and an oversized chunk (400), and a chunk over the body limit (413), each with a request pipelined behind it. Each gets exactly one error response, the connection closes, and the pipelined request is never served; agreeing duplicate lengths are served. Nothing leaks. The 413 by `Content-Length` and by summed chunks stays in `http_body_limit_and_write_timeout`. |
| 121 | | − - **More broadly:** `tilrt` has 34 `#[test]`s (18 on the v1 base, 9 at the audit), and `tilrt-prims` 7. New: `int::parse`, small ints read without a heap, `utf8_error`, the hash values (pinned in `tilrt-prims` to what `tilc run` prints), and the lists and tuples `tl_string_split` and `tl_string_parse_int` build (a test actor, leak oracle). `url_decode`, `html_escape`, `split` and the rejection sampling are tested in `tilrt-prims` (PR 2). |
| 120 | + - **End to end:** `crates/louise/tests/cli.rs` `http_rejects_malformed_requests` (fixture `tests/fixtures/http/malformed.lse`) sends conflicting and non-decimal lengths, both framings (400), `Transfer-Encoding: gzip, chunked` (501), whitespace before a colon, an invalid, an unterminated and an oversized chunk (400), and a chunk over the body limit (413), each with a request pipelined behind it. Each gets exactly one error response, the connection closes, and the pipelined request is never served; agreeing duplicate lengths are served. Nothing leaks. The 413 by `Content-Length` and by summed chunks stays in `http_body_limit_and_write_timeout`. |
| 121 | + - **More broadly:** `louise_rt` has 34 `#[test]`s (18 on the v1 base, 9 at the audit), and `louise_rt_prims` 7. New: `int::parse`, small ints read without a heap, `utf8_error`, the hash values (pinned in `louise_rt_prims` to what `louise run` prints), and the lists and tuples `tl_string_split` and `tl_string_parse_int` build (a test actor, leak oracle). `url_decode`, `html_escape`, `split` and the rejection sampling are tested in `louise_rt_prims` (PR 2). |
| 122 | 122 | - Found on the way: N4. |
| 123 | | − - **Status (PR 4):** nothing left. PR 3's `http_rejects_malformed_requests` covers `std/http.til`'s 400 and 501 answers, the part of H3 in `std`. |
| 123 | + - **Status (PR 4):** nothing left. PR 3's `http_rejects_malformed_requests` covers `std/http.lse`'s 400 and 501 answers, the part of H3 in `std`. |
| 124 | 124 | |
| 125 | 125 | ### Medium |
| 126 | 126 | |
| 127 | 127 | - [x] **M1. Codegen owns the C build driver, so it depends on the whole front end.** Size **S**, PRs **(2)** and **(4)**. |
| 128 | | − - **The paths:** `crates/tilc_codegen_c/Cargo.toml` depends on `tilc_db` and `toml`. |
| 129 | | − - The only use of `tilc_db` is `driver.rs:7` (`NativeDep`, `NativeKind`). |
| 128 | + - **The paths:** `crates/louise_codegen_c/Cargo.toml` depends on `louise_db` and `toml`. |
| 129 | + - The only use of `louise_db` is `driver.rs:7` (`NativeDep`, `NativeKind`). |
| 130 | 130 | - The only use of `toml` is reading a binding crate's `Cargo.toml` (`driver.rs:252-283`). |
| 131 | | − - `cargo tree -p tilc_codegen_c` shows codegen → `tilc_db` → syntax, hir and types: the back end depends on the front end. |
| 131 | + - `cargo tree -p louise_codegen_c` shows codegen → `louise_db` → syntax, hir and types: the back end depends on the front end. |
| 132 | 132 | - `driver.rs:286` is a third copy of FNV-1a (see M3). |
| 133 | | − - **The fix:** move `driver.rs` into the `tilc` driver: compiler invocation, native dependencies, cargo and pkg-config. Codegen keeps `generate`/`generate_entries` → C text, and depends only on `tilc_core`, `tilc_perceus` and `tilc_span`. |
| 133 | + - **The fix:** move `driver.rs` into the `louise` driver: compiler invocation, native dependencies, cargo and pkg-config. Codegen keeps `generate`/`generate_entries` → C text, and depends only on `louise_core`, `louise_perceus` and `louise_span`. |
| 134 | 134 | - **Status (PR 2, done):** |
| 135 | | − - `driver.rs` moved, unchanged, to a new crate, `tilc_build`, rather than into the `tilc` binary: the native tests need it too, and a binary crate is not a library. `tilc_build` depends on `tilc_db` (for `NativeDep`) and `toml`. |
| 136 | | − - `Timings`, which codegen also records into, moved from `tilc_db` to `tilc_span`, the leaf every compiler crate shares. |
| 137 | | − - Codegen now depends on `tilc_core`, `tilc_perceus`, `tilc_span` and `tilrt-prims` only. Through `tilc_core` it still reaches `tilc_hir` and `tilc_types` (see M2). |
| 138 | | − - **Not done, deliberately:** the FNV-1a in `tilc_build` (and the one in `tilc_db/src/package/git.rs`, now `tilc_package/src/git.rs`) stay. They name cache entries and need only be stable; they are not the language's hash, and sharing four lines would tie the build to the runtime's kernels. |
| 135 | + - `driver.rs` moved, unchanged, to a new crate, `louise_build`, rather than into the `louise` binary: the native tests need it too, and a binary crate is not a library. `louise_build` depends on `louise_db` (for `NativeDep`) and `toml`. |
| 136 | + - `Timings`, which codegen also records into, moved from `louise_db` to `louise_span`, the leaf every compiler crate shares. |
| 137 | + - Codegen now depends on `louise_core`, `louise_perceus`, `louise_span` and `louise_rt_prims` only. Through `louise_core` it still reaches `louise_hir` and `louise_types` (see M2). |
| 138 | + - **Not done, deliberately:** the FNV-1a in `louise_build` (and the one in `louise_db/src/package/git.rs`, now `louise_package/src/git.rs`) stay. They name cache entries and need only be stable; they are not the language's hash, and sharing four lines would tie the build to the runtime's kernels. |
| 139 | 139 | |
| 140 | | − - **Status (PR 4, done):** what was left is that `tilc_build` depended on `tilc_db`, and through it on the whole front end, for the manifest's `NativeDep`. Manifests, the lockfile, the git cache, resolution and `find_package_root` moved, unchanged, from `tilc_db` to a leaf crate, `tilc_package` (serde and toml only). `tilc_build` depends on it, `tilc_span` and `toml`; `tilc_db` loads the modules of the packages `tilc_package` resolves. No compiler crate below the driver depends on the front end without needing it. |
| 140 | + - **Status (PR 4, done):** what was left is that `louise_build` depended on `louise_db`, and through it on the whole front end, for the manifest's `NativeDep`. Manifests, the lockfile, the git cache, resolution and `find_package_root` moved, unchanged, from `louise_db` to a leaf crate, `louise_package` (serde and toml only). `louise_build` depends on it, `louise_span` and `toml`; `louise_db` loads the modules of the packages `louise_package` resolves. No compiler crate below the driver depends on the front end without needing it. |
| 141 | 141 | |
| 142 | | −- [x] **M2. `tilc_core` mixes the IR, lowering and the interpreter.** Size **M**, PR **(2)**. |
| 143 | | − - **The paths:** `crates/tilc_core/src` holds `ir.rs` (411 lines), `lower.rs` (2,002), `interp.rs` (929) and `sched.rs` (586). |
| 144 | | − - **The problem:** `tilc_perceus` and `tilc_codegen_c` need only `ir`. Through `tilc_core` they also depend on `tilc_hir`, `tilc_types` and `corosensei`. A change in the interpreter rebuilds the back end. |
| 145 | | − - **The fix:** split `interp.rs` and `sched.rs` into a `tilc_interp` crate, used by the driver and the tests. Keep `ir` and `lower` in `tilc_core`. If the front-end dependency of Perceus matters later, move `ir` to its own crate. |
| 146 | | − - **Status (PR 2, done):** `crates/tilc_interp` holds the CEK machine (`lib.rs`, 1,000 lines), its built-in externs (`externs.rs`, split from the machine along its "built-ins" section), its scheduler and its `Int` arithmetic, moved unchanged. `tilc_core` keeps the IR, lowering, the evidence pass and the externs table, and no longer depends on `num-bigint`. `ir` stays in `tilc_core`: nothing needs the back end to build without the front end yet. |
| 142 | +- [x] **M2. `louise_core` mixes the IR, lowering and the interpreter.** Size **M**, PR **(2)**. |
| 143 | + - **The paths:** `crates/louise_core/src` holds `ir.rs` (411 lines), `lower.rs` (2,002), `interp.rs` (929) and `sched.rs` (586). |
| 144 | + - **The problem:** `louise_perceus` and `louise_codegen_c` need only `ir`. Through `louise_core` they also depend on `louise_hir`, `louise_types` and `corosensei`. A change in the interpreter rebuilds the back end. |
| 145 | + - **The fix:** split `interp.rs` and `sched.rs` into a `louise_interp` crate, used by the driver and the tests. Keep `ir` and `lower` in `louise_core`. If the front-end dependency of Perceus matters later, move `ir` to its own crate. |
| 146 | + - **Status (PR 2, done):** `crates/louise_interp` holds the CEK machine (`lib.rs`, 1,000 lines), its built-in externs (`externs.rs`, split from the machine along its "built-ins" section), its scheduler and its `Int` arithmetic, moved unchanged. `louise_core` keeps the IR, lowering, the evidence pass and the externs table, and no longer depends on `num-bigint`. `ir` stays in `louise_core`: nothing needs the back end to build without the front end yet. |
| 147 | 147 | |
| 148 | 148 | - [x] **M3. The interpreter and the runtime duplicate pure helpers, and they have already drifted.** Size **S**, PRs **(2)** and **(3)**. |
| 149 | 149 | - **The duplicated code:** |
| 150 | 150 | |
| 151 | | − | Helper | Interpreter (`tilc_core/src/interp.rs`) | Runtime (`tilrt/src/prims.rs`) | |
| 151 | + | Helper | Interpreter (`louise_core/src/interp.rs`) | Runtime (`louise_rt/src/prims.rs`) | |
| 152 | 152 | |---|---|---| |
| 153 | 153 | | `mix` | `:917` | `:95` | |
| 154 | | − | FNV-1a `hash_bytes` | `:873` | `:399` (third copy: `tilc_codegen_c/src/driver.rs:286`) | |
| 154 | + | FNV-1a `hash_bytes` | `:873` | `:399` (third copy: `louise_codegen_c/src/driver.rs:286`) | |
| 155 | 155 | | `url_decode` | `:882` | `:694` | |
| 156 | 156 | | HTML escaping | `:696` | `:438` | |
| 157 | 157 | | `random_bytes` | `:906` | `:637` | |
| 158 | 158 | | `string_split` semantics | `:642` | `:335` | |
| 159 | 159 | |
| 160 | | − The 63-bit Int range is spelled out 8 times: `interp.rs:594,665`, `emit.rs:493`, `tilc_hir/src/lower.rs:1066`, `prims.rs:87,367`, `net.rs:365,419`. |
| 160 | + The 63-bit Int range is spelled out 8 times: `interp.rs:594,665`, `emit.rs:493`, `louise_hir/src/lower.rs:1066`, `prims.rs:87,367`, `net.rs:365,419`. |
| 161 | 161 | - **The drift:** `tl_random_int` uses rejection sampling in the runtime (`prims.rs:648-664`), but plain modulo, which is biased, in the interpreter (`interp.rs:724-731`). |
| 162 | 162 | - **Why this is accidental, not deliberate:** the interpreter is the oracle for the compiler (lowering, Perceus, codegen). For leaf functions over bytes, a second copy adds no oracle value; it only drifts. |
| 163 | | − - **The fix:** a dependency-free crate (e.g. `crates/tilc_prims`) holding: |
| 163 | + - **The fix:** a dependency-free crate (e.g. `crates/louise_prims`) holding: |
| 164 | 164 | - the pure kernels: `mix`, `hash_bytes`, `hash_combine`, `url_decode`, `html_escape`, `split`, `random_below`; |
| 165 | 165 | - `INT_MIN` and `INT_MAX` with a `checked_int` helper. |
| 166 | 166 | |
| 167 | | − Both `tilrt` and the interpreter call it. Value marshalling stays separate in each. |
| 167 | + Both `louise_rt` and the interpreter call it. Value marshalling stays separate in each. |
| 168 | 168 | - **Status (PR 2, done; touching the runtime only where it called its copies):** |
| 169 | | − - The crate is `runtime/tilrt-prims` (it is the runtime's semantics, which the interpreter shares, so it sits with the runtime). It is dependency-free and holds `mix`, `hash_bytes`, `hash_limbs`, `hash_combine`, `split`, `html_escape`, `url_decode`, `random_bytes`, `random_below`, `SMALL_INT` (the 63-bit range) and `PROC_OPS`, with unit tests (URL decoding, escaping, splitting, the rejection of the biased zone). |
| 170 | | − - `tilrt` (`prims.rs`, `int.rs`, `bytes.rs`, `process.rs`), the interpreter and codegen call it; their copies are gone. `tl_random_int` in the interpreter now uses rejection sampling, like the runtime. |
| 171 | | − - **Left:** `net.rs`'s two `1 << 62` (PR 3 refactors those parsers, H3), and `tilc_hir`'s `i128` range check of literals (front end; a front-end crate should not depend on the runtime's). |
| 172 | | − - **Status (PR 3, done):** the HTTP parsers (now `http.rs`) check lengths against `SMALL_INT`. PR 3's tests pin the hash values in `tilrt-prims`. |
| 169 | + - The crate is `runtime/louise_rt_prims` (it is the runtime's semantics, which the interpreter shares, so it sits with the runtime). It is dependency-free and holds `mix`, `hash_bytes`, `hash_limbs`, `hash_combine`, `split`, `html_escape`, `url_decode`, `random_bytes`, `random_below`, `SMALL_INT` (the 63-bit range) and `PROC_OPS`, with unit tests (URL decoding, escaping, splitting, the rejection of the biased zone). |
| 170 | + - `louise_rt` (`prims.rs`, `int.rs`, `bytes.rs`, `process.rs`), the interpreter and codegen call it; their copies are gone. `tl_random_int` in the interpreter now uses rejection sampling, like the runtime. |
| 171 | + - **Left:** `net.rs`'s two `1 << 62` (PR 3 refactors those parsers, H3), and `louise_hir`'s `i128` range check of literals (front end; a front-end crate should not depend on the runtime's). |
| 172 | + - **Status (PR 3, done):** the HTTP parsers (now `http.rs`) check lengths against `SMALL_INT`. PR 3's tests pin the hash values in `louise_rt_prims`. |
| 173 | 173 | |
| 174 | 174 | - [x] **M4. Std items are identified by name and constructor position across all layers.** Size **M**, PRs **(1)**, **(2)** and **(3)**. |
| 175 | 175 | - **Effect names as strings:** |
| @@ -181,9 +181,9 @@ The reference interpreter duplicates the runtime's semantics on purpose: it is t |
| 181 | 181 | - `Ok`/`Error` = 0/1 (`values.rs:95-103`); |
| 182 | 182 | - `Nil`/`Cons` (`values.rs:108-111`, again by hand in `prims.rs:343-353`); |
| 183 | 183 | - `Lt`/`Eq`/`Gt` (`prims.rs:77`); |
| 184 | | − - `Head` and `Chunk` tags 0-3 (`net.rs:353-427`, against `std/http.til:343-360`); |
| 184 | + - `Head` and `Chunk` tags 0-3 (`net.rs:353-427`, against `std/http.lse:343-360`); |
| 185 | 185 | - and the same tags again in the interpreter (`interp.rs:799+`, `:835+`). |
| 186 | | − - **The problem:** reordering the constructors of a std type silently breaks both back ends. Only the constructors `tilrt/src/process.rs` builds (`Option` and the `std/process` types) are covered by a test, per its module doc (`:14-22`). For `proc`, the runtime checks only the number of operations (`tl_root_cap(ctx, PROC_OPS.len())`, `emit.rs:223`), not their order. |
| 186 | + - **The problem:** reordering the constructors of a std type silently breaks both back ends. Only the constructors `louise_rt/src/process.rs` builds (`Option` and the `std/process` types) are covered by a test, per its module doc (`:14-22`). For `proc`, the runtime checks only the number of operations (`tl_root_cap(ctx, PROC_OPS.len())`, `emit.rs:223`), not their order. |
| 187 | 187 | - **The fix:** |
| 188 | 188 | - Extend `WellKnown` into one resolved table of the std items the back ends know: types, effects, constructors. |
| 189 | 189 | - Carry it into Core, e.g. `EffectDecl::builtin: Option<BuiltinEffect>`, so codegen and the interpreter match on an enum. |
| @@ -191,55 +191,55 @@ The reference interpreter duplicates the runtime's semantics on purpose: it is t |
| 191 | 191 | - **Status (PR 1, front end, done; PRs 2 and 3 open):** the type checker names a std item in one place, `WellKnown::find`, which now also resolves `Ref`, `Resource` and `Subject` for the `Send` check (`send.rs` looked them up by path). The HIR extern check resolves the prelude's `ffi` once instead of comparing names and module paths. The back-end parts (Core lowering, codegen, interpreter, runtime tags) and the tag test belong to PRs 2 and 3. |
| 192 | 192 | - **Status (PR 2, back end, done):** |
| 193 | 193 | - Core carries `EffectDecl::builtin: Option<BuiltinEffect>` (`Proc`, `St`, `Alloc`), set by lowering from `WellKnown` (which now resolves `proc` too, and whose `find` is public). Codegen (`check_supported`, the `ref` operations, the never-unwinds analysis) and the interpreter's scheduler match on it; no back end compares an effect's name. Region lowering takes `st` and `alloc` from `WellKnown` instead of `module_by_path("std/ref")`. |
| 194 | | − - `tilc_core/tests/runtime_constructors.rs` asserts the tag of every constructor that `tilrt`, the interpreter or lowering builds by number (`Bool`, `List`, `Option`, `Result`, `Order`, the `std/process` types, the HTTP parse results) against the analysed std. |
| 194 | + - `louise_core/tests/runtime_constructors.rs` asserts the tag of every constructor that `louise_rt`, the interpreter or lowering builds by number (`Bool`, `List`, `Option`, `Result`, `Order`, the `std/process` types, the HTTP parse results) against the analysed std. |
| 195 | 195 | - **Not done, deliberately:** the runtime and the interpreter still write those tags as numbers. With the test, reordering a constructor fails instead of silently breaking a back end; generating the numbers would add machinery for types that do not change. Lowering still finds `std/html`'s constructors by name (`html_ctor`): lowering is where names become tags. The `ref` operations are told apart by name (`get`) within the `St` effect. |
| 196 | 196 | - **Status (PR 3, runtime part, done):** the runtime writes each tag in fewer places. `tl_string_split`, `tl_string_parse_int` and `tl_os_env` build their lists and tuples with `values::list` and `values::cell` (L2), `process::data` uses `values::cell`, and `http.rs` names `Head`'s and `Chunk`'s tags. Unit tests check the tags and fields of the values these externs return; `docs/runtime-abi.md` lists the constructors the runtime builds. |
| 197 | 197 | |
| 198 | 198 | - [x] **M5. Which module a path denotes is decided in four places, and one of them is wrong.** Size **S**, PR **(4)**. |
| 199 | 199 | - **The four places:** |
| 200 | | − - `crates/tilc/src/main.rs:142` `add_target`; |
| 200 | + - `crates/louise/src/main.rs:142` `add_target`; |
| 201 | 201 | - `main.rs:336-354`, inside `test`; |
| 202 | 202 | - `main.rs:294` `package_natives`; |
| 203 | | − - `crates/tilc_lsp/src/lib.rs:234` `open`. |
| 204 | | − - **The bug, reproduced:** in a package with `src/main.til` and `src/util.til`, `tilc test src/util.til` printed `test main.in_main ... ok`. It ran `main`'s tests and skipped `util`'s, whose test would have failed: `add_target` returns `"main"` for any file under `src/` (`main.rs:153`). |
| 205 | | − - **A related problem:** the LSP discards manifest errors (`let _ = self.db.load_package(&root)`, `tilc_lsp/src/lib.rs:241`), so a broken `tilcayo.toml` shows up as unresolved imports. Manifest errors are plain `String`s (`tilc_db/src/manifest.rs:109,117,198`), not diagnostics. |
| 203 | + - `crates/louise_lsp/src/lib.rs:234` `open`. |
| 204 | + - **The bug, reproduced:** in a package with `src/main.lse` and `src/util.lse`, `louise test src/util.lse` printed `test main.in_main ... ok`. It ran `main`'s tests and skipped `util`'s, whose test would have failed: `add_target` returns `"main"` for any file under `src/` (`main.rs:153`). |
| 205 | + - **A related problem:** the LSP discards manifest errors (`let _ = self.db.load_package(&root)`, `louise_lsp/src/lib.rs:241`), so a broken `louise.toml` shows up as unresolved imports. Manifest errors are plain `String`s (`louise_db/src/manifest.rs:109,117,198`), not diagnostics. |
| 206 | 206 | - **The fix:** |
| 207 | | − - Add `Db::add_target(path) -> Result<Target, LoadError>` in `tilc_db`. It loads the package or the file, and returns the module(s) the path names, from its place under `src/` or `test/`. The driver subcommands and the LSP all use it. |
| 208 | | − - Make manifest errors diagnostics pointing into `tilcayo.toml`, so the CLI and the LSP both report them. |
| 207 | + - Add `Db::add_target(path) -> Result<Target, LoadError>` in `louise_db`. It loads the package or the file, and returns the module(s) the path names, from its place under `src/` or `test/`. The driver subcommands and the LSP all use it. |
| 208 | + - Make manifest errors diagnostics pointing into `louise.toml`, so the CLI and the LSP both report them. |
| 209 | 209 | - **Status (PR 4, done):** |
| 210 | | − - **One decision:** `tilc_package::Target::of(path)`, with its rules in a table in `target.rs`: a directory in a package names the package; a file under `src/` or `test/` names that module of its package (which is loaded whole); any other file is a module of its own. It is not `Db::add_target`: deciding needs no database and works on paths that do not exist yet (an editor's new buffer), and the driver and the server load differently (the driver resolves with `--offline`/`--locked` and prints lockfile changes; the server never fetches nor writes). The module a file names is the one `Db::module_of_file` says it was loaded as, so the rule naming a package's modules stays in one place too. |
| 210 | + - **One decision:** `louise_package::Target::of(path)`, with its rules in a table in `target.rs`: a directory in a package names the package; a file under `src/` or `test/` names that module of its package (which is loaded whole); any other file is a module of its own. It is not `Db::add_target`: deciding needs no database and works on paths that do not exist yet (an editor's new buffer), and the driver and the server load differently (the driver resolves with `--offline`/`--locked` and prints lockfile changes; the server never fetches nor writes). The module a file names is the one `Db::module_of_file` says it was loaded as, so the rule naming a package's modules stays in one place too. |
| 211 | 211 | - **The driver** loads every path through `load::load`, used by `check`, and by `compile`, which `run`, `build`, `core` and `test` share. The package is resolved once per command; `build` resolved it a second time for its native dependencies (which keep absolute paths). |
| 212 | | − - **The bug is fixed:** `tilc test src/util.til` runs `util`'s tests. Test: `cli.rs` `test_runs_the_module_a_file_names`. By the same rule, intended changes: `tilc run src/util.til` runs `util`'s `main` (it ran the package's); a file under `test/` loads its package and its tests (so `tilc check test/x.til` resolves its imports, and `tilc test test/x.til` runs that module's tests only, not the whole package's); a file inside a package directory but outside `src/` and `test/` is standalone for every command (`build` used to give it the package's native dependencies and name). |
| 213 | | − - **The language server** opens files through `Target::of` too: a file under `test/` loads its package (it used to stand alone, so its imports failed). `Db::load_package` reports what goes wrong as a diagnostic, `E0801`, in the manifest at fault, at the entry concerned, and still loads the package's own modules. Test: `tilc_lsp/tests/server.rs` `reports_manifest_errors_and_loads_tests`. |
| 212 | + - **The bug is fixed:** `louise test src/util.lse` runs `util`'s tests. Test: `cli.rs` `test_runs_the_module_a_file_names`. By the same rule, intended changes: `louise run src/util.lse` runs `util`'s `main` (it ran the package's); a file under `test/` loads its package and its tests (so `louise check test/x.lse` resolves its imports, and `louise test test/x.lse` runs that module's tests only, not the whole package's); a file inside a package directory but outside `src/` and `test/` is standalone for every command (`build` used to give it the package's native dependencies and name). |
| 213 | + - **The language server** opens files through `Target::of` too: a file under `test/` loads its package (it used to stand alone, so its imports failed). `Db::load_package` reports what goes wrong as a diagnostic, `E0801`, in the manifest at fault, at the entry concerned, and still loads the package's own modules. Test: `louise_lsp/tests/server.rs` `reports_manifest_errors_and_loads_tests`. |
| 214 | 214 | - **Not done, deliberately:** the command line prints manifest errors as before (`error: <path>: <message>`), not as rendered diagnostics. They stop the command before any checking, the message already names the file, and TOML's own errors already show the line with a caret. Found on the way: N5. |
| 215 | 215 | |
| 216 | 216 | - [x] **M6. Oversized files and functions.** Size **M**, PRs **(1)**, **(2)** and **(3)** (mechanical moves along existing section comments). |
| 217 | | − - `tilc_core/src/lower.rs` (2,002 lines). Its `// ----` sections are already in place, so the split is mechanical: |
| 217 | + - `louise_core/src/lower.rs` (2,002 lines). Its `// ----` sections are already in place, so the split is mechanical: |
| 218 | 218 | - move "derived impls" (`:679-988`) to `lower/derive.rs`; |
| 219 | 219 | - move "HTML" (`:1164-1290`) to `lower/html.rs`; |
| 220 | 220 | - move "patterns" (the decision tree, `:1667-2002`) to `lower/pattern.rs`. |
| 221 | | − - `tilc_types/src/infer.rs` (1,567 lines): move `handle` (176 lines, `:1266`) and `region` to `infer/handlers.rs`, and patterns (`:1443+`) to `infer/pat.rs`. `FnInfer::new` and `check_body_against` take 8 and 10 arguments (`#[allow(clippy::too_many_arguments)]`, `infer.rs:93`, `lib.rs:577`); pass a context struct instead. |
| 222 | | − - `tilc_codegen_c/src/emit.rs` (1,227 lines): |
| 221 | + - `louise_types/src/infer.rs` (1,567 lines): move `handle` (176 lines, `:1266`) and `region` to `infer/handlers.rs`, and patterns (`:1443+`) to `infer/pat.rs`. `FnInfer::new` and `check_body_against` take 8 and 10 arguments (`#[allow(clippy::too_many_arguments)]`, `infer.rs:93`, `lib.rs:577`); pass a context struct instead. |
| 222 | + - `louise_codegen_c/src/emit.rs` (1,227 lines): |
| 223 | 223 | - `value` is 271 lines (`:826`); move its `Perform`, `Handle` and `Region` arms to `emit/effects.rs`; |
| 224 | 224 | - move the 60-line C `PRELUDE` string (`:16-70`) to `prelude.h`, pulled in with `include_str!`. It can then be read and compiled as C. |
| 225 | | − - `tilrt/src/sched.rs` (1,367 lines) holds five concerns. Split them into: |
| 225 | + - `louise_rt/src/sched.rs` (1,367 lines) holds five concerns. Split them into: |
| 226 | 226 | - `actor.rs`: actor state and the mailbox (`Proc`, `Mailbox`, `Cell`, `:85-330`); |
| 227 | 227 | - `reactor.rs`: the reactor and I/O (`:1031-1170`); |
| 228 | 228 | - `clock.rs`: the clock and timers (`:1172-1250`); |
| 229 | 229 | - `sched.rs` keeps the queues and workers (`:826-1018`) and the C entry points (`:1252-1367`). |
| 230 | | − - `tilc_core/src/sched.rs` `request` (218 lines): one function per operation, as `tilrt/src/process.rs` already does. |
| 231 | | − - Leave as they are: `tilc_hir/src/lib.rs` `collect_items` (175 lines) and `tilc_types/src/lib.rs` `infer_scc` (173 lines) are long, but each is one linear pipeline. |
| 230 | + - `louise_core/src/sched.rs` `request` (218 lines): one function per operation, as `louise_rt/src/process.rs` already does. |
| 231 | + - Leave as they are: `louise_hir/src/lib.rs` `collect_items` (175 lines) and `louise_types/src/lib.rs` `infer_scc` (173 lines) are long, but each is one linear pipeline. |
| 232 | 232 | - **Status (PR 1, front end, done; PRs 2 and 3 open):** moves were verbatim (checked by comparing the moved lines), and generated C is unchanged. |
| 233 | | − - `tilc_types/src/infer.rs` (1,617 lines on the v1 base) became `infer/mod.rs` (1,018), `infer/effects.rs` (500: performing, label resolution, `handle`, `region`, `defer`) and `infer/pat.rs` (131). |
| 234 | | − - `tilc_hir/src/lower.rs` (1,417 on the v1 base) became `lower/mod.rs` (1,033), `lower/html.rs` (219) and `lower/pat.rs` (216). |
| 235 | | − - `tilc_types/src/env.rs` (1,303, three concerns) became `env/mod.rs` (975) and `env/impls.rs` (351: the impl table and coherence). |
| 236 | | − - The derive checks of ADR 0019 moved from `tilc_types/src/lib.rs` to `derive.rs`, leaving `lib.rs` (759) the checker's pipeline. |
| 233 | + - `louise_types/src/infer.rs` (1,617 lines on the v1 base) became `infer/mod.rs` (1,018), `infer/effects.rs` (500: performing, label resolution, `handle`, `region`, `defer`) and `infer/pat.rs` (131). |
| 234 | + - `louise_hir/src/lower.rs` (1,417 on the v1 base) became `lower/mod.rs` (1,033), `lower/html.rs` (219) and `lower/pat.rs` (216). |
| 235 | + - `louise_types/src/env.rs` (1,303, three concerns) became `env/mod.rs` (975) and `env/impls.rs` (351: the impl table and coherence). |
| 236 | + - The derive checks of ADR 0019 moved from `louise_types/src/lib.rs` to `derive.rs`, leaving `lib.rs` (759) the checker's pipeline. |
| 237 | 237 | - `check_body_against` takes a `KnownSig` instead of four more arguments. **Not done, deliberately:** `FnInfer::new` keeps its 8 arguments. They are distinct borrows the inference keeps; a struct would only be taken apart in `new`. |
| 238 | 238 | - **Not done, deliberately:** long front-end functions (`infer.rs` `handle` 176 lines, `infer_expr`, `call`, `check_impls`, `lower_expr`, `resolve_imports`). Each is one `match` or one linear pipeline; splitting them is not a mechanical move, and the file splits already put each in a cohesive module. |
| 239 | 239 | - **Status (PR 2, back end, done; PR 3 open):** moves were verbatim (checked by comparing the sorted lines), and generated C is unchanged. |
| 240 | | − - `tilc_core/src/lower.rs` (1,987 lines) became `lower/mod.rs` (1,278), `lower/derive.rs` (299), `lower/html.rs` (104) and `lower/pattern.rs` (332), along its section comments. Methods called across modules are `pub(super)`. |
| 241 | | − - `tilc_codegen_c/src/emit.rs` (1,290) became `emit/mod.rs` (1,023) and `emit/effects.rs` (206: the `Perform`, `Handle`, `Region` and `Defer` arms of `value`, now methods). The C prelude is `emit/prelude.h`, read with `include_str!`. `value` lost an unused `held` parameter. |
| 242 | | − - **Not done, deliberately:** the interpreter scheduler's `request` (now in `tilc_interp/src/sched.rs`, 193 lines) stays one `match` over the operations; one function per operation is not a mechanical move, and this PR keeps to those. `emit`'s `expr` (205 lines) is one loop over a `match` on Core statements. |
| 240 | + - `louise_core/src/lower.rs` (1,987 lines) became `lower/mod.rs` (1,278), `lower/derive.rs` (299), `lower/html.rs` (104) and `lower/pattern.rs` (332), along its section comments. Methods called across modules are `pub(super)`. |
| 241 | + - `louise_codegen_c/src/emit.rs` (1,290) became `emit/mod.rs` (1,023) and `emit/effects.rs` (206: the `Perform`, `Handle`, `Region` and `Defer` arms of `value`, now methods). The C prelude is `emit/prelude.h`, read with `include_str!`. `value` lost an unused `held` parameter. |
| 242 | + - **Not done, deliberately:** the interpreter scheduler's `request` (now in `louise_interp/src/sched.rs`, 193 lines) stays one `match` over the operations; one function per operation is not a mechanical move, and this PR keeps to those. `emit`'s `expr` (205 lines) is one loop over a `match` on Core statements. |
| 243 | 243 | - **Status (PR 3, runtime, done):** moves were verbatim (checked by comparing the moved lines). |
| 244 | 244 | - `net.rs` (431 lines on the v1 base) became `net.rs` (321: sockets) and `http.rs` (488, of which 300 are tests: HTTP framing, H3). |
| 245 | 245 | - `prims.rs` (663 lines after PR 2) became `prims.rs` (447: the std externs over floats, strings, randomness and the environment, panics, shared helpers), `region.rs` (154: regions and their references) and `resource.rs` (60). Both are runtime block kinds with a hook `heap.rs` calls when freeing. |
| @@ -260,59 +260,59 @@ The reference interpreter duplicates the runtime's semantics on purpose: it is t |
| 260 | 260 | - On the v1 base the panicking arithmetic (`tl_int_div_slow`, `tl_int_rem_slow`) and `tl_random_int` were already `unsafe extern "C"`. |
| 261 | 261 | - `prims::dup` is gone; `heap::dup_value` returns its argument, like the C `tl_dup`. |
| 262 | 262 | - `panic_with` is `unsafe`, and each caller says why its context is the running actor's. `tl_coerce` (a safe extern that dup'd its argument) and `array::out_of_range` (which reads the array) are `unsafe`. A scan of every safe function taking a raw pointer or a `Value` found no other that dereferences one. |
| 263 | | − - **The rule** is in the `tilrt` crate doc: a function that may dereference a context, a `Value` or another raw pointer is `unsafe`. Functions that only allocate and fill a fresh block stay safe though they take a context (`values::cell`, `ok`, `error`, `list`, `string`, `bytes_from`, `tl_float_from`, `tl_region_new`, `tl_resource_new`, `tl_closure_alloc`, `int::from_big`): `tl_alloc` never reads its context, which its doc now states as an invariant they rely on. |
| 263 | + - **The rule** is in the `louise_rt` crate doc: a function that may dereference a context, a `Value` or another raw pointer is `unsafe`. Functions that only allocate and fill a fresh block stay safe though they take a context (`values::cell`, `ok`, `error`, `list`, `string`, `bytes_from`, `tl_float_from`, `tl_region_new`, `tl_resource_new`, `tl_closure_alloc`, `int::from_big`): `tl_alloc` never reads its context, which its doc now states as an invariant they rely on. |
| 264 | 264 | - **Not done, deliberately:** turning `*mut Ctx` into `&mut Ctx` at the entry points. Generated C, closures and callbacks the runtime calls write through the same context, so a `&mut Ctx` held across those calls would itself break Rust's aliasing rules; and it would touch every extern for no gain in what is checked. |
| 265 | 265 | - **`Fiber: Send`.** The `SAFETY` comment now names every thread-local reached on an actor's fiber and why its address is not reused after the fiber moves (the optimiser treats a thread-local's address as constant within a function, after inlining). `IN_SLICE` and `DEFERRED` (read inline in `Shared::push` since issue #61) and `LOCAL` in `local_index` are now read in `#[inline(never)]` functions, like `push_local`: no measurable cost. `callback`'s thread-locals are read only while a C call is in progress, when the actor never suspends. |
| 266 | | − - **`stats::MINE` stays inline.** Out of line, it cost 12% on `tests/bench/floats.til` and 2–3% on `lists` and `dict` (interleaved runs). Disassembling the release `libtilrt.a` shows no function that both reaches a thread-local and calls something that suspends (only `sched::worker`, which runs on the scheduler thread's own stack). Nothing guarantees this across compiler versions or inlining changes; if it broke, an allocation after a migration would update another thread's count (a wrong leak-oracle total) or, if that thread never allocated, register into its thread-local slot (a data race). |
| 266 | + - **`stats::MINE` stays inline.** Out of line, it cost 12% on `tests/bench/floats.lse` and 2–3% on `lists` and `dict` (interleaved runs). Disassembling the release `liblouise_rt.a` shows no function that both reaches a thread-local and calls something that suspends (only `sched::worker`, which runs on the scheduler thread's own stack). Nothing guarantees this across compiler versions or inlining changes; if it broke, an allocation after a migration would update another thread's count (a wrong leak-oracle total) or, if that thread never allocated, register into its thread-local slot (a data race). |
| 267 | 267 | - **For engineering review:** (a) whether relying on today's inlining for `MINE` is acceptable, or the oracle should pay the call, or count per actor through `ctx->rt` (which would make `tl_alloc` read its context, and the helpers above `unsafe`); (b) the `Fiber` argument as a whole. |
| 268 | 268 | |
| 269 | 269 | - [x] **M8. The test harnesses duplicate the pipeline and the expectation format.** Size **S**, PRs **(2)** and **(4)**. |
| 270 | 270 | - **The pipeline** (analyse → errors → `lower` → `entry`) is copied 7 times: |
| 271 | | − - `tilc/src/main.rs:235,360`; |
| 272 | | − - `tilc_core/tests/run.rs:28-38` and `lowering.rs:33`; |
| 273 | | − - `tilc_perceus/tests/programs.rs:11-18`; |
| 274 | | − - `tilc_codegen_c/tests/native.rs:26-40` and `lines.rs:25`. |
| 271 | + - `louise/src/main.rs:235,360`; |
| 272 | + - `louise_core/tests/run.rs:28-38` and `lowering.rs:33`; |
| 273 | + - `louise_perceus/tests/programs.rs:11-18`; |
| 274 | + - `louise_codegen_c/tests/native.rs:26-40` and `lines.rs:25`. |
| 275 | 275 | - **The expectation format** (`//>` lines and `//! panic:`) is parsed 4 times: `run.rs:44-53`, `native.rs:73-90`, `scripts/stress.sh:15` and `scripts/bench.sh:34`. |
| 276 | 276 | - **Leftover scaffolding:** `NOT_YET` is empty (`native.rs:21-22`), but its handling remains (`:110-125`), along with "M5 part 1" comments. |
| 277 | 277 | - **The fix:** |
| 278 | | − - Add a dev-only `crates/tilc_testkit` with `compile(path) -> Compiled { db, analysis, program, entry }` and `Expectations::parse(text)`. |
| 278 | + - Add a dev-only `crates/louise_testkit` with `compile(path) -> Compiled { db, analysis, program, entry }` and `Expectations::parse(text)`. |
| 279 | 279 | - Remove `NOT_YET`. |
| 280 | 280 | - Document the `//>` format once, in `tests/README.md`, which the scripts point to. |
| 281 | | − - **Status (PR 2, done; PR 4 open):** `crates/tilc_testkit` (a dev-dependency) has `compile`, `compile_file`, `Compiled::entry`, `run_programs`, `Expectations::parse` and `build_runtime`. The interpreter, native, `#line`, never-unwinds, externs, Perceus, lowering and evidence harnesses use it; `NOT_YET` and its handling are gone. `tests/README.md` documents the format, and `scripts/stress.sh` and `bench.sh` point to it. Left for PR 4: the two copies of the pipeline in `tilc/src/main.rs`. |
| 282 | | − - **Status (PR 4, done):** `tilc test` loaded, analysed and lowered by itself; it now goes through `compile`, like `run`, `build` and `core`, which returns a `Compiled` (database, analysis, Core, and what the path named). The driver does not use `tilc_testkit`: that is a dev-dependency, and the driver reports diagnostics and resolves packages, which the test kit does not. `bench.sh` and `stress.sh` share their `//>` extraction in `scripts/lib.sh`. |
| 281 | + - **Status (PR 2, done; PR 4 open):** `crates/louise_testkit` (a dev-dependency) has `compile`, `compile_file`, `Compiled::entry`, `run_programs`, `Expectations::parse` and `build_runtime`. The interpreter, native, `#line`, never-unwinds, externs, Perceus, lowering and evidence harnesses use it; `NOT_YET` and its handling are gone. `tests/README.md` documents the format, and `scripts/stress.sh` and `bench.sh` point to it. Left for PR 4: the two copies of the pipeline in `louise/src/main.rs`. |
| 282 | + - **Status (PR 4, done):** `louise test` loaded, analysed and lowered by itself; it now goes through `compile`, like `run`, `build` and `core`, which returns a `Compiled` (database, analysis, Core, and what the path named). The driver does not use `louise_testkit`: that is a dev-dependency, and the driver reports diagnostics and resolves packages, which the test kit does not. `bench.sh` and `stress.sh` share their `//>` extraction in `scripts/lib.sh`. |
| 283 | 283 | |
| 284 | 284 | - [x] **M9. Smaller test gaps.** Size **S** each, PRs **(1)** and **(2)**. |
| 285 | 285 | - **Diagnostic codes:** 6 of the 51 are never asserted by any test: `E0109`, `E0112`, `E0211`, `E0212`, `E0405` (orphan impls) and `E0411`. Add `tests/ui` cases. |
| 286 | | − - **The unifier and row operations** (`tilc_types/src/ty.rs`: `unify`, row rewriting) are tested only through whole programs (4 unit tests in a 4.6k-line crate). A handful of table-driven tests would pinpoint regressions in the subtlest code. |
| 287 | | − - **Match compilation** (`tilc_core/src/lower.rs:1667+`) is checked only by running programs. One snapshot test exists (`tests/lowering.rs`, 42 lines). Add snapshots of decision trees: or-patterns, nested constructors, literals. |
| 288 | | − - **`tilc_perceus::verify`** runs only in `tilc_perceus/tests/programs.rs`. Run it under `cfg(debug_assertions)` in `generate_entries` (`tilc_codegen_c/src/lib.rs:93`), so every program compiled in debug builds is checked. |
| 286 | + - **The unifier and row operations** (`louise_types/src/ty.rs`: `unify`, row rewriting) are tested only through whole programs (4 unit tests in a 4.6k-line crate). A handful of table-driven tests would pinpoint regressions in the subtlest code. |
| 287 | + - **Match compilation** (`louise_core/src/lower.rs:1667+`) is checked only by running programs. One snapshot test exists (`tests/lowering.rs`, 42 lines). Add snapshots of decision trees: or-patterns, nested constructors, literals. |
| 288 | + - **`louise_perceus::verify`** runs only in `louise_perceus/tests/programs.rs`. Run it under `cfg(debug_assertions)` in `generate_entries` (`louise_codegen_c/src/lib.rs:93`), so every program compiled in debug builds is checked. |
| 289 | 289 | - **Status (PR 1, front end, done; PR 2 open):** |
| 290 | | − - On the v1 base, `E0212`, `E0405` and `E0411` were already asserted. `tests/ui/names.til` and `tests/ui/definitions.til` now assert `E0109`, `E0112` and `E0211`, so every documented code is asserted, including the new `E0114` and `E0115`. |
| 291 | | − - `tilc_types/src/ty.rs` has 10 unit tests of the unifier and row operations. |
| 290 | + - On the v1 base, `E0212`, `E0405` and `E0411` were already asserted. `tests/ui/names.lse` and `tests/ui/definitions.lse` now assert `E0109`, `E0112` and `E0211`, so every documented code is asserted, including the new `E0114` and `E0115`. |
| 291 | + - `louise_types/src/ty.rs` has 10 unit tests of the unifier and row operations. |
| 292 | 292 | - Match compilation snapshots and `verify` in debug builds are PR 2's. |
| 293 | 293 | - **Status (PR 2, done):** |
| 294 | | − - `tilc_core/tests/lowering.rs` snapshots the decision trees of or-patterns (of constructors with and without fields), nested constructors in a tuple, `Int`, `String` and `Float` literals, and list patterns with a guard and an `as` binding (see N3). |
| 295 | | − - `generate_units` runs `tilc_perceus::verify` after Perceus when the compiler is built with debug assertions, inside the `perceus` phase. Every native test and every debug build now checks the counts of what it compiles; release builds do not pay for it. |
| 294 | + - `louise_core/tests/lowering.rs` snapshots the decision trees of or-patterns (of constructors with and without fields), nested constructors in a tuple, `Int`, `String` and `Float` literals, and list patterns with a guard and an `as` binding (see N3). |
| 295 | + - `generate_units` runs `louise_perceus::verify` after Perceus when the compiler is built with debug assertions, inside the `perceus` phase. Every native test and every debug build now checks the counts of what it compiles; release builds do not pay for it. |
| 296 | 296 | |
| 297 | 297 | - [x] **M10. `runtime-abi.md`, the ADR statuses and module docs contradict themselves.** Size **M**, PR **(3)** for the runtime docs, PR **(4)** for the ADR index. |
| 298 | 298 | - **`docs/runtime-abi.md` reads as an append-only log**, so a reader cannot tell the current ABI from the superseded ones: |
| 299 | 299 | - Revision 1 says unwinding is table-driven, with `-fexceptions` and `_Unwind_ForcedUnwind` (`:179-183`). "Unwinding (part 2)" (`:201-204`) and the code (`emit.rs:649`) use yield checks. |
| 300 | 300 | - `:217` says the threads "share one round-robin queue"; `:230` says (correctly) that each thread has a FIFO queue. |
| 301 | | − - **The `tilrt/src/sched.rs:4` module doc** says "a round-robin run queue, shared by the scheduler threads", while its own `:16-19` describes per-thread queues with stealing. |
| 301 | + - **The `louise_rt/src/sched.rs:4` module doc** says "a round-robin run queue, shared by the scheduler threads", while its own `:16-19` describes per-thread queues with stealing. |
| 302 | 302 | - **ADR statuses disagree with each other:** |
| 303 | 303 | - ADRs 0001-0004 say "Accepted … including Revision 1" in their header, but their Revision 1 status lines (`0001:59`, `0002:55`, `0003:46`, `0004:108`) still say "Proposed … needs engineering review (#2)"; |
| 304 | 304 | - `docs/adr/README.md:9` lists what awaits review, but omits ADR 0005 Revision 1 (`0005:68`, Proposed); |
| 305 | 305 | - ADR 0006 (`:58`) names an API (`parse(file)`, `interface(module)`, `check_item(item)`) that does not exist; `Db` has `analyze()`. |
| 306 | | − - **`tilrt.h` does not separate audiences.** It mixes the API for generated code with the API for bindings, without saying which is which. It also lacks the 16 exported functions listed in H1. |
| 306 | + - **`louise_rt.h` does not separate audiences.** It mixes the API for generated code with the API for bindings, without saying which is which. It also lacks the 16 exported functions listed in H1. |
| 307 | 307 | - **The fix:** |
| 308 | | − - Split `runtime-abi.md` into "Current ABI" (normative, matching `tilrt.h`) and "History" (or move the history into the ADR revisions). |
| 308 | + - Split `runtime-abi.md` into "Current ABI" (normative, matching `louise_rt.h`) and "History" (or move the history into the ADR revisions). |
| 309 | 309 | - Fix the `sched.rs` doc. |
| 310 | 310 | - Give each ADR section exactly one status, and make the index match it. |
| 311 | | − - Mark the binding-facing part of `tilrt.h`. |
| 311 | + - Mark the binding-facing part of `louise_rt.h`. |
| 312 | 312 | - **Status (PR 3, runtime docs, done; PR 4 open for the ADRs):** |
| 313 | 313 | - `docs/runtime-abi.md` describes the ABI the code implements, section by section (values, blocks, context, calls, reference counting, unwinding, preemption, handlers, actors, native dependencies, the standard library in the runtime), with a status table pointing at the ADRs, PR 2's "Adding a runtime extern", and a short History of what changed when. The anchors other documents link to are kept. Fixed on the way: Revision 1's table-driven unwinding (never implemented) presented as current, the shared round-robin queue, a 4000-entry budget (it is 2000), "`TL_ABI_VERSION` stays 1" for callbacks (it is 2), v0's single thread and 256 KiB stacks, and the "Cycles through `Ref`s leak" limitation (regions clear them). |
| 314 | 314 | - The `sched.rs` module doc no longer describes one shared round-robin queue, and names all five revisions of ADR 0004. |
| 315 | | − - `tilrt.h` says which functions C bindings use (the rest is for generated code), and loses its "M0: single scheduler thread" and "opaque in ABI v0" notes. Comment changes only; PR 2 added the missing prototypes (H1). |
| 315 | + - `louise_rt.h` says which functions C bindings use (the rest is for generated code), and loses its "M0: single scheduler thread" and "opaque in ABI v0" notes. Comment changes only; PR 2 added the missing prototypes (H1). |
| 316 | 316 | - The ADRs' contradictory statuses are PR 4's; `runtime-abi.md` points at them instead of restating them. |
| 317 | 317 | - **Status (PR 4, ADRs, done):** |
| 318 | 318 | - Every ADR section has one status. The Revision 1 of ADRs 0001–0004 now says what their headers say: accepted with the ADR (issue #2). Sections written after that review that pointed at the closed #2, or at no issue (ADR 0004's M6 part 5 and part 6, ADR 0005's Revision 1, ADR 0010, ADR 0003's Revision 2), point at #44. |
| @@ -322,139 +322,139 @@ The reference interpreter duplicates the runtime's semantics on purpose: it is t |
| 322 | 322 | ### Low |
| 323 | 323 | |
| 324 | 324 | - [x] **L1. Stale user-facing text.** Size **S**, PRs **(4)** and **(2)**. |
| 325 | | − - The `tilc run --native` help says "(M5: programs without `ctl`, `final ctl` or actors)" (`tilc/src/main.rs:39-40`). Everything compiles natively now. |
| 326 | | − - The `tilc_lsp` crate doc (`lib.rs:3-5`) lists 6 features. The server implements 10: references, formatting, inlay hints and semantic tokens are missing from the list. |
| 327 | | − - **Status (PR 2):** the back end's stale milestone note is gone (`tilc_core/src/ir.rs` said C codegen was to come). The two items above are PR 4's. |
| 328 | | − - **Status (PR 4, done):** the `run --native` help, the driver's crate doc ("through C, M5") and the language server's crate doc (all ten features, and how packages load) are current. Also: the help of `run`, `build` and `test` says what a path names (M5); `tilc_lsp`'s Cargo description promised hover "in later milestones"; the README called `std` "prelude so far". `docs/reference/language.md` and ADR 0020 say what M5 changed. |
| 325 | + - The `louise run --native` help says "(M5: programs without `ctl`, `final ctl` or actors)" (`louise/src/main.rs:39-40`). Everything compiles natively now. |
| 326 | + - The `louise_lsp` crate doc (`lib.rs:3-5`) lists 6 features. The server implements 10: references, formatting, inlay hints and semantic tokens are missing from the list. |
| 327 | + - **Status (PR 2):** the back end's stale milestone note is gone (`louise_core/src/ir.rs` said C codegen was to come). The two items above are PR 4's. |
| 328 | + - **Status (PR 4, done):** the `run --native` help, the driver's crate doc ("through C, M5") and the language server's crate doc (all ten features, and how packages load) are current. Also: the help of `run`, `build` and `test` says what a path names (M5); `louise_lsp`'s Cargo description promised hover "in later milestones"; the README called `std` "prelude so far". `docs/reference/language.md` and ADR 0020 say what M5 changed. |
| 329 | 329 | - [x] **L2. Small dead code and internal duplication.** Size **S**, PRs **(2)** and **(3)**. |
| 330 | 330 | - **Unused or redundant code:** |
| 331 | | − - `check_supported` has an unused `_reachable` parameter (`tilc_codegen_c/src/lib.rs:168`); |
| 331 | + - `check_supported` has an unused `_reachable` parameter (`louise_codegen_c/src/lib.rs:168`); |
| 332 | 332 | - `prims::text_of` only forwards to `text` (`prims.rs:51-64`). |
| 333 | | − - **Duplication inside `tilrt`:** |
| 333 | + - **Duplication inside `louise_rt`:** |
| 334 | 334 | - `fn string` is defined twice (`prims.rs:67`, `net.rs:431`); |
| 335 | 335 | - `tl_string_split` (`prims.rs:343-354`), `tl_os_env` (`:683`) and `tl_string_parse_int` (`:368`) build cells by hand instead of using `values::list` and `values::cell`. |
| 336 | | − - **Status (PR 2):** `check_supported` lost its `_reachable` parameter, and codegen's `value` its unused `held`. The `tilrt` items are PR 3's. |
| 336 | + - **Status (PR 2):** `check_supported` lost its `_reachable` parameter, and codegen's `value` its unused `held`. The `louise_rt` items are PR 3's. |
| 337 | 337 | - **Status (PR 3, done):** `prims::text_of` is gone (`values::text`), the two `fn string` are one `values::string`, and `tl_string_split`, `tl_os_env` and `tl_string_parse_int` use `values::list` and `values::cell`. |
| 338 | | −- [x] **L3. A hand-copied ABI constant with no compile-time check.** Size **S**, PR **(2)**. `XARGS = 26` is in `emit.rs:14` ("must match"), `abi.rs:92` and `tilrt.h:119`. The Rust and C sides are asserted against each other; codegen is not. The fix: emit `_Static_assert(TL_XARGS == 26, …)` in the generated prelude. |
| 338 | +- [x] **L3. A hand-copied ABI constant with no compile-time check.** Size **S**, PR **(2)**. `XARGS = 26` is in `emit.rs:14` ("must match"), `abi.rs:92` and `louise_rt.h:119`. The Rust and C sides are asserted against each other; codegen is not. The fix: emit `_Static_assert(TL_XARGS == 26, …)` in the generated prelude. |
| 339 | 339 | - **Status (PR 2, done):** every generated C file asserts `TL_XARGS == 26` (from codegen's `XARGS`) right after the prelude. A mismatch is a C compile error. This is the one change to every generated file. |
| 340 | 340 | - [x] **L4. Stringly-typed errors in crate APIs.** Size **S**, PR **(4)**. |
| 341 | | − - `tilc_core::entry` and `runnable` (`lib.rs:27`), `manifest::{load, parse, closure}` and `tilc_perceus::verify` all return `Result<_, String>`. |
| 341 | + - `louise_core::entry` and `runnable` (`lib.rs:27`), `manifest::{load, parse, closure}` and `louise_perceus::verify` all return `Result<_, String>`. |
| 342 | 342 | - Native test failures are forced into `interp::RtError::Panic` (`main.rs:456-475`). |
| 343 | 343 | - Add typed errors when a second consumer appears. For manifests, do it now (M5). |
| 344 | 344 | - **Status (PR 4, done for manifests and tests; the rest left deliberately):** |
| 345 | | − - `manifest::load` and `parse` return a `ManifestError` (the manifest's path, the byte span of the entry at fault, a message), and `tilc_package::resolve` an `Error` (`Manifest`, or `Other` for the lockfile, git and conflicting requirements). Both print what the `String` did, so the command line is unchanged (checked on broken manifests with `check`, `run`, `test` and `build`); the language server turns them into diagnostics (M5). There is no `closure` any more (resolution replaced it). |
| 345 | + - `manifest::load` and `parse` return a `ManifestError` (the manifest's path, the byte span of the entry at fault, a message), and `louise_package::resolve` an `Error` (`Manifest`, or `Other` for the lockfile, git and conflicting requirements). Both print what the `String` did, so the command line is unchanged (checked on broken manifests with `check`, `run`, `test` and `build`); the language server turns them into diagnostics (M5). There is no `closure` any more (resolution replaced it). |
| 346 | 346 | - **Native test results** are no longer forced into `RtError::Panic`. Both back ends report an `Ended` (returned, panicked, failed) and one verdict decides. Fixed with it: a native test that crashed, or whose process could not start, counted as a panic, and passed `@should_panic` (whose fragment is empty without an argument). Such a failure is no longer printed with "panic: ". Test: `only_a_panic_satisfies_should_panic`. |
| 347 | | − - **Not done, deliberately:** `tilc_core::entry`, `runnable` and `tilc_perceus::verify` still return `String`. Every consumer prints the message and stops; none matches on the reason, so an enum would add variants without a reader. |
| 348 | | −- [x] **L5. `tilc test --native` leaves `$TMPDIR/tilc-test-<pid>/` behind** (`main.rs:442-446`). `run_native` cleans up after itself (`:316`). Size **S**, PR **(4)**. |
| 349 | | − - **Status (PR 4, done):** on the v1 base both removed their directory after a successful build only; a failed build (a C compiler error, a missing runtime) left `tilc-run-<pid>` or `tilc-test-<pid>` behind. A `TempDir` guard removes it on every way out. Checked with `TILC_CC=false`: the old binary left both directories, the new one none. |
| 347 | + - **Not done, deliberately:** `louise_core::entry`, `runnable` and `louise_perceus::verify` still return `String`. Every consumer prints the message and stops; none matches on the reason, so an enum would add variants without a reader. |
| 348 | +- [x] **L5. `louise test --native` leaves `$TMPDIR/louise-test-<pid>/` behind** (`main.rs:442-446`). `run_native` cleans up after itself (`:316`). Size **S**, PR **(4)**. |
| 349 | + - **Status (PR 4, done):** on the v1 base both removed their directory after a successful build only; a failed build (a C compiler error, a missing runtime) left `louise-run-<pid>` or `louise-test-<pid>` behind. A `TempDir` guard removes it on every way out. Checked with `LOUISE_CC=false`: the old binary left both directories, the new one none. |
| 350 | 350 | |
| 351 | 351 | --- |
| 352 | 352 | |
| 353 | 353 | ### Found during the cleanliness PRs |
| 354 | 354 | |
| 355 | 355 | - [ ] **N1. `@derive(module.Trait)` is documented but does not parse.** Size **S**, PR: a feature fix, outside the behaviour-preserving cleanliness PRs. |
| 356 | | − - `docs/reference/language.md` ("Elsewhere: derive a trait of another module with `@derive(module.Trait)`") and ADR 0019 promise it, and `Env::lookup_trait_name` handles a dotted name. But the attribute grammar (`tilc_syntax/src/grammar/mod.rs` `attr`) accepts only single identifiers, strings and Ints as arguments: `@derive(json.ToJson)` is a syntax error (`E0001`, "expected `,`, found `.`"). No test uses the form. |
| 357 | | − - **The fix:** accept `name.name` as an attribute argument in both grammars (rowan and tree-sitter), keep it as one `Arg` in `tilc_hir::attrs`, and add a `tests/run` case. |
| 356 | + - `docs/reference/language.md` ("Elsewhere: derive a trait of another module with `@derive(module.Trait)`") and ADR 0019 promise it, and `Env::lookup_trait_name` handles a dotted name. But the attribute grammar (`louise_syntax/src/grammar/mod.rs` `attr`) accepts only single identifiers, strings and Ints as arguments: `@derive(json.ToJson)` is a syntax error (`E0001`, "expected `,`, found `.`"). No test uses the form. |
| 357 | + - **The fix:** accept `name.name` as an attribute argument in both grammars (rowan and tree-sitter), keep it as one `Arg` in `louise_hir::attrs`, and add a `tests/run` case. |
| 358 | 358 | - [ ] **N2. A trait method's body is silently ignored.** Size **S**, PR **(1)** follow-up, needs a language decision. |
| 359 | | − - `trait Size<a> { fn size(x: a) -> Int { 1 } }` passes `tilc check`, and the body is never used: impls must still define every method. Default methods are not a feature. |
| 359 | + - `trait Size<a> { fn size(x: a) -> Int { 1 } }` passes `louise check`, and the body is never used: impls must still define every method. Default methods are not a feature. |
| 360 | 360 | - **The fix:** either report the body (`E0115`, as for an `@extern` function with a body), or design default methods. Left as is here because reporting it rejects programs that compile today, which these PRs avoid. |
| 361 | 361 | - [ ] **N3. Match compilation repeats tests and projections across rows.** Size **M**, needs engineering review (it changes generated code). |
| 362 | | − - The decision-tree snapshot (`tilc_core/tests/snapshots/lowering__decision_trees.snap`, `both`) shows it: matching `(a, b)` against the four combinations of `Some`/`None` and `Ok`/`Error` projects both columns once per row (8 projections), and when a row fails it tests the next row from its first column, so the tree repeats switches already decided and keeps `panic` arms that cannot be reached. The result is correct (every `tests/run` program agrees with the interpreter) but grows with rows times columns. |
| 362 | + - The decision-tree snapshot (`louise_core/tests/snapshots/lowering__decision_trees.snap`, `both`) shows it: matching `(a, b)` against the four combinations of `Some`/`None` and `Ok`/`Error` projects both columns once per row (8 projections), and when a row fails it tests the next row from its first column, so the tree repeats switches already decided and keeps `panic` arms that cannot be reached. The result is correct (every `tests/run` program agrees with the interpreter) but grows with rows times columns. |
| 363 | 363 | - **The fix:** a column-based decision tree (specialise the matrix on the constructor of one column, as in Maranget's "Compiling pattern matching to good decision trees"), sharing projections. Not done here: it changes the generated code, which these PRs keep byte-identical. |
| 364 | 364 | |
| 365 | 365 | - [x] **N4. `Content-Length` accepts Unicode whitespace around the number.** Size **S**, PR: a behaviour change, outside the behaviour-preserving cleanliness PRs. |
| 366 | | − - `tilrt/src/http.rs` `decimal_length` trims the value with `str::trim`, which removes Unicode whitespace, and httparse lets bytes 0x80–0xFF into header values (obs-text). So `Content-Length: \u{a0}5` (a no-break space) is read as 5. RFC 9110 allows only spaces and tabs around a field value, and a proxy in front of the server may read the header differently: a request-smuggling risk, though a small one (most proxies reject the header). |
| 366 | + - `louise_rt/src/http.rs` `decimal_length` trims the value with `str::trim`, which removes Unicode whitespace, and httparse lets bytes 0x80–0xFF into header values (obs-text). So `Content-Length: \u{a0}5` (a no-break space) is read as 5. RFC 9110 allows only spaces and tabs around a field value, and a proxy in front of the server may read the header differently: a request-smuggling risk, though a small one (most proxies reject the header). |
| 367 | 367 | - **The fix:** trim only spaces and tabs (`trim_ascii` would also do), and add the case to the unit tests and to `http_rejects_malformed_requests`. Left as is because it rejects requests that are served today. |
| 368 | 368 | - **Status: fixed** right after the runtime PR, as its own commit: `decimal_length` trims only spaces and tabs, and the unit test covers a no-break space (and checks that httparse already rejects a form feed or a vertical tab). A deliberate behaviour change: such requests now get 400. |
| 369 | 369 | |
| 370 | 370 | - [ ] **N5. The language server loads a package once.** Size **S**, needs a small design (file watching). |
| 371 | | − - It loads a package, its tests and its dependencies when the first of its files is opened, and never again. Editing `tilcayo.toml`, adding or deleting a module on disk, or fetching a missing dependency with a command-line build takes effect only after a restart; until then, a fixed manifest's `E0801` stays published. (A new, unsaved `src/lib.til` is also named `lib`, not after the package, until then.) |
| 372 | | − - **The fix:** register for `workspace/didChangeWatchedFiles` on `tilcayo.toml`, `tilcayo.lock` and `*.til`, and rebuild the package's part of the `Db` when one changes. Not done here: it is a feature, not a cleanup. |
| 373 | | −- [ ] **N6. `tilc check` does not check a package's `test/`.** Size **S**, PR: a behaviour change. |
| 374 | | − - `tilc check` loads `src/` only, so a test module with a type error passes `check` and fails `tilc test` (reproduced: `pub fn broken() -> Int { "no" }` under `test/`). The language server, since M5, does check `test/`, as ADR 0001's Revision 1 says ("Test functions are type-checked with everything else, so the LSP sees them"). |
| 371 | + - It loads a package, its tests and its dependencies when the first of its files is opened, and never again. Editing `louise.toml`, adding or deleting a module on disk, or fetching a missing dependency with a command-line build takes effect only after a restart; until then, a fixed manifest's `E0801` stays published. (A new, unsaved `src/lib.lse` is also named `lib`, not after the package, until then.) |
| 372 | + - **The fix:** register for `workspace/didChangeWatchedFiles` on `louise.toml`, `louise.lock` and `*.lse`, and rebuild the package's part of the `Db` when one changes. Not done here: it is a feature, not a cleanup. |
| 373 | +- [ ] **N6. `louise check` does not check a package's `test/`.** Size **S**, PR: a behaviour change. |
| 374 | + - `louise check` loads `src/` only, so a test module with a type error passes `check` and fails `louise test` (reproduced: `pub fn broken() -> Int { "no" }` under `test/`). The language server, since M5, does check `test/`, as ADR 0001's Revision 1 says ("Test functions are type-checked with everything else, so the LSP sees them"). |
| 375 | 375 | - **The fix:** load the tests in `check` (`load(…, tests: true, …)`). Left as is because it reports errors in programs that `check` accepts today. |
| 376 | | −- [ ] **N7. `tilc test` runs the dependencies' inline tests too.** Size **S**, PR: a behaviour change, needs a decision. |
| 377 | | − - For a package directory it runs the tests of every module outside `std`, which includes its dependencies' modules (reproduced: a path dependency's `@test` in its `src/lib.til` runs with the package's). No package in the repository has inline tests in a dependency, so nothing shows it today. |
| 376 | +- [ ] **N7. `louise test` runs the dependencies' inline tests too.** Size **S**, PR: a behaviour change, needs a decision. |
| 377 | + - For a package directory it runs the tests of every module outside `std`, which includes its dependencies' modules (reproduced: a path dependency's `@test` in its `src/lib.lse` runs with the package's). No package in the repository has inline tests in a dependency, so nothing shows it today. |
| 378 | 378 | - **The fix:** run the tests of the root package's modules only (those `Db::load_resolved` names without a dependency prefix), and decide whether a flag runs the dependencies'. Left as is: it changes which tests run. |
| 379 | 379 | |
| 380 | 380 | ## Deliberate choices, not defects |
| 381 | 381 | |
| 382 | | −- **The reference interpreter and its scheduler** (`tilc_interp`; `tilc_core/src/interp.rs` and `sched.rs` when audited) re-implement what `tilrt` does. They are the oracle: `tilc_codegen_c/tests/native.rs` runs every `tests/run` program natively with `TILC_THREADS=1`, and requires the same `//>` output and zero live blocks. Keep them. Share only the pure leaf helpers (M3). |
| 383 | | −- **The ABI layout is written twice:** `tilrt.h` by hand, next to `abi.rs`. Both sides are checked by `_Static_assert` (`tilrt.h:38,76-77,131-136`) and Rust assertions (`abi.rs:103`). That is the right way to mirror a C ABI without bindgen. |
| 384 | | −- **There are two parsers.** The rowan parser is the compiler's; the tree-sitter grammar (`editors/tree-sitter-tilcayo`) serves editors. A test keeps them in step: the grammar must parse every `.til` file in the repository (`bindings/rust/lib.rs:78`), and CI regenerates it and diffs. |
| 382 | +- **The reference interpreter and its scheduler** (`louise_interp`; `louise_core/src/interp.rs` and `sched.rs` when audited) re-implement what `louise_rt` does. They are the oracle: `louise_codegen_c/tests/native.rs` runs every `tests/run` program natively with `LOUISE_THREADS=1`, and requires the same `//>` output and zero live blocks. Keep them. Share only the pure leaf helpers (M3). |
| 383 | +- **The ABI layout is written twice:** `louise_rt.h` by hand, next to `abi.rs`. Both sides are checked by `_Static_assert` (`louise_rt.h:38,76-77,131-136`) and Rust assertions (`abi.rs:103`). That is the right way to mirror a C ABI without bindgen. |
| 384 | +- **There are two parsers.** The rowan parser is the compiler's; the tree-sitter grammar (`editors/tree-sitter-louise`) serves editors. A test keeps them in step: the grammar must parse every `.lse` file in the repository (`bindings/rust/lib.rs:78`), and CI regenerates it and diffs. |
| 385 | 385 | - **No query framework; the whole package is re-analysed** (ADR 0006), with a stated condition for revisiting. |
| 386 | 386 | - **`runtime/spike/spike.c`** is the M0 ABI spike. It is still CI's C-side ABI smoke test, including under ASan/UBSan (`scripts/ci.sh`), so it is not dead code. Its name suggests a throwaway, though; consider renaming it `runtime/abi-test`. |
| 387 | | −- **Two failure policies in the runtime:** `expect("tilrt: …")` aborts on a runtime invariant violation, while user errors go through `tl_panic`. This is documented (`runtime-abi.md`, "Known limitations"). |
| 387 | +- **Two failure policies in the runtime:** `expect("louise: …")` aborts on a runtime invariant violation, while user errors go through `tl_panic`. This is documented (`runtime-abi.md`, "Known limitations"). |
| 388 | 388 | - **The runtime's own context switch** (ADR 0011) is assembly on x86_64 Linux, with corosensei elsewhere. The fallback is type-checked for aarch64 in CI. |
| 389 | 389 | - **Per-thread leak counters with plain stores** (`heap.rs:320-352`; ADR 0002, implementation note) are a measured performance trade-off. The `stats` feature is on by default. See M7 for the open review point. |
| 390 | 390 | - **`let _ = writeln!(…)` appears 104 times in `emit.rs`.** Writing to a `String` cannot fail. |
| 391 | 391 | - **The interpreter dispatches externs by their C symbol.** The symbol is the interface. This is fine once H1's table exists. |
| 392 | | −- **The std library is embedded with `include_str!`** (`tilc_db/src/lib.rs:23-46`), which keeps the toolchain a single binary. Adding a std module touches only that list. |
| 392 | +- **The std library is embedded with `include_str!`** (`louise_db/src/lib.rs:23-46`), which keeps the toolchain a single binary. Adding a std module touches only that list. |
| 393 | 393 | - **Large exhaustive `match`es over Core nodes** in emit, Perceus and the interpreter. They are the visitor; the compiler checks that each is exhaustive. |
| 394 | 394 | |
| 395 | 395 | ## Metrics and method |
| 396 | 396 | |
| 397 | | −**Tools:** `cargo tree` (normal edges and `-d`), the crates' `Cargo.toml` files, `cargo clippy --workspace --all-targets` (default lints, and `-W clippy::pedantic`), `wc -l`, a small script measuring function length (from `fn` to the closing brace at the same indentation), and `grep` counts. Every finding was confirmed by reading the code. H2 and M5 were also reproduced with `tilc check`, `run` and `test` on scratch programs. Builds used a separate target directory, and nothing in the repository was modified. |
| 397 | +**Tools:** `cargo tree` (normal edges and `-d`), the crates' `Cargo.toml` files, `cargo clippy --workspace --all-targets` (default lints, and `-W clippy::pedantic`), `wc -l`, a small script measuring function length (from `fn` to the closing brace at the same indentation), and `grep` counts. Every finding was confirmed by reading the code. H2 and M5 were also reproduced with `louise check`, `run` and `test` on scratch programs. Builds used a separate target directory, and nothing in the repository was modified. |
| 398 | 398 | |
| 399 | 399 | **Size per crate** (lines in `src/`, lines in `tests/`, number of `#[test]` functions; most tests are data-driven over `tests/run` (25 programs), `tests/ui` (13 files) and 18 snapshot files): |
| 400 | 400 | |
| 401 | 401 | | Crate | src | tests/ | `#[test]` | |
| 402 | 402 | |---|---:|---:|---:| |
| 403 | | −| tilc_span | 155 | 0 | 2 | |
| 404 | | −| tilc_diag | 155 | 0 | 1 | |
| 405 | | −| tilc_syntax | 3,359 | 507 | 20 | |
| 406 | | −| tilc_hir | 2,570 | 225 | 11 | |
| 407 | | −| tilc_types | 4,647 | 128 | 4 | |
| 408 | | −| tilc_core | 4,048 | 124 | 2 | |
| 409 | | −| tilc_perceus | 1,183 | 211 | 6 | |
| 410 | | −| tilc_codegen_c | 1,699 | 377 | 6 | |
| 411 | | −| tilc_db | 2,195 | 151 | 16 | |
| 412 | | −| tilc_lsp | 712 | 399 | 3 | |
| 413 | | −| tilc (driver) | 581 | 514 | 12 | |
| 414 | | −| tilrt | 5,848 | 0 | 9 | |
| 415 | | −| tilcayo-ffi | 95 | 0 | 1 | |
| 416 | | − |
| 417 | | −The std library is 2,718 lines of tilcayo across 19 modules. There are 2,307 lines of `.til` test programs. |
| 403 | +| louise_span | 155 | 0 | 2 | |
| 404 | +| louise_diag | 155 | 0 | 1 | |
| 405 | +| louise_syntax | 3,359 | 507 | 20 | |
| 406 | +| louise_hir | 2,570 | 225 | 11 | |
| 407 | +| louise_types | 4,647 | 128 | 4 | |
| 408 | +| louise_core | 4,048 | 124 | 2 | |
| 409 | +| louise_perceus | 1,183 | 211 | 6 | |
| 410 | +| louise_codegen_c | 1,699 | 377 | 6 | |
| 411 | +| louise_db | 2,195 | 151 | 16 | |
| 412 | +| louise_lsp | 712 | 399 | 3 | |
| 413 | +| louise (driver) | 581 | 514 | 12 | |
| 414 | +| louise_rt | 5,848 | 0 | 9 | |
| 415 | +| louise-ffi | 95 | 0 | 1 | |
| 416 | + |
| 417 | +The std library is 2,718 lines of Louise across 19 modules. There are 2,307 lines of `.lse` test programs. |
| 418 | 418 | |
| 419 | 419 | **Files over 800 lines:** |
| 420 | 420 | |
| 421 | 421 | | File | Lines | |
| 422 | 422 | |---|---:| |
| 423 | | −| `tilc_core/src/lower.rs` | 2,002 | |
| 424 | | −| `tilc_types/src/infer.rs` | 1,567 | |
| 425 | | −| `tilc_hir/src/lower.rs` | 1,391 | |
| 426 | | −| `tilrt/src/sched.rs` | 1,367 | |
| 427 | | −| `tilc_codegen_c/src/emit.rs` | 1,227 | |
| 428 | | −| `tilc_core/src/interp.rs` | 929 | |
| 429 | | −| `tilc_syntax/src/ast.rs` | 902 (macro-generated accessors; fine) | |
| 430 | | −| `tilc_types/src/env.rs` | 826 | |
| 431 | | −| `tilc_types/src/lib.rs` | 812 | |
| 423 | +| `louise_core/src/lower.rs` | 2,002 | |
| 424 | +| `louise_types/src/infer.rs` | 1,567 | |
| 425 | +| `louise_hir/src/lower.rs` | 1,391 | |
| 426 | +| `louise_rt/src/sched.rs` | 1,367 | |
| 427 | +| `louise_codegen_c/src/emit.rs` | 1,227 | |
| 428 | +| `louise_core/src/interp.rs` | 929 | |
| 429 | +| `louise_syntax/src/ast.rs` | 902 (macro-generated accessors; fine) | |
| 430 | +| `louise_types/src/env.rs` | 826 | |
| 431 | +| `louise_types/src/lib.rs` | 812 | |
| 432 | 432 | |
| 433 | 433 | **Functions over 100 lines** (17 non-test functions; clippy pedantic `too_many_lines`, threshold 100): |
| 434 | 434 | |
| 435 | 435 | | Function | Lines | |
| 436 | 436 | |---|---:| |
| 437 | 437 | | `emit.rs` `value` | 271 | |
| 438 | | −| `tilc_core` `sched.rs` `request` | 218 | |
| 438 | +| `louise_core` `sched.rs` `request` | 218 | |
| 439 | 439 | | `emit.rs` `expr` | 205 | |
| 440 | 440 | | `infer.rs` `handle` | 176 | |
| 441 | | −| `tilc_hir` `collect_items` | 175 | |
| 442 | | −| `tilc_types` `infer_scc` | 173 | |
| 441 | +| `louise_hir` `collect_items` | 175 | |
| 442 | +| `louise_types` `infer_scc` | 173 | |
| 443 | 443 | | `interp.rs` `call_extern` | 169 | |
| 444 | 444 | | `lower.rs` `expr_kind` | 149 | |
| 445 | 445 | | `lower.rs` `compile` | 139 | |
| 446 | 446 | | `infer.rs` `infer_expr` | 129 | |
| 447 | | −| `tilc_perceus` `expr` | 121 | |
| 447 | +| `louise_perceus` `expr` | 121 | |
| 448 | 448 | | `check_impls` | 115 | |
| 449 | 449 | | `infer.rs` `call` | 115 | |
| 450 | | −| `tilc_hir` `lower_expr` | 108 | |
| 450 | +| `louise_hir` `lower_expr` | 108 | |
| 451 | 451 | | `verify` `expr` | 106 | |
| 452 | 452 | | `resolve_imports` | 105 | |
| 453 | 453 | | `lower.rs` `call` | 104 | |
| 454 | 454 | |
| 455 | 455 | **Dependencies:** |
| 456 | | −- The layers are respected (syntax → hir → types → core → perceus → codegen → driver), with one exception: codegen → `tilc_db` (M1). |
| 457 | | −- `tilc_types` uses `tilc_syntax` only as a dev-dependency. |
| 456 | +- The layers are respected (syntax → hir → types → core → perceus → codegen → driver), with one exception: codegen → `louise_db` (M1). |
| 457 | +- `louise_types` uses `louise_syntax` only as a dev-dependency. |
| 458 | 458 | - The only duplicated third-party crate is `winnow` (0.7 and 1.0, both through `toml`), which is harmless. |
| 459 | 459 | - `Cargo.lock` has 135 packages. |
| 460 | 460 | |
| @@ -464,7 +464,7 @@ The std library is 2,718 lines of tilcayo across 19 modules. There are 2,307 lin |
| 464 | 464 | - `#[allow]`s: 5 in the whole workspace, each justified. |
| 465 | 465 | - No `TODO`, `FIXME`, `todo!` or `unimplemented!`. |
| 466 | 466 | |
| 467 | | −**Unsafe code in `tilrt`:** |
| 467 | +**Unsafe code in `louise_rt`:** |
| 468 | 468 | |
| 469 | 469 | | Construct | Count | |
| 470 | 470 | |---|---:| |
| @@ -480,4 +480,4 @@ The std library is 2,718 lines of tilcayo across 19 modules. There are 2,307 lin |
| 480 | 480 | - 100% of source files have a module doc. |
| 481 | 481 | - The 51 diagnostic codes are all documented; 45 of them are tested (M9). |
| 482 | 482 | - Names of `tl_*` runtime functions in the docs were cross-checked against the code. The only names that do not exist are the planned `Bytes` accessors (`runtime-abi.md`, listed as not yet implemented) and the superseded `tl_bytes_alloc` and `tl_string_alloc` (ADR 0005, roadmap v0). |
| 483 | | −- Exports in `tilrt.h` versus the runtime versus std externs: 16 runtime exports are missing from the header (H1). |
| 483 | +- Exports in `louise_rt.h` versus the runtime versus std externs: 16 runtime exports are missing from the header (H1). |