Repository navigation
Fix the 7 failing corpus asserts (Frill parse/types, ObjC vtables on Z80, host externs in the assert sandbox) - #375
Merged
Merged
Conversation
A call to a function parsed later in the module (Frill parses top-level lets in source order) defaulted its result type to u8, and let that default spread into the binding and its variable references. The mir2 VM returns the full machine register regardless of the contract, so the mistyped forward call only produced wrong code on the Z80 backend, which reads exactly the contract register (A for u8) — visible as 'assert eval "5" == 5 got 0' in examples/frill/expr_eval.frl under --asserts-force z80 (eval_atom's forward call to eval_expr was u8 while eval_expr returns u16, truncating the parenthesised-input path to 0). After the whole module is parsed, rewrite call result types from the now- known p.returnTypes, fix let-bound variable references, re-derive the return types of functions whose annotation was inferred from a body that contained such a call, and walk again. Regression test: pkg/frill/forward_ref_type_test.go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
parseLoopBody recognised only do/for/while/poke statements and broke on anything else, so a loop body starting with 'let x = ... in' (e.g. the nested while loops in examples/frill/graphics.frl render_xor) ended the body early. The 'end' tokens then fell out of sync, and the leftover 'end 0' was silently parsed as a call to an unknown function 'end', emitting 'JP end' with an undefined label — the z80 assert failed with 'assemble errors: line 448: unknown instruction or invalid operands: JP'. Parse 'let name = expr in' in loop bodies as a flat VarDeclStmt, matching parseBodyExpr, so the nesting depth stays aligned. Regression test: pkg/frill/loop_body_let_test.go (nested while with a let at the top of the outer body used to leave a call to "end" in the HIR). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
ObjC protocol vtable globals (pkg/c89 objc_lower, producer
c89.generateVtable) carry VtableSyms: the function name for each slot.
The VM patches the addresses into its heap at load, which is why dynamic
dispatch passed under mir2, but the Z80 emitter only wrote the zero
initialiser — every vtable was assembled as 'DW 0, 0', so a dynamic
dispatch jumped to address 0 and wandered through memory until the cycle
limit. examples/objc/dynamic.m under --asserts-force z80 returned
garbage (0xFEFA) for 'Drawable Circle{radius:7}.area() == 49' with the
same root cause in canvas_shapes.m and plasma.m.
Emit each slot as 'DW <symbol>' (DW 0 for an empty slot), the static
equivalent of what the VM patches at load.
Regression test: pkg/mir2/objc_vtable_codegen_test.go.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
An addressless extern had no implementation anywhere — the mir2 VM dispatches those calls to registered host functions, but on Z80 the emitted symbol was a bare label, so a CALL fell through into whatever function followed. examples/nanz/canvas_house.nanz under --asserts-force z80 ran off into unrelated code until the cycle limit reported 'execution limit exceeded'; its canvas_* hosts are exactly such addressless @extern declarations. Frontends now mark host-only externs (nanz @extern without an address, C89/ObjC prototypes registered as externs — next commit) with NoImpl; the Z80 backend then emits a defined stub: LD HL,0 / RET (16-bit returns), XOR A / RET (8-bit), RET (void). Plain externs keep the bare label — their bodies may be linked in later or live at ExternAddr, which several tests rely on by concatenating their own bodies. Regression test: pkg/mir2/extern_stub_codegen_test.go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
C prototypes without a body were dropped entirely ('Skip function
declarations'), so a call to a prototype-only function emitted a CALL to
a symbol nothing defined — the objc examples' canvas_* VM hosts failed
to assemble under the z80 asserts with 'unknown instruction or invalid
operands: CALL' (examples/objc/canvas_shapes.m line 88, plasma.m line
271), and plasma's Plasma.render assert executed that dangling call,
running off into unrelated code until the cycle limit. The mir2 VM
resolved those calls through its host table, which is why only the z80
verdicts failed.
Prototypes are now registered as extern hir.Funcs marked NoImpl, so the
Z80 backend emits a defined zero-return stub (see the previous commit);
a later definition replaces the placeholder, and a direct call adopts
the declared return type when the parse falls back to the C89
implicit-int rule (void canvas_* hosts called from int-returning ObjC
methods used to make the HIR verifier reject 'call canvas_circle return
type u16, declared void').
The VM path is unchanged: vm.execCall consults the host table before
module functions, so registered hosts keep working.
Test accommodation: pkg/pipeline/grace_infinite_loop_test.go linked the
tick body by appending a second 'tick:' label to the assembly; it now
inserts the body after the existing (stub) label like the nanz branch
already did.
Regression test: pkg/c89/extern_prototype_test.go (external test
package — pkg/c89 cannot import pkg/pipeline in-package).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
buildAssertBootstrap loaded assertion arguments as raw integers, but a string-literal argument's raw value is a placeholder 0 — the real address lives in the interned data label (_mir2_str_N). The mir2 runner resolves the same symbols via vm.ResolveSymbol, which is why 'assert eval "5" == 5' passed under mir2 and returned 0 under z80: the asserted function received a pointer to address 0 (examples/frill/expr_eval.frl line 65, examples/frill/stress_test.frl line 87 under --asserts-force z80). Emit the sanitized label for register-held string arguments (LD HL, _mir2_str_N), and build the address in HL and store both bytes through A for a string argument spilled to memory; trampolineSize accounts for the 11-byte spill form so the sandbox NOP padding stays exact. Regression test: pkg/frill/assert_string_args_test.go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
This reverts commit 8f76fa5.
Review of 43833ba^..43833ba (compile_sweep vs main) rejected the product-path zero-return stubs: addressless @extern symbols are provided by the platform, host, or a later link step, and emitting RET / XOR A / LD HL,0 bodies for them silently changed real programs (22 Nanz outputs moved, e.g. tui_demo, tetris_tui, sqlite_demo, irc_client). Remove the NoImpl attribute (mir2.FuncAttrs, hir.Func, the hir lowerer's threading and the nanz @extern marker) and the genFunc stub emission; product output for every addressless extern is again the bare label that main produces, reported by label-audit when it stays undefined. The assert sandbox gets its own accommodation in the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
Review of the first round (compile_sweep vs main) rejected product-path accommodations: NoImpl zero-return stubs after addressless @extern labels silently changed 22 Nanz programs (tui_demo, tetris_tui, sqlite_demo, irc_client, …) whose externs are provided by the platform at link time, and registering C prototypes changed call ABI and exit status for previously compiling files (examples/c89/fatfs ff.c / ffsystem.c: 'external ABI f_expand unsupported parameter width'). After 80f68f7 (C prototypes reverted) and f36554b (product stubs removed), this commit puts the whole accommodation inside the assert sandbox: - Z80CodegenOptions.AssertSandbox: for a CALL to a symbol with no function in the module (dropped C prototype, host-only extern), the result is picked up from the convention register (A for bytes, HL for words) instead of being silently dropped when its destination home differs — examples/objc/plasma.m Diamond_render read canvas_width/ canvas_height into garbage homes and looped forever on the resulting garbage bounds. Product codegen never sets the flag. - Steps.assertSandboxAssembly re-emits the product with the flag (same allocation and variant decisions) and is what RunAssertsZ80 executes in both the direct and the variant-search path; Steps.Assembly is byte-identical to main's product. - withAssertSandboxStubs (sandbox assembly text only): an undefined CALL/JP target gets an appended zero-return definition; a bare-label extern (nanz @extern without address) gets the stub body inserted in place, only when the module says the symbol is an extern without blocks — a function whose body merely starts with a local label is never touched. Product output stays byte-identical to main for every file except the fixed assert examples; verified by compile_sweep. Regression test: pkg/pipeline/assert_sandbox_stubs_test.go (product assembly keeps the bare undefined label; the sandbox assert passes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
The assert-sandbox re-emission (59d1d90) printed its own Z80-VALIDATE report to stdout, duplicating the product's diagnostics for modules with invalid instructions (examples/_archive editor_demo.minz printed the report twice; compile_sweep stdout_changes). The sandbox emission now discards its validation report; product diagnostics are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
The stable pipeline requires every pkg/pipeline test to appear exactly once in the profile manifest; the new assert-sandbox regression test runs in seconds and belongs in fast. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
…tter The first sandbox wiring regenerated Z80 code in the assert runners with reconstructed per-function variant options, which lost the Z80N MUL selection for the winning variants (TestZ80NMulExhaustive looped on shift-and-add fallbacks) and, for variant-search products whose trials compile with AssertMode none, produced no sandbox emission at all (examples/objc/plasma.m still hit the execution limit). compileMIRProductSteps now emits Steps.SandboxAssembly right after the product: identical options (the caller's FunctionVariants are the selected decisions in variant candidates), AssertSandbox on, validation report discarded. Variant-search trials skip the extra emission via variantCandidate; compileVariantSearch sets assertSandboxEmission so the winning product still carries it, and finishVariantSearch regenerates from the recorded recipes when a product predates the field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
…lures Resolve conflicts with the target layer: the sandbox emission uses opt.wide24() and the target instead of the backend name; the assert sandbox is emitted only when the module has asserts (a program without asserts compiles once). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS
PR tests: 🟢 passCommit:
Deep pipeline domains and the full assertion corpus run on release tags, nightly and manual audits. |
oisee
added a commit
that referenced
this pull request
Dec 1, 2026
…of expectations, stub label fix (#377) * pipeline: apply the assert-sandbox stubs to the eZ80 assert program #375 gave the forced-z80 assert sandbox appended/inserted zero-return stubs for call targets with no executable body, but the eZ80 runner (EZ80AssertEach) assembled the product body as-is. An addressless @extern keeps a bare label there too, so the sandbox assert of examples/nanz/canvas_house.nanz fell through the canvas_* labels into unrelated code and hit the cycle limit: "no return after 400000000 cycles (PC $040027)". The stub body (XOR A / LD L,A / LD H,A / RET) is valid ADL text, so the same withAssertSandboxStubs pass covers both. Product output is untouched: the pass runs only on the body the assert runner assembles, never on Steps.Assembly or Steps.EZ80Body. Regression test: pkg/pipeline TestEZ80AssertSandboxStubsUndefinedExtern (product keeps the bare label; the eZ80 sandbox assert passes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS * asserts: target-aware "ez80 = N" expectations for the eZ80 corpus fails Five eZ80 assert-corpus fails are target-dependent facts, not compiler bugs (ADR 0054 §2/§3): - sizeof_test.c 22, c99_enum_typedef.c 68, c99_pointers.c 73: sizeof a pointer is 2 on the Z80, 3 under the eZ80 ADL pointer ABI. - 30_stream_test.nanz (first/seq byte): the program stores &buf into a u16 cell, which under the 24-bit ABI truncates the bank byte, so the write lands in bank 0 (unwritable on the Agon) and buf stays 0. The compiled code matches the specification exactly (bufstream_init does two byte stores, LD (IX+0),E / LD (IX+1),D); the Z80 verdicts still pass against the original expectations. Both frontends now accept an optional per-target expectation after the normal one: "assert f() == 2 ez80 = 3" (Nanz) and "// assert f() == 2 ez80 = 3" (C // assert comment). hir.Assert gains ExpectedEZ80 (*int64, nil = use Expected); only the eZ80 verdict paths consult it — checkEZ80AssertResult and the ez80_asserts harness's fab verdict — so Z80, Z80N, mir2 and wasm behaviour is unchanged, and compile_sweep shows Z80 output byte-identical to main (the only exit changes are the four edited corpus sources, which the main binary rejects as malformed directives because it predates the syntax; the candidate compiles their original and edited texts to identical .a80). The 30_stream_test.nanz edit refreshes its pinned record in docs/grace-integration-338/reviewed-updates.json (source_sha256 + boundary note) per the reviewed-catalog workflow. Regression tests: pkg/nanz TestParseAssertEZ80Override (clause, via interaction, nil default, truncated clause is an error), pkg/c89 TestAssertEZ80Override (hex/negative/comment forms, malformed refused), pkg/pipeline TestEZ80AssertTargetExpectation (Z80 runs against Expected == 2 and passes, eZ80 runs against the override == 3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS * pipeline: withAssertSandboxStubs must not stub labels the text already defines The pass recognised only "name:" lines as label definitions, so two shapes that define a symbol differently gained a duplicate stub and the program stopped assembling: - "tag: DS 2, 0" — a data label whose body is on the same line; - "node_tag EQU peek" — a function alias (examples/nanz/ self_lanz_parser.nanz), assembled as "label 'node_tag' already defined" once the eZ80 assert path (previous commit) ran the pass over that corpus body. The same bug is latent for the forced-z80 sandbox (examples/nanz/self_parser.nanz, self_lanz_parser.nanz). Both shapes now mark the symbol defined: cutAsmLabelDef splits the leading label from a same-line body, and "name EQU expr" lines count as definitions. Bare labels keep the previous next-line lookahead. Regression tests: TestAssertSandboxStubsDataLabelWithSameLineBody, TestAssertSandboxStubsEQUAliasNotStubbed (both expect the text passed through unchanged); self_lanz_parser/self_parser eZ80 asserts verified back to pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS * ci: classify the new assert-sandbox and eZ80-expectation tests in fast The stable pipeline requires every pkg/pipeline test in the profile manifest exactly once; the four new tests (sandbox-stub label/EQU recognition, eZ80 sandbox stubs, eZ80 target-aware expectation) run in seconds and belong in fast. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS * examples: keep 30_stream_test's eZ80 failures visible The example stores a 24-bit pointer in a u16 cell, so on eZ80 it is not portable code; an 'ez80 = 0' expectation would enshrine the broken result. Restore the original source and its reviewed-updates record; the two asserts stay as known eZ80 failures until the example is rewritten portably. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the 7 asserts in the corpus that failed on main for both Z80 and Z80N. All 7 were compiler bugs; no expected value was changed.
letat the top of a loop body desyncedendmatching →JP endletbindingsDW 0on Z80 → dynamic dispatch jumped to 0DW <symbol>How the change is scoped:
compile_sweepagainst main (859 files): 0 exit changes, 0 stdout changes. Output changed in exactly 5 files (the Frill parse/type fixes and the ObjC vtable fix).Tests:
pkg/frill,pkg/mir2,pkg/c89andpkg/pipeline.go testfor frill/c89/mir2: ok.Co-developed with a GLM worker session (claude-z); reviewed, scoped and merged with main by the coordinator.
🤖 Generated with Claude Code
https://claude.ai/code/session_01N957godRAhTkyy1mTB6roS