Skip to content

Port tools, wasm, benchmarks and challenges Python to Flow - #965

Merged
godofecht merged 10 commits into
mainfrom
port/tools-to-flow
Sep 27, 2026
Merged

godofecht merged 10 commits into
mainfrom
port/tools-to-flow

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Removes Python from tools/, scripts/tools/, wasm/, benchmarks/, tests/benchmarks/ and challenges/. 89 .py files deleted, 10 ported to Flow with parity checks, and the rest listed below with the reason each one stays. Every ported tool builds with the Stage-A compiler from the checked-in bootstrap C (scripts/tools/build_tool.sh), so building the tools needs only cc.

scripts/tools/build_tool.sh, lib/json.flow and lib/text.flow are byte-identical copies of the ones on port/doc-checkers-to-flow, so the two ports share one toolkit. This PR adds lib/regex.flow, lib/proc.flow and lib/bench.flow.

Ported (Python deleted in the same PR)

Was Now Parity evidence
challenges/flow-specific/check.py, test_check.py challenges/flow-specific/check.sh -> scripts/tools/challenge_check check.sh scan over all 2,227 tracked .flow files x 36 challenges: 80,172 verdicts byte-identical to check_patterns. list, --syntax-only pass and fail, unknown id, missing file, wrong suffix and directory argument: identical stdout, stderr and exit code. Full runs and --timeout 0: same lines and exit codes. check.sh self-test carries the three test_check.py cases plus 43 re.search verdicts recorded from CPython.
tools/grad/flow_grad_c.py, flow_grad_flow.py (and scripts/tools/grad/ copies) scripts/tools/grad/grad.sh {c,flow} 18 cases with identical stdout, stderr and exit code, covering every op, literal forms, inlining and the error paths. grad.sh flow regenerates lib/stdlib/nn_xor_loss_clean_grad.flow and nn_xor_loss_params_grad.flow byte for byte.
tools/size/measure_size.py scripts/tools/measure_size/measure_size.sh With FLOW_HOST=python (the host the Python tool hardcoded), stdout and the --out report are byte-identical.
wasm/flow_wasm_threads.py, flow_wasm_sockets.py, flow_wasm_python.py, flow_wasm_fs.py, flow_wasm_crossings.py wasm/crossings.sh -> scripts/tools/wasm_crossings; page text in wasm/crossing_assets/pages/*.html --no-build: every page and asset byte-identical, stdout identical. Full emcc builds of all four crossings plus a single-program fs --fs idbfs --preload build: every .js, .wasm and .data identical (fs_preload.js embeds its own output path; identical once normalised), and the echoed emcc command lines identical. ./flow wasm --threads and --fs now go through it.
benchmarks/baselines/run_baselines.py benchmarks/baselines/run_baselines.sh -> scripts/tools/bench_baselines Run back to back: stdout, baseline_results.md and .json identical with timing values masked; metadata and results match exactly. The float repr and .2f/.4f/.6f formatting agree with CPython on 5,021 values.
benchmarks/run_publish.py benchmarks/run_publish.sh -> scripts/tools/bench_publish --reps 1 and --quick: stdout and RESULTS.md identical with timings masked, environment block and result values included.

The page and docs follow-up commit regenerates the five affected site/wasm-crossings pages with the new builder names. ./flow know and ./flow doc were pointing at tools/flow_*.py paths that did not exist; they now point at tools/doc/.

Deleted without a port

File(s) Why
scripts/tools/audio/plot_lattice_allpass.py, lattice_allpass_audio_demo.py, srir_viewer.py Duplicates of tools/audio/. The scripts/tools copies computed the repo root as scripts/, so they were broken.
scripts/tools/doc/flow_doc.py, flow_know.py Same: duplicates of tools/doc/ with a broken root.
tools/ and scripts/tools/backlog_sorter/ (15 .py each, plus generated reports) Keyword-voting ROADMAP sorters ("godmode", "ludicrous", "philosophical" agents). Nothing outside the directory referenced them; the backlog now lives in GitHub issues and Helm.
tools/ and scripts/tools/euclid/generate_euclid_book_{i..vi}.py One-shot generators for examples/verify/euclid/. Book I has been hand-edited since, so a rerun destroys content. The TOC generator: keys pointed at paths that did not exist; removed.
tools/ and scripts/tools/jit/flow_jit_pipeline.py, flow_jit_opt.py, simd/simd_check.py Superseded by ./flow jit. simd_check's default input tests/test_simd_saxpy.flow no longer exists. Only a CHANGELOG line mentioned them.
tools/ and scripts/tools/debug/flow_debug.py Superseded by ./flow debug (covered by tests/unit/test_debug_info.py).
tools/audio/srir_viewer.py pygame viewer referenced only from docs/project/archive/.
wasm/demo_wasm_build.py Every input it builds (examples/fibonacci.flow etc.) is gone.
wasm/wasm_build_system.py Batch driver for the legacy converter, superseded by scripts/build_wasm_gallery.py; referenced only by a README tree.
wasm/flow_wasm.py Superseded by ./flow wasm; demos/index.html and docs/language/wasm.md updated.
benchmarks/benchmark_aosoa.py Hardcoded /app/build/aosoa sandbox path; unreferenced.
benchmarks/benchmark_gemm_cutlass_evaluation.py numpy-only estimate that never touches Flow; its output stays in cutlass_benchmark_results.txt.
tests/benchmarks/publish/python/*, suite/python/*, standardized/record/record_numpy.py Byte-identical copies of the benchmarks/ baselines. tests/benchmarks/suite/run_benchmarks.sh now points at the benchmarks/ copies.
tests/benchmarks/run_benchmarks.py, run_publish.py, run_publish.sh An empty file and an older copy of the publish harness (plus its wrapper).

Stays in Python, and why

File(s) Reason
benchmarks/suite/python/*, benchmarks/publish/python/*, benchmarks/cross_harness/**/*.py, benchmarks/standardized/record/record_numpy.py These are the Python side of cross-language benchmarks. They exist to measure CPython.
benchmarks/run_benchmarks.py tests/unit/test_benchmarks.py imports it (tests/unit is out of scope here).
benchmarks/cross_harness/compiler/fusion_benchmark.py, micro/shape_specialization_benchmark.py, micro/transform_tuning_benchmark.py, mlir_pipelining/benchmark.py, gpu/gpu_microbenchmark.py, crossover/calibrate.py, crossover/test_crossover.py Each drives src/flow internals in process (MLIRJIT, MLIROptimizer, cost_model, gpu_runtime, flow.run). They move when those modules do.
wasm/flow_wasm_gpu.py, wasm/crossing_common.py The WGSL comes from src/flow's WgslCodegen and ModuleResolver, called in process. crossing_common.py now serves only this script.
wasm/flow_to_wasm.py, wasm/flow_webgpu_shader.py ./flow wasm --legacy and the vgpu WGSL preview; both are thin fronts over src/flow's C and WGSL generators.
tools/doc/flow_doc.py, flow_know.py ./flow doc and ./flow know; thin CLIs over src/flow/know.py, proof_document.py and proof_kernel.py.
tools/audio/plot_lattice_allpass.py, lattice_allpass_audio_demo.py matplotlib and numpy plotting for the Schur lattice paper figures.
tools/discord-welcome/*.py The bot is built on discord.py's gateway client; Flow has no websocket or HTTP client.

Note that the ported WASM, baseline and publish tools still call python3 -m flow.transpiler to turn Flow into C, as the originals did. That is the src/flow migration's lane.

Issues opened

Also hit while porting, already filed: #958 (extern prototypes clash with libc headers: realpath, strtoll) and #957 (string + string as pointer addition).

Not done

  • docs/language/mathlib-equivalence-toc.md still names the retired Euclid generators as plans. Every edit to that file has to clear 38 existing dash tells first, so it is left for a docs pass.
  • docs/library/stdlib-api.md is generated; its nn_autogen line updates on the next gen_stdlib_docs.py run (the source comment is updated here).
  • scripts/wasm/ holds older copies of the removed wasm helpers; it was outside this PR's scope.

build_tool.sh, lib/json.flow and lib/text.flow, byte-identical to the
copies on port/doc-checkers-to-flow so the two ports share one toolkit.
scripts/tools/ held stale copies of several tools/ scripts whose
parents[2] root lookup broke in the move, so the working tools/ copy is
kept and the scripts/tools/ duplicate goes:
  scripts/tools/audio (plot_lattice_allpass, lattice_allpass_audio_demo)
  scripts/tools/doc (flow_doc, flow_know)

Retired outright, with nothing outside their own directory using them:
  tools/ and scripts/tools/backlog_sorter: keyword-voting ROADMAP
    sorters and their generated reports.
  tools/ and scripts/tools/euclid: one-shot generators for
    examples/verify/euclid. Book I has been hand-edited since, so a
    rerun would destroy content. The TOC generator keys pointed at
    paths that no longer existed.
  tools/ and scripts/tools/jit, simd: superseded by ./flow jit;
    simd_check's default input tests/test_simd_saxpy.flow is gone.
  tools/ and scripts/tools/debug: superseded by ./flow debug.
  tools/audio/srir_viewer.py: pygame viewer, referenced only from an
    archived structure doc.
  wasm/demo_wasm_build.py: every input it builds is gone.
  wasm/wasm_build_system.py: batch driver for the legacy converter,
    superseded by scripts/build_wasm_gallery.py.
  wasm/flow_wasm.py: superseded by ./flow wasm.
  benchmarks/benchmark_aosoa.py: hardcoded /app/build sandbox path.
  benchmarks/benchmark_gemm_cutlass_evaluation.py: numpy-only estimate,
    its output stays in cutlass_benchmark_results.txt.
  tests/benchmarks/*.py: byte-identical copies of the benchmarks/
    baselines, an empty run_benchmarks.py and an older run_publish.py.

Also fixes ./flow know and ./flow doc, which pointed at tools/flow_*.py
paths that did not exist, and clears the dash tells in the docs touched.
challenges/flow-specific/check.sh builds scripts/tools/challenge_check
with the Stage-A compiler and runs it. It replaces check.py and
test_check.py.

The catalog rules are Python regular expressions, so this adds
scripts/tools/lib/regex.flow: a backtracking matcher over code points
for the subset the catalog uses (classes, \s \w \d \b, groups,
alternation, greedy and lazy bounded repeats, MULTILINE and DOTALL).
The submission is run with fork/execvp and a polled waitpid timeout.

Parity with the Python checker:
- check.sh scan over all 2,227 tracked .flow files x 36 challenges:
  80,172 verdicts, byte-identical to check.py's check_patterns.
- list, --syntax-only passes and failures, unknown id, missing file,
  wrong suffix, directory argument: identical stdout, stderr and exit
  code (program name aside).
- Full runs and --timeout 0: same lines and exit codes. Output order
  follows program order, as check.py does on a terminal.
- check.sh self-test carries the three test_check.py cases and 43
  re.search verdicts recorded from CPython.
scripts/tools/grad/main.flow replaces flow_grad_c.py and
flow_grad_flow.py (both the tools/ and scripts/tools/ copies). The
Python versions leaned on src/flow's parser; the port carries its own
lexer and precedence-climbing parser for the subset they accept.

  scripts/tools/grad/grad.sh c    <file.flow> <function>
  scripts/tools/grad/grad.sh flow <file.flow> <function>

Parity: 18 cases, identical stdout, stderr and exit code against the
Python generators, covering every op, literal forms (2.0, 3.0e1, 1e-3),
double negation, unused parameters, inlined multi-argument helpers, and
the error paths (non-f32 literal, unknown call in C mode, missing
function). grad.sh flow regenerates lib/stdlib/nn_xor_loss_clean_grad.flow
and nn_xor_loss_params_grad.flow byte for byte.

scripts/tools/grad/demo.flow replaces the examples/grad_tool_demo.flow
input the autodiff doc named but which no longer existed.
scripts/tools/measure_size/measure_size.sh replaces tools/size/measure_size.py.
The Flow program runs ./flow compile, size(1) and strip itself through
system() and popen(), and formats the same Markdown table.

Parity: with FLOW_HOST=python (the host the Python tool hardcoded), stdout
and the --out report are byte-identical to measure_size.py for the three
default programs. The port takes the host from FLOW_HOST and defaults to
flowc, the ./flow default.
wasm/crossings.sh runs scripts/tools/wasm_crossings, which replaces
flow_wasm_threads.py, flow_wasm_sockets.py, flow_wasm_python.py,
flow_wasm_fs.py and flow_wasm_crossings.py. ./flow wasm --threads and
--fs now call it.

The page f-strings moved to wasm/crossing_assets/pages/*.html with
@@field@@ slots, extracted mechanically from the Python sources.
scripts/tools/lib/proc.flow adds shell quoting, command capture and
Path.resolve() for the tools.

The GPU crossing (flow_wasm_gpu.py) and crossing_common.py stay: the
WGSL comes from src/flow's WgslCodegen and ModuleResolver, called in
process. Flow sources still reach C through python3 -m flow.transpiler,
the compiler these pages were built with.

Parity against the Python builders:
- --no-build for threads, sockets, python, fs and the index: every page
  and asset byte-identical, stdout identical.
- Full emcc builds of all four crossings plus a single-program
  fs --fs idbfs --preload build: every .js, .wasm and .data identical
  (fs_preload.js embeds its own output path; identical once that is
  normalised), and the echoed emcc command lines identical.
- ./flow wasm fs_counter.flow --fs idbfs and ./flow wasm
  parallel_sum.flow --threads both build through the port.
Replaces every mention of the retired flow_wasm_*.py builders and
regenerates the five affected site/wasm-crossings pages with
wasm/crossings.sh --no-build. The page diffs are the builder names only.
Also clears the dash and contrast tells in wasm-crossings.md.
benchmarks/baselines/run_baselines.sh runs scripts/tools/bench_baselines,
which replaces run_baselines.py. scripts/tools/lib/bench.flow adds wall
timing (clock_gettime), a fork/execvp runner that times from spawn to
reap like subprocess.run, median/min/max, and Python's float repr for the
JSON output.

Parity: run back to back with run_baselines.py, stdout,
baseline_results.md and baseline_results.json are identical once timing
values are masked; metadata and every result value match exactly.
bn_py_repr and the .2f/.4f/.6f formats agree with CPython on 5,021
values, edge cases included (5e-324, 1e16, 1.7976931348623157e308).
The committed result files are left as they were.
benchmarks/run_publish.sh now runs scripts/tools/bench_publish, which
replaces run_publish.py: compile each benchmark in C, Flow, Rust and
Python, run a warmup plus N timed repetitions, check the results agree,
and write benchmarks/RESULTS.md (or print one line per run with --quick).
The two hand-written notes sections of the report live in
scripts/tools/bench_publish/notes.md, extracted verbatim.

Parity, run back to back on the same machine with --reps 1 and with
--quick: stdout and RESULTS.md are identical to run_publish.py once the
timing values are masked, including the environment block, every result
value and the agreement check.

On macOS both harnesses stop at the first clang call, because the
publish C sources define _POSIX_C_SOURCE and so hide
clock_gettime_nsec_np. The parity runs used a clang wrapper adding
-D_DARWIN_C_SOURCE for both; the sources are left as they were and the
bug is filed separately.
@godofecht
godofecht merged commit d0a6a92 into main Sep 27, 2026
28 checks passed
godofecht added a commit that referenced this pull request Sep 29, 2026
Adds the scripts and tools ported to Flow in #959, #965 and #981, notes
that flow run needs no Python since #960, and lists open pull requests
as in progress. The LSP is Python and the only server; the Flow REPL is
in open PR #987.
godofecht added a commit that referenced this pull request Sep 29, 2026
The README names the flow-lsp launcher, since there is no flow lsp
subcommand. Reproducible-build docs point at the test that exists. The
mathlib TOC drops the Euclid generators removed in #965, and the tests
inventory drops a Python test that tests/lang now covers.
godofecht added a commit that referenced this pull request Sep 29, 2026
Adds the scripts and tools ported to Flow in #959, #965 and #981, notes
that flow run needs no Python since #960, and lists open pull requests
as in progress. The LSP is Python and the only server; the Flow REPL is
in open PR #987.
godofecht added a commit that referenced this pull request Sep 29, 2026
The README names the flow-lsp launcher, since there is no flow lsp
subcommand. Reproducible-build docs point at the test that exists. The
mathlib TOC drops the Euclid generators removed in #965, and the tests
inventory drops a Python test that tests/lang now covers.
@godofecht
godofecht deleted the port/tools-to-flow 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