feat(vm): count a one-pointer retain or release in the loop (#164) #305

Merged
argus merged 1 commit from loop/164-retain-release-instruction into main 2026-10-10 13:47:49 +00:00
Collaborator

Part 2 of #164, now that the published seed torb-seed-5f22f071d02f (nightly-20261010) knows Machine.countUp/Machine.countDown from part 1 (d43017cd, PR #239).

What

  • Emitter (compiler/src/backend/bytecode/emit.trb, countedPointerOf): a kernel retain / kernel release whose value shape is one counted word that holds its block (no inline variant, no nested variant) carries B = register of that word and C = 1 (retain) / 2 (release) in the head. Every other kernel instruction keeps B = C = 0, so older program text runs as before and the format stays torb-bytecode-1.
  • Loop (compiler/src/vm/interpret.trb, .Kernel arm): C == 1 tries Machine.countUp, C == 2 tries Machine.countDown on the register's word and skips the tail when the native did the whole work; otherwise the kernel call runs exactly as today (shared block, last count with destructor, count of zero, open sandbox).
  • Test (compiler/tests/bytecode.test.trb): every retain/release of a one-pointer shape is marked with its register and direction, an inline variant's is not.
  • Docs: VM.md section 7 (new bullet) and section 10 (the step is in), PERFORMANCE.md 9.12 (option taken).

Measurement

This is the code measured as the "natives" form in PERFORMANCE.md 9.12 (run 419, reference commit e6468e2d on loop/164-measure2): chain-walk 1.16x faster, list-iterate 1.06x, map-count 1.02x, fibonacci/cons-stack/closures level. Numbers for VM.md section 8 are carried by #165.

Closes #164

Part 2 of #164, now that the published seed torb-seed-5f22f071d02f (nightly-20261010) knows `Machine.countUp`/`Machine.countDown` from part 1 (d43017cd, PR #239). ## What - **Emitter** (`compiler/src/backend/bytecode/emit.trb`, `countedPointerOf`): a `kernel retain` / `kernel release` whose value shape is one counted word that holds its block (no inline variant, no nested variant) carries `B` = register of that word and `C` = 1 (retain) / 2 (release) in the head. Every other kernel instruction keeps `B = C = 0`, so older program text runs as before and the format stays `torb-bytecode-1`. - **Loop** (`compiler/src/vm/interpret.trb`, `.Kernel` arm): `C == 1` tries `Machine.countUp`, `C == 2` tries `Machine.countDown` on the register's word and skips the tail when the native did the whole work; otherwise the kernel call runs exactly as today (shared block, last count with destructor, count of zero, open sandbox). - **Test** (`compiler/tests/bytecode.test.trb`): every retain/release of a one-pointer shape is marked with its register and direction, an inline variant's is not. - **Docs**: VM.md section 7 (new bullet) and section 10 (the step is in), PERFORMANCE.md 9.12 (option taken). ## Measurement This is the code measured as the "natives" form in PERFORMANCE.md 9.12 (run 419, reference commit e6468e2d on `loop/164-measure2`): `chain-walk` 1.16x faster, `list-iterate` 1.06x, `map-count` 1.02x, fibonacci/cons-stack/closures level. Numbers for VM.md section 8 are carried by #165. Closes #164
feat(vm): count a one-pointer retain or release in the loop (#164)
Some checks failed
ci / commit messages (pull_request) Successful in 6s
ci / what the change touches (pull_request) Successful in 7s
pdisc / pdisc (pull_request) Successful in 9s
ci / gates (pull_request) Has been cancelled
ci / which runners exist (pull_request) Has been cancelled
ci / bootstrap (linux-x64) (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
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
ci / bootstrap and conformance (windows-x64) (pull_request) Has been cancelled
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been cancelled
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the VS Code extension (editors/vscode) (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
d2bcebcd03
orion requested review from argus 2026-10-10 09:45:09 +00:00
orion force-pushed loop/164-retain-release-instruction from d2bcebcd03
Some checks failed
ci / commit messages (pull_request) Successful in 6s
ci / what the change touches (pull_request) Successful in 7s
pdisc / pdisc (pull_request) Successful in 9s
ci / gates (pull_request) Has been cancelled
ci / which runners exist (pull_request) Has been cancelled
ci / bootstrap (linux-x64) (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
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
ci / bootstrap and conformance (windows-x64) (pull_request) Has been cancelled
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been cancelled
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the VS Code extension (editors/vscode) (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
to e75be78ca5
Some checks failed
ci / commit messages (pull_request) Successful in 4s
ci / what the change touches (pull_request) Successful in 4s
pdisc / pdisc (pull_request) Successful in 10s
ci / gates (pull_request) Has been cancelled
ci / which runners exist (pull_request) Has been cancelled
ci / bootstrap (linux-x64) (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
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
ci / bootstrap and conformance (windows-x64) (pull_request) Has been cancelled
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been cancelled
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the VS Code extension (editors/vscode) (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
2026-10-10 10:11:07 +00:00
Compare
test(vm): pin the head marks of a one-pointer retain (#164)
Some checks failed
ci / commit messages (pull_request) Has been cancelled
ci / what the change touches (pull_request) Has been cancelled
ci / gates (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
9e2b8c62aa
orion force-pushed loop/164-retain-release-instruction from 9e2b8c62aa
Some checks failed
ci / commit messages (pull_request) Has been cancelled
ci / what the change touches (pull_request) Has been cancelled
ci / gates (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
to b76eaeab17
Some checks failed
ci / commit messages (pull_request) Successful in 3s
ci / what the change touches (pull_request) Successful in 3s
ci / gates (pull_request) Has been cancelled
ci / which runners exist (pull_request) Has been cancelled
ci / bootstrap (linux-x64) (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
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
ci / bootstrap and conformance (windows-x64) (pull_request) Has been cancelled
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been cancelled
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the VS Code extension (editors/vscode) (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
2026-10-10 10:33:42 +00:00
Compare
orion force-pushed loop/164-retain-release-instruction from b76eaeab17
Some checks failed
ci / commit messages (pull_request) Successful in 3s
ci / what the change touches (pull_request) Successful in 3s
ci / gates (pull_request) Has been cancelled
ci / which runners exist (pull_request) Has been cancelled
ci / bootstrap (linux-x64) (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
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
ci / bootstrap and conformance (windows-x64) (pull_request) Has been cancelled
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been cancelled
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the VS Code extension (editors/vscode) (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
to 5790cc3086
Some checks failed
ci / commit messages (pull_request) Successful in 6s
ci / what the change touches (pull_request) Successful in 5s
pdisc / pdisc (pull_request) Successful in 10s
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 / the VS Code extension (editors/vscode) (pull_request) Successful in 16s
ci / bootstrap (linux-x64) (pull_request) Successful in 5m8s
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 A (linux-x64) (pull_request) Failing after 3m49s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 1m29s
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
2026-10-10 10:39:05 +00:00
Compare
orion force-pushed loop/164-retain-release-instruction from 5790cc3086
Some checks failed
ci / commit messages (pull_request) Successful in 6s
ci / what the change touches (pull_request) Successful in 5s
pdisc / pdisc (pull_request) Successful in 10s
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 / the VS Code extension (editors/vscode) (pull_request) Successful in 16s
ci / bootstrap (linux-x64) (pull_request) Successful in 5m8s
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 A (linux-x64) (pull_request) Failing after 3m49s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 1m29s
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
to 141d0aee2d
Some checks failed
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 6s
pdisc / pdisc (pull_request) Successful in 9s
ci / which runners exist (pull_request) Successful in 0s
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 / the VS Code extension (editors/vscode) (pull_request) Successful in 13s
ci / bootstrap (linux-x64) (pull_request) Successful in 4m57s
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 A (linux-x64) (pull_request) Successful in 3m50s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Failing after 1m50s
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
2026-10-10 11:42:02 +00:00
Compare
orion force-pushed loop/164-retain-release-instruction from 141d0aee2d
Some checks failed
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 6s
pdisc / pdisc (pull_request) Successful in 9s
ci / which runners exist (pull_request) Successful in 0s
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 / the VS Code extension (editors/vscode) (pull_request) Successful in 13s
ci / bootstrap (linux-x64) (pull_request) Successful in 4m57s
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 A (linux-x64) (pull_request) Successful in 3m50s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Failing after 1m50s
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
to b4a6ba9107
All checks were successful
ci / commit messages (pull_request) Successful in 7s
ci / what the change touches (pull_request) Successful in 5s
pdisc / pdisc (pull_request) Successful in 8s
ci / which runners exist (pull_request) Successful in 2s
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 2m0s
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 / the VS Code extension (editors/vscode) (pull_request) Successful in 13s
ci / tier A (linux-x64) (pull_request) Successful in 3m49s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 1m31s
ci / every host emits the same C (pull_request) Successful in 4m20s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 1m47s
ci / tier B (linux-x64) (pull_request) Successful in 11m18s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
2026-10-10 12:52:04 +00:00
Compare
argus approved these changes 2026-10-10 13:47:47 +00:00
argus left a comment

Approved at b4a6ba91. CI green on this head (bootstrap, tier A/B, conformance, pdisc, C parity).

  • Tests: ok - the new bytecode test pins the mark for a one-pointer retain ((6, 6, 1)) and the zero mark for an inline variant's field read; the loop path is exercised by tier A/B and the leak gate.
  • Correctness: ok - countedPointerOf mirrors the kernel's retain/release (torb_machine_retain_group: first word, only Nested excluded), pointer is range-checked against largestOperand, and the loop falls back to the kernel on every false (shared, last count, zero count, open sandbox), so destructor queue and live-block counter see what they saw. Skipping the tail with pc + 1 + a matches the kernel arm.
  • Format/compat: ok - B/C were unused (0) for Kernel, older program text still runs through the kernel, torb-bytecode-1 unchanged.
  • Scope: ok - exactly part 2 of #164.
  • Security/data: ok - no new permissions, deps or storage formats.
  • Docs: ok - VM.md 7/10 and PERFORMANCE.md 9.12 updated; pdisc green.

Non-blocking:

  • [suggestion] The test only asserts the retain side (retainsOf filters on Retain); the release mark (C = 2) has no direct assertion. A one-line extension to Release would pin it in the format test as well.
Approved at b4a6ba91. CI green on this head (bootstrap, tier A/B, conformance, pdisc, C parity). - Tests: ok - the new bytecode test pins the mark for a one-pointer retain (`(6, 6, 1)`) and the zero mark for an inline variant's field read; the loop path is exercised by tier A/B and the leak gate. - Correctness: ok - `countedPointerOf` mirrors the kernel's retain/release (`torb_machine_retain_group`: first word, only `Nested` excluded), `pointer` is range-checked against `largestOperand`, and the loop falls back to the kernel on every `false` (shared, last count, zero count, open sandbox), so destructor queue and live-block counter see what they saw. Skipping the tail with `pc + 1 + a` matches the kernel arm. - Format/compat: ok - `B`/`C` were unused (0) for `Kernel`, older program text still runs through the kernel, `torb-bytecode-1` unchanged. - Scope: ok - exactly part 2 of #164. - Security/data: ok - no new permissions, deps or storage formats. - Docs: ok - VM.md 7/10 and PERFORMANCE.md 9.12 updated; pdisc green. Non-blocking: - [suggestion] The test only asserts the retain side (`retainsOf` filters on `Retain`); the release mark (`C` = 2) has no direct assertion. A one-line extension to `Release` would pin it in the format test as well.
argus merged commit d1710631d2 into main 2026-10-10 13:47:49 +00:00
argus deleted branch loop/164-retain-release-instruction 2026-10-10 13:47:50 +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!305
No description provided.