Skip to content

s4: image, seed and fixpoint CI (k237) - #106

Merged
vic merged 23 commits into
mainfrom
s4-k237
Nov 17, 2026
Merged

vic merged 23 commits into
mainfrom
s4-k237

Conversation

@vic

@vic vic commented Nov 17, 2026

Copy link
Copy Markdown
Owner

This branch brings s4: the language image as a tree of units in srs/, the kernel seed C and runtime in bootstrap/, and the fixpoint CI.

The top change holds the k237 image (2770 units) and its seed:

  • The emitter guards the sizes of Array.fill and Array.tabulate with one unsigned compare. A negative or overflowing size stops the program before it allocates.
  • 55 NegTests copied from the s2 corpus are removed. Their bodies called s2 library code that the image does not have, so they failed on an unknown name and tested no rule.
  • New self-contained NegTests: useAfterFree, allocAfterFree, regionEscapeLocal, unknownState, factTwice, factNotOp, branchJoinState and loopState.
  • README.md describes the language features.

Local check: just fixpoint exits 0. The kernel built from bootstrap/srs_seed.c loads srs/ through its whole gate (typer, Datalog families, every NegTest) and emits C byte-identical to the seed.

vic added 23 commits November 13, 2026 20:26
…U32 columns, 9 bytes per token; layout tokens Nl/Indent/Dedent and Doc follow the s2 lexer rules; no EOF token and no -1 sentinel. Oracles: tokens plus gaps cover each byte of the 31 Y1 files once; gaps hold only whitespace or comments; token text sequence equals tests/s2/lex.out (13/13); diagnostics tab, badchar, unterminated, bighex, baddedent at the expected offsets. Mutants killed: two-byte operators, integers, indent width, dedent code. Y1: 295,063 tokens, 58.2 M instructions, 8.8 MB peak.
…o top-level decls (def, extern, enum, capability, handler, trait, type, val, given) as flat U8/U32 columns, 17 bytes per decl; bodies stay token ranges for later parallel parsing. Oracles: decl counts per kind equal the source counts on the 31 Y1 files (2,880); decl ranges are ordered, disjoint and leave only layout and doc tokens outside; all names match the source; diagnostics unknownDecl and missingName at the expected tokens. Mutants killed: extern keyword removed, body ended at the first dedent. Y1: 69.2 M instructions with lexing, 9.0 MB peak.
…int.srs). Nodes are flat U8/U32 columns, 13 bytes per node, 0.42 nodes per token; absence is a named node kind. A printer prints each decl back. Oracle: parse, print, relex gives the same tokens as the source for all 2,354 def and 397 enum decls of the 31 Y1 files, 0 parse errors. Mutants killed: parser drops else branch, printer drops parentheses. 7 of 12 parse-error tests match their line; the 5 others are in capability, type and extern bodies. Y1: 119.8 M instructions with lexing, 124,919 nodes.
… val, given) and for requires/ensures/forall/exists clauses. Oracle: parse, print, relex gives the source tokens for all 2,880 decls of the 31 Y1 files and for every decl in the 535 formatted gate files outside tests/s2/neg; all 12 parse-error tests give a parse diagnostic at their expected line. Mutants killed: capability op parser removed, type match arm removed. Y1: 124.6 M instructions with lexing, 126,480 nodes, 30 MB peak.
…columns in append-only row stores with hash indexes, semi-naive rounds, stratified negation. On the Y1 Mem dump (65 relations, 837,862 rows) every relation equals Souffle's output row for row; dropping a rule changes the expected relations. Mutants killed: negation in the same stratum. 1.72 G instructions (s2 engine 1.98 G, Souffle compiled 4.45 G), 45.3 MB peak (s2 engine about 700 MB). Rule planning and symbol interning still run in an awk script.
…global decl, local binder, enum case, capability op, builtin) as flat U32/U8 columns; unresolved is its own kind. On the 31 Y1 files as one program 62,405 uses resolve, 0 unresolved; every local binder precedes its use in the same decl; all 8 unknown-name tests report at their line; shadowing binds the latest binder. Mutants killed: arm binders left out, globals looked up before locals. Y1: 197.3 M instructions with parsing, 61 MB peak.
…notations, type arguments, handle heads, capability op signatures, trait/given groups and type decl bodies resolve to a closed set of type kinds; a type binder never captures a value of the same name. On the 31 Y1 files all 15,612 type uses resolve, 0 unresolved; the 3 unknown-type tests report at their line. Mutant killed: enum names dropped from the type namespace. All s3 oracles now live in tests/s3 (lex, parse, names, subset gate) and tests/s3/run.sh runs 15 of them (15 pass; a planted failure fails). Y1: 206.4 M instructions with parsing, 66 MB peak.
…s are interned U32 ids with a flat union-find per def; check mode pushes the declared result type into bodies, vals, ifs and match arms; generic calls unify per call site. On the 31 Y1 files all 2,258 non-generic C prototypes equal the s2c reference, all 2,354 def bodies are typed with 0 mismatches. Mutant killed: integer literals always U32 (2,521 mismatches). Oracles tests/s3/types/ta.sh and tb.sh join tests/s3/run.sh (17 pass). Y1: 262.5 M instructions with parsing and names, 99 MB peak.
…types.srs). Every generic instantiation reachable on Y1 is collected: all 1,210 equal the s2c reference by type name and fall into 152 layout classes; all 3,468 C prototypes equal the reference; handler bodies are typed; a match that misses a case is an error; a type variable still unsolved at the end of a def is an error (no defaulting; integer literals are I64 unless the expected type is U32 or U64). The declared C type of every local of the 2,258 non-generic defs compiles with 0 diagnostics. Mutants killed: expected type not pushed into match arms, unsolved variables defaulted to Unit. tests/s3/run.sh: 21 pass. Y1: 276.8 M instructions, 115 MB peak. Open: 12 of 32 mismatch tests, locals of generic instances.
…tter reads has its decision recorded: a ground type per node, the resolved callee and instance type arguments per call, the enum and case tag per constructor and pattern, the kind per integer literal; Array, Cell and ACell builtins are typed. On Y1 every required node kind has one record per node (missingEntry 0); 81 of the 82 in-subset tests/s2/prog programs type fully (cstruct_new: extern struct field methods open); 206 of 206 annotated vals match. Mutants killed: case tags not recorded (15,286 missing entries), Array.fill untyped. tests/s3/run.sh: 22 pass. Y1: 335.1 M instructions (+21%), 118 MB peak; built by s2c, information only.
…ables for every node the emitter reads (a ground type, the resolved callee, the enum and case tag, the integer kind); then the emitter prints one C chunk per def from the tables and the signature table only, with explicit C11 types. A handler whose handle is known at compile time becomes static handler functions; an op of such a handler is a direct call. Oracles: tests/s3/emit/ea.sh (C compiles with 0 diagnostics), eb.sh (the built program prints the .out of tests/s2/prog), ec.sh (mutants), ed.sh (Y1). Gate measured at the child commit (FIXPOINT 1): run.sh 26 pass, 2 fail on cstruct_new.
…ne 64 KiB chunk. FIXPOINT 1: s3c compiles itself, byte-identical, on the SUBSET, with NO checks; s2c stays the acceptance gate for every s3c source commit. The seed-built s3c (bin1) emits C for its 13 source files (943,501 bytes); the build of that C (bin2z) emits the same bytes (sha256 9e08476512d3bc42e95f0ba7b4ea55051cbd203c308829ee3a61259df9968bc8). A one-character source change gives other C. The new standing test tests/s3/emit/fixpoint.sh runs this inside run.sh. Output: all emitter output goes through one 64 KiB chunk; type and symbol text is cheaper. Y1 --emit with bin2z at this commit: 610,662,878 instructions, 123,572 KB max RSS, 24,190 minor page faults, 0.31 s wall (indicative, load 3); the emitted C of Y1 (7,602,761 bytes) is unchanged. The subset is 78 programs (tests/s3/emit/progs.txt): ms_state_trip (multi-shot) and cap_nested, eff_shadow, eff_stateless (two handles of one non-Region capability) are out; every count literal in tests/s3 says 78. tests/s3/run.sh with bin1 and bin2z: 26 pass, 2 fail, identical output. RED: E-a and E-b fail on cstruct_new only (77/78): extern struct field calls are untyped; s3c rejects it with 'phase A failed: missingEntry=6 untyped=5', exit 1, no C (bead srs3-0gc, TYPES-1d; td.sh 21/32). E-a needs tcc at a pinned store path that a GC removes (bead srs3-1j2). The 4 programs outside the subset today: cap_nested emits C that crashes, exit 139 (bead srs3-1ny, P0); eff_stateless emits C that prints 33, expected 310 (srs3-4kj, P0); eff_shadow emits C with the right output; ms_state_trip exits 1 with unsupportedResume=2 but still writes 190,248 bytes of C (srs3-7wa, P1). The subset law becomes a Datalog check with negative tests (srs3-v2m). The MOVES changes are not in this commit.
…a scan of every type id (s3/emit.srs). Em.enumTypes walked all type ids once per enum root: on Y1 16.9 M of 610.7 M instructions. The new index is built once per program, again at each closure pass (types are interned during closure): flat U32 arrays from a counting sort, one list of type ids per enum head symbol, searched by binary search for the first id at or above the scan position; the old scan remains for the tail of ids interned after a build and as the fallback. Same order and same closedT filter as before. Numbers (bin2z, Y1 --emit): 610,662,878 -> 595,059,243 instructions (-2.6%); Em.enumTypes self 16.9 M -> 1.2 M; max RSS 123.5 MB, 24,190 minor faults (unchanged). Oracle: emitted C unchanged: Y1 (7,602,761 bytes) byte-identical to the previous build, the 78 programs identical in stdout and exit code; fixpoint C2 == C3 (956,834 bytes); tests/s3/run.sh with bin1 and bin2z: 26 pass, 2 fail, identical output (E-a and E-b fail on cstruct_new only, as before). Mutant: the binary search bound changed from < to <= in Em.ixLb drops an id: the emitted Y1 C differs (7,563,813 bytes) and the compare fails. Fallback counters on the emit summary line: ixUnindexed=0 ixOverflow=0 ixBuilds=2 on both sets; ixTailRange (size of the ranges left to the old scan) 90 on the 13 s3c files, 26,083 on Y1. This is the cost that the length-in-type-id change exposed: it adds type ids, and the scan grew with them.
…s/s3/types). Array[A](n) and Array[A](m) are different types: the interned type id of an array carries its length as an exact key (a literal, or the resolved binder token of an immutable local; fresh and hidden lengths for slice results, unannotated arrays and joins; no truncation, no wildcard). At a call or a pattern the callee's length binder is replaced by the argument's or the pattern's binder before the compare. A written length that is neither a literal nor a plain immutable local (compound, call, global constant, var, an assigned name) gives lengthNotName at file:line; the mutability pass runs before the headers. A length that got lengthNotName becomes an error length that suppresses follow-on compares, so each of these programs prints exactly one diag line. Every type mode of s3c now exits 1 when any diag was printed. The instance key excludes the length (instances 1,210 on Y1 and 22 on the 13 s3c files, layoutkeys 152 and 22, unchanged); printed type names and the emitted C are unchanged (Y1 C and the 78 programs byte-identical to the build before). Old base: the typer accepted Array[A](n) = Array[A](m) (unsound); --types on Y1: 334,506,033 -> 350,158,014 instructions (+4.7%), s3c's own files 124,553,098 -> 132,271,230 (+6.2%); type ids on Y1 1,753 -> 9,921; defs with a length: 4 of 2,444 on Y1, 369 of 1,126 in s3. This is the new baseline. bin2z Y1 --emit: 595,059,243 -> 613,826,136 (+3.2%, bar 642 M), max RSS 125.3 MB, 24,624 minor faults; the emitter walks the added type ids only in its two index builds (+9 k instructions). Standing test T-l (tests/s3/types/tl.sh, in run.sh): 3 s2 negatives (array_field :6, array_grow_stale :7, bytes_len :9), planted n1-n15 and p1-p7 including the assigned parameter used as a length, the shadowed binder and the one-diag cases; 7 mutants all fail the test: no call substitution, no pattern substitution, a wildcard length, modulo keys, mutability pass after the headers, skipped fresh lengths, an error length that is equal everywhere. tests/s3/run.sh with bin1 and bin2z: 27 pass, 2 fail, identical output (E-a and E-b on cstruct_new); fixpoint C2 = C3 (988,918 bytes). Beads: srs3-5ol, srs3-reo (the non-user cost of this change).
…corpus). The 13 files that build s3c (lib/prelude.srs, s2/sym.srs, s2/coll.srs, s2/bmap.srs and the 9 files of s3/) are copied to tests/s3/corpus/s3c, pinned at commit df70e04 (PINNED), with their order (ORDER) and path, bytes and sha256 (MANIFEST). The three s2 collection files and the prelude stay in the corpus as data until the flat s3 collections replace them; the corpus is refrozen only when it stops compiling. baseline.txt holds the numbers of the last landed s3c (bin2z built by itself) on it: --types 133,650,783 instructions, peak 52,376 KB, 9,483 minor faults; --emit 167,911,711 instructions, 53,432 KB, 9,726 faults; 10,039 lines, 396,396 bytes. bench.sh (tests/s3/corpus/bench.sh BIN) checks the corpus against the MANIFEST, measures instructions (callgrind), peak and faults of --types and --emit and fails when a number is above the baseline (instructions +0.01%, the measured noise of one binary is 51 instructions of 133.65 M; peak and faults +2%); --record writes the baseline; --selftest lowers the baseline by 10% in a copy and requires the comparison to fail (it does). It is the perf gate of every land and stays out of tests/s3/run.sh (it needs valgrind and takes about 3 minutes). Numbers of the landed tip, per source line, own source against Y1 (23,961 lines): --types 13,312 instructions per line against 14,754; --emit 16,725 against 25,617; peak 53.4 MB against 125.4 MB; wall 0.07 s against 0.21 s. Y1 retires with s2. No check is ever switched off to meet a baseline.
…/bounds.srs). The engine gets typed compare atoms (Lt, Le, Ne), a stratum validator (Dl.chkStrata) and Dl.clear. s3/bounds.srs is the proof of an index site as a hand-written numeric plan of 14 relations; tests/s3/bounds/proof.dl is the same rules as text, and the plan stays hand data until a rule-text to plan compiler exists (bead srs3-j1l, must land before the third rule family). dlmain.srs gets --prf and --prf-dump. Oracle tests/s3/bounds/run.sh, in tests/s3/run.sh: the engine equals Souffle per site (0 diff) on s3 own 336 sites / 234 proved / 102 unproved, Y1 119/7/112, the 78 programs 83/27/56; a missing reference is a FAIL. Planted controls ctl1 (1 proved, 3 unproved), ctl_kill (0/1), ctl_eq (2/1). Mutants killed: 7 of 7 (drop of a rule, drop of the lower-bound atom, three compare-form swaps, negation removed, unbound compare operand). The DL plan costs +0.42% Ir (compare dispatch, test engine only); one solve has a fixed cost of about 58 k Ir including load (bead srs3-kjm). The text loader is an oracle only. s3c is unchanged: tests/s3/run.sh 28 pass, 2 fail (E-a and E-b on cstruct_new, as before); bench.sh PASS: --types 132,273,137 Ir (baseline 133,650,783), --emit 166,441,215 Ir (167,911,711).
…s today, with repro and expected Diag; each entry is deleted in the commit that fixes it.
…me in bootstrap/, the flake, Justfile and the fixpoint CI workflow
The emitter guards Array.fill and Array.tabulate sizes with one unsigned
compare: a negative or overflowing size stops the program before it
allocates. The image C has 34 guarded sites; the cost is not measurable.

55 NegTests copied from the s2 corpus are removed: their bodies call s2
library code (sum, build, Cons, Nil, CFile, File) that the image does not
have, so they failed on an unknown name and tested no rule.

New self-contained NegTests: useAfterFree, allocAfterFree,
regionEscapeLocal, unknownState, factTwice, factNotOp, branchJoinState and
loopState. Every gate code now has a NegTest.

README.md describes the language features only.

bootstrap/srs_seed.c is the C that this image emits; the kernel built from
it loads srs/ through its whole gate and emits the seed again, byte for
byte.
@vic
vic merged commit 7536927 into main Nov 17, 2026
2 checks passed
@vic
vic deleted the s4-k237 branch November 17, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant