Repository navigation
flowc: lower match patterns, ui layout, pipeline forks, declarative sort, [T; N], ?, vectors, module and unit (#996) - #1012
Merged
Merged
Conversation
godofecht
added a commit
that referenced
this pull request
Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's parse-only mode, located parse errors (flowc_parser_print_error, which the driver, emit and bundle paths now use), theorem/assume/therefore/claim references, flow blocks, handle, ui layout and pipeline blocks, let without initializer, contextual unit, distinct, effect rows, or-patterns, guards, nested patterns, [T; N], capability types, ?, vector literals, soft names, sort-by keys, entropy policies and module blocks, the parse coverage script and its CI floor, and the Python-grammar parser contract test. The #1001/#1003 reconciliation follows the one in #1012.
godofecht
added a commit
that referenced
this pull request
Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's parse-only mode, located parse errors (flowc_parser_print_error, which the driver, emit and bundle paths now use), theorem/assume/therefore/claim references, flow blocks, handle, ui layout and pipeline blocks, let without initializer, contextual unit, distinct, effect rows, or-patterns, guards, nested patterns, [T; N], capability types, ?, vector literals, soft names, sort-by keys, entropy policies and module blocks, the parse coverage script and its CI floor, and the Python-grammar parser contract test. The #1001/#1003 reconciliation follows the one in #1012.
godofecht
force-pushed
the
selfhost/lower-patterns
branch
from
September 29, 2026 07:52
994e8e3 to
e6c84ca
Compare
godofecht
added a commit
that referenced
this pull request
Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's parse-only mode, located parse errors (flowc_parser_print_error, which the driver, emit and bundle paths now use), theorem/assume/therefore/claim references, flow blocks, handle, ui layout and pipeline blocks, let without initializer, contextual unit, distinct, effect rows, or-patterns, guards, nested patterns, [T; N], capability types, ?, vector literals, soft names, sort-by keys, entropy policies and module blocks, the parse coverage script and its CI floor, and the Python-grammar parser contract test. The #1001/#1003 reconciliation follows the one in #1012.
godofecht
added a commit
that referenced
this pull request
Sep 29, 2026
…s lowered test_parser_python_forms asserted that handle blocks, or-patterns, effect rows and fork blocks stay parse-only. #1012 lowers or-patterns and forks and #1014 lowers handle and effect rows, so the test exited 7 (6 with both). It now checks that each form parses to its node and is lowered, and exits 0 on flowc and the Python host alike. The parity_lowering golden follows.
Match arms with or-patterns, guards, nested struct patterns with literal
fields, and variant patterns on an enum value now lower in Stage-A the
way c_generator._gen_match does: an if/else chain whose condition ORs
the alternatives' checks, a guard that sees the first alternative's
bindings through a statement expression, and bindings typed with
__typeof__ from the matched field.
The or-pattern fixture that roundtrip.sh used as a negative case is now
a positive case, stage_a_match_ext (exit 42).
Unblocks 5 tracked files (tests/core/test_match_{nested,advanced,
enum_exhaustive}.flow, test_coverage_match_deep.flow and the fixture);
each builds and runs with the same output and exit code as the Python
host.
cgen.flow is about to pass 256 KiB, the old per-module source buffer. Bundle mode, the single-file emit path and the Stage-A driver now read up to 1 MiB per module.
ui_layout / ui_row / ui_column / ui_stack / ui_grid blocks lower the way
c_generator._gen_layout does: <word>_begin(args), the body, then
<word>_end(first arg). Unless the first argument is a pointer or array
variable, the implicit _ui_state pointer goes first. A module that uses
it gets the guarded global. ui_layout_bind(p) and an undefined
i32_to_f32(v) lower inline as the Python host's intrinsics do.
tests/core/test_ui_layout{,_std,_positions,_snapshot}.flow and
examples/ui/layout_hello.flow now build on flowc with the same run
output and exit code as the Python host (test_ui_layout and
test_ui_layout_std segfault identically on both hosts).
src |> Record { a = f, ... }, the anonymous src |> { a = f, ... } and
src |> choose sel { A => f, ... } now lower the way
src/flow/fork_records.py desugars them. Each block is one GNU statement
expression that binds the source once; a fork builds its record (an
inline struct typed from the branches for the anonymous form) and a
choose assigns the selected arm through the general match lowering.
Branches parse as pipelines over a placeholder source, and a bare _
argument now marks the pipe slot (x |> f(1, _)) as in _insert_pipe_arg.
The typecheck rejects an uninferrable anonymous field or choose with
the Python messages. Flow stage parameters stay with flow blocks.
examples/basics/pipeline_{fork,fork_inferred,choose}.flow now build on
flowc with the same output and exit code as the Python host.
Every |> sort, |> sortBy and |> order is now a declarative sort, as the Python parser's _at_declarative_sort claims them. It sorts the fixed-size array in place with a stable bottom-up merge sort, keys compared lexicographically with per-key and global direction, and unique compacts the prefix, as c_generator._gen_sort_expr and _sort_cmp_fragment do. Compares follow _scalar_cmp: strcmp for strings, IEEE totalOrder for floats, < and > otherwise. Entropy and speed policies parse and change nothing, as in the Python host (the plan choice there changes speed only). examples/basics/declarative_sort.flow now builds on flowc; before, its sortBy [desc .score, asc .name] sorted by the first field only and printed a different order. It and the tests/lang sort tests match the Python host's output.
The Python type form [T; N] is array<T, N>. The parser now marks its AST_TYPE with AST_TYPE_FIXED_ARRAY, and cgen asks flowc_cgen_ty_is_array wherever it matched the array name span, so the nameless node emits as T name[N] and is no longer mistaken for the [T] span sugar. benchmarks/cross_harness/runtime/arrays/arrays.flow builds and runs with the Python host's exit code; benchmarks/aosoa.flow compiles and links.
…#996) - expr? binds the Result once, returns it unless is_ok and yields .value, as c_generator's TryExpr does (pending defers run first). - <a, b, c> is a GCC/Clang vector literal whose lane type comes from the first element, and vecN<T> is T __attribute__((vector_size)), both as in the Python host. return <a, b> now parses as a value. - module Name { ... } declarations join the top level, as flatten_module_declarations does. tests/core/test_production_features.flow and tests/simd/test_{simple_simd, simd_vector}.flow now build on flowc with the Python host's output and exit code.
A top-level unit Name [= ...] is an f64 at run time, as in the Python host, so it now lowers to typedef double Name, emitted before structs whose fields may use it. flowc does not check dimensions yet (#1008). tests/core/test_units_basic.flow and test_coverage_units.flow now build on flowc and match the Python host's output and exit code.
compiler/scripts/parity_lowering.sh builds 66 tracked files that use the newly lowered constructs, match, unit or distinct declarations on flowc, runs the ones that link, and holds accept/reject, the rejection diagnostic, the exit code and the stdout to the Python host. Goldens in compiler/parity_lowering/expected.tsv come from ff99639; --python <rev> repeats the comparison live and --write-golden rewrites them. Result on flowc and live against python@ff99639e: 66 files, 47 same accept/reject, 38 same exit code and output, 2 same diagnostics, 19 known divergences outside this work (listed with reasons in divergent.txt; #1006, #1007), 0 failures. New: tests/lang/test_lowered_forms.flow exercises each construct and passes on both hosts; two negative fixtures pin the fork and choose inference messages.
cgen.flow now passes 256 KiB, so roundtrip.sh's g2_emit of cgen through the C host driver ran out of source buffer. The output buffer grows to 4 MiB to match.
godofecht
force-pushed
the
selfhost/lower-patterns
branch
from
September 29, 2026 08:48
e6c84ca to
e2bd4cb
Compare
godofecht
added a commit
that referenced
this pull request
Sep 29, 2026
…s lowered test_parser_python_forms asserted that handle blocks, or-patterns, effect rows and fork blocks stay parse-only. #1012 lowers or-patterns and forks and #1014 lowers handle and effect rows, so the test exited 7 (6 with both). It now checks that each form parses to its node and is lowered, and exits 0 on flowc and the Python host alike. The parity_lowering golden follows.
godofecht
added a commit
that referenced
this pull request
Sep 29, 2026
Effect declarations, capabilities, handle blocks, effect rows and E.op calls lower in flowc (effects.flow) with the Python host's diagnostics, gated by parity_effects.sh. Merged over #1012: AST_TYPE_CAPABILITY is 3 (FIXED_ARRAY is 2), effect rows and capability types join flowc_ast_parse_only_lowered, and the parser contract test expects handle, or-patterns, rows and forks lowered. CI passed on 0510995, whose tree (4902590) is identical to this rebased head. Bootstrap C regenerated (fixed point, bootstrap_from_c --verify, self_host_full, parity_effects and parity_lowering pass).
This was referenced Sep 30, 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.
Part of #996 and #678. flowc now lowers the parse-only constructs outside proofs, effects and flow blocks. Each one follows the Python host's lowering.
Based on #1001 and #1003, which are merged in because both are still open. Review after them, or read from
a02dfdc2.Constructs
c_generator._gen_matchui_layout/ui_row/ui_column/ui_stack/ui_grid,_ui_state,ui_layout_bind_gen_layoutsrc |> R { a = f }, anonymous fork,|> choose sel { ... }, the_pipe slotfork_records.py,_insert_pipe_arg|> sort,sort by keys,sortBy,order,with entropy,unique,descending_gen_sort_expr,_sort_cmp_fragment,_scalar_cmpsortBy [desc .score, asc .name]used to sort by the first field only)[T; N]array<T, N>expr?TryExpr<a, b, c>andvecN<T>VectorLiteral,_c_typemodule Name { ... }flatten_module_declarations?aboveunit Name [= ...]distinct typeFlow stage parameters
x |> Stage { k: v }still refuse: they are part of flow blocks, which this PR does not lower (75 files,src/flow/flow_blocks.py).Tracked files that compile on flowc
Bundle emit plus
cc -c, over every tracked .flow file the Python parser accepts, on this tree:The 36 include cgen.flow, main.flow, driver.flow, resolve.flow and examples/systems/tiny_pointers.flow, which need the 1 MiB source buffers now that cgen.flow is past 256 KiB.
Parity gate
compiler/scripts/parity_lowering.shholds 66 tracked files (every file above plus everymatch,unitanddistinctuser) to the Python host: same accept/reject, the Python diagnostic for rejects, and the same exit code and stdout for programs that link. Goldens are recorded from ff99639;--python ff99639erepeats it live.The 19 known divergences are outside this work and listed with reasons in
compiler/parity_lowering/divergent.txt:The gate is not wired into CI in this PR. It needs only cc and runs in about a minute.
Python removed
None.
fork_records.py, the sort plans and_gen_match/_gen_layoutstill serve the MLIR backend, the Python C path thatflow-examplesCI runs with FLOW_HOST=python, and tests/integration/test_pipeline_examples.py. They can go once those move off the Python host. The ratchet passes and did not grow.Other changes
tests/lang/test_lowered_forms.flowcovers every construct and passes on both hosts.compiler/fixtures/stage_a_match_ext.flowreplaces the old negativematch_unsupported.flow.Verification
bootstrap_from_c.sh --verify,self_host_full.sh,roundtrip.sh,parse_coverage.sh --check,parity_field_dsl.shandparity_lowering.shpass.Follow-ups