Skip to content

selfhost: corpus parity 2: closures, runtime checks, lenient mode, and the rest of #1018's gaps - #1025

Merged
godofecht merged 2 commits into
mainfrom
selfhost/corpus-parity-2
Sep 29, 2026
Merged

godofecht merged 2 commits into
mainfrom
selfhost/corpus-parity-2

Conversation

@godofecht

@godofecht godofecht commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #1018 (now merged; this branch was built on its head and has main merged in).

Corpus parity (C backend, flowc vs the Python host)

files at parity flowc better not behind Python
#1018 report 1014 960 5 965
this branch 1053 1037 6 1043

Floor (Darwin): 955 -> 1033. Every fix below has a tests/lang test.

Fixes

  1. Closures. A value of function type (A) -> R is the fat closure the Python host uses everywhere (fn_A__R { R (*fn)(void*, A); void* env; }): parameters, returns and annotated locals. Capturing lambdas copy their environment to the heap; non-capturing lambdas and named functions go through env-dropping bridges. cfn(A) -> R stays a plain pointer. Lambda parameters keep their declared types. Test: test_closure_abi.
  2. Runtime checks (FLOWC_CHECKS=1, set by the driver for flow compile/run/build and test-lang): integer / % by zero, every shift, reads of sized arrays and spans out of bounds, with the Python host's macros and messages; flow: <what> and abort (134). Writes stay plain lvalues, as on Python. Runtime library units stay unchecked, as Python's --library units. Integer overflow is not checked on either host (Python's overflow checks are switched off). Test: test_runtime_checks.
  3. Generic templates across bundle modules (Chan<T> from stdlib/concurrent), with nested generic calls instantiated at the enclosing types. Test: test_generic_channels (existing).
    impl blocks: impl Trait for Type methods become Type_Trait_method. Test: test_trait_impl.
    flow.toml [paths]. Test: toml_paths/test_toml_paths.
    Tensor operator sugar. Test: test_tensor_sugar.
    Also: quantity literals (1000.0 Hertz), method calls passing &recv to a pointer receiver in another module, array<T>(N), a step-less for range counting toward its end, @cImport emitting only #include (and its functions type-checking), libc-named Flow functions (log(Dual), malloc(i32) -> i32) reaching their definitions, and the python_embed runtime trying every library candidate. Each has a test.
  4. Lenient mode. FLOWC_LENIENT=1 is Python's --lenient: type errors are warnings except the ones Python keeps fatal (capability used as a value) plus constructs Stage-A cannot lower. The driver sets it for flow compile/run/build, where Python passes --lenient; test-lang and every direct flowc call (the parity scripts) stay strict, as Python's default --strict. So the units/effects negative fixtures run under compile and are rejected under strict, on both hosts. No file both hosts reject started to build.
  5. ga_hash uses u32 wrapping arithmetic; the nine GA programs' Python goldens are re-recorded and match. Test: test_ga_hash.

#1017 (unary operands)

Not reproducible on this tree, main, or selfhost/mlir-emit with any bootstrap: the C backend already wrapped binary operands (#999). Every unary emit site now parenthesizes non-primary operands anyway (C, JS, Metal, WGSL); the JS backend dropped ~ entirely. Test: test_unary_parens (!, not, -, ~ over every binary operator and nested unary/cast operands).

Emitted code before/after for every tracked .flow file:

  • C (as flow compile emits it): 3 files differ, only by added parentheses; none changes meaning: lib/stdlib/psychstats.flow, tests/stdlib/test_psychstats.flow ((-(double)(i)) -> (-((double)(i)))), tests/lang/test_unary_parens.flow.
  • JS: 460 files differ by added parentheses. Meaning changes only where ~ was dropped: benchmarks/micro/frame_arena_benchmark.flow, compiler/fixtures/mlir/arith.flow, examples/audio/lifetime_domains.flow, examples/crypto/sha256.flow, lib/runtime/crypto.flow, lib/stdlib/memory_simple.flow, lib/stdlib/memory.flow, tests/core/test_bitwise.flow, tests/lang/test_lifetime_domains.flow, tests/lang/test_unary_parens.flow.
  • Metal/WGSL: no tracked shader source nests a unary operator.

What still differs

16 files, none a flowc bug that Python gets right:

  • flowc builds what Python cannot (6 flowc-better): ok_existing_import, stage_a_match, compiler/src/driver.flow, scripts/tools/pkg_sync/main.flow, test_c_import_python, test_closure_abi.
  • flowc-accepts, Python rejects (3): compiler/src/pkg_main.flow and tools/repl/main.flow (Python rejects the \x escape), tools/lsp/main.flow (Python cannot parse handle as a name). These are Flow tools that must build on flowc, so flowc keeps accepting them.
  • examples/rf/iq_mixer.flow: Python prints creal(...) with %d (garbage integers); flowc prints the double.
  • Timing and load: examples/concurrency/fiber_async, fiber_suspend (hang under the parallel run on both hosts' builds), tests/runtime/test_fiber_async (Python golden is a timeout), examples/concurrency/http_tls (network). cont_flow_resume, flowlm_charlm, chemostat (Python goldens are timeouts), gomaxprocs, http_middleware and http_tls move in and out between runs for the same reasons.

Verification

Bootstrap C regenerated last from the Python host build (separate commit); fixed point holds. Passing: bootstrap_from_c.sh --verify, self_host_full.sh, roundtrip.sh, parse_coverage.sh --check, parity_dynamics_dsl, parity_effects, parity_field_dsl, parity_flow_blocks, parity_lowering, parity_mlir, parity_proofs, corpus_parity.sh --check. parity_shader_dsl passes its fixtures and host stub checks; its Metal end-to-end step needs the Metal toolchain, which this machine lacks (as on #1018).

History: the fixes were rebuilt on #1018's rebased head, then origin/main (with #1018 squash-merged) was merged in and the bootstrap C checked against the merged sources (unchanged; fixed point holds).

…d the rest of #1018's gaps

One closure representation for function types, the Python host's runtime
checks under FLOWC_CHECKS=1, generic templates across bundle modules,
parenthesised unary operands (#1017), impl blocks and flow.toml [paths]
imports with a fallback, Tensor operator sugar, quantity literals,
FLOWC_LENIENT=1, pointer receivers across modules, array<T>(N), @cImport
as a plain include, for ranges without a step, and libc-named Flow
functions reaching their definitions. Squashed from
selfhost/corpus-parity-2 onto main.
test_closure_abi tests the single closure representation flowc uses for
function types. The Python host keeps a separate function-pointer ABI and
its C does not compile, so tier-2 and Tier 1 failed. A file marked
flow:flowc-only in its first three lines is skipped by the Python-host
sweep; the flowc bootstrap suite and test-lang on flowc still run it.
@godofecht

Copy link
Copy Markdown
Contributor Author

Merge train: squashed onto main after #1021 (one commit with the branch's content, plus a fix commit). test_closure_abi.flow is marked flow:flowc-only and the Python-host tier-2 sweep skips such files; the Python host keeps its own function-pointer ABI, which is why tier-2 and Tier 1 failed. Locally: fixed point OK, bootstrap_from_c --verify and self_host_full pass, every parity gate passes (shader except its Metal step, which needs a Metal toolchain this Mac lacks), parse coverage 2344 >= 2276, fmt gate OK, corpus parity 1044 >= 1033 on Darwin.

@godofecht
godofecht force-pushed the selfhost/corpus-parity-2 branch from 753113d to 7d97141 Compare September 29, 2026 12:05
@godofecht
godofecht merged commit 9751b33 into main Sep 29, 2026
29 checks passed
godofecht added a commit that referenced this pull request Sep 29, 2026
#1025 changed stdlib (ga_hash wraps as u32), which changed the MLIR of 35
corpus programs that import it. Rerecorded with --write-golden 84806b0:
789 programs.
@godofecht
godofecht deleted the selfhost/corpus-parity-2 branch October 1, 2026 12:50
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