Skip to content

refactor(vm): tidy chunk boundary for optimizer prep 🧹#161

Merged
timfennis merged 2 commits into
masterfrom
housekeeping/optimizer-prep
May 25, 2026
Merged

refactor(vm): tidy chunk boundary for optimizer prep 🧹#161
timfennis merged 2 commits into
masterfrom
housekeeping/optimizer-prep

Conversation

@timfennis
Copy link
Copy Markdown
Owner

Summary

Two small, mechanical refactors that pre-stage the seams a future bytecode optimizer will need, without introducing any optimizer infrastructure or behaviour change.

  • Move patch_jump and write_jump_back out of Chunk into Compiler. Chunk now exposes only the low-level set_jump_offset(idx, JumpOffset) primitive. The policy of "what offset to compute from the current write position" lives in the compiler, where it belongs. Chunk becomes closer to "pure data: instructions + constants + spans" with no compile-time emission protocol baked in.
  • Newtype JumpOffset for jump operands. Replaces raw isize operands on Jump, JumpIfTrue, JumpIfFalse, and IterNext with a JumpOffset newtype. Gives the contract a single definition site so a future representation change (label IDs, basic-block targets) is a localized edit.

(A third item discussed — dropping an unused Stage / PhantomData from Chunk — was uncommitted local WIP and didn't produce a commit; the branch matches master's Chunk shape.)

Test plan

  • cargo build clean
  • cargo test — 389 passed, 0 failed
  • cargo clippy -p ndc_vm --all-targets — no new warnings introduced (baseline 4, after change 4)
  • cargo fmt

🤖 Generated with Claude Code

timfennis and others added 2 commits May 25, 2026 12:52
Chunk now exposes only the low-level `set_jump_offset` primitive; the
policy of "what offset to compute from current write position" lives in
the compiler where it belongs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Wraps the `isize` operand of jump-family opcodes in a `JumpOffset`
newtype so the contract has a single definition site and future
representations (label IDs, basic-block targets) can be slotted in
without touching every call site.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@timfennis timfennis force-pushed the housekeeping/optimizer-prep branch from ea59212 to 2a823ed Compare May 25, 2026 10:52
@timfennis timfennis merged commit d24f60a into master May 25, 2026
1 check passed
@timfennis timfennis deleted the housekeeping/optimizer-prep branch May 25, 2026 12:15
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