Repository navigation
selfhost: corpus parity between flowc and the Python host, and the top gaps closed - #1018
Merged
Merged
Conversation
godofecht
force-pushed
the
selfhost/corpus-parity
branch
from
September 29, 2026 09:51
46d5bfb to
6580ea9
Compare
The merged compiler imports more than 32 modules and its bundled C is past 1 MiB, so flowc could no longer emit itself. MAX_MODS goes to 128 and the emit buffer to 4 MiB in main.flow and driver.flow.
compiler/scripts/corpus_parity.sh builds every tracked .flow file with a main() the way flow run does, once per host, runs both with a timeout and compares build accept or reject, exit code and stdout. It prints a table by directory and the failure causes ranked by the first flowc diagnostic. Without flags it runs flowc against Python results recorded in compiler/corpus_parity/python_golden.tsv, so it needs no Python and can run in CI. --python compares against the live Python host and --record rewrites the goldens. --check gates on a per-OS floor in floor.txt. Measured on the merged base: 792 of 998 files at parity (79.4%), 543 of the 743 that Python builds run the same.
flowc_link_c linked the generated C alone, so any program that used channels, fibers, TLS, the audio stub, GPU memory or another runtime entry point failed at link time on FLOW_HOST=flowc. It now links the same runtime the Python path does: runtime/*.c (concurrency, fibers, TLS, the dlopen Python bridge, Metal on Darwin) and the always-linked lib/runtime/*.flow modules, with those modules emitted by flowc rather than Python. The objects are built once per source and flowc state into build/flowc_runtime/<key>/libflowrt.a, so a program pulls in only what it uses. -lm and the program's own directory as an include path come along. FLOWC_NO_RUNTIME=1 keeps the old single-file link. Corpus parity (compiler/scripts/corpus_parity.sh), link failures on the flowc side: 73 before, 9 after.
The overload compatibility check read span_mut_i32 as a span of mut_i32, so passing an array to a span<mut T> parameter was "no matching overload". memref_T, a pointer to T on the Python host, did not accept an array either. Corpus parity: "no matching overload" 3 before, 1 after. Tests: tests/lang/test_span_mut_array_arg.flow, test_memref_param.flow.
Bundle gathering failed with no message on imports the Python host resolves: - a bare stdlib module, import "io.flow" or import "lib/stdlib/nn.flow", now falls back to lib/stdlib; - import "stdlib/vec" without the .flow suffix; - dotted imports against the importing module's directory, and with a trailing symbol (import a.b.sym names sym in a/b.flow); - relative .a.b imports name a/b.flow. An import no search path finds now says so: flowc gather: <module>: cannot resolve import <text>. The cross-module signature table grows to 1 MiB for the span parameter entries cgen adds. Corpus parity: gather failures 14 before, 1 after (http_json_cache needs flow.toml [paths]). Test: tests/lang/test_import_path_forms.flow.
Each fix comes from a cluster in the corpus parity report, with a test in tests/lang: - A const named like a libc macro (CLOCKS_PER_SEC) gets #undef first; the preamble includes <time.h>. expected ')': 29 files before, 1 after. test_const_libc_macro_name. - A struct literal field set from a named array is copied in with memcpy; C decides at compile time whether the field is an array or a pointer. float[256] initializers: 9 before, 0 after. test_struct_lit_array_field. - Overload selection types an identifier argument by the declaration in scope. It used to take the first parameter of that name in the whole program. test_overload_param_scope. - i % x with an integer left side and a float right side casts the right side, as the Python host does. test_mod_int_by_float. - An array passed to a &[T] parameter of a function in another module of the bundle is wrapped in a span: the signature table now records span parameters. test_span_param_cross_module. - print/println of a value flowc cannot type picks the conversion from the C type (complex prints as (re + im j)), and several arguments print separated by spaces. test_print_complex_multi. - memref_T is a pointer to T. test_memref_param. - @cImport preprocesses with cc -E -std=c11 -D_DEFAULT_SOURCE, the flags programs build with, so Annex K prototypes such as memset_s no longer leak in and the SDK headers no longer print preprocessor errors. Corpus parity with all fixes so far: 792 of 998 (79.4%) before, 919 (92.1%) after.
A file whose Python-generated C does not compile but whose flowc build succeeds is "flowc better"; the floor gates on parity plus better. compiler/corpus_parity/nondet.txt lists files whose stdout depends on the clock although two back-to-back Python runs agreed. Link failures name the first undefined symbol, and a C error in the generated file wins over preprocessor noise from system headers. The driver runs as one function so editing the script during a run is safe.
More corpus parity clusters, each with a test in tests/lang: - Struct typedefs come after the structs their fields hold by value; flowc kept source order, so a struct that used a later one did not compile. - let f = f(x), where f is also a function, evaluates the initializer into a temporary first; C put the new local in scope inside its own initializer. - Assigning to a local sized array copies (memcpy), from a call or from an array literal. test_struct_order_shadow_array_assign. - gpu_thread_id() with no Flow definition is the Python host's host stub, thread 0. link: undefined symbol gpu_thread_id: 5 files before, 0 after. - An imported module's own main() steps aside for the entry's. flowc renamed the entry's main and ran the library demo. test_import_module_with_main.
- A Flow function named like a libc function that the preamble's headers declare with another signature (heapsort on macOS, index, random, abs) is renamed for the unit with a #define. The Python host mangles every function by its parameter types and never clashed. conflicting types: 2 files before, 0 after. - str is the Python host's other spelling of string. - return void is a bare return in the type checker too; cgen already emitted it. - The return checks now say what failed. They counted an error with no message, which the parity report could not cluster. Test: tests/lang/test_libc_names_return_void.flow.
a + b, a - b, a * b and a / b with a Dual operand call add, sub, mul and div, and -x on a Dual calls neg. Overloads resolve by operand type (Dual or f32); a single local definition keeps its plain name. div joins the libc-named functions that get a #define, since <stdlib.h> declares div(). Corpus parity: Dual operand errors 4 files before, 1 after. The corpus run timeout goes to 20 s; fiber programs timed out under a 12-job load. Test: tests/lang/test_dual_operator_sugar.flow.
- A let of function type bound to a plain function (a named function, a function parameter, a non-capturing lambda variable or a cast to a function type) is a plain C function pointer, like function parameters. cfn(...) lets always are. flowc emitted a closure struct and could not call it. tests/lang/test_dlopen passes. - (p as ptr<T>)[i] keeps the cast in parentheses; C indexed first. - A float literal argument selects the f32/f64 overload. tests/lang/test_function_as_value passes. - len() of a sized array is its element count. test_len_sized_array. Closures that capture and are passed to a function-typed parameter (test_fn_ptr, test_closures, examples/book/11_closure_snapshot) still need one closure ABI for parameters and locals.
A statement-level expect parses to a bare AST_UNARY, which emit_stmt did not handle, so every expect was dropped. It now emits, and a failed expect prints "expect failed (line N)" and exits 1, as on the Python host. dbg prints with the conversion of its operand's type. tests/lang/test_expect_fails and test_dbg_expect now pass on flowc; the corpus parity run-exit cluster (Python 1, flowc 0) is gone.
An array literal passed to an array<T>, ptr<T> or memref_T parameter is
emitted as (T[]){ ... }. A bare brace list is not a C expression.
Test: tests/lang/test_array_literal_argument.flow.
compiler/corpus_parity/report.txt, from the flowc built from the
regenerated bootstrap C against the Python goldens:
before (merged base): 792 of 998 at parity (79.4%); 543 of 743 that
Python builds run the same (73.1%)
after: 960 of 1014 at parity (94.7%), plus 5 where only
flowc's C compiles; 712 of 759 that Python builds
run the same (93.8%)
The corpus grew by the new tests/lang regression tests and their goldens.
The floor is set 10 under the run (955) for the HTTP and timing programs
that are flaky in parallel, the default run timeout is back to the 10 s the
goldens were recorded with, --only skips the floor, and a run names the
untracked files programs leave in the tree.
godofecht
force-pushed
the
selfhost/corpus-parity
branch
from
September 29, 2026 10:30
6580ea9 to
2a53316
Compare
godofecht
added a commit
that referenced
this pull request
Sep 29, 2026
…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.
godofecht
added a commit
that referenced
this pull request
Sep 29, 2026
…d the rest of #1018's gaps (#1025) One closure representation for function types, the Python host's runtime checks under FLOWC_CHECKS=1, generic templates across bundle modules, impl blocks and flow.toml [paths] imports, 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. Files marked flow:flowc-only are skipped by the Python-host test sweep. Corpus parity 1044 >= 1033 (Darwin); every parity gate passes.
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.
Measures how far the flowc host is from replacing the Python host on the C backend, then closes the largest gaps.
Measuring base
Built on origin/main merged with the in-flight compiler branches: fix/stage-a-batch-3, selfhost/lower-proofs, selfhost/lower-effects, port/dynamics-dsl-flowc, port/shader-dsl-flowc and port/pkg-native. The bootstrap C was regenerated for the merge. The merged compiler imports more than 32 modules and emits more than 1 MiB of C, so the bundle caps went up first. This branch should be rebased or re-merged as the train lands.
compiler/scripts/corpus_parity.sh
Every tracked .flow file with a main() is built the way
flow runbuilds it, once with FLOW_HOST=flowc and once with FLOW_HOST=python. Both executables run with a timeout, and the script compares build accept or reject, exit code and stdout. It prints a table by directory and ranks the failure causes by the first flowc diagnostic.--pythoncompares against the live Python host.--python --recordrewrites the goldens.--checkgates on a per-OS floor in compiler/corpus_parity/floor.txt, set 10 under the run for flaky HTTP and timing programs.Result
The corpus grew by the new regression tests.
Fixes, largest cluster first
Each fix has a test in tests/lang.
#undeffirst.expected ')'went from 29 to 1."stdlib/vec"without a suffix, dotted imports relative to the module with a trailing symbol, and.a.bimports. An import that cannot be resolved now prints a message. Gather failures went from 14 to 1.len()of sized arrays.span<mut T>andmemref_T. Dual operator sugar ([roadmap] Dual + Tensor operators + mutable params #161).&[T]parameters wrap array arguments in a span, via the signature table.let f = f(x), libc-named functions (heapsort, index, div),str,return void,gpu_thread_id, and an imported module's own main().(p as ptr<T>)[i].Top remaining causes
--lenienton the units and effects fixtures, 9 rejections. These files are meant to be rejected.Chan<T>from an imported module (test_generic_channels), trait impl calls, flow.toml [paths], and Tensor operator sugar.Verification
corpus_parity.sh is bash because it runs processes, builds and timeouts. The clustering could move into a Flow program later.