Repository navigation
test(gates): check comptime C equivalence - #1705
vicmcorrea wants to merge 2 commits into
Conversation
Lorenzobattistela
left a comment
There was a problem hiding this comment.
Thanks, this closes the gap left in #1314. Merged onto main f5cee56: repo, test (1670/1670), perf, ping and safe are all green, and the new check passes (hand and tmpl C are byte-identical after the FID rename).
A few changes before this can go in:
-
Load the twins by name, not by position.
books.slice(-2)andbooks.slice(0, files.length)depend on the twins being the last two entries of the inline array. Appending or reordering a fixture would silently compare the wrong pair. Loadhandandtmplseparately (one copy each) instead of through thecopiesloop. -
Drop the second copies. Each twin is loaded and validated twice, but only the first copy is used.
-
Compare the twins in a clean spot. Right now they compile after the 44 state steps in the same process, so any compiler state left over from the earlier compiles (the #976 class
state_runexists to catch) can make the comparison fail falsely or hide a real difference. Compile them before the state sequence, or in their own function. -
Make a failure actionable. On a mismatch, report the first differing line (or line number plus both lines) of the normalized C instead of two hashes.
-
Update the docs. The file header and the
state_runcomment still describe only the four state fixtures, andtests/comptime/hand.bendsays "the report diffs the two programs' C". This check is now that report.
Also, this changes gates/, which needs Taelin's sign-off. He may prefer the check somewhere other than the test gate.
Problem and fix
The comptime twins print the same value, but their documented same-C claim was untested, as noted in #1314. Compare their emitted C after replacing declared FID names with their numeric IDs, preserving the identifier prefix and every other byte.
Load
handandtmplexplicitly, once each, incomptime_run, before any state-fixture work. A mismatch reports the first differing line number and both normalized C lines, including an end-of-file marker when needed.Blast radius
gates/test.tsadds the local comparison and updates its comments;tests/comptime/hand.bendonly corrects its stale report/benchmark comment. The existing four-fixture state sequence, raw output hashes and probe-count checks remain intact. The twins stay outside those repeated compiles and term-normalization steps. Compiler/runtime code, fixture behavior, APIs and token caps are unchanged.Regression evidence
The original local state check accepts changing the template from
~U32.incto~(x => U32.sub(U32.add(x, 2), 1)). The revised check rejects its different C and shows both statements at the first differing line. Hand, template and mutant still print50005000in source execution, emitted JavaScript under Bun and native C. Unmodified twins and a consistent definition rename pass.Checks
repo-gateandgit diff --checkpass.f5cee564and rejects that mutant there.22764c3) loader/compiler probe passes with its external namespace/main-alias adaptation and rejects the mutant.Validation limits
Taelin's sign-off on gate placement is still pending, as the review requests; this revision does not claim that approval. Local checks used macOS arm64 and Bun 1.3.11. Full cluster, GPU and performance gates were not rerun for this revision. This checks emitted C text, not machine-code identity or runtime performance. The #1585 probe covers only the adapted parser/compiler dependencies; its existing
safe.tsmerge conflict prevents a full-branch integration claim. Node runtime checks were not rerun.