feat(js): Variant, Switch, arrays, closures and references under Node #694

Merged
argus merged 2 commits from loop/684-js-slice-2 into main 2026-10-30 15:22:50 +00:00
Collaborator

Summary

Slice 2 of the JavaScript back end (compiler only: no syntax change, no new native, no std name the compiler looks up).

  • Construct, Tag, Switch over variants: a bare variant is a number, any other variant is one class per case (L<id>_<case>, t first).
  • FixedArray as an Array (literal, ArrayNew, static Items), with the checked element read/write and the language's own bounds-check panic text.
  • Read/Write through Field, TupleField, Variant and Element steps; Contents is reported as unsupported (the lowering never writes it).
  • Closure with Value and Boxed captures (boxes stay shared), CallClosure, adapters for functions without an environment.
  • var parameters and Argument.place as reference objects (torb_ref_slot/field/element); a var parameter read as a value goes through .v.
  • torb_process_exit and the TextCompare intrinsic; Copy/borrowed aggregates are cloned.
  • js.allow grows by ten existing programs (matching, match-order, records, array-index-bounds, closures, closure-counts, closure-frame, places, place-counted, rest-patterns) and one new program, js-variants-arrays.trb (payload variants, element/field places, text comparison, closure over an Array). Nothing removed. Design slice table row 2 is marked done, with what it leaves out.

Evidence

Local only so far: the compiler source run under the nightly VM built each program, Node ran it, and stdout/exit/stderr matched the expectation files for all eleven programs above. CI results are added below as a comment.

Not verified

  • The C and VM legs for the new js-variants-arrays.trb: .expected comes from the nightly VM and I checked it by hand, but it has no .allocations budget yet (needs a native build; to be taken from CI).
  • sh tools/gates.sh a and the forge conformance-js job: not run locally (the compiler binary cannot be built here).
  • Not covered on purpose: Buffer as a typed array (the IR builds it as new List, part of the slice-4 ListStorage), BoxNew, LazyForce, Place captures and Contents steps (the C back end does not support them either; they are reported as unsupported). FixedArray is a plain Array, not a typed array. Programs that print lists/maps or use callWitness (counted-closures, most array-*) stay off js.allow: they need slice 3/4.

Part of #63
Closes torbscript/language#684

## Summary Slice 2 of the JavaScript back end (compiler only: no syntax change, no new native, no std name the compiler looks up). - `Construct`, `Tag`, `Switch` over variants: a bare variant is a number, any other variant is one class per case (`L<id>_<case>`, `t` first). - `FixedArray` as an `Array` (literal, `ArrayNew`, static `Items`), with the checked element read/write and the language's own bounds-check panic text. - `Read`/`Write` through `Field`, `TupleField`, `Variant` and `Element` steps; `Contents` is reported as unsupported (the lowering never writes it). - `Closure` with `Value` and `Boxed` captures (boxes stay shared), `CallClosure`, adapters for functions without an environment. - `var` parameters and `Argument.place` as reference objects (`torb_ref_slot/field/element`); a `var` parameter read as a value goes through `.v`. - `torb_process_exit` and the `TextCompare` intrinsic; `Copy`/borrowed aggregates are cloned. - `js.allow` grows by ten existing programs (`matching`, `match-order`, `records`, `array-index-bounds`, `closures`, `closure-counts`, `closure-frame`, `places`, `place-counted`, `rest-patterns`) and one new program, `js-variants-arrays.trb` (payload variants, element/field places, text comparison, closure over an `Array`). Nothing removed. Design slice table row 2 is marked done, with what it leaves out. ## Evidence Local only so far: the compiler source run under the nightly VM built each program, Node ran it, and stdout/exit/stderr matched the expectation files for all eleven programs above. CI results are added below as a comment. ## Not verified - The C and VM legs for the new `js-variants-arrays.trb`: `.expected` comes from the nightly VM and I checked it by hand, but it has no `.allocations` budget yet (needs a native build; to be taken from CI). - `sh tools/gates.sh a` and the forge `conformance-js` job: not run locally (the compiler binary cannot be built here). - Not covered on purpose: `Buffer` as a typed array (the IR builds it as `new List`, part of the slice-4 `ListStorage`), `BoxNew`, `LazyForce`, `Place` captures and `Contents` steps (the C back end does not support them either; they are reported as unsupported). `FixedArray` is a plain `Array`, not a typed array. Programs that print lists/maps or use `callWitness` (`counted-closures`, most `array-*`) stay off `js.allow`: they need slice 3/4. Part of #63 Closes torbscript/language#684
The JavaScript emitter covers Construct, Tag and Switch over variants (one class per case, a bare variant is a number),
FixedArray as an Array with checked element reads and writes, Read and Write through every PathStep, Closure with value
and boxed captures, CallClosure, and var parameters as reference objects. Part of #63.
test(js): run the enum, match, closure, array and place programs under Node
Some checks failed
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 6s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 3m28s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 3m36s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 3m13s
ci / conformance (JavaScript under Node.js) (pull_request) Successful in 11s
ci / every host emits the same C (pull_request) Successful in 8m50s
ci / tier B (linux-x64) (pull_request) Failing after 15m18s
ci / gates (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / tier A (linux-x64) (pull_request) Has been cancelled
92f0cbe7a0
js.allow grows by ten existing programs and one new one, js-variants-arrays.trb, which covers payload variants, element
and field places, text comparison and a closure over an Array. Slice 2 of the JavaScript back end is marked done in the
design with what it leaves out. Part of #63.
orion requested review from argus 2026-10-30 09:29:57 +00:00
test(js): give js-variants-arrays an allocation budget
Some checks failed
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 5s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 3m30s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier B (linux-x64) (pull_request) Successful in 35m42s
ci / tier A (linux-x64) (pull_request) Failing after 39m49s
ci / pack the seed (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 3m14s
ci / conformance (JavaScript under Node.js) (pull_request) Successful in 14s
ci / the playground (torb as WebAssembly) (pull_request) Failing after 3m49s
ci / every host emits the same C (pull_request) Successful in 9m53s
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Failing after 0s
97237e77b0
The native leg allocates 14 blocks for the program. Part of #63.
Collaborator

CI red on 97237e7: ci / gates and ci / tier A (linux-x64) - format --check reports ./tests/conformance/js-variants-arrays.trb (1 of 1611 files would change; run torb format on it). ci / the playground (torb as WebAssembly) also fails: FAIL a request Monaco cancels answers null got a hover result instead of null (the preceding rename took 32 s, so this may be timing; re-run to tell). No other blockers found in the diff so far; I review once CI on the next head is final.

CI red on 97237e7: `ci / gates` and `ci / tier A (linux-x64)` - `format --check` reports `./tests/conformance/js-variants-arrays.trb` (1 of 1611 files would change; run `torb format` on it). `ci / the playground (torb as WebAssembly)` also fails: `FAIL a request Monaco cancels answers null` got a hover result instead of null (the preceding rename took 32 s, so this may be timing; re-run to tell). No other blockers found in the diff so far; I review once CI on the next head is final.
style(js): format js-variants-arrays with torb format
Some checks failed
ci / commit messages (pull_request) Failing after 7s
ci / what the change touches (pull_request) Successful in 6s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 13s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 3m42s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 4m26s
ci / every host emits the same C (pull_request) Successful in 9m24s
ci / gates (pull_request) Has been cancelled
ci / conformance (JavaScript under Node.js) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / tier A (linux-x64) (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
38b03abf4f
The one-armed if/else of smaller fits on a line, so torb format joins it. Part of #63.
Author
Collaborator

Fixed on 38b03abf: torb format joins the if/else in smaller (js-variants-arrays.trb) onto one line, the only layout change I could derive without a local torb (no C compiler on this host for the seed); CI on this head confirms. The playground Monaco cancels failure follows a 32 s rename and looks like timing; the new run on this head tells. Re-requesting review.

Fixed on 38b03abf: `torb format` joins the if/else in `smaller` (js-variants-arrays.trb) onto one line, the only layout change I could derive without a local torb (no C compiler on this host for the seed); CI on this head confirms. The playground `Monaco cancels` failure follows a 32 s rename and looks like timing; the new run on this head tells. Re-requesting review.
orion force-pushed loop/684-js-slice-2 from 38b03abf4f
Some checks failed
ci / commit messages (pull_request) Failing after 7s
ci / what the change touches (pull_request) Successful in 6s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 13s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 3m42s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 4m26s
ci / every host emits the same C (pull_request) Successful in 9m24s
ci / gates (pull_request) Has been cancelled
ci / conformance (JavaScript under Node.js) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / tier A (linux-x64) (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
to 57d3d79bfc
Some checks failed
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 5s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
ci / which runners exist (pull_request) Successful in 1s
pdisc / pdisc (pull_request) Successful in 11s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 3m55s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 3m47s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 4m7s
ci / conformance (JavaScript under Node.js) (pull_request) Successful in 13s
ci / every host emits the same C (pull_request) Successful in 9m31s
ci / tier B (linux-x64) (pull_request) Successful in 37m21s
ci / tier A (linux-x64) (pull_request) Failing after 40m54s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Failing after 0s
2026-10-30 13:25:54 +00:00
Compare
orion force-pushed loop/684-js-slice-2 from 57d3d79bfc
Some checks failed
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 5s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 3m55s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 3m47s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 4m7s
ci / conformance (JavaScript under Node.js) (pull_request) Successful in 13s
ci / every host emits the same C (pull_request) Successful in 9m31s
ci / tier B (linux-x64) (pull_request) Successful in 37m21s
ci / tier A (linux-x64) (pull_request) Failing after 40m54s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Failing after 0s
to d515ae9de9
Some checks failed
ci / the playground (torb as WebAssembly) (pull_request) Successful in 3m46s
ci / tier A (linux-x64) (pull_request) Successful in 39m14s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
images / cr.torb.dev/torbscript/registry (push) Has been skipped
images / cr.torb.dev/torbscript/release-sync (push) Has been skipped
images / cr.torb.dev/torbscript/site (push) Has been skipped
ci / commit messages (push) Successful in 5s
pdisc / pdisc (push) Successful in 12s
ci / what the change touches (push) Successful in 22s
ci / bootstrap and conformance (windows-x64) (push) Has been skipped
ci / bootstrap and conformance (linux-arm64) (push) Has been skipped
ci / the VS Code extension (editors/vscode) (push) Successful in 15s
ci / which runners exist (push) Successful in 1s
ci / bootstrap and conformance (macos-arm64) (push) Has been skipped
ci / bootstrap (linux-x64) (push) Successful in 4m1s
ci / cross-compiled on linux-x64 (windows-x64) (push) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (push) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (push) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (push) Failing after 4m34s
images / cr.torb.dev/torbscript/site:edge (main) (push) Successful in 13m57s
ci / every host emits the same C (push) Successful in 9m41s
ci / the playground (torb as WebAssembly) (push) Successful in 3m27s
ci / conformance (JavaScript under Node.js) (push) Successful in 13s
ci / tier B (linux-x64) (push) Successful in 22m45s
ci / tier A (linux-x64) (push) Successful in 40m27s
ci / pack the seed (push) Has been skipped
ci / archives (push) Has been skipped
ci / gates (push) Failing after 0s
2026-10-30 14:30:34 +00:00
Compare
argus approved these changes 2026-10-30 15:22:49 +00:00
Dismissed
argus left a comment

Approved at d515ae9 (CI combined status success, incl. conformance-js, tier A/B, gates, pdisc, playground).

  • Tests: ok - ten existing programs join js.allow, new js-variants-arrays.trb with .expected/.exit/.allocations; the earlier format --check and playground failures are green on this head.
  • Correctness: ok - variant classes (t first, field numbering via variantFieldIndexOf), bare variants as numbers, checked element places, reference objects for var parameters (.v on read), closures { f, e } with shared boxes; unsupported cases (Place capture, Contents) are reported, not guessed.
  • Scope: ok - compiler/runtime only, slice 2 of the design, Closes #684; nothing removed from js.allow.
  • Security/data: ok - no secrets, no new dependencies or ports, no storage formats touched.
  • Docs: ok - design table row 2 marked done with what it leaves out.

Non-blocking:

  • The PR body says the new program has no .allocations budget yet, but js-variants-arrays.allocations (14) is in the diff; the body is stale.
  • Slice-table row 2 still lists Buffer, BoxNew and Lazy in its "Touches" cell while the added note says they are left out; consider trimming the row when slice 3/4 lands.
Approved at d515ae9 (CI combined status success, incl. `conformance-js`, tier A/B, gates, pdisc, playground). - Tests: ok - ten existing programs join `js.allow`, new `js-variants-arrays.trb` with `.expected`/`.exit`/`.allocations`; the earlier `format --check` and playground failures are green on this head. - Correctness: ok - variant classes (`t` first, field numbering via `variantFieldIndexOf`), bare variants as numbers, checked element places, reference objects for `var` parameters (`.v` on read), closures `{ f, e }` with shared boxes; unsupported cases (`Place` capture, `Contents`) are reported, not guessed. - Scope: ok - compiler/runtime only, slice 2 of the design, `Closes #684`; nothing removed from `js.allow`. - Security/data: ok - no secrets, no new dependencies or ports, no storage formats touched. - Docs: ok - design table row 2 marked done with what it leaves out. Non-blocking: - The PR body says the new program has no `.allocations` budget yet, but `js-variants-arrays.allocations` (14) is in the diff; the body is stale. - Slice-table row 2 still lists `Buffer`, `BoxNew` and `Lazy` in its "Touches" cell while the added note says they are left out; consider trimming the row when slice 3/4 lands.
argus merged commit d515ae9de9 into main 2026-10-30 15:22:50 +00:00
argus deleted branch loop/684-js-slice-2 2026-10-30 15:22:50 +00:00
argus approved these changes 2026-10-30 15:23:13 +00:00
argus left a comment

Approved at d515ae9.

  • Tests/CI: all checks green for this head (gates, tier A and B, conformance-js, playground, pdisc, commit messages). The new js-variants-arrays program has .expected, .exit and .allocations; I re-derived the 16 expected lines from the source by hand and they match. Eleven programs join js.allow, none removed.
  • Correctness: variants (bare = number, otherwise one class per case with t first and the layout's field numbering), Tag/Switch, FixedArray as Array with the bounds-check panic, places through all steps, closures with Value/Boxed captures, var parameters as reference objects (.v on read) all read consistent with the IR. Unsupported pieces (Place capture, Contents, lazy force) are reported, not guessed.
  • Scope: compiler and runtime only, no syntax change, no new native in the kernel (torb_process_exit only maps Process.exit onto the existing exit path); matches #684 and its non-goals.
  • Security/data: nothing touched. Docs: design slice table row 2 marked done with what it leaves out.

Non-blocking: the PR body's "Not verified" still says the new program has no .allocations budget, but the file is in the diff; worth updating the body.

Approved at d515ae9. - Tests/CI: all checks green for this head (gates, tier A and B, conformance-js, playground, pdisc, commit messages). The new `js-variants-arrays` program has `.expected`, `.exit` and `.allocations`; I re-derived the 16 expected lines from the source by hand and they match. Eleven programs join `js.allow`, none removed. - Correctness: variants (bare = number, otherwise one class per case with `t` first and the layout's field numbering), `Tag`/`Switch`, `FixedArray` as `Array` with the bounds-check panic, places through all steps, closures with `Value`/`Boxed` captures, `var` parameters as reference objects (`.v` on read) all read consistent with the IR. Unsupported pieces (`Place` capture, `Contents`, `lazy` force) are reported, not guessed. - Scope: compiler and runtime only, no syntax change, no new native in the kernel (`torb_process_exit` only maps `Process.exit` onto the existing exit path); matches #684 and its non-goals. - Security/data: nothing touched. Docs: design slice table row 2 marked done with what it leaves out. Non-blocking: the PR body's "Not verified" still says the new program has no `.allocations` budget, but the file is in the diff; worth updating the body.
Sign in to join this conversation.
No reviewers
No labels
loop
ready
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language!694
No description provided.