Repository navigation
selfhost: lower algebraic effects in flowc (#996, #675) - #1014
Merged
Merged
Conversation
godofecht
force-pushed
the
selfhost/lower-effects
branch
from
September 29, 2026 08:27
f5c7df0 to
0510995
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.
flowc now parses, checks and lowers effect declarations, capabilities, handle blocks, effect rows and capability parameter types, the same way the Python host does: - parser: effect and capability declarations become AST_EFFECT and AST_CAPABILITY (methods are AST_CAP_METHOD); `capability E` types carry AST_TYPE_CAPABILITY. handle and effect rows are no longer parse-only. - effects.flow: an effect table that rides in the bundle signature table so imported effects, capabilities and rows are known in later modules. - typecheck: the Python host's effect diagnostics (unknown effect or operation, arity, literal argument types, unqualified operations, capability used as a value, unknown effects in rows and handle), plus the --strict-effects row checks under FLOWC_STRICT_EFFECTS=1. - cgen: handler vtables, fiber-local handler slots, dispatch functions, capability vtables, handle install and restore, E.op calls, implicit capability arguments, the FiberAsync main wrapper, and the unhandled policy (zero default, FLOW_STRICT_EFFECTS=1 aborts). - fmt and jsgen still refuse effect programs instead of dropping them. - Source buffers grow to 512 KiB: cgen.flow passed 256 KiB. Corpus (45 tracked .flow files using effects), flowc vs Python host at 860b7dd: every program that builds and runs on the Python host (17) now builds and runs on flowc with identical output and exit code, except tests/runtime/test_flow_way_examples.flow, which stops on the pipeline placeholder `_`. Before: 2 of those 17 ran on flowc. Bootstrap C is regenerated in a later commit.
compiler/scripts/parity_effects.sh holds flowc to the Python host on algebraic effects. 15 fixtures in compiler/fixtures/effects (14 programs and the log registry package demo from #991, built with the package beside it) carry goldens recorded from the Python host at 860b7dd: the effect diagnostics of a rejected program, or the run output and exit code of an accepted one. --python <rev> also runs the Python host live over the fixtures and over every tracked .flow file that uses effects. Results against 860b7dd: - fixtures: 15/15 match the goldens, 15/15 match the live Python host - corpus: 46 files, 16 run with identical output and exit code, 29 are rejected by both hosts (5 at a different stage, all non-effect cgen gaps), 1 known gap (#1005, pipeline placeholder), 0 failures flowc also treats putenv, setenv and unsetenv as libc (the log package declares putenv) and maps the legacy array_f32 type spelling to a pointer. Python removed: tests/unit/test_effect_rows.py, test_unqualified_effect_op.py, test_capability_not_a_value.py and test_capability_method_params.py (their cases are fixtures now), and the effect checks of test_strict_effects.py. python_ratchet --update: limit 104478 lines.
roundtrip.sh, stage_a_self_emit.sh and stage_a_self_emit_g2.sh compile each compiler module on its own and link the objects. They now emit effects.flow, include its header in cgen, typecheck and resolve, and link it into the frontend object. The C host driver reads sources up to 512 KiB, matching flowc.
…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
force-pushed
the
selfhost/lower-effects
branch
from
September 29, 2026 08:59
0510995 to
8785a76
Compare
This was referenced Sep 29, 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 #675. Addresses the handler half of #991.
flowc now parses, checks and lowers algebraic effects the way the Python host does:
effectandcapabilitydeclarations,handle E1, E2 with H1, H2 { }, effect rows (-> T with E),capability Eparameter types,E.op(args), and the unhandled-effect policy.This branch contains #1001 and #1003, which are still open. Merge those first; the diff then shrinks to the effect work.
What changed
compiler/src/effects.flow(new): an effect table (effects, operation signatures, capabilities,withrows) that rides in the bundle signature table, so a module sees what its imports declare. This is what thelogpackage needs:export effect Login one module,handle Log with ConsoleLogin another.AST_EFFECT/AST_CAPABILITY(methods areAST_CAP_METHOD, so the whole-arena function scans never seeConsole.infoas a functioninfo).capability Emarks itsAST_TYPE.handleand effect rows are no longer parse-only.handleor awithrow. WithFLOWC_STRICT_EFFECTS=1(the Python host's--strict-effects) it also reports unhandled performs and calls whose row no handler covers. Diagnostics print aspath:line:col: error: <message>.handlesaves, installs and restores the slots; implicit capability arguments insidehandle; the FiberAsync main wrapper. An unhandled operation returns zero, or aborts withFLOW_STRICT_EFFECTS=1at run time (hard-wired byFLOWC_STRICT_EFFECTS=1at compile time).cgen.flowpassed 256 KiB). The per-module self-host scripts build and linkeffects.flow.printf,fprintf,sprintf,scanf,sscanfare typecheck builtins as on the Python host;putenv,setenv,unsetenvare libc; the legacyarray_f32type spelling lowers tofloat*.Parity gate
compiler/scripts/parity_effects.sh, modelled onparity_field_dsl.sh. It needs only cc for the goldens, and--python <rev>adds a live comparison with the Python host from that revision (extracted withgit archive).compiler/fixtures/effects/: every diagnostic above, strict and non-strict, runtime zero defaults and nested handler restore, theFLOW_STRICT_EFFECTS=1abort (stderr and exit code 134), multi-effecthandle, capability method printing, and thelogregistry package demo with the package beside it. Goldens recorded from the Python host at 860b7dd..flowfile that uses effects, compiled the wayflow rundoes, linked againstruntime/*.c, run with a 10 s limit.Results with the regenerated bootstrap:
Diagnostics match as text. Two Python messages use an em dash and an ellipsis as separators; flowc writes
:and..., and the gate maps the Python spelling before comparing.Before and after on flowc
Of the 17 corpus programs that build and run on the Python host:
unsupported in Stage-A: handleoreffect rowtests/runtime/test_flow_way_examples.flow, stops on the pipeline placeholder_(Stage-A: pipeline placeholder argumentx |> f(a, _, b)#1005)../flow run examples/effects/effect_rows.flownow runs on the default flowc host.The 29 programs both hosts reject are mostly the concurrency, GPU and stdlib files that need the Flow-side runtime in
lib/runtimeor GPU libraries at link time. Five reject at a different stage (Python at link, flowc at C compile); the flowc errors are general cgen gaps unrelated to effects, filed as #1009.lib/stdlib/audio/notation.flowis one of them.Python removed
tests/unit/test_effect_rows.py,test_unqualified_effect_op.py,test_capability_not_a_value.py,test_capability_method_params.py: their cases are now gate fixtures.tests/unit/test_strict_effects.py(the file keeps its one debug-info test).python_ratchet.sh --update: limit 97003 lines.The effect lowering in
src/flow/c_generator.pyandtype_checker.pystays while the Python host is still selectable withFLOW_HOST=python.Verification
main.flowequals the rebuilt bootstrap's emit.bootstrap_from_c.sh --verify,self_host_full.sh,roundtrip.sh,parse_coverage.sh --check(2139 ≥ 2082),parity_field_dsl.sh,parity_effects.sh --python 860b7dd7: all pass.test_effectsis one of the new passes.python_ratchet.sh: PASS.Not done
import log.libthrough a package install needs flowc package resolution from Package management in Flow: native install/add/sync and flowc package imports #989. The gate builds the log demo with the package beside it instead.app_cachealso needs the sqlite and HTTP runtimes at link time on both hosts.testing_demo's typecheck failure from flow run (flowc host) does not build registry packages' [native] C sources, so sqlite_demo and app_cache fail to link #991 is outside effects.