Skip to content

selfhost: Field DSL expansion on flowc, Python expander retired (#682) - #956

Merged
godofecht merged 5 commits into
mainfrom
port/selfhost-next
Sep 27, 2026
Merged

godofecht merged 5 commits into
mainfrom
port/selfhost-next

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

What

field / boundary / evolves as laplacian (the Field DSL, #163) now expands inside flowc. The Python expander is gone.

  • compiler/src/field_dsl.flow: the whole of the former src/flow/field_dsl.py. Detection, parsing, all ten diagnostics, T_field_step generation and injection before main(). Each regex is a hand-written scan. Output is byte-identical to the Python, including its quirks.
  • flowc expands the DSL on every source read: the emit path in main.flow and driver.flow, and all four bundle passes in resolve.flow. FLOWC_EXPAND_ONLY=1 writes the expanded source.
  • flow-driver: on the flowc host, a program with an import (or the Field DSL, which adds one) is bundled from the repository root. Programs with imports under examples/ and tests/lang that build on flowc go from 5 of 346 to 90, with none lost.
  • src/flow/field_dsl.py: 234 lines down to a 60-line bridge that runs flowc FLOWC_EXPAND_ONLY=1 for the Python host, LSP and check_doc_examples.py. Net Python: -178 lines.
  • Self-emit scripts build field_dsl as a new leaf frontend module.

./flow compile examples/evolution/heat_diffusion.flow now builds and runs with python3 and python shimmed to exit 127. No call was logged.

Parity

compiler/scripts/parity_field_dsl.sh (shell):

fixtures: pass=21 fail=0
passthrough: files=1995 fail=0
live python@3dbbac87: files=2017 fail=0
e2e: heat_diffusion exit 0 on flowc
parity_field_dsl: PASS

21 fixtures (11 expansions, 10 errors) are checked against goldens recorded from the Python expander. Every other .flow in the repo must pass through untouched. --python <rev> diffs live against the Python at any revision.

Bootstrap

Regenerated last, in its own commit, following AGENTS.md. The fixed point holds, bootstrap_from_c.sh --verify passes, and self_host_full.sh passes (three generations, byte-identical). The Python-host self-test prints flowc: PASS.

Known, not from this PR

  • roundtrip.sh fails at compile_module lexer, before any module touched here. lexer.flow uses KW_SHADER without importing it (from selfhost: port Shader DSL lexing, parsing and validation to Flow (#683) #890).
  • flow run still calls python3 -m flow.package sync for every program. flow compile is Python-free. This is listed in python-in-flow.md.
  • The Python expander had a bug that is kept for parity: a one-line boundary T { ... } also consumes the next line. If that line opens a block, as function main() { does, the result is an error. Fixture err_swallow_main records it.

godofecht added a commit that referenced this pull request Sep 27, 2026
Same hunk as the flow-driver part of #956, so either branch rebases
cleanly over the other. Without it no example with an import builds on
the default host, and the no-Python run check needs some that do.
compiler/src/field_dsl.flow is the whole of src/flow/field_dsl.py:
detection, `field` / `boundary` / `evolves as laplacian` parsing, the
diagnostics, helper generation and injection before main(). Each regex is
a hand-written scan. Output is byte-identical to the Python expander,
including its quirks (trailing newline dropped, a one-line boundary
consuming the next line).

Every flowc source read now expands the DSL before parse: the emit path
in main.flow and driver.flow, and all four bundle passes in resolve.flow.
FLOWC_EXPAND_ONLY=1 writes the expanded source instead of C.

compiler/scripts/parity_field_dsl.sh holds flowc to goldens recorded from
the Python expander (21 fixtures), checks that the 1995 other .flow files
pass through untouched, can diff live against the Python at any git rev
(--python), and compiles and runs examples/evolution/heat_diffusion.flow
on flowc alone.

The self-emit scripts build field_dsl as a new leaf frontend module.
src/flow/field_dsl.py keeps its two public functions for the Python host,
the LSP and check_doc_examples.py, but expand_field_dsl now runs flowc
with FLOWC_EXPAND_ONLY=1 (FLOWC_BIN, else flowc built with cc from the
checked-in bootstrap C) and raises flowc's diagnostic as SyntaxError. The
regex parser, FieldDecl and compile_fields are gone.

The unit test asserts through the public API only, since parse_field_dsl
no longer exists.
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