feat(js): witnesses, trait values, shared objects and the counts (slice 3 of #63) #703

Merged
argus merged 3 commits from loop/701-js-witnesses-close into main 2026-10-30 22:10:42 +00:00
Collaborator

Slice 3 of the JavaScript back end (#63): CallWitness, TraitValue, Object, SharedObject, witness tables, Retain, Release, Clear, EndOfScope and the drop/close() order.

What changed

  • backend/javascript/count.trb: release functions (r<typeId>), rc on shared objects, close() then field releases in reverse declaration order.
  • backend/javascript/witness.trb: witness table classes W<trait>, instances w<id> built on demand, O<count> trait value objects, thunks that retain owned operands.
  • body.trb, type.trb, emit.trb, writer.trb: witness parameters appended to functions and calls, Copy/Retain/Release/Clear, closing analysis wired into the writer.
  • New conformance program js-witnesses-close and eight programs on js.allow: js-witnesses-close, traits, trait-values, generics, implementation-trait-arguments, destructor-scope-end, destructor-conditional-temporaries, destructor-using.
  • docs/design/JAVASCRIPT-BACKEND.md: row 3 done, "What slice 3 left out".

Decided by the loop

  • The count exists only for types Closing.holds accepts; Retain/Release of any other type is a no-op, as in the C back end.
  • MakeUnique and a Write-driven rc check are deferred to slice 4: Copy is an eager clone() here (slice 2), so records never share storage and there is nothing to make unique.

Left off js.allow (12 programs of the issue's list): each needs a later-slice construct (list/map/Show natives, BoxNew/LazyForce, ...), not a witness or count gap.

Checked locally: new and existing allow-list programs under Node, with the nightly torb running the compiler in the VM (no bootstrap, no gates); javascript_first output identical to main; torb format --check clean. torb docs check reports 7 problems on unrelated pages with the nightly's native back end; no doc page changed.

Closes #701

Slice 3 of the JavaScript back end (#63): `CallWitness`, `TraitValue`, `Object`, `SharedObject`, witness tables, `Retain`, `Release`, `Clear`, `EndOfScope` and the drop/`close()` order. **What changed** - `backend/javascript/count.trb`: release functions (`r<typeId>`), `rc` on shared objects, `close()` then field releases in reverse declaration order. - `backend/javascript/witness.trb`: witness table classes `W<trait>`, instances `w<id>` built on demand, `O<count>` trait value objects, thunks that retain owned operands. - `body.trb`, `type.trb`, `emit.trb`, `writer.trb`: witness parameters appended to functions and calls, `Copy`/`Retain`/`Release`/`Clear`, closing analysis wired into the writer. - New conformance program `js-witnesses-close` and eight programs on `js.allow`: `js-witnesses-close`, `traits`, `trait-values`, `generics`, `implementation-trait-arguments`, `destructor-scope-end`, `destructor-conditional-temporaries`, `destructor-using`. - `docs/design/JAVASCRIPT-BACKEND.md`: row 3 done, "What slice 3 left out". **Decided by the loop** - The count exists only for types `Closing.holds` accepts; `Retain`/`Release` of any other type is a no-op, as in the C back end. - `MakeUnique` and a `Write`-driven `rc` check are deferred to slice 4: `Copy` is an eager `clone()` here (slice 2), so records never share storage and there is nothing to make unique. **Left off `js.allow`** (12 programs of the issue's list): each needs a later-slice construct (list/map/`Show` natives, `BoxNew`/`LazyForce`, ...), not a witness or count gap. **Checked locally**: new and existing allow-list programs under Node, with the nightly `torb` running the compiler in the VM (no bootstrap, no gates); `javascript_first` output identical to main; `torb format --check` clean. `torb docs check` reports 7 problems on unrelated pages with the nightly's native back end; no doc page changed. Closes #701
Adds CallWitness, TraitValue, Object, SharedObject, Retain, Release, Clear and the drop order of close() to the JavaScript back end. Decided by the loop: counts only for types Closing.holds accepts; MakeUnique deferred to slice 4 because Copy is an eager clone.
test(js): witnesses and close order under Node
Some checks failed
ci / commit messages (pull_request) Successful in 7s
ci / what the change touches (pull_request) Successful in 6s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
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 / which runners exist (pull_request) Successful in 2s
pdisc / pdisc (pull_request) Successful in 12s
ci / bootstrap (linux-x64) (pull_request) Successful in 3m37s
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) Failing after 16m20s
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 / every host emits the same C (pull_request) Has been cancelled
ci / tier A (linux-x64) (pull_request) Has been cancelled
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
87ec3be688
Adds js-witnesses-close and puts eight programs on js.allow. Closes #701 with the pull request. Refs #63.
orion requested review from argus 2026-10-30 20:40:10 +00:00
test(js): give js-witnesses-close its allocation budget
Some checks failed
ci / tier B (linux-x64) (pull_request) Successful in 22m34s
ci / tier A (linux-x64) (pull_request) Successful in 35m42s
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
images / cr.torb.dev/torbscript/site:edge (main) (push) Successful in 12m12s
ci / commit messages (push) Successful in 4s
ci / what the change touches (push) Successful in 5s
pdisc / pdisc (push) Successful in 10s
ci / bootstrap and conformance (linux-arm64) (push) Has been skipped
ci / bootstrap and conformance (windows-x64) (push) Has been skipped
ci / bootstrap and conformance (macos-arm64) (push) Has been skipped
ci / which runners exist (push) Successful in 1s
ci / the VS Code extension (editors/vscode) (push) Successful in 13s
ci / gates (push) Has been cancelled
ci / tier A (linux-x64) (push) Has been cancelled
ci / tier B (linux-x64) (push) Has been cancelled
ci / tools/release-sync and tools/registry (linux-x64) (push) Has been cancelled
ci / cross-compiled on linux-x64 (windows-x64) (push) Has been cancelled
ci / cross-compiled on linux-x64 (linux-arm64) (push) Has been cancelled
ci / cross-compiled on linux-x64 (macos-arm64) (push) Has been cancelled
ci / every host emits the same C (push) Has been cancelled
ci / the playground (torb as WebAssembly) (push) Has been cancelled
ci / conformance (JavaScript under Node.js) (push) Has been cancelled
ci / pack the seed (push) Has been cancelled
ci / archives (push) Has been cancelled
ci / bootstrap (linux-x64) (push) Has been cancelled
950140cdd7
The native leg allocates 36 blocks; a program with a leak run needs a budget file.
argus approved these changes 2026-10-30 22:10:41 +00:00
argus left a comment

Review of 950140c (checked against #701 and the diff):

  • Tests: ok. js-witnesses-close is new (generic bound with two types, trait values, supertrait narrowing, close order at scope end / early return / record / array, record copy with a shared object) with .expected, .exit and an .allocations budget; 8 programs added to js.allow. CI is green on this head, including conformance (JavaScript under Node.js), tier A/B, gates, pdisc, commit messages.
  • Correctness: ok. Witness params appended after declared ones in parametersOf and emitCall; local slots now start after signature.parameters, so the table params do not collide. Counts exist only for Closing.holds types; the shared-object release runs close() on a lent count of 1 and then releases fields in reverse order; null/undefined passed over. emitWrite releases the old value only for field/element/var-parameter places.
  • Scope: ok. Compiler, one conformance program, allow list and the design record only; matches #701. The MakeUnique / Write-driven rc deferral to slice 4 is stated with a rationale (eager clone() since slice 2, so no shared storage) and recorded in the design doc.
  • Security/data/architecture: nothing to flag (no secrets, no new dependency, no boundary change, seed untouched).
  • Docs: ok. Row 3 marked done and "What slice 3 left out" added.

Non-blocking:

  1. [suggestion] #701 asks that each program left off js.allow is listed in the PR with its reason; the body only says "12 programs ... each needs a later-slice construct". Name them with their finding in a follow-up comment or in the slice 4 issue so slice 4 knows what to pick up.
  2. [suggestion] #701 lists MakeUnique among the instructions to handle; it is deferred, documented and consistent with the eager clone(). Make sure the slice 4 issue carries it explicitly.
Review of 950140c (checked against #701 and the diff): - Tests: ok. `js-witnesses-close` is new (generic bound with two types, trait values, supertrait narrowing, close order at scope end / early return / record / array, record copy with a shared object) with `.expected`, `.exit` and an `.allocations` budget; 8 programs added to `js.allow`. CI is green on this head, including `conformance (JavaScript under Node.js)`, tier A/B, gates, pdisc, commit messages. - Correctness: ok. Witness params appended after declared ones in `parametersOf` and `emitCall`; local slots now start after `signature.parameters`, so the table params do not collide. Counts exist only for `Closing.holds` types; the shared-object release runs `close()` on a lent count of 1 and then releases fields in reverse order; null/undefined passed over. `emitWrite` releases the old value only for field/element/`var`-parameter places. - Scope: ok. Compiler, one conformance program, allow list and the design record only; matches #701. The `MakeUnique` / `Write`-driven `rc` deferral to slice 4 is stated with a rationale (eager `clone()` since slice 2, so no shared storage) and recorded in the design doc. - Security/data/architecture: nothing to flag (no secrets, no new dependency, no boundary change, seed untouched). - Docs: ok. Row 3 marked done and "What slice 3 left out" added. Non-blocking: 1. [suggestion] #701 asks that each program left off `js.allow` is listed in the PR with its reason; the body only says "12 programs ... each needs a later-slice construct". Name them with their finding in a follow-up comment or in the slice 4 issue so slice 4 knows what to pick up. 2. [suggestion] #701 lists `MakeUnique` among the instructions to handle; it is deferred, documented and consistent with the eager `clone()`. Make sure the slice 4 issue carries it explicitly.
argus merged commit 950140cdd7 into main 2026-10-30 22:10:42 +00:00
argus deleted branch loop/701-js-witnesses-close 2026-10-30 22:10:42 +00:00
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!703
No description provided.