From 51ba230b75cae5ef2cd95a06b04c8b1f57d45960 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Thu, 12 Mar 2026 12:27:34 +0100 Subject: [PATCH 1/3] Align methods for newtype opargs --- crates/codegen/src/ir.rs | 8 +- crates/compiler-core/src/bytecode.rs | 2 +- crates/compiler-core/src/bytecode/oparg.rs | 339 +++++++++------------ crates/vm/src/frame.rs | 44 +-- 4 files changed, 167 insertions(+), 226 deletions(-) diff --git a/crates/codegen/src/ir.rs b/crates/codegen/src/ir.rs index 8d5fbdb8bd..67c60dd561 100644 --- a/crates/codegen/src/ir.rs +++ b/crates/codegen/src/ir.rs @@ -342,7 +342,7 @@ impl CodeInfo { } } - let mut block_to_offset = vec![Label(0); blocks.len()]; + let mut block_to_offset = vec![Label::new(0); blocks.len()]; // block_to_index: maps block idx to instruction index (for exception table) // This is the index into the final instructions array, including EXTENDED_ARG and CACHE let mut block_to_index = vec![0u32; blocks.len()]; @@ -351,7 +351,7 @@ impl CodeInfo { loop { let mut num_instructions = 0; for (idx, block) in iter_blocks(&blocks) { - block_to_offset[idx.idx()] = Label(num_instructions as u32); + block_to_offset[idx.idx()] = Label::new(num_instructions as u32); // block_to_index uses the same value as block_to_offset but as u32 // because lasti in frame.rs is the index into instructions array // and instructions array index == byte offset (each instruction is 1 CodeUnit) @@ -369,7 +369,7 @@ impl CodeInfo { while next_block != BlockIdx::NULL { let block = &mut blocks[next_block]; // Track current instruction offset for jump direction resolution - let mut current_offset = block_to_offset[next_block.idx()].0; + let mut current_offset = block_to_offset[next_block.idx()].as_u32(); for info in &mut block.instructions { let target = info.target; let mut op = info.instr.expect_real(); @@ -380,7 +380,7 @@ impl CodeInfo { let offset_after = current_offset + old_arg_size as u32 + old_cache_entries; if target != BlockIdx::NULL { - let target_offset = block_to_offset[target.idx()].0; + let target_offset = block_to_offset[target.idx()].as_u32(); // Direction must be based on concrete instruction offsets. // Empty blocks can share offsets, so block-order-based resolution // may classify some jumps incorrectly. diff --git a/crates/compiler-core/src/bytecode.rs b/crates/compiler-core/src/bytecode.rs index 80cf01bc02..169d4e8e53 100644 --- a/crates/compiler-core/src/bytecode.rs +++ b/crates/compiler-core/src/bytecode.rs @@ -1024,7 +1024,7 @@ impl CodeObject { } // arrow and offset - let arrow = if label_targets.contains(&Label(offset as u32)) { + let arrow = if label_targets.contains(&Label::new(offset as u32)) { ">>" } else { " " diff --git a/crates/compiler-core/src/bytecode/oparg.rs b/crates/compiler-core/src/bytecode/oparg.rs index 2cb7921312..b73ea1e89e 100644 --- a/crates/compiler-core/src/bytecode/oparg.rs +++ b/crates/compiler-core/src/bytecode/oparg.rs @@ -293,77 +293,6 @@ pub type NameIdx = u32; impl OpArgType for u32 {} -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] -#[repr(transparent)] -pub struct Label(pub u32); - -impl Label { - pub const fn new(value: u32) -> Self { - Self(value) - } -} - -impl From for Label { - fn from(value: u32) -> Self { - Self::new(value) - } -} - -impl From