Skip to content

selfhost: Shader DSL (FSL) on flowc, Python backends retired (#683) - #998

Merged
godofecht merged 9 commits into
mainfrom
port/shader-dsl-flowc
Sep 29, 2026
Merged

godofecht merged 9 commits into
mainfrom
port/shader-dsl-flowc

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

What

The Shader DSL (FSL, shader fill blocks and fn helpers) now builds entirely inside flowc. The three Python modules behind it are gone.

  • compiler/src/shader_dsl.flow: the whole of the former shader_dsl.py, shader_codegen.py and shader_codegen_wgsl.py. Head extraction, the FSL lexer and parser, guess_type, both backends and both preludes. Each regex is a hand-written scan. Output is byte-identical to the Python, including its quirks (unmatched characters are skipped, // lexes as two divisions, braces in comments count during extraction).
  • compiler/src/shader_emit.flow: FLOWC_SHADER=metal|wgsl|list|expand writes the same files the Python did (<stem>_gallery.metal, .entries, per-fill .metal / .entry; <stem>_gallery.wgsl or <name>_fill.wgsl, .wgsl.entries). FLOWC_SHADER_NAME selects one fill.
  • Host stub at every source read: a fill-shader module compiles as function main() -> i32 { return 0 }, as the Python module resolver did, in main.flow, driver.flow and all five bundle reads in resolve.flow. The self-emit scripts and roundtrip.sh build shader_dsl as a leaf frontend module.
  • ./flow shader calls flowc for the Metal gallery, and with --wgsl for WGSL. The viewer host (lib/runtime/shader_host.flow) is also transpiled by flowc instead of python3 -m flow.transpiler.
  • Python: shader_codegen.py (370), shader_codegen_wgsl.py (394), scripts/emit_fsl_wgsl.py (29) and tests/unit/test_shader_codegen_wgsl.py (122) deleted. shader_dsl.py is a 96-line bridge to flowc (was 483) for the module resolver, wasm/flow_webgpu_shader.py and scripts/record_shader_gallery.py. module_resolver.py loses its AST stub. Net: 1,575 Python lines removed, 183 added (-1,392). Ratchet lowered.
  • tests/lang/test_shader_dsl_port.flow covers the Flow API.

One deliberate difference: flowc stubs a module only when a fill head starts a line. The Python matched one anywhere, so it replaced tests/lang/test_dsl_detect.flow (which names the syntax in a string literal) with an empty stub under the Python host. That test now runs for real on both hosts.

Parity

compiler/scripts/parity_shader_dsl.sh --python 58a5fea8:

fixtures: pass=102 fail=0
host stub: files=2262 stubbed=6 fail=0
live python@58a5fea8: files=2292 checks=6876 fail=0 (deviation: tests/lang/test_dsl_detect.flow tests/lang/test_shader_dsl_port.flow)
e2e: ./flow shader --emit-only wrote 12 entries
e2e: xcrun metal compiled build/shaders/shader_showcase_gallery.metal
e2e: ./flow shader --wgsl wrote build/shaders/vgpu_gradient_fill.wgsl
e2e: ./flow compile shader_plasma host stub exit 0
e2e: no python call logged
parity_shader_dsl: PASS
  • 30 fixtures in compiler/fixtures/shader_dsl/, each with Metal and WGSL goldens (every output file) or the error text, plus the host-stub outcome, recorded from the Python. The six shader examples are held by SHA-256 of their full output (the 60-material Metal gallery runs to megabytes).
  • The live mode runs the Python at any revision over every tracked .flow file, both targets, and requires the same bytes or the same error from flowc, plus the same host-stub outcome.
  • End to end runs with python and python3 on PATH replaced by stubs that log and exit 127. The log stayed empty.

Bootstrap

Regenerated last, in its own commit, on top of 58a5fea, per AGENTS.md. Python-host self-test prints flowc: PASS. Fixed point holds. bootstrap_from_c.sh --verify, self_host_full.sh (three generations byte-identical) and roundtrip.sh pass. Bootstrap suite 120/19, identical pass and fail sets to origin/main's bootstrap with the same harness.

Not changed

  • docs/language/shaders.md, docs/project/python-in-flow.md and docs/project/vgpu-parity.md still name the Python modules. The prose hook blocks them for pre-existing dashes, so they are left for a docs pass.
  • The Metal viewer does not link on main before or after this PR: lib/runtime/shader_host.flow calls flow_shader_show_gallery_file_ex, which runtime/shader_view_metal.m does not define. --emit-only and --wgsl are unaffected.
  • wasm/flow_webgpu_shader.py and scripts/record_shader_gallery.py stay Python; they now only call flowc for the shader.

Issues opened for Flow gaps met on the way: #985 (shared growable byte buffer for compiler modules), #986 (Stage-A parse errors give only a byte offset).

Closes #683.

@godofecht

Copy link
Copy Markdown
Contributor Author

Merge train: rebased onto #999 (which is rebased onto #1003). The fill-shader stub is now the first stage (mask 8) of flowc_expand_stages_in_place in resolve.flow, so main.flow, driver.flow and every bundle read get it through the shared helper; #998's own read helper and per-site calls are gone. Old bootstrap commit dropped and C regenerated: fixed point OK, bootstrap_from_c --verify and self_host_full pass, parity field/dynamics/flow_blocks pass. parity_shader_dsl passes fixtures (102/0), host stub (2530 files) and WGSL/host e2e; its Metal e2e step fails locally only because this Mac's Metal toolchain component is missing.

@godofecht
godofecht force-pushed the port/shader-dsl-flowc branch 2 times, most recently from 8e4ead2 to 2c4be72 Compare September 29, 2026 07:10
godofecht added a commit that referenced this pull request Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's
parse-only mode, located parse errors (flowc_parser_print_error, which the
driver, emit and bundle paths now use), theorem/assume/therefore/claim
references, flow blocks, handle, ui layout and pipeline blocks, let without
initializer, contextual unit, distinct, effect rows, or-patterns, guards,
nested patterns, [T; N], capability types, ?, vector literals, soft names,
sort-by keys, entropy policies and module blocks, the parse coverage script
and its CI floor, and the Python-grammar parser contract test. The
#1001/#1003 reconciliation follows the one in #1012.
…in flowc (#683)

compiler/src/shader_dsl.flow is the whole of the former shader_dsl.py,
shader_codegen.py and shader_codegen_wgsl.py: head extraction, the FSL
lexer and parser, type guessing, and both backends with their preludes.
compiler/src/shader_emit.flow writes the gallery files. main.flow
dispatches FLOWC_SHADER=metal|wgsl|list|expand.
src/flow/shader_codegen.py and shader_codegen_wgsl.py are gone and
shader_dsl.py is a bridge to flowc FLOWC_SHADER. ./flow shader builds
Metal (and, with --wgsl, WGSL) and transpiles the viewer host with flowc
instead of python3. The module resolver takes the fill-shader host stub
from flowc. scripts/emit_fsl_wgsl.py is replaced by ./flow shader --wgsl.
A fill-shader module is not host Flow. The Python module resolver gave it
a stub main so the C transpile corpus passes. flowc now does the same as
the first stage of flowc_expand_stages_in_place in resolve.flow (mask 8),
so the compile paths in main.flow and driver.flow and every bundle pass
see the stub through the shared read helper. The self-emit scripts build
shader_dsl as a leaf frontend module.

Only a fill head that starts a line counts. The Python matched one
anywhere, which turned tests/lang/test_dsl_detect.flow (it names the
syntax in a string) into an empty stub.
compiler/scripts/parity_shader_dsl.sh holds flowc to goldens recorded from
the Python at 0b6d6ac (30 fixtures, both targets, plus digests of the six
shader examples), checks the host stub over every tracked .flow file,
diffs live against the Python at any revision, and builds the examples
with python and python3 stubbed out. tests/lang/test_shader_dsl_port.flow
covers the Flow API.
@godofecht
godofecht force-pushed the port/shader-dsl-flowc branch from 2c4be72 to 0a35225 Compare September 29, 2026 07:35
extract_shader_module left with the Python shader backends, so
check_doc_examples.py failed to import and every doc-example job and
test_docs_blocks failed. It asks flowc for the fill names instead.
line_starts_with and line_starts_with_ns declared i32 and returned a
bool. The Python host used to turn tests/lang/test_dsl_detect.flow into a
fill-shader stub, so it never type-checked the module; with the stub now
limited to a fill head at line start it does, and tier-2 failed.
godofecht added a commit that referenced this pull request Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's
parse-only mode, located parse errors (flowc_parser_print_error, which the
driver, emit and bundle paths now use), theorem/assume/therefore/claim
references, flow blocks, handle, ui layout and pipeline blocks, let without
initializer, contextual unit, distinct, effect rows, or-patterns, guards,
nested patterns, [T; N], capability types, ?, vector literals, soft names,
sort-by keys, entropy policies and module blocks, the parse coverage script
and its CI floor, and the Python-grammar parser contract test. The
#1001/#1003 reconciliation follows the one in #1012.
@godofecht
godofecht merged commit a7cfecc into main Sep 29, 2026
28 checks passed
godofecht added a commit that referenced this pull request Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's
parse-only mode, located parse errors (flowc_parser_print_error, which the
driver, emit and bundle paths now use), theorem/assume/therefore/claim
references, flow blocks, handle, ui layout and pipeline blocks, let without
initializer, contextual unit, distinct, effect rows, or-patterns, guards,
nested patterns, [T; N], capability types, ?, vector literals, soft names,
sort-by keys, entropy policies and module blocks, the parse coverage script
and its CI floor, and the Python-grammar parser contract test. The
#1001/#1003 reconciliation follows the one in #1012.
@godofecht
godofecht deleted the port/shader-dsl-flowc 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.

[Self-Hosting Phase 2] Port Shader DSL to Native Flow

1 participant