30. Front-end recovery (2026-11-21)
- 28.8
impl Trait fora built-in type;Hashon it.impl Hash for Int: fn hash(self) -> U64 = ..givesInta methodx.hash(), found by the value's type afterfieldsunrolls or a generic is instantiated; before, animplattached only to structs.std.deriveuses it for aHashtrait overInt,U64,Char,BoolandStr(splitmix64) andhash_fields, soimpl Hash for P: fn hash(self) = hash_fields(self)is a struct's whole derive. Reason: the derive must be library code, and a field-wise fold needs one method name that dispatches on each field's type; free fns cannot overload. Not yet: the compiler's ownHashMapkey hash does not callHash. Reverse: deleteattach_impls_for_builtinsandprim_methodsincpl-ir/src/lowerand theHashpart ofstdlib/derive.cp.
- 28.9 A struct built field by field:
P(e for f in fields(..)). A struct constructor whose one argument is a generator overfieldsrunseonce per field, in order, with that field's type expected, and builds the struct from the values:P(read() for _ in fields(P))reads one,P(x + y for (x, y) in fields(a, b))adds two.fields(P)names the type being built and binds nothing (_); values must be of that type. It is the construction half of reflection (28.1 walks fields, this makes them), soReadand field-wise maps are library code:std.derive.read_fields<T>() = T(read() for _ in fields(T)). A struct with anewstill goes throughnew, so its invariants hold. Rejected:T(..tuple)spread (..talready means a range) andfields(mut x)(needs a starting value, and a struct has none). Reverse: deletefields_ctorincpl-ir/src/lower/call.rsandcpl-check/src/check/call.rs.
- 30.1 A broken-ports benchmark scores recovery.
crates/cpl-cli/tests/recovery.rsapplies six single-line edits (drop a closer, drop a block colon, cut a value, double an operator, garble a declared name) to every port and counts errors, cascades (every error after the first, since each copy has one root cause) and whether the first error is on the broken line. It gates no silent copies, first-error accuracy >= 99.5% and cascades per broken copy under a ratchet. The ratchet is a rate, not a count, because port lanes keep adding ports. Reason: "no cascades" needs a number.RECOVERY_SHOW=<edit name>prints every copy that cascades under that edit. Reversible: delete the test and itsscripts/check.shstep.
- 30.2 Lexer diagnostics are pushed before the lexer's poison. Reason: the poison exists to keep
other errors off a reported span; applied first it also hid the report itself, so
let $x = 1checked clean. Reversible: revert the sink order incpl-check/src/db.rs.
- 30.3 The parser reads past an unreadable character inside a statement.
bumpskipsT::Errortokens that do not start a line and marks the statement recovering, so it is poisoned. Reason: the character is already reported; dropping the whole line also dropped the names it declares. A line-initial error token still drops the line, since nothing says what statement it was. Reversible: remove the loop inParser::bump.
- 30.4 A function whose header has a syntax error stays bound with an unknown type.
FileCtx::defmaps the defs of a statement poisoned on its first line throughDef::recovered, which gives functionsTy::Error. Reason: a header missing its)parsed as a different signature (fn ask(d: Char, dist: Int -> Int:takes afn(Int) -> Int), and every call reported a mismatch. Values keep their inferred type: a broken initializer already infersTy::Errorwhere it is broken, andvar total = 0 +should still hover asInt. Struct and enum headers keep their parsed shape (open: a struct missing its)still reports every later field use). Reversible: drop thehead_is_poisonedbranch inFileCtx::def.
- 30.5 Planned syntax is one table, parsed and reported as
E0504.cpl-syntax/src/planned.rslists each 0.3 form this version does not implement: its feature name, the design section that specifies it, what to write today, and an example whose one error is that one. The parser reads the form (so the statement and its names survive), reports "not implemented yet: (see
- 30.6 Golden diagnostics are rendered
cpl checkoutput.cpl-cli/tests/diagnostics/*.cpwith the exact stderr beside it in.err; planned-syntax examples are written there from the table.BLESS=1rewrites them. Reason: the rendered text is what the contestant reads, including help lines and spans, so that is what is pinned. Reversible: delete the directory anddiagnostics.rs.
- 28.10 A struct's
?borrows a field's niche; noNichetrait.?Sfor a struct with anIntfield (not narrowed below 64 bits) or a position field storesnoneas that field atINT64_MINor -1, the value noSholds (decision 49.1), so?Edgeis as wide asEdge: 16 bytes forEdge(to: Int, w: Int), not 24. The first such field is used, fixed per type (spec 22: niches are fixed per type, never per use). It majorizesstd::optional<S>(narrower, same operations), so it is implicit. A userNichetrait naming anonevalue was rejected: every struct that has a free value already has one in a field, and a trait would let a library claim a value its own code can produce, turning a wrongnoneinto silent corruption. Interpreter unchanged. Measured (scoreboard.py --full, 7 runs, same machine):cf2147f604 -> 420 ms (2.84x -> 1.80x matched C++), RSS 24.2 -> 19.9 MB;cf2057dRSS 9.9 -> 8.7 MB. Emitted C++ grows about 1.1 KB on the six ports that use it (theOptFieldruntime piece), so the baseline was rewritten. Reverse: drop theTy::Structarm ofTy::Optincpl-codegen/src/names.rsand theniche_fieldruntime piece.
- 28.11 A trait writes its own unimplemented message. A call
f(x)whoseT: Trboundx's type has noimpl Tr fornow fails at the call,`Bool` does not implement `Tr`, instead of later insidef's body as "no method"; a trait declared with@on_unimplemented("...{T}...")adds its text as the help,{T}the type shown (spec 14 writes#on_unimplemented;@is the one decorator sigil, CORE-ALIGN). Any library can declare it, so the stdlib has no privilege (std.derive.Hashuses it to point athash_fields). Only traits declared in a module are checked; animplover a generic type counts as met, so no valid program is newly rejected (291/291 ports passscoreboard.py --fast). Test:diagnostics/trait_names_its_own_fix. Reverse: returntruefromimplementsincpl-ir/src/lower/mono.rs.
- 28.12
Genis a trait of static fns, and a generic call takes its return type from the type wanted.trait Gen: fn gen(mut r: Rng) -> Selfhas noself;T.gen(mut r)insidefn gen<T: Gen>calls theimplof whatever fillsT, built-in types included. A generic fn whose type parameter appears only in its return type (fn gen<T: Gen>(mut r: Rng) -> T) takes it from the expected type, solet x: Int = gen(mut r)andP(gen(mut r) for _ in fields(P))draw each field by its own type; before, such a parameter silently defaulted toInt.gen_fields<T>is then one line ofstd.derive, andimpl Gen for S: fn gen(mut r: Rng) -> S = gen_fields(mut r)derives a generator for a stress test. Same seed, same values incpl runand the C++ (programs/derive_gen). Reason: generators derived from types are the stress goal, and the missing pieces were general (static trait calls, return-type inference), not generator-specific. Reverse: dropcall_hintincpl-ir/src/lower/mono.rsand the built-in arm beforematch self.sym(base)inLowerer::method.
- 28.13
read()of a struct calls itsimpl Read. A struct whoseimpl Readdeclaresfn read() -> Sis read through it whereverread()meets it: alone, as an array element, as a field of another struct. The read plan (Spec) gains one node,Spec::Call, holding the lowered call, so the interpreter evaluates it and the C++ emits it like any expression. Before, the impl was accepted and silently ignored, and the input was read field by field (silent wrongness). Test:programs/read_impl(1-based input read as 0-based cells). Reason: spec 00 makesReada library trait with return-type dispatch; this is the user half of that.cpl stressstill generates such a struct's input field by field. Reverse: drop thereadlookup at the top ofstruct_specincpl-ir/src/lower/mod.rs.
- 28.14
??stays core. The §1 queue listed??for the stdlib on lazy parameters; it stays a core operator. Its right side may leave the enclosing fn or loop (read_opt() ?? return,?? continue), and a lazy argument is a closure, wherereturnwould leave only the closure. Spec 00 places??in core C4 for exactly this ("laziness andNever"). A libraryfn or<T>(x: ?T, lazy d: () -> T) -> Twould be a second spelling of the same idea with less power. Reverse: give lazy arguments non-localreturn/break(a core change), then define??as that fn.
- 30.7 Dreams are a diagnostics corpus.
scripts/dream-gaps.pychecks everyproto/ports/*/dream/*.cpand files each error under the gap it names:syntax:(anE0504feature),library:(a name, module or method "not in the stdlib (yet)"),import:(a stdlib name used without itsuse),rule:(a decided rule the dream breaks),backend:(anE0501the interpreter or codegen can't run yet), orunnamed:. The scoreboard prints the ranked summary. The bar is that every dream's first error names its gap. Reason: the factory needs to see which missing construct blocks the most dreams, and a dream whose first error is "expected X" teaches nothing. Reversible: drop the script and the scoreboard'sdreamsblock.
- 30.8 A planned form outside the design still gets
E0504, marked "(not in the design)". Dreams reach for forms the design never specified (fn (a: T) + (b: T),by: <,Str of "01?",enum E: a = -1,e is x,var a, b: T = 0). Each is read, reported once by name with today's spelling as help, and recovered as today's nearest form. Reason: naming the feature is the useful message, and the marker keeps the table from passing these off as designed; a design section replaces the marker when the design takes the form up. Reversible: makeseemandatory and turn those entries back into parse errors.
- 30.9 "Not in the stdlib (yet)" goes on names unknown everywhere, except one-letter names. An
unresolved name with no close in-scope or prelude name, no stdlib module and no removed keyword gets
the suffix, plus a did-you-mean against stdlib names (with the
useas a fix) when one is close; a missingstd.module or a name astd.module lacks gets it too. No stdlib export is one letter and contest code is full of one-letter locals, sonowin scopestays bare. Reversible: theunknowncondition inChecker::unresolvedand the two branches indb.rs.
- 30.10
const A = 1, B = 2declares several constants; a field used in a method withoutselfsays so. The first is how dreams write related limits, costs nothing to read (each becomes its ownconst, so every tool sees ordinary declarations); the second turns a bare "not in scope" into the fix (addself). Fields already resolve bare inside methods that takeself. Reversible: thewhileafter the firstconstinparser/stmt.rs; thefield_of_selfbranch inChecker::unresolved.
- 30.11 C spellings (
&&,||,!x,..<) are errors with the cp spelling as the fix, and parse as that spelling. Reason: they are the commonest slips from C++ and Python, the fix is exact, and recovering asand/or/not/..keeps the rest of the file checked. A single&or|stays bitwise. Reversible:Parser::c_logicandParser::range_opincpl-syntax.
- 30.12
cpl fixapplies the fixes errors carry first, then lint fixes. It is the editor's quick fixes run in a loop (at most 8 rounds); once no error is left it also makes the fixescpl lint --fixmakes, which the lint codemods (L0204, L0415, L0510, L0511) document ascpl fix. Assigning to aletfixes the declaration (letbecomesvar), and only the first assignment to oneletis reported. A plain number where a domain is needed getsV(...)as its fix. Reason: one command for every machine-applicable fix; lint fixes wait for a file without errors so a codemod never rewrites a program that does not check. The fix-it benchmark measures error fixes alone (apply_error_fixes). Reversible:cpl_cli::apply_error_fixesandapply_lint_fixes; drop theASSIGN_TO_LETde-duplication indb.rs.
- 30.13 Fix-its are measured on a second benchmark of common mistakes. The broken-ports edits
(cut a value, drop a closer) have no single right fix, so
fix_it_scoreboardplants one mistake per copy instead (C spellings,letfor avar, a misspelled member) and counts errors with a fix and copies acpl fixrestores byte for byte. Ratchet: fix-its on at least 88% of errors and restoring at least 95% of the copies that report one. Only this benchmark applies every fix: the broken-ports scoreboard counts fix-its but skips the rewrite, which kept the recovery test inside the fast gate's time. Reversible: deletefix_it_scoreboard.
- 30.14 A domain or range mismatch labels where each side's index space comes from. The
message already names both spaces (
ais indexed by V, butnis a 1..=9); a label on each plain name's declaration says where each got it (ais declared over V here,nis declared as a 1..=9 here). A top-level name declared in another item is labelled as a point at its use, and the database moves the label onto the declaration. Reason: the fix is usually at the declaration, not the use. Reversible:Checker::originand theWRONG_DOMAINbranch indb.rs.
- 30.15 After a lowering error,
cpl rundoes not report names it does not know. The checker has accepted every name by the time lowering runs, so an unknown name there means an earlier lowering error dropped its binding (for (i, c) in s.item:losesiandc). Reason: one error per root cause; this cut the member-typo benchmark from 656 to 522 errors. Reversible:Lower::reported_an_errorincpl-ir/src/lower/mod.rs.