Register VM opcode handlers on first use instead of at module load - #21584
Draft
NullVoxPopuli-ai-agent wants to merge 1 commit into
Draft
Register VM opcode handlers on first use instead of at module load#21584NullVoxPopuli-ai-agent wants to merge 1 commit into
NullVoxPopuli-ai-agent wants to merge 1 commit into
Conversation
NullVoxPopuli-ai-agent
force-pushed
the
nvp/opcodes-1-runtime-handlers
branch
2 times, most recently
from
August 31, 2026 00:19
fdc4a6d to
529c7fc
Compare
Each syscall handler in `runtime/lib/compiled/opcodes/` is now a named
export that carries its opcode number: `syscall(VM_X_OP, fn)` returns
`{ type, evaluate }` and registers nothing. The compile-time code in
`opcode-compiler` pushes the handler object instead of the bare number,
and `encodeOp` registers it in the dispatch table the first time a
template pushes it.
This removes `runtime/lib/bootstrap.ts`, whose eight side-effect imports
forced every handler into any bundle that used the VM. A bundler can now
drop a handler when no compile-time code that emits it survives
tree-shaking. The `/*#__PURE__*/` annotation on each `syscall(...)` call
is what lets the bundler drop it.
The numeric dispatch table and the int32 heap layout are unchanged. In
DEBUG, an opcode with no registered handler throws with the opcode number
instead of failing inside `unwrap`.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PQyBrSj4CZaqMcKc7aW81
NullVoxPopuli-ai-agent
force-pushed
the
nvp/opcodes-1-runtime-handlers
branch
from
August 31, 2026 02:16
529c7fc to
3e89e1e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 1 of 4 for importable wire format opcodes. Base:
main. Next: NullVoxPopuli-ai-agent#3.Each syscall handler in
runtime/lib/compiled/opcodes/becomes a named export that carries its opcode number.syscall(VM_X_OP, fn)returns{ type, evaluate }and registers nothing. The compile-time code inopcode-compilerpushes the handler object instead of the number, andencodeOpregisters it in the dispatch table on first push.Why:
runtime/lib/bootstrap.tshad eight side-effect imports that put every handler into any bundle that used the VM. With this change a bundler drops a handler when no compile-time code that emits it survives tree-shaking.What does not change:
low-level.ts.How to check:
pnpm type-check:internalspnpm testOutput of
pnpm teston the full stack: 9470 tests, 17 skipped, 0 failures.Context: https://claude.ai/code/artifact/153fb9f5-67b3-44e3-b2d9-d6f2f618f25b
🤖 Generated with Claude Code
https://claude.ai/code/session_017PQyBrSj4CZaqMcKc7aW81