Repository navigation
selfhost: lower the proof layer on flowc and retire the Python proof tools (#996) - #1013
Merged
Merged
Conversation
This was referenced Sep 29, 2026
godofecht
force-pushed
the
selfhost/lower-proofs
branch
from
September 29, 2026 08:27
2ef49a7 to
7ecd812
Compare
) 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.
godofecht
force-pushed
the
selfhost/lower-proofs
branch
from
September 29, 2026 09:07
436f672 to
b2bef8d
Compare
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.
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: the proof and verification constructs.
theorem,assume,thereforeand claim references now lower on flowc, and the proof tools that turn verification files into documents (flow doc proof|bundle|kernel,flow know) run on flowc too. The Python that served only this path is deleted.This branch merges #1001 (parse coverage, which added the parse-only kinds) and the current head of #1003 (which now carries #1002's plain punctuation). Review the commits from
f5c02343on.What the Python host did, and what flowc does now
The Python host has no proof checking. It treats the proof layer as metadata:
theoremdeclaration is dropped by the C generator;assume/thereforeinside an ordinary function become C comments;exportandimportlists are citations, never bindings, andimport verify.Nat/+resolves tolib/verify/Nat.flow.compiler/src/proof_lower.flowdoes the same on flowc. cgen, jsgen and the typecheck run it first; it unlinks the proof nodes and retags them, soflowc_ast_first_unsupportedno longer refuses kinds 80 to 83. The bundle resolver maps aDomain/opsegment to the domain module and accepts a module that emits no C.Proof documents were the other half.
compiler/src/proof_doc.flow,geometry_script.flowand the extendedgeometry_diagram.flowport proof_document.py, geometry_diagram.py, geometry_script.py, proof_kernel.py and know.py, including the claim tier index, the.geomdiagram language, the proof-book bundles and kernel JSON. The earlier partial Flow helpers in math_prose, claim_address and claim_path returned fixed strings for a few claims; they now follow the Python tables. The book's part lists move from Python constants totools/doc/proof_book.txt.examples/verify on flowc
flow compileruns it)The other 156 files do not parse under either host. Only
circuits/full_adder.flowhas amain(); it runs on flowc with the same output. There is noflow verifycommand;flow compileon a theorem-only file fails at link, as it does on the Python host.Parity gate
compiler/scripts/parity_proofs.sh. Alone it needs only cc: accept/reject against the recorded list, program output, and a report of how many checked-in documents match. With--python <rev>it runs the Python host from that revision. Against 9103c99:The six checked-in documents that differ are for full_adder, ring_buffer_fifo and matmul_vectorize, which the current Python also no longer reproduces. CI runs the gate in place of the three Flow-vs-Python parity scripts it replaces.
Python removed
6990 lines: 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 and flow_know.py; compiler/scripts/parity_know_index.py, parity_math_prose_expr.py and parity_proof_parse.py; and their pytest files. The ratchet baseline is 90530 lines (it was 130042 on this branch's base;
--updatealso dropped files other changes had already removed).Verification
bootstrap_from_c.sh --verify,self_host_full.sh,roundtrip.sh,selfcompile_audit.sh,parity_field_dsl.sh: pass. roundtrip and the self-emit gens now build and link proof_lower.parse_coverage.sh --check: pass, no regression.Notes for merging
flowc_parser_reportthere (roundtrip's keyword_param check expects it) and flowc: parse every .flow file the Python parser accepts (1002 -> 2082) #1001'sflowc_parser_print_errorin emit, parse-only and bundle modes (parse_coverage.sh reads it).flow doc kernel --plot x.pngnow writes Graphviz DOT and renders the image withdotwhen installed, where the Python used matplotlib.Follow-ups: #1010 (string
+with an indexed operand), #1011 (regenerate the six stale documents; the kernel plot change).