Repository navigation
Stage-A: fix the bugs blocking the Python-to-Flow test port - #966
Merged
Merged
Conversation
This was referenced Sep 27, 2026
godofecht
force-pushed
the
fix/stage-a-test-blockers
branch
from
September 27, 2026 19:27
249161d to
7941faf
Compare
This was referenced Sep 27, 2026
… by type
println and print chose %d for every argument that was not a literal, so a
string variable or a concat result printed as a pointer. String + with an
i64, u32, f64 or bool operand passed the raw value to the concat helper.
cgen now classifies an expression's primitive kind from literals, casts,
declared variables, known call return types and arithmetic, and uses it for
both paths. Numbers go through new __flowc_str_of_{i64,u64,f64} helpers.
Fixes #948. Fixes #946.
lexer.flow returns KW_SHADER for the shader keyword but never imported it, so compile_module lexer in compiler/scripts/roundtrip.sh failed.
cgen emitted a block's defers before its return statement, so the return read memory the defer had already freed, and a return inside an if body skipped the enclosing block's defers entirely. Pending defers now live on a stack in CgenBuf. Every statement chain (block, if branch, match arm) is one scope. A return evaluates its value into __flowc_ret, runs every pending defer innermost first, then returns. break and continue run the loop body's defers. A scope that falls off its end runs its own defers. tests/lang/test_defer_return_order.flow replaces tests/integration/test_defer_ordering.py. Fixes #947.
…terns A bare ident arm parses as a catch-all binding, so a match with one arm per variant (Kind_A => ..., Kind_B => ...) failed with 'catch-all match arm must be last'. After parsing a program, arms whose ident spells <Enum>_<Variant> for an enum in the same program become value patterns. tests/lang/test_enum_match_arms.flow replaces test_match_exhaustive_returns.py::test_every_arm_still_dispatches_to_its_own_variant. Fixes #941.
…rays
[value; N] now parses. The array literal node keeps the count in b and
cgen lowers it to a GNU range initializer, { [0 ... N - 1] = value }.
A function returning array<T, N> returns a struct wrapper
__flowc_arr_<T>_<N> { T v[N]; }, typedef'd once before its first use. A
call to it appends .v, including calls into other bundle modules (the
signature table records the wrapper). A return builds the wrapper from a
literal, a named array or rows given by name.
array<array<T, M>, N> lets and params are T x[N][M] instead of an array of
pointers. A sized-array let from anything other than a literal is copied
with memcpy.
The C identifier I (a <complex.h> macro, always included) is now mangled,
which stdlib/audio/scales.flow needed.
tests/lang/test_array_repeat.flow, test_array_return_values.flow and
test_stdlib_scales.flow replace the value tests in
tests/integration/test_array_return.py.
Fixes #945. Fixes #943. Fixes #944.
sum(a..b), sum(a..b step s), and the union or intersection of two stepped ranges (sum(A | B), sum(A & B)) now parse. Bounds and steps bind tighter than the | and & that combine ranges. The call is marked with ival 2, 3 or 4 and lowers to preamble helpers, so every bound is evaluated once: __flowc_range_sum is the closed form in 64-bit arithmetic, and the intersection is one progression with step lcm(p1, p2) found by CRT. The self-test cgen buffers grow from 8 KiB to 32 KiB; the preamble passed 8 KiB with these helpers. tests/lang/test_range_sum_step.flow and test_range_algebra.flow replace the run tests in tests/integration/test_range_sum.py and test_range_algebra.py. Fixes #949.
A bundle is one C TU, so two modules that each define a private function with the same name failed with 'conflicting types'. Before emitting, the bundle lists every module's top-level function definitions. A private definition whose name is exported by another module, or defined privately by an earlier one, is wrapped in #define name __flowc_m<i>_name and a matching #undef around its module's C. One definition keeps its name, and a bundle without collisions emits the same C as before. tests/lang/test_private_fn_collision.flow replaces tests/integration/test_private_function_module_collision.py. Fixes #950.
Statement attributes were skipped, so @max_iterations(N) had no effect. The parser now keeps an integer bound on the while node (ival), and cgen counts iterations and aborts past the bound with the same diagnostic as the Python host: 'flow: while exceeded @max_iterations(N)'. tests/lang/test_max_iterations_bound.flow checks a loop inside the bound and one past it (exit 134, diagnostic on stderr). Fixes #940.
The checker rejected c64, c128 and the <complex.h> functions (creal, cimag, cabs, carg, conj, cexp, clog, csqrt, cpow) as unbound calls, though cgen already lowered the constructors and C provides the rest. They are now intrinsics. sizeof<T>() was also an unbound call. It is now an intrinsic that lowers to ((int64_t)sizeof(T)). The Python host's --strict checker rejects sizeof<T>(), so its test is a Stage-A fixture in roundtrip.sh (compiler/fixtures/stage_a_sizeof.flow) rather than a tests/lang program. tests/lang/test_complex_builtins.flow replaces test_complex_types.py::test_complex_compile_and_run. Fixes #942. Part of #952 (the stdlib mutex half stays open).
Stage-A emitted plain recursion, so a million-deep tail-recursive function overflowed the stack. When a function's body contains 'return f(...)' calling itself (same name, one argument per parameter, not overloaded, not generic), the body opens with a __flowc_tail label, and each such return evaluates every argument into a temporary, rebinds the parameters and jumps back. Returns with pending defers and returns inside lambdas keep the real call. tests/lang/test_deep_tail_recursion.flow replaces test_tco_shim.py::test_deep_tail_recursion_runs_without_stack_overflow. Fixes #951.
Regenerated from compiler/src with the Python host in bundle mode. Fixed point verified: the rebuilt bootstrap emits byte-identical C.
Contributor
Author
|
Merge train: rebased onto main after #980 (the ruff fix). The check.py commit dropped as already upstream. Please avoid pushing to this branch while the train is running. |
godofecht
force-pushed
the
fix/stage-a-test-blockers
branch
from
September 27, 2026 20:03
d453cdc to
613ab0d
Compare
godofecht
added a commit
that referenced
this pull request
Sep 27, 2026
Thirteen tests/lang programs cover run tests that used to transpile, compile and run from Python. The superseded Python tests are deleted. Rebased over #966, which had already deleted test_defer_ordering.py and the numeric cases of test_cast_in_string_concat.py; with both sides' deletions the latter file has no tests left and is removed.
This was referenced Sep 27, 2026
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.
Stage-A fixes that unblock porting Python run tests to tests/lang/. Each fix has a Flow regression test, and the Python tests that were kept only because of the bug are ported and deleted.
Fixes #948. Fixes #946. Fixes #947. Fixes #941. Fixes #945. Fixes #943. Fixes #944. Fixes #949. Fixes #950. Fixes #940. Fixes #942. Fixes #951. Part of #952.
Fixes
+formats number and bool operands through new__flowc_str_of_*helpers.__flowc_ret, runs all pending defers innermost first, then returns. break and continue run the loop body's defers.<Enum>_<Variant>for an enum in the program is a value pattern.[value; N]parses; lowers to{ [0 ... N - 1] = value }.array<T, N>returns a typedef'd wrapper__flowc_arr_<T>_<N> { T v[N]; }; calls append.v, also across bundle modules via the signature table. The C identifierI(a<complex.h>macro) is now mangled, which stdlib/audio/scales.flow needed.array<array<T, M>, N>lets and params areT x[N][M]. A sized-array let from a non-literal is copied with memcpy.sum(a..b),sum(a..b step s),sum(A | B),sum(A & B)parse and lower to preamble helpers (closed form in 64-bit, intersection by CRT). Each bound is evaluated once.#define name __flowc_m<i>_name/#undef. Bundles without collisions emit the same C as before.@max_iterations(N)on a while loop is kept on the node; cgen counts and aborts with the Python host's diagnostic.<complex.h>functions are checker intrinsics.sizeof<T>()is an intrinsic,((int64_t)sizeof(T)). The Python host's --strict checker rejectssizeof<T>(), so the test is a Stage-A fixture in roundtrip.sh: compiler/fixtures/stage_a_sizeof.flow.__flowc_taillabel. The tail return evaluates all arguments into temporaries, rebinds the parameters and jumps. Not applied with pending defers or inside lambdas.Also: lexer.flow now imports KW_SHADER (leftover from #890), which made
compile_module lexerin roundtrip.sh fail. The self-test cgen buffers in main.flow grow from 8 KiB to 32 KiB because the preamble passed 8 KiB.Not fixed
#952, stdlib mutex half. concurrent.flow's functions are not
exported. The Python resolver puts every declaration of an imported module in one flat namespace, while the Stage-A bundle checker seeds only exports. Making Stage-A match means deciding what private means across imports, which conflicts with the #950 behaviour. With the checker off, the concurrent.flow bundle compiles to an object. Linking still needs the runtime sources (#953).Python tests deleted or trimmed
Known gaps
./flow runnow writes to build/run.*/.k.tag("use of undeclared identifier"). test_enum_match_arms.flow uses_.Verification
FLOW_HOST=python ./flow run compiler/src/main.flow) printsflowc: PASS../flow test-lang(Python host) and exits as expected under Stage-A.