Skip to content

Retire the Python REPL and test_runner; keep the LSP with evidence - #987

Merged
godofecht merged 7 commits into
mainfrom
port/retire-python-host-tools
Sep 29, 2026
Merged

godofecht merged 7 commits into
mainfrom
port/retire-python-host-tools

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

What this does

Checks the claim that native Flow paths cover the LSP, the REPL and project tests, then retires the Python modules where that is now true.

Module Before After
src/flow/test_runner.py (237 lines) No callers anywhere Deleted
src/flow/repl.py (369 lines) flow repl ran it Deleted. flow repl runs tools/repl/main.flow
src/flow/lsp_server.py (2,284 lines) Only implementation Kept. See below

REPL

tools/repl/main.flow is the REPL written in Flow, with shared string, buffer, file and process helpers in tools/hostlib/text.flow. flow-driver builds it with the Stage-A driver on first use (flow_native_tool), caches the binary in build/tools (or ~/.cache/flow/tools on a read-only install), and rebuilds when a Flow source it can import is newer.

Each line is wrapped in a program with the session's structs, functions and variables, compiled with flowc and cc, and run under a five second alarm, the same model as before.

Transcript evidence: tests/tools/repl/session.in (30 lines: help, let, float and int expressions, one-line and multi-line functions, struct, :vars, :funcs, :type, unknown command, redefinition, :clear, missing initializer, :quit) produces byte-identical output from python3 -m flow.repl and the Flow REPL:

$ python3 -c "...from flow.repl import main; main()" < session.in > py.out
$ ./flow repl < session.in > native.out
$ diff py.out native.out && echo IDENTICAL
IDENTICAL

A second session with compile errors differs only in the C line numbers inside the cc error text. One deliberate change: the expression is wrapped in parentheses. Before, 1 + absorbed the generated printf on the next line and printed an uninitialized value (-129511928); now it is a compile error.

tests/tools/run.sh runs the transcripts. The new CI job native-tools builds flowc from the checked-in C and runs them with python and python3 replaced by failing stubs. The workflow now also triggers on tools/** and flow-driver.

LSP: kept, and why

There is no native LSP on main. compiler/src/lsp_intel.flow, lsp_syntax.flow, lsp_dynamics.flow, lsp_ordering.flow and lsp_utils.flow are helper ports; nothing serves JSON-RPC in Flow. Every editor path (flow-lsp and the VS Code extension) runs python3 -m flow.lsp_server.

Diagnostics and symbol extraction come from the Python parser and type checker. The Stage-A driver fails to parse 1,174 of the 1,725 .flow files under examples/, lib/stdlib/ and tests/lang/ (all 1,054 proof files in examples/verify, 109 other examples, 10 in tests/lang, lib/stdlib/ui_layout.flow). A Flow server that took diagnostics from flowc would flag most of the repo as a syntax error, and flowc also reports sqrt/printf as unbound where the Python checker treats them as built-ins. Details in #693.

./flow lsp is documented in README, the wiki and the one-hour tutorial but printed the help text. It now starts the server.

Not changed

  • project_test_runner.py is the real flow test runner for projects and has no Flow port. Tracked in [Self-Hosting Phase 5] Port Test Runner, REPL, and Native CLI Executable #695.
  • package.py is owned by other work.
  • docs/project/python-in-flow.md and docs/project/CHANGELOG.md are not updated here. The prose hook blocks any commit to either file because of existing em dashes elsewhere in them. Intended edits for python-in-flow.md:
    • Host plugins table: lsp_server.py row says diagnostics, symbols and hover types come from the Python parser and type checker. Replace test_runner.py, package.py, repl.py with project_test_runner.py, package.py.
    • Boundary table: LSP row states the flowc parse coverage above; a separate row says flow test in a project runs python3 -m flow.project_test_runner.
    • Landed in Flow: add flow repl with tools/repl/main.flow and the transcript test.
  • tools/python_ratchet/baseline.txt is tightened with --update in this PR.

Issues

The module had no callers. ./flow test dispatches to flow-driver (compiler
sweep) or flow.project_test_runner (project mode), and nothing in tests,
CI or the drivers imports flow.test_runner.
flow repl now runs tools/repl/main.flow, built by the Stage-A driver on
first use and cached in build/tools (or the user cache dir on a read-only
install). Each line is wrapped in a program, compiled with flowc and cc,
and run under a five second alarm, as before.

The session transcript in tests/tools/repl/session.in produces the same
bytes as the deleted src/flow/repl.py. One deliberate change: the
expression is wrapped in parentheses, so an incomplete line such as
'1 +' is a compile error instead of silently absorbing the printf call
on the next generated line and printing an uninitialized value.

tests/tools/run.sh runs the transcripts without Python.
README, the wiki and the one-hour tutorial document ./flow lsp, but the
driver had no lsp case and printed the help text. It now runs the same
server as the flow-lsp launcher.
New native-tools job builds flowc from the checked-in C and runs
tests/tools/run.sh with python and python3 shadowed by failing stubs.
The workflow now also triggers on tools/** and flow-driver, which
previously changed without CI noticing.
A stale flowc build prints to stderr on the first run, which made the
REPL transcript fail after a pull. stderr is now kept aside and shown
when a case fails.
Drops src/flow/repl.py and src/flow/test_runner.py, plus two test files
already deleted on main. Limit falls from 130042 to 128844 lines.
@godofecht
godofecht force-pushed the port/retire-python-host-tools branch from 90bc88b to 3115091 Compare September 29, 2026 05:42
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.
./flow lsp is a new CLI command, and doc coverage failed with
'cli:lsp has no documented home'. It is listed in the command reference.
@godofecht
godofecht merged commit 5f36fc6 into main Sep 29, 2026
27 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
godofecht deleted the port/retire-python-host-tools 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