Skip to content

selfhost: lower the proof layer on flowc and retire the Python proof tools (#996) - #1013

Merged
godofecht merged 16 commits into
mainfrom
selfhost/lower-proofs
Sep 29, 2026
Merged

godofecht merged 16 commits into
mainfrom
selfhost/lower-proofs

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Part of #996: the proof and verification constructs. theorem, assume, therefore and 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 f5c02343 on.

What the Python host did, and what flowc does now

The Python host has no proof checking. It treats the proof layer as metadata:

  • a theorem declaration is dropped by the C generator;
  • assume / therefore inside an ordinary function become C comments;
  • claim names in export and import lists are citations, never bindings, and import verify.Nat/+ resolves to lib/verify/Nat.flow.

compiler/src/proof_lower.flow does the same on flowc. cgen, jsgen and the typecheck run it first; it unlinks the proof nodes and retags them, so flowc_ast_first_unsupported no longer refuses kinds 80 to 83. The bundle resolver maps a Domain/op segment 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.flow and the extended geometry_diagram.flow port proof_document.py, geometry_diagram.py, geometry_script.py, proof_kernel.py and know.py, including the claim tier index, the .geom diagram 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 to tools/doc/proof_book.txt.

examples/verify on flowc

before after
emit (as flow compile runs it) 0 / 1054 898 / 1054
Python host 898 / 1054 898 / 1054

The other 156 files do not parse under either host. Only circuits/full_adder.flow has a main(); it runs on flowc with the same output. There is no flow verify command; flow compile on 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:

emit: flowc accepts 898/1054; accept/reject mismatches vs recorded list: 0
run: 1 program(s), mismatches: 0
docs: 2102/2108 match the checked-in .proof.md/.proof.tex (report only)
live python@9103c996: python accepts 898/1054, flowc 898/1054; accept/reject mismatches: 0
live diagnostics: same line 103, same token 53, mismatches 0
live programs: 1 run on both hosts, mismatches: 0
live proof documents: 2342/2342 files byte-identical
live directory mode: 452/452 files byte-identical
live bundles: 3/3 files byte-identical
live kernels: 22/22 files byte-identical
live flow know: 2/2 files byte-identical
parity_proofs: PASS

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; --update also dropped files other changes had already removed).

Verification

  • Bootstrap C regenerated last from the Python host emit, in its own commit; fixed point holds.
  • 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.
  • Bootstrap suite (tests/lang): 148 pass, 12 fail. The merge base without this lowering gives 147 and 13; the extra pass is the new test_proof_erase, and the 12 failing files are the same in both.
  • New Flow tests: tests/lang/test_proof_erase.flow, tests/lang/test_proof_doc_render.flow.

Notes for merging

Follow-ups: #1010 (string + with an indexed operand), #1011 (regenerate the six stale documents; the kernel plot change).

)

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
godofecht force-pushed the selfhost/lower-proofs branch from 436f672 to b2bef8d Compare September 29, 2026 09:07
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.
@godofecht
godofecht merged commit ca7975a into main Sep 29, 2026
30 checks passed
@godofecht
godofecht deleted the selfhost/lower-proofs branch October 1, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant