Skip to content

Move DEF(debug) to end of opcode list to preserve opcode numbering#2

Merged
G-Yong merged 3 commits intomasterfrom
copilot/compare-quickjs-atom
Apr 1, 2026
Merged

Move DEF(debug) to end of opcode list to preserve opcode numbering#2
G-Yong merged 3 commits intomasterfrom
copilot/compare-quickjs-atom

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 1, 2026

Inserting DEF(debug, 1, 0, 0, none) at position 1 (after OP_invalid) shifts every subsequent opcode number by +1, invalidating all pre-compiled bytecode files (gen/*.c, builtin-*.h) and causing "invalid atom index" errors at runtime.

  • Move DEF(debug) to end of opcode list — placed after all short opcodes, before temporary def opcodes. No existing opcode values change, so checked-in bytecode files remain valid with no regeneration needed.
  • Revert bytecode regeneration — the prior commits unnecessarily regenerated all bytecode files; reverted to upstream state.

OP_debug is only emitted when a debug context is active (JS_NewDebugContext) and never appears in pre-compiled bytecode, so its numeric position is unconstrained.

// Before: shifts all opcodes by +1
DEF(invalid, 1, 0, 0, none)
DEF(  debug, 1, 0, 0, none)  // position 1
DEF(push_i32, 5, 0, 1, i32)  // now 2 instead of 1 — breaks bytecode

// After: no shift
DEF(typeof_is_function, 1, 1, 1, none)
DEF(  debug, 1, 0, 0, none)  // appended at end

Copilot AI and others added 3 commits April 1, 2026 06:09
The commit 1e05bd7 added OP_debug to quickjs-opcode.h but did not
regenerate the pre-compiled bytecode files. This shifted all opcode
numbers by +1, causing the interpreter to misparse the bytecode
stream and trigger "invalid atom index" errors.

Regenerated all bytecode files using `make codegen` with the updated
qjsc compiler that includes the OP_debug opcode.

Agent-Logs-Url: https://github.com/G-Yong/quickjs/sessions/9ded3eef-eaab-421f-a1d7-0fca19fee48d

Co-authored-by: G-Yong <21030893+G-Yong@users.noreply.github.com>
Instead of inserting OP_debug at position 1 (which shifted all
subsequent opcode numbers and broke pre-compiled bytecode), place
it after all short opcodes at the end of the opcode list.

This way:
- All regular and short opcodes keep their upstream positions
- OP_debug gets a new unique index (246) that doesn't conflict
- Future upstream merges won't cause bytecode incompatibilities
- The codegen check passes with no stale bytecode

Agent-Logs-Url: https://github.com/G-Yong/quickjs/sessions/96e96c96-17d4-40c3-8131-ec6375bb30c8

Co-authored-by: G-Yong <21030893+G-Yong@users.noreply.github.com>
…ode list

Place the new OP_debug opcode after all short opcodes instead of
right after OP_invalid.  Inserting it near the top of the table
shifts every subsequent opcode number by one, which silently
invalidates all pre-compiled bytecode files (gen/*.c, builtin-*.h)
and causes "invalid atom index" errors at runtime.

By appending it at the end of the DEF list (but before the
temporary 'def' opcodes), no existing opcode value changes, so
the checked-in bytecode files remain valid and no regeneration
step is required.

OP_debug is only emitted at compile time when a debug context is
active (JS_NewDebugContext) and never appears in pre-compiled
bytecode, so its exact numeric value is irrelevant to stored
bytecode compatibility.

Agent-Logs-Url: https://github.com/G-Yong/quickjs/sessions/33150476-2312-48c9-98b4-113ff7039512

Co-authored-by: G-Yong <21030893+G-Yong@users.noreply.github.com>
@G-Yong G-Yong marked this pull request as ready for review April 1, 2026 06:44
@G-Yong G-Yong merged commit 793ced2 into master Apr 1, 2026
@G-Yong G-Yong deleted the copilot/compare-quickjs-atom branch April 1, 2026 06:44
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.

2 participants