Skip to content

selfhost: the flow command is a Flow program (tools/flow_cli) - #1095

Merged
godofecht merged 16 commits into
mainfrom
selfhost/native-cli
Oct 1, 2026
Merged

godofecht merged 16 commits into
mainfrom
selfhost/native-cli

Conversation

@godofecht

@godofecht godofecht commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Part of #695 (Self-Hosting Phase 5): the native driver executable. The flow command is now a Flow program.

What changed

Parity

tests/cli/run.sh runs 149 invocations: every subcommand with a representative input, plus the error paths (unknown command, missing file, bad flags). For each it compares stdout, stderr, the exit code and the files written against goldens recorded from the bash driver, one set per OS.

  • macOS: 149 of 149 match.
  • Linux (Ubuntu 24.04, clang 18, 2-core VPS): goldens recorded there from the bash driver. The Flow CLI matched 148 of 149. The one miss was a random clang temp object name in a linker warning, which the normalisation now rewrites.
  • ./flow test --tier2 --strict over 861 files printed byte for byte what the bash driver printed. ./flow test-lang gave the same results with both drivers.
  • Intended differences: bash printed its own job-control noise when a child died from a signal (line 3048: PID Abort trap: 6). The CLI does not. The compiler sweep now skips tests/cli/, whose fixtures include a file that does not parse, on purpose.

Gates run on this branch (macOS, rebased on main)

All pass: bootstrap_from_c.sh --verify, self_host_full.sh, roundtrip.sh, parse_coverage.sh --check, fmt_check.sh --check, tests/cgen (107), test-lang (239), test-scripts, corpus_parity.sh --check, parity_typecheck.sh --check, typecheck_rules.sh, parity_lowering/field_dsl/dynamics_dsl/flow_blocks/effects/proofs/mlir/dap/project_test, tests/mlir_commands (72), check_run_without_python.sh (31, sqlite and app_cache included), tests/tools, tests/check, pywheel, fir, flow_run, gpu, check_pkg_commands, check_bench_publish, makefile contract, doc coverage, sync_version, python ratchet, tier 2 strict (870), tests/cli (149).

parity_shader_dsl fails only at its xcrun metal step (no Metal Toolchain on this machine), the step excepted. parity_project_test's config_cli_timeout case once hit its 2.5 s compile limit while every gate ran at once. It passed 32 of 32 when run alone.

On Linux, test-lang has two failures with either driver: test_dlopen opens libm.dylib, and test_c_import_dirs exits 3. These are existing test issues and are unrelated to the CLI.

What stays shell

  • ./flow: it has to build the Flow CLI before any Flow program can run.
  • flow-lsp: a 15-line launcher for editors that need a dedicated executable.
  • The scripts the driver already called (compiler/scripts/*.sh, scripts/wasm_build.sh, scripts/bpf_target.sh and the rest). Most are thin shims over Flow tools, and CI and other gates call them directly.
  • flowc runs as a subprocess. flowc takes its settings from FLOWC_* variables and exits when it is done, and linking it into the CLI would mean building the whole compiler twice on first use.

tests/cli/run.sh runs 121 invocations of ./flow (every subcommand with a
representative input, plus the error paths) and compares stdout, stderr,
the exit code and the files written against tests/cli/goldens. The goldens
record the bash driver, so they are the parity gate for a Flow CLI.
./flow is now a POSIX sh stub that builds tools/flow_cli from the checked-in
bootstrap C with cc on first use (cached in build/cli, or the user cache
dir for a read-only install) and execs it. The CLI ports every subcommand,
flag and environment variable of flow-driver: argument parsing, dispatch,
the flowc and tool builds, C flags and sanitizers, the runtime archive, the
C and MLIR link steps, the test tiers, packages, docs and proofs. External
programs run through std.process with argument vectors.

tests/cli/run.sh: 121 of 121 goldens match the bash driver.
sync_version mirrors the version strings in tools/flow_cli/help.flow and
doc_coverage reads the command table from tools/flow_cli/main.flow (help
and know are now listed and documented). The scripts that ran flow-driver
directly run ./flow. The Homebrew formula builds the CLI at install time
and still accepts a release tarball that ships flow-driver.

tests/cli: 149 of 149 goldens match the bash driver, including the MLIR
pipeline, jit, proofs, shaders, the recorder, the REPL, packages and the
GPU and interop test tiers.
The bash driver (4,311 lines) is gone: the stub and tools/flow_cli cover
every command, with 149 of 149 goldens matching it. The goldens move to
tests/cli/goldens/darwin, since clang, ld and the tools on PATH print
differently per OS.
tests/cli/fixtures/bad_syntax.flow does not parse on purpose; tests/cli/run.sh
checks the fixtures. The tier-2 sweep output of the Flow CLI was byte for
byte the bash driver's over 861 files before this change.
native-tools runs tests/cli/run.sh. tests/cli/goldens/linux was recorded
on Ubuntu 24.04 (clang 18) from the bash driver; the Flow CLI matched 148
of 149 there, the miss being a random clang temp object name in a linker
warning, which the normalisation now rewrites. flow-driver leaves the
paths filters and chmod lines.
…-driver

flowc_link_c asks the package manager (native-link) for the objects and
flags of the project's and installed packages' [native] sources when a
flow.toml declares [native], and links them ahead of the runtime archive.
check_run_without_python.sh: 31 of 31, including sqlite_demo and
app_cache.
…added to flow-driver

#1093 changed flow-driver's flow_link_mlir_ll to link the .mlir.c the MLIR
emitter writes for @cembed blocks. flow-driver is deleted here, so the
Flow CLI's flow_link_mlir_ll takes the same optional file. pkg_main.flow's
comments name the flow command in place of flow-driver.
The emitter writes a newline in an MLIR string constant as \0A since
#1093. mlir_hello and mlir_run_hello were recorded before it.
…n load

Nine programs time out or exit differently from run to run: concurrency
examples and nbody under seven parallel jobs with a 10s limit, and three
whose Python golden run timed out. They moved the count across the floor
(1031 to 1038 on one tree). compiler/corpus_parity/timing.txt lists them
and corpus_parity.sh compares their build only, as nondet.txt already
does for stdout. The floor stays 1033; this tree scores 1038.
@godofecht
godofecht force-pushed the selfhost/native-cli branch from e223eeb to d98f298 Compare October 1, 2026 06:30
…d programs

#1098 changed test_c_import_dirs.flow, so its digest moves. The corpus
also gains the tests/cli fixtures and #1096's test.
The Linux goldens held exit codes and stderr from the bash driver but no
stdout, so every case failed on Linux with a missing golden. These were
recorded on ubuntu-latest with the native CLI. The same run found no
.code or .err that differs from the bash driver's recordings. The
temporary workflow that recorded them is removed here.
@godofecht
godofecht merged commit 2ff6a47 into main Oct 1, 2026
32 checks passed
godofecht added a commit that referenced this pull request Oct 1, 2026
flow-driver was deleted in #1095. The ./flow stub builds tools/flow_cli
from compiler/bootstrap, so tools/ is always installed beside it.
godofecht added a commit that referenced this pull request Oct 1, 2026
* cli, process: drop the #1078 and #1089 workarounds

Both bugs are fixed on main (#1082, #1102). Read SINK fields straight off
the module static, and spell the C strings in the sys.flow and
std.process shims as quoted literals instead of char arrays.

* packaging: drop flow-driver from the Homebrew formula

flow-driver was deleted in #1095. The ./flow stub builds tools/flow_cli
from compiler/bootstrap, so tools/ is always installed beside it.

* parity_typecheck: read logs as text with grep -a

Some frontend logs echo source bytes that are not valid UTF-8. GNU grep
then printed "binary file matches" on stderr 151 times per CI run and
left the message empty. The verdicts and the class table are unchanged.

* cli: keep the toolchain state in string statics

#1103 allows module-level strings (#1086), so the Toolchain struct
behind a pointer static and its tc() accessor (a #1078 workaround) go.

* parity_typecheck: keep the shell line count flat

The shell ratchet counts lines; the rationale for grep -a lives in the
previous commit message.
godofecht added a commit that referenced this pull request Oct 1, 2026
flow-driver was deleted in #1095. The ./flow stub builds tools/flow_cli
from compiler/bootstrap, so tools/ is always installed beside it.
@godofecht
godofecht deleted the selfhost/native-cli 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