BoundaryML/baml · critical

expected jump instruction at index {instruction_idx}

Error message

expected jump instruction at index {instruction_idx}

What it means

Panic in the jump-patching helper: after computing a jump offset, the instruction at instruction_idx in the bytecode array is not one of the recognized jump variants, so the replacement match falls through to a panic. This means the emitter patched an index that no longer holds a placeholder jump instruction — typically index drift between where a jump was emitted and where it is patched.

Source

Thrown at baml_language/crates/baml_compiler2_emit/src/emit.rs:2770

                self.bytecode.instructions[instruction_idx] = Instruction::PopJumpIfFalse(offset);
            }
            Instruction::JumpIfFalse(_) => {
                self.bytecode.instructions[instruction_idx] = Instruction::JumpIfFalse(offset);
            }
            Instruction::PopJumpIfTrue(_) => {
                self.bytecode.instructions[instruction_idx] = Instruction::PopJumpIfTrue(offset);
            }
            Instruction::JumpIfFalseOrPop(_) => {
                self.bytecode.instructions[instruction_idx] = Instruction::JumpIfFalseOrPop(offset);
            }
            Instruction::JumpIfTrueOrPop(_) => {
                self.bytecode.instructions[instruction_idx] = Instruction::JumpIfTrueOrPop(offset);
            }
            Instruction::JumpIfNotNullOrPop(_) => {
                self.bytecode.instructions[instruction_idx] =
                    Instruction::JumpIfNotNullOrPop(offset);
            }
            _ => panic!("expected jump instruction at index {instruction_idx}"),
        }
    }

    /// Patch all pending jump tables with actual offsets.
    #[allow(clippy::cast_possible_wrap)]
    fn patch_jump_tables(&mut self) {
        for pending in std::mem::take(&mut self.pending_jump_tables) {
            let jump_table_pc = pending.jump_table_pc;
            let mut table = pending.table;

            // Patch each arm's offset
            for (value, target) in &pending.arms {
                let target_pc = self.resolve_pending_target_pc(*target);
                let offset = target_pc as isize - jump_table_pc as isize;
                table.set(*value, offset);
            }

            // Patch default offset

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Update the patch routine's match arms to include the new jump instruction variant that was emitted.
  2. Ensure every instruction insertion/emission keeps recorded jump indices in sync with the bytecode array.
  3. Verify which instruction actually sits at instruction_idx when the panic fires and fix the emitter bookkeeping accordingly.
  4. Report the reproducible BAML source as a compiler bug.

Example fix

// before: match missing the new variant
_ => panic!("expected jump instruction at index {instruction_idx}"),
// after: handle the variant
Instruction::JumpIfFalseOrPop(_) => {
    self.bytecode.instructions[instruction_idx] = Instruction::JumpIfFalseOrPop(offset);
}
Defensive patterns

Strategy: validation

Validate before calling

fn is_jump_instruction(inst: &Instruction) -> bool {
    matches!(inst,
        Instruction::Jump(_) | Instruction::JumpIfTrueOrPop(_) |
        Instruction::JumpIfFalseOrPop(_) | Instruction::JumpIfNotNullOrPop(_))
}

Try / catch

// compiler panic — catch at the build-tool boundary
match baml_cli_compile(file) {
    Err(_) => report_bug_with_minimal_repro(),
    Ok(_) => {}
}

Prevention

When it happens

Trigger: Calling the patch routine with an instruction_idx whose bytecode slot holds a non-jump instruction, e.g. after another pass inserted or reordered instructions without updating recorded jump indices.

Common situations: Compiler development scenario: adding a new Instruction variant or an emitting step that shifts instructions, leaving stale patch indices.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/42e1e13be5d5d235. Report an issue: GitHub.