Skip to content

feat(bytecode): coverage guard + drop dead :set_global opcode - #362

Merged
davydog187 merged 1 commit into
mainfrom
vm/dispatcher-coverage-guard
Jun 14, 2026
Merged

davydog187 merged 1 commit into
mainfrom
vm/dispatcher-coverage-guard

Conversation

@davydog187

Copy link
Copy Markdown
Contributor

Context

First of three PRs driving the bytecode Dispatcher to 100% opcode coverage so no prototype silently falls back to the interpreter. This PR establishes the invariant the rest of the work defends, and clears one dead-code gap.

The two remaining coverage gaps were :goto/:label (real, ported in the next PR) and :set_global (dead). This PR handles the guard + the dead one.

What changed

  • Bytecode.fully_compiled?/1 — walks the prototype tree, returns true iff every prototype carries a bytecode encoding. The guard against a prototype quietly reverting to the interpreter.
  • Coverage corpus test — 14 programs spanning every covered opcode family (arithmetic, comparison/branch, recursion, bitwise, tables, all four loop forms, break, closures/upvalues, varargs/multi-return, method calls, concat) assert fully_compiled?/1. One test pins goto/label as the only documented exception — this flips in PR 3.
  • Removed the dead :set_global opcode — builder (Instruction.set_global/2) + executor handler. Modern codegen emits :set_field on _ENV for free-name assignment (Plan A16) and never produces :set_global. Confirmed zero emitters repo-wide. State.set_global/3 (the runtime globals API) is unrelated and untouched.

Verification

  • mix test test/lua/compiler/bytecode_test.exs — 39 pass
  • mix test test/lua/vm test/lua/compiler — 1295 pass, 4 skipped
  • mix format --check-formatted clean

Follow-ups

  • PR 2: :goto/:label via the label-map strategy (encoder label-resolution + dispatcher unwind_blocks).
  • PR 3: flip the coverage guard to strict (goto programs expected to compile).

…code

Adds `Bytecode.fully_compiled?/1`, which walks the prototype tree and
returns true iff every prototype carries a bytecode encoding — a guard
against a prototype silently falling back to the interpreter. A new
coverage corpus pins that every covered opcode family compiles
end-to-end, with `:goto` / `:label` documented as the one remaining
exception.

Removes the `:set_global` opcode (builder + executor handler). Modern
codegen emits `:set_field` on `_ENV` for free-name assignment (Plan A16)
and never produces `:set_global`; it was dead code. `State.set_global/3`,
the runtime globals API, is unaffected.
@davydog187
davydog187 merged commit dd2850e into main Jun 14, 2026
5 checks passed
@davydog187
davydog187 deleted the vm/dispatcher-coverage-guard branch June 14, 2026 16:21
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