Skip to content

Every Solve It the Flow Way example runs in the browser - #617

Merged
godofecht merged 1 commit into
mainfrom
gallery-runs-in-browser
Aug 20, 2026
Merged

godofecht merged 1 commit into
mainfrom
gallery-runs-in-browser

Conversation

@godofecht

@godofecht godofecht commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Two of the five ran. The gallery teaches idioms, so a reader pressing Run and being told to go install a compiler is the wrong answer.

before                          after
0: RUNS                         0: RUNS   exit=0
1: unsupported  effects         1: RUNS   exit=0  "control step"
2: error        line 14 ','     2: RUNS   exit=0
3: unsupported  enums           3: RUNS   exit=0
4: error        'flow'          4: RUNS   exit=0

Each program returns 1 on a failed assertion, so exit 0 is the program checking itself rather than merely reaching the end.

First, something that had been lost

The effects work from #581 was written but not merged. That merge took the gallery and the wiki publishing and left site/flow-compile.js and site/wiki.js behind, so effect declarations, capabilities, handle blocks and Effect.op dispatch were absent from main. Recovered from the dangling commit rather than rewritten.

Three features

Pipeline forks. n |> Stats { doubled = twice, plus_ten = add(_, 10) } runs each named function over the piped value and collects the results. The _ placeholder logic already existed for ordinary stages and is now shared between the two.

Enums and choose. enum Mode { Double, Triple } becomes a struct holding a tag plus one constant per variant, which is exactly what the native compiler lowers it to, so Mode { tag: Mode_Double } and m.tag mean the same thing in both. |> choose m.tag { Mode_Double => double } selects which function the value flows through.

Flow blocks. flow Thermostat { state … param … solver … evolves as … every 100 ms { … } } lowers to a struct plus Name_new, Name_default_dt and Name_step. That reuses the existing struct, pointer and call machinery rather than putting a second evaluator beside the first. Explicit Euler only; a method that is not euler says which one it was asked for.

Checked against the native compiler, not a tolerance

20000 Euler steps with the every-block firing 200 times:

native:   temp=20.414 heater=1.0
browser:  temp=20.414 heater=1.0

A stepper that is close is not the same as one that agrees.

A bug this surfaced

Top-level const never worked. prog.consts was written by the parser and read by nothing, so every reference to a constant was an undefined variable. Enum variants are constants, which is how it came to light. Fixed generally, not just for enums.

Verification

Check Result
verify_browser_interp.py 240 snippets, unsupported 13 → 12, no new disagreement (pipelines-3 was already failing on main)
pytest tests/ 1721 passed, 6 skipped
gallery in a real browser 5 runners, all "Exited 0"

Nine tests in tests/unit/test_browser_interpreter_gallery.py, including a guard that fails if the gallery grows past the five programs it asserts about. They read the gallery through docs_blocks.iter_blocks rather than a regex, since a regex over fences mispairs a closing fence with the next opening one.

Two of the five ran. The other three needed features the browser interpreter
did not have, and the gallery teaches idioms, so a reader pressing Run on one
and being told to go and install a compiler is the wrong answer.

Restored first: the effects work from #581 was written but not merged. The
merge took the gallery and the wiki publishing and left site/flow-compile.js
and site/wiki.js behind, so effect declarations, capabilities, handle blocks
and Effect.op dispatch were absent from main. Recovered from the dangling
commit rather than rewritten.

Then three features:

Pipeline forks. `n |> Stats { doubled = twice, plus_ten = add(_, 10) }` runs
each named function over the piped value and collects the results. The `_`
placeholder logic already existed for ordinary stages and is now shared.

Enums and choose. `enum Mode { Double, Triple }` becomes a struct holding a
tag plus one constant per variant, which is what the native compiler lowers
it to, so `Mode { tag: Mode_Double }` and `m.tag` mean the same thing in
both. `|> choose m.tag { Mode_Double => double }` selects which function the
value flows through.

Flow blocks. `flow Thermostat { state ... param ... solver ... evolves as ...
every 100 ms { ... } }` lowers to a struct plus Name_new, Name_default_dt and
Name_step, so the existing struct, pointer and call machinery runs it instead
of a second evaluator living beside the first. Explicit Euler; a method that
is not euler says which one it was asked for.

Checked against the native compiler rather than against a tolerance. 20000
steps of the thermostat with its every-block firing 200 times prints
temp=20.414 heater=1.0 from both.

Top-level constants were parsed and never installed as globals, so every
reference to one was an undefined variable. Enum variants are constants,
which is how that surfaced.

verify_browser_interp.py: 240 snippets, unsupported 13 -> 12, no new
disagreement.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@godofecht
godofecht merged commit e3c73aa into main Aug 20, 2026
22 checks passed
@godofecht
godofecht deleted the gallery-runs-in-browser branch August 20, 2026 09:45
@godofecht godofecht added bug Something isn't working compiler medium and removed bug Something isn't working compiler medium labels Aug 20, 2026
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