Repository navigation
selfhost: retire the Python C host; flowc is the only C compiler - #1027
Merged
Merged
Conversation
) The Python host treats the proof layer as metadata: the C generator skips theorem declarations, writes assume / therefore as comments, and the module resolver treats claim names in export and import lists as citations. compiler/src/proof_lower.flow gives flowc the same semantics. It runs at the start of cgen, jsgen and the typecheck, unlinks the proof nodes and retags them so no backend sees them. The formatter still refuses a theorem, as it cannot print one. The bundle resolver now maps a claim-path segment `Nat/+` to the domain module `Nat.flow` when no literal file exists, as the Python resolver does, and accepts a module that emits no C. examples/verify on the flowc host (emit, as flow-driver runs it): before 0/1054, after 898/1054. Python accepts the same 898 and rejects the same 156. full_adder.flow runs on flowc with the same output.
compiler/src/proof_doc.flow ports the single-file half of src/flow/proof_document.py: parse_proof_file, build_tutorial_lines, render_english, render_latex, write_proof_artifacts and the tree variant, with the global claim tier index from flow.know. compiler/src/geometry_script.flow ports the .geom diagram language and diagram_for_theorem; geometry_diagram.flow gains the diagram model, the built-in templates and the SVG and TikZ renderers. The earlier Flow helpers in math_prose, claim_address and claim_path returned fixed strings for a handful of claims. They now follow the Python tables: carrier and structure names, law_phrase, addr_prose, tier_opening_mathematical, the coordinate lines (with the middle dot) and normalize_tier (strip and lower-case). Parity on examples/verify (1054 files), flowc against the Python generator at 9103c99 (the prose without dashes): 2294 of 2294 output files byte-identical (1054 .proof.md, 1054 .proof.tex, 93 .proof.svg, 93 .proof-diagram.tex).
proof_doc.flow gains the rest of the proof tooling that src/flow/proof_document.py, proof_kernel.py and know.py provided: - FLOWC_PROOF_BOOK=book|basic|geometry writes the side-by-side LaTeX (render_side_by_side_bundle) and refreshes each file's documents. The part lists move from Python constants to tools/doc/proof_book.txt. - FLOWC_PROOF_KERNEL=1 writes the proof kernel JSON (json.dumps with indent 2 and ASCII escapes) and the Graphviz DOT plot. - FLOWC_KNOW=<claim> and FLOWC_KNOW_LINT=1 are `flow know` and `flow know --lint-duplicates`. Parity with the Python at 9103c99: the three bundle .tex files are byte-identical (25440, 5952 and 1214 lines); 13 of 13 kernel JSON and DOT pairs match; 13 of 13 `flow know` lookups and the 162-line duplicate lint match (the lint compared in sorted file order, since the Python walks rglob unsorted).
`flow doc proof|bundle|basic-bundle|geometry-bundle|kernel` and `flow know` call the flowc proof tools instead of tools/doc/*.py. The driver keeps the thin parts in bash: argument parsing, listing a directory in pathlib's sorted rglob order, and running pdflatex, xelatex or tectonic on the bundle. `flow doc kernel --plot x.png` writes the Graphviz DOT and renders the image with `dot` when it is installed; the Python rendered it with matplotlib. flowc now prints what the Python printed: the written paths for a file, the per-file listing and count for a directory, and paths joined the way pathlib prints them.
compiler/scripts/parity_proofs.sh runs flowc over every examples/verify file. Alone it checks accept/reject against the recorded Python list and program output against the recorded output. With --python <rev> it also runs the Python host from that revision and requires the same accept/reject, the same first diagnostic (line, or offending token when Python gives no line), the same program output, and byte-identical proof documents, figures, directory mode, bundles, kernels and `flow know`. Run against 9103c99: emit: python 898/1054, flowc 898/1054, 0 accept/reject mismatches diagnostics: 103 same line, 53 same token, 0 mismatches programs: 1 run on both hosts, 0 mismatches proof documents: 2342/2342 files byte-identical (examples/verify and lib/verify: .proof.md, .proof.tex, .proof.svg, .proof-diagram.tex) directory mode: 452/452, bundles: 3/3, kernels: 22/22, know: 2/2 The Stage-A `module` field in proof_doc.flow is renamed `modname`: the Python host treats `module` as a keyword, and it still builds Gen0. New tests: tests/lang/test_proof_erase.flow and tests/lang/test_proof_doc_render.flow.
flowc now covers everything these served, held byte-for-byte by compiler/scripts/parity_proofs.sh against the Python at 9103c99: - src/flow/proof_document.py, geometry_diagram.py, geometry_script.py, proof_kernel.py, know.py, claim_address.py, claim_path.py, math_prose.py, proof_substitution.py - tools/doc/flow_doc.py, tools/doc/flow_know.py - compiler/scripts/parity_know_index.py, parity_math_prose_expr.py, parity_proof_parse.py (Flow-vs-Python gates for the partial ports; parity_proofs.sh replaces them, and CI runs it instead) - the pytest files for those modules 6990 lines of Python go. The ratchet baseline is updated with ./scripts/python_ratchet.sh --update (it also drops files other changes already removed): limit 130042 -> 98005.
…ors as #1003 does roundtrip.sh builds the frontend module by module, so proof_lower.flow (called from cgen, jsgen and the typecheck) is compiled, given a header and linked into flowc_frontend.o and flowc_jsgen_fmt.o. driver.flow keeps #1003's flowc_parser_report where #1001 and #1003 both changed the same line; the roundtrip's keyword_param check (from
stage_a_self_emit.sh and stage_a_self_emit_g2.sh build the frontend module by module like roundtrip.sh, so they emit proof_lower.flow, give cgen and the typecheck its header, link it into the frontend objects, and include it in the self/g2 fixed-point comparison. roundtrip.sh passes end to end.
With the dynamics, flow-block, shader, package, effects and proof modules compiler/src/main.flow bundles more than 32 modules and more than 1 MiB of C. Raise FLOWC_RESOLVE_MAX_MODS to 64 and the emit output buffer in main.flow and driver.flow to 4 MiB, the size the C host driver already uses.
The proof layer puts geometry and kernel evaluation (sin, cos, pow, sqrt) into flowc. macOS links libm implicitly and Linux does not, so every CI job that built compiler/bootstrap/flowc_stage_a.c failed to link. Add -lm to each place that compiles it: the bootstrap and ensure scripts, the tool builder, flow-driver, the packager, the parity gates, parse coverage, the Python ratchet and the two Python bridges.
flowc_gen1..3 and the Stage-A driver links now carry the proof layer's math calls; Linux needs -lm for them.
gs_bool takes a bool, and string results of getenv and strstr are compared with null through ptr<u8>. The Python checker rejected both, so tier-2 failed to transpile tests/lang/test_proof_doc_render.flow.
With the proof layer in the compiler bundle each roundtrip step takes about 36s on the runner, and the run passed the 30 minute timeout at the FLOWC_TYPECHECK fixtures.
…receivers, declare &[T] spans (#1006, #1007) - typecheck: the Python checker's BUILTIN_FUNCTIONS table (printf, strlen, sqrt, malloc and the rest) is known without an extern block. - typecheck: an explicit instantiation f<T>(args) is not held to the template's T-typed parameters; an implicit generic call still reports no matching overload, as the Python checker does. - cgen: recv.method(args) on a by-value struct passes &recv when the first parameter is ptr<ThatStruct>, as _gen_method_call does. - cgen: &[T] / &mut [T] parameters declare their flowc_span_T typedef, and an array argument converts to the parameter's span type. - cgen: a capturing lambda takes its environment pointer first, matching the closure's fn(&env, ...) call. The eight flowc-side lines leave compiler/parity_lowering/divergent.txt.
typecheck.flow gains the units-of-measure pass from src/flow/type_checker.py: unit registration (base and derived, duplicate and unknown-factor errors), dimension composition through * and /, the + - % and comparison rules, the operator rule for logical, bitwise and shift, casts into and out of units, the dimensionless-or-Radian rule for sin and friends, and the unit branch of coercion at let, assignment, return, call arguments, struct literals, consts and module statics. Messages match the Python checker word for word, including the line of the operator, so binary-operator nodes now span their operator token. Unknown types never report, so a gap can only accept what Python rejects. All 31 cases of tests/unit/test_units.py and 12 more give the same errors on both checkers. compiler/parity_lowering gains seven negative unit fixtures and a runtime test, with goldens from the Python host; a Python type error's golden is its first ✗ line.
compiler/parse_coverage/python_rejects.txt now files each entry under its reason: negative fixtures, source for a pre-parse DSL expansion, Flow-only \x escapes, docs/vision sketches, and the flow-verify proof corpus. None is a broken program. Two files were broken and now parse on both parsers: - scripts/tools/wasm_crossings/main.flow named a local `module`, a keyword in the Python lexer. - tests/runtime/wip/test_short_circuit.flow used block expressions; it now counts evaluations through a pointer and passes on both hosts. 23 tracked files the Python parser rejects were missing from the list (fixtures added since, and tools/repl); they are listed and classified.
The bundle typecheck seeded an import's functions and consts but not the C functions its extern block declares, so lib/stdlib/ui2d.flow (SDL_Init from stdlib/sdl2.flow) and the Vulkan layout demos stopped at `unbound call`. They are now seeded, and flowc_cgen_collect_sigs records their return types so an importer's inferred `let` gets the C type. demos/vulkan_tetris_flow read `_ui_state[0].unit` through the untyped layout pointer, which neither host can compile; it now calls ui_layout_unit(_ui_state) like the examples/demos copy. The 11 lines left in compiler/parity_lowering/divergent.txt are Python host import failures; flowc builds all 11.
…ness tools/lsp/main.flow speaks JSON-RPC over stdio and takes diagnostics from the flowc parser and Stage-A checker in process. ./flow lsp builds and runs it. tests/tools/lsp/run.sh drives it with recorded sessions; the *.python files are the Python server's answers to the same sessions.
Formatting takes fmt.flow's output only when it keeps every token and comment, and otherwise re-indents. The idiom check counts writes by token, so assignments inside brace-skipped blocks count.
src/flow/lsp_server.py, lsp_intel.py, lsp_syntax.py, lsp_dynamics.py and lsp_ordering.py are replaced by tools/lsp. The behavioral checks of scripts/test_lsp_server.py, tests/unit/test_lsp_*.py and the re-export index test now live in the transcript sessions under tests/tools/lsp. Python ratchet tightened.
tests/tools/run.sh now runs the language server sessions too, so the native-tools CI job (Python stubbed out) covers flow lsp.
With #999 on main, flowc expands dyn. blocks, so the server indexes dynamics files the way it compiles them.
Restore the text that said sort and find pick a plan by cost and that flow explain prints the record, and point it at compiler/src/sort_plans.flow and compiler/src/sort_sites.flow instead of the deleted Python modules. multi-implementation.md now says plainly that require / prefer and the matmul / reduce cost models are not wired into any lowering, which was also true of the Python host.
# Conflicts: # compiler/src/cgen.flow
…, #954) A source expansion, run after the impl expansion on every compile path, parses a module that declares a generic struct and rewrites Box { value: 1.5 } as Box<f64> { value: 1.5 }. The type arguments come from the annotation of the let the literal initialises, else from the values of the fields typed by a bare type parameter: literals, casts, plain struct literals, calls to module functions, and names declared earlier in the function. A literal it cannot fully infer is left alone. An unannotated let now takes the specialized type of a generic struct literal (Box_f64 c = (Box_f64){ ... }) and the substituted return type of an explicit generic call (double y = identity_f64(3.14)), so the docs/tutorials/intermediate.md generics examples build. The Python host typed every bare literal as Box<i32>.
# Conflicts: # compiler/src/cgen.flow
… the if (#1054) The parser nests each elif in a block it makes for it. The provenance walk skipped every block, so an elif condition saw no ordering facts. The Python host evaluated it with the facts known before the if. The golden is the Python host's --explain text.
This was referenced Sep 29, 2026
…handle block (#1056) Inside handle E with C { ... } the handler is known at compile time, so an operation written lexically in the block emits C_op(args) instead of the vtable dispatch E_op(args), as the Python host did. The innermost block wins; lambda bodies and functions called from the block keep the runtime dispatch. Also stop treating an effect or capability name as a lambda capture (#1057): the closure env held .Log = Log and the C did not build.
Regenerated with bootstrap_from_c.sh --regen. bootstrap_from_c.sh --verify and self_host_full.sh pass.
parser, typecheck and cgen now import attributes.flow, and cgen imports sort_plans.flow and sort_sites.flow (with ordering_hints.flow). The per-module roundtrip, both self-emit generations and the C host header compile and link them.
The C host changes move the MLIR of 17 corpus programs that import compiler modules. Rerecorded with --write-golden 84806b0: 834 programs.
Contributor
Author
|
Merge train: #1058 (selfhost/restore-c-features) is merged into this branch, then origin/main (#1025, #1041). Bootstrap C regenerated with bootstrap_from_c.sh --regen (fixed point at gen2). Local results: bootstrap_from_c --verify, self_host_full, roundtrip.sh, tests/cgen/run.sh (99/0), ./flow test-lang (216 passed), parity_lowering, parity_effects, parity_proofs, parity_mlir (corpus rerecorded, 834 programs), parity_field_dsl, parity_dynamics_dsl, parity_flow_blocks, parse_coverage --check, fmt_check --check and corpus_parity --check all pass. parity_shader_dsl passes except its Metal step, which needs a Metal toolchain this Mac lacks. |
- link libm for the Stage-A C host driver builds (the sort-plan code in the frontend calls log2 and sqrt) - drop an unused import from src/flow/package.py (ruff) - cli:transpile maps to the command reference, which still mentions it - rerecord the LSP repo_files transcript: a comment in tests/lang/test_generics.flow got two lines shorter - skip tests/cgen/ in the flow test sweep; its goldens include rejected programs and tests/cgen/run.sh checks them
godofecht
added a commit
that referenced
this pull request
Sep 29, 2026
The flowc MLIR emitter covers spans, list patterns, array<T>(n), repeat and memref literals, folded consts, lambdas and closures, functions as values, algebraic effects, C varargs externs, overloads, method calls, forward declarations, package imports, @gpu kernels and mode guards (with a GPU dialect module under FLOWC_MLIR_GPU=1), record update Name { ..base, f: v }, type aliases and units. Rebased onto main after #1027; bootstrap C regenerated with bootstrap_from_c.sh --regen; parity_mlir corpus rerecorded (18 fixtures, 1040 programs); parse coverage floor 2480. Every gate passes locally.
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.
Builds on #1025 (selfhost/corpus-parity-2), which is still open; this branch contains it. Merge #1025 first; the diff then shrinks to the 15 commits from 05cae22 on.
flowc is now the only C compiler. The Python C backend is deleted, every caller is switched to flowc, and the bootstrap C regenerates without Python.
Deleted Python
Plus 31 pytest files that only tested the Python C output. Ratchet: 310 files and 79712 lines on main, now 278 files and 67005 lines (12707 lines out).
Callers switched
compiler/scripts/flowc_emit.sh IN.flow OUT.cis the one Flow-to-C command for scripts and tools (defaults offlow compile;--strict,--no-checks).compiler/scripts/flowc_host.shprints a flowc built from the current compiler/src by the bootstrap binary.FLOW_HOST=pythonstops with a pointer to flowc;autois flowc.python3 -m flow.transpiler --cexits 2 with the same pointer. The MLIR path and--pythonstay.--python REVruns the Python host of an old revision.flow pythontakes its C from flowc.tests/cgen/run.shruns in the no-Python job.Regeneration without Python
bootstrap_from_c.sh --regenself-emits from the previous bootstrap until two generations emit the same C, then rewrites flowc_stage_a.c and the checked-in binary. AGENTS.md documents it, with the by-hand steps. This PR's bootstrap was regenerated that way (fixed point at gen2).flowc changes (compiler/src)
FLOWC_DEBUG_INFO=1writes#line N "file"before every statement (per module in a bundle), soflow debugkeeps source-level breakpoints. Checked with lldb: a breakpoint on fibonacci.flow:11 stops at fibonacci.flow:11.allocais renamed for the unit, with the libc macro undefined first.Tests
Class-b tests (assertions on the Python backend's C): 64 goldens in tests/cgen (
.flow+.expect, checked bytests/cgen/run.sh) and 2 new tests/lang programs where the assertion still describes the language. Tests of Python backend internals, sort plan internals and the deleted plan selector are removed. The commit messages list what happened per file.Gates
Lost or changed
flow explainand sort plan selection: flowc lowers every|> sortto a stable insertion sort. The ordering benchmark drops its plan report.--exportaliases (flow_export_<name>) and--librarymode for wasm/FFI: flowc emits plain names.#pragma ompforparallel for, vectorize pragmas,@inline/@noinlineattributes, direct handler calls insidehandleblocks.flowc gaps found while converting tests (not fixed here)
Variadic extern prototypes lose
...; an exhaustive match emits its last arm aselse if; bare generic literalBox { .. }typedBox<i32>; user functions namedfindorbsearchhit builtins; lambdas passed to afn(f32) -> f32parameter across modules arrive as bare pointers; overloaded imports call the unmangled name; chained assignmenta = b = 1does not parse; stringlenand string==; block-lambda locals treated as captures;import concurrent(bare stdlib name);import M as name;@onlyguards keep every guarded function.What Python remains
The MLIR generator (
--backend=mlirfalls back to it when the Flow emitter refuses),flow check,flow pythonwheel generation, package publish/build, the wcet and misra scanners, the fir tools, the DAP server, the project test runner,compiler/scripts/flowc_c_to_hdr.py(roundtrip headers), and scripts not yet ported. The Python parser, type checker and monomorphizer stay for those.