Skip to content

fix: do not update last_opcode_pos when emitting OP_debug#3

Merged
G-Yong merged 1 commit intomasterfrom
fix/op-debug-last-opcode-pos
Apr 2, 2026
Merged

fix: do not update last_opcode_pos when emitting OP_debug#3
G-Yong merged 1 commit intomasterfrom
fix/op-debug-last-opcode-pos

Conversation

@G-Yong
Copy link
Copy Markdown
Owner

@G-Yong G-Yong commented Apr 2, 2026

OP_debug is a transparent no-op (0 pop, 0 push) used solely for debugger breakpoints. The previous code in emit_source_loc() set last_opcode_pos to point at OP_debug:

fd->last_opcode_pos = bc->size;  // ← pointed at OP_debug
dbuf_putc(bc, OP_debug);

This breaks all peephole optimizations that rely on get_prev_opcode(), because they see OP_debug instead of the real preceding opcode.

Affected code paths

Function Impact
js_is_live_code() Misidentifies dead code as live (OP_debug doesn't match any terminal opcode)
set_object_name() Fails to match OP_set_name / OP_set_class_name, skips name assignment
set_object_name_computed() Same as above for computed names
lvalue parsing (js_parse_unary) Falls into default → "invalid lvalue" error

This caused CI test failures when OP_debug was always emitted (after removing the emit_debug flag).

Fix

Remove fd->last_opcode_pos = bc->size; from emit_source_loc(), making OP_debug transparent to the peephole optimizer — just like OP_source_loc already is. Neither opcode updates last_opcode_pos.

OP_debug is a transparent no-op (0 pop, 0 push) used solely for
debugger breakpoints. Setting last_opcode_pos to point at OP_debug
breaks all peephole optimizations that rely on get_prev_opcode(),
because they see OP_debug instead of the real preceding opcode.

Affected code paths include:
- js_is_live_code(): misidentifies dead code as live
- set_object_name(): fails to match OP_set_name / OP_set_class_name
- lvalue parsing: falls into the default (invalid lvalue) branch
- set_object_name_computed(): fails to rewrite opcodes

This caused CI test failures when OP_debug was always emitted.

Fix: stop updating last_opcode_pos in emit_source_loc(), making
OP_debug transparent to the peephole optimizer, just like
OP_source_loc already is.
@G-Yong G-Yong merged commit 4d34848 into master Apr 2, 2026
120 of 121 checks passed
@G-Yong G-Yong deleted the fix/op-debug-last-opcode-pos branch April 2, 2026 06:17
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