Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
fad76c6
save
ShaharNaveh Jan 11, 2026
af70361
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 11, 2026
ea53cec
save
ShaharNaveh Jan 11, 2026
1ca20a9
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 12, 2026
6f09ebe
Base compiler-core
ShaharNaveh Jan 12, 2026
6805175
save
ShaharNaveh Jan 12, 2026
046e17a
Codegen compile
ShaharNaveh Jan 12, 2026
d627623
Move LoadCloure back to RealInstruction
ShaharNaveh Jan 12, 2026
697fe41
Fix opcode.rs
ShaharNaveh Jan 12, 2026
11fc63f
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 13, 2026
33b4554
Fix `TryFrom<u8>` for RealInstruction
ShaharNaveh Jan 13, 2026
6140186
Fix script
ShaharNaveh Jan 13, 2026
7acdc1a
Fix jit
ShaharNaveh Jan 13, 2026
0fad43f
Fix typo
ShaharNaveh Jan 13, 2026
24f5161
Fix typo
ShaharNaveh Jan 13, 2026
6e91410
Remove popblock
ShaharNaveh Jan 13, 2026
8751953
Fix docs
ShaharNaveh Jan 13, 2026
8b73441
Fix more docs
ShaharNaveh Jan 13, 2026
d6e46f8
ok word `argty`
ShaharNaveh Jan 13, 2026
0872cb6
Revert "ok word `argty`"
ShaharNaveh Jan 13, 2026
0c7880d
Rename argty -> arg_ty
ShaharNaveh Jan 13, 2026
1a5c72b
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 13, 2026
761fa4a
Simplify `emit` macro
ShaharNaveh Jan 13, 2026
4eed137
Trigger CI
ShaharNaveh Jan 13, 2026
8f777d2
Trigger CI
ShaharNaveh Jan 13, 2026
bff25eb
Trigger CI
ShaharNaveh Jan 13, 2026
91c01e6
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 14, 2026
f6a0b26
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 14, 2026
118ecf3
Move docs
ShaharNaveh Jan 14, 2026
c517585
Fix oparg docs
ShaharNaveh Jan 14, 2026
78958aa
Revert "Move docs"
ShaharNaveh Jan 14, 2026
a405cca
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 14, 2026
8ae98b2
Remove `Eq` & `ParitalEq` for RealInstruction
ShaharNaveh Jan 14, 2026
1453726
Simplify `match` arms
ShaharNaveh Jan 14, 2026
f207284
Trigger CI
ShaharNaveh Jan 14, 2026
a1555dc
Trigger CI
ShaharNaveh Jan 14, 2026
c443f8e
Remove `repr(u16)` for `Instruction`
ShaharNaveh Jan 14, 2026
453212e
Fix doc
ShaharNaveh Jan 14, 2026
1f8722a
Rename the enums
ShaharNaveh Jan 14, 2026
0096a65
Restore fmt_dis for LoadClousure
ShaharNaveh Jan 14, 2026
045d576
Fix script
ShaharNaveh Jan 14, 2026
b00f81f
Fix commet
ShaharNaveh Jan 14, 2026
4823d17
Merge remote-tracking branch 'upstream/main' into bytecode-pseudo-opc…
ShaharNaveh Jan 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove repr(u16) for Instruction
  • Loading branch information
ShaharNaveh committed Jan 14, 2026
commit c443f8e8c00c24bfc671ab8eb70ff400f8ae756e
1 change: 0 additions & 1 deletion crates/compiler-core/src/bytecode/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,6 @@ impl InstructionMetadata for PseudoInstruction {
}
Comment on lines +881 to +892
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

fmt_dis for PseudoInstruction panics unconditionally.

This unimplemented!() will panic if Instruction::Pseudo is ever formatted via the InstructionMetadata trait (e.g., during debug/disassembly output). Consider providing a minimal implementation or at least using todo!("PseudoInstruction display not yet implemented") for a clearer error message.

Minimal implementation suggestion
     fn fmt_dis(
         &self,
-        _arg: OpArg,
-        _f: &mut fmt::Formatter<'_>,
-        _ctx: &impl InstrDisplayContext,
+        arg: OpArg,
+        f: &mut fmt::Formatter<'_>,
+        _ctx: &impl InstrDisplayContext,
         _expand_code_objects: bool,
-        _pad: usize,
+        pad: usize,
         _level: usize,
     ) -> fmt::Result {
-        unimplemented!()
+        match self {
+            Self::Jump { target } => write!(f, "{:pad$}({})", "JUMP", target.get(arg)),
+            Self::JumpNoInterrupt { target } => write!(f, "{:pad$}({})", "JUMP_NO_INTERRUPT", target.get(arg)),
+            Self::LoadAttrMethod { idx } => write!(f, "{:pad$}({})", "LOAD_ATTR_METHOD", idx.get(arg)),
+            Self::LoadSuperMethod { idx } => write!(f, "{:pad$}({})", "LOAD_SUPER_METHOD", idx.get(arg)),
+            Self::LoadZeroSuperAttr { idx } => write!(f, "{:pad$}({})", "LOAD_ZERO_SUPER_ATTR", idx.get(arg)),
+            Self::LoadZeroSuperMethod { idx } => write!(f, "{:pad$}({})", "LOAD_ZERO_SUPER_METHOD", idx.get(arg)),
+            Self::PopBlock => write!(f, "POP_BLOCK"),
+            _ => write!(f, "PSEUDO_PLACEHOLDER"),
+        }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn fmt_dis(
&self,
_arg: OpArg,
_f: &mut fmt::Formatter<'_>,
_ctx: &impl InstrDisplayContext,
_expand_code_objects: bool,
_pad: usize,
_level: usize,
) -> fmt::Result {
unimplemented!()
}
}
fn fmt_dis(
&self,
arg: OpArg,
f: &mut fmt::Formatter<'_>,
_ctx: &impl InstrDisplayContext,
_expand_code_objects: bool,
pad: usize,
_level: usize,
) -> fmt::Result {
match self {
Self::Jump { target } => write!(f, "{:pad$}({})", "JUMP", target.get(arg)),
Self::JumpNoInterrupt { target } => write!(f, "{:pad$}({})", "JUMP_NO_INTERRUPT", target.get(arg)),
Self::LoadAttrMethod { idx } => write!(f, "{:pad$}({})", "LOAD_ATTR_METHOD", idx.get(arg)),
Self::LoadSuperMethod { idx } => write!(f, "{:pad$}({})", "LOAD_SUPER_METHOD", idx.get(arg)),
Self::LoadZeroSuperAttr { idx } => write!(f, "{:pad$}({})", "LOAD_ZERO_SUPER_ATTR", idx.get(arg)),
Self::LoadZeroSuperMethod { idx } => write!(f, "{:pad$}({})", "LOAD_ZERO_SUPER_METHOD", idx.get(arg)),
Self::PopBlock => write!(f, "POP_BLOCK"),
_ => write!(f, "PSEUDO_PLACEHOLDER"),
}
}
}
🤖 Prompt for AI Agents
In `@crates/compiler-core/src/bytecode/instruction.rs` around lines 893 - 904, The
fmt_dis implementation for PseudoInstruction currently calls unimplemented!()
and will panic if Instruction::Pseudo is ever formatted via InstructionMetadata;
replace the panic with a defensive implementation (or at minimum a clearer
todo!) by updating the fmt_dis method on the
PseudoInstruction/Instruction::Pseudo branch: either call
todo!("PseudoInstruction display not yet implemented") to provide a clearer
error or implement a minimal formatter that writes a placeholder string (e.g.,
the pseudo opcode name and any relevant fields) to the provided fmt::Formatter,
respecting the signature of fmt_dis and using the
_ctx/_expand_code_objects/_pad/_level params as no-ops if not needed. Ensure the
change is made in the fmt_dis function so formatting of Instruction::Pseudo no
longer panics.


#[derive(Clone, Copy, Debug)]
#[repr(u16)]
pub enum Instruction {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this type fit in u16? Otherwise union could be better

Copy link
Copy Markdown
Contributor Author

@ShaharNaveh ShaharNaveh Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ain't sure what you mean, could you please explain?

And yes, this type fit in a u16 it can hold a RealInstruction (u8) or a PseudoInstruction (u16)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add #[repr(u16)] or static_assertions::assert_eq_size to ensure compiler actually recognize it or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to add #[repr(u16)], but core::mem::size_of::<Instruction>() gives 4.
Why do we care about the the size of Instruction? It's not intended to be marshaled directly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you are right! I didn't catch that.
Still union looks more fit than Instruction because they are just separated types sharing a same space. Will that be too much painful to use union than enum for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you are right! I didn't catch that. Still union looks more fit than Instruction because they are just separated types sharing a same space. Will that be too much painful to use union than enum for this?

IMO yes it will. And we wouldn't gain a lot from it tbh as the instruction loop will only have RealInstruction anyway (which is what we had until now)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to remove the #[repr(u16)] so the compiler can have some further optimizations?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, if this is only used by compiler anyway, probably that could be better idea.

I was originally thinking

union Instruction {
    real: RealInstruction,
    pseudo: PseudoInstruction,
    raw: u16,
}

impl Instruction {
    fn real(&self) -> Option<RealInstruction> {
        if self.raw < ... { 
            Some(...)
        } else {
             ...
        }
    }
}

btw, if The pseudo instruction is only used for compiler, vm only will have RealInstruction. That looks a bit awkward. How about keeping the RealInstruction name as Instruction, and the wrapper as AnyInstruction?

enum AnyInstruction {
    Real(Instruction),
    Pseudo(PseudoInstruction),
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, if this is only used by compiler anyway, probably that could be better idea.

I was originally thinking

union Instruction {
    real: RealInstruction,
    pseudo: PseudoInstruction,
    raw: u16,
}

impl Instruction {
    fn real(&self) -> Option<RealInstruction> {
        if self.raw < ... { 
            Some(...)
        } else {
             ...
        }
    }
}

While it's cool (and doable) I don't think we will gain much from doing that.

btw, if The pseudo instruction is only used for compiler, vm only will have RealInstruction. That looks a bit awkward. How about keeping the RealInstruction name as Instruction, and the wrapper as AnyInstruction?

enum AnyInstruction {
    Real(Instruction),
    Pseudo(PseudoInstruction),
}

Sure, I can do that

Real(RealInstruction),
Pseudo(PseudoInstruction),
Expand Down
Loading