Skip to content

Commit 3ac5a49

Browse files
authored
Newtype oparg align methods (RustPython#7403)
* Align methods for newtype opargs
1 parent 1755a31 commit 3ac5a49

6 files changed

Lines changed: 171 additions & 236 deletions

File tree

crates/codegen/src/ir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl CodeInfo {
342342
}
343343
}
344344

345-
let mut block_to_offset = vec![Label(0); blocks.len()];
345+
let mut block_to_offset = vec![Label::new(0); blocks.len()];
346346
// block_to_index: maps block idx to instruction index (for exception table)
347347
// This is the index into the final instructions array, including EXTENDED_ARG and CACHE
348348
let mut block_to_index = vec![0u32; blocks.len()];
@@ -351,7 +351,7 @@ impl CodeInfo {
351351
loop {
352352
let mut num_instructions = 0;
353353
for (idx, block) in iter_blocks(&blocks) {
354-
block_to_offset[idx.idx()] = Label(num_instructions as u32);
354+
block_to_offset[idx.idx()] = Label::new(num_instructions as u32);
355355
// block_to_index uses the same value as block_to_offset but as u32
356356
// because lasti in frame.rs is the index into instructions array
357357
// and instructions array index == byte offset (each instruction is 1 CodeUnit)
@@ -369,7 +369,7 @@ impl CodeInfo {
369369
while next_block != BlockIdx::NULL {
370370
let block = &mut blocks[next_block];
371371
// Track current instruction offset for jump direction resolution
372-
let mut current_offset = block_to_offset[next_block.idx()].0;
372+
let mut current_offset = block_to_offset[next_block.idx()].as_u32();
373373
for info in &mut block.instructions {
374374
let target = info.target;
375375
let mut op = info.instr.expect_real();
@@ -380,7 +380,7 @@ impl CodeInfo {
380380
let offset_after = current_offset + old_arg_size as u32 + old_cache_entries;
381381

382382
if target != BlockIdx::NULL {
383-
let target_offset = block_to_offset[target.idx()].0;
383+
let target_offset = block_to_offset[target.idx()].as_u32();
384384
// Direction must be based on concrete instruction offsets.
385385
// Empty blocks can share offsets, so block-order-based resolution
386386
// may classify some jumps incorrectly.

crates/compiler-core/src/bytecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ impl<C: Constant> CodeObject<C> {
10241024
}
10251025

10261026
// arrow and offset
1027-
let arrow = if label_targets.contains(&Label(offset as u32)) {
1027+
let arrow = if label_targets.contains(&Label::new(offset as u32)) {
10281028
">>"
10291029
} else {
10301030
" "

crates/compiler-core/src/bytecode/instruction.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,13 +1105,7 @@ impl InstructionMetadata for Instruction {
11051105
};
11061106
($variant:ident, $map:ident = $arg_marker:expr) => {{
11071107
let arg = $arg_marker.get(arg);
1108-
write!(
1109-
f,
1110-
"{:pad$}({}, {})",
1111-
stringify!($variant),
1112-
u32::from(arg),
1113-
$map(arg)
1114-
)
1108+
write!(f, "{:pad$}({}, {})", stringify!($variant), arg, $map(arg))
11151109
}};
11161110
($variant:ident, $arg_marker:expr) => {
11171111
write!(f, "{:pad$}({})", stringify!($variant), $arg_marker.get(arg))

0 commit comments

Comments
 (0)