Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Split stack_effect into pushed & popped
  • Loading branch information
ShaharNaveh committed Jan 29, 2026
commit 52b65a88a092d245890f8a3c4cecc130834a0692
8 changes: 3 additions & 5 deletions crates/codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustpython_compiler_core::{
bytecode::{
AnyInstruction, Arg, CodeFlags, CodeObject, CodeUnit, CodeUnits, ConstantData,
ExceptionTableEntry, InstrDisplayContext, Instruction, InstructionMetadata, Label, OpArg,
PseudoInstruction, PyCodeLocationInfoKind, encode_exception_table,
PseudoInstruction, PyCodeLocationInfoKind, StackEffect, encode_exception_table,
},
varint::{write_signed_varint, write_varint},
};
Expand Down Expand Up @@ -697,8 +697,6 @@ impl CodeInfo {
/// This is a reference counting optimization in CPython; in RustPython
/// we implement it for bytecode compatibility.
fn optimize_load_fast_borrow(&mut self) {
use rustpython_compiler_core::bytecode::InstructionMetadata;

// NOT_LOCAL marker: instruction didn't come from a LOAD_FAST
const NOT_LOCAL: usize = usize::MAX;

Expand Down Expand Up @@ -733,7 +731,7 @@ impl CodeInfo {
// is pop 2 push 1, not pop 1 push 0). We list those explicitly;
// the fallback under-pops and under-pushes, which is conservative
// (may miss optimisation opportunities but never miscompiles).
let effect = instr.stack_effect(info.arg);
let effect = instr.stack_effect(u32::from(info.arg) as i32);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
let (pops, pushes) = match instr {
// --- pop 2, push 1 ---
Instruction::BinaryOp { .. }
Expand Down Expand Up @@ -866,7 +864,7 @@ impl CodeInfo {
let block = &self.blocks[block_idx];
for ins in &block.instructions {
let instr = &ins.instr;
let effect = instr.stack_effect(ins.arg);
let effect = instr.stack_effect(u32::from(ins.arg) as i32);
if DEBUG {
let display_arg = if ins.target == BlockIdx::NULL {
ins.arg
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler-core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustpython_wtf8::{Wtf8, Wtf8Buf};

pub use crate::bytecode::{
instruction::{
AnyInstruction, Arg, Instruction, InstructionMetadata, PseudoInstruction,
AnyInstruction, Arg, Instruction, InstructionMetadata, PseudoInstruction, StackEffect,
decode_load_attr_arg, decode_load_super_attr_arg, encode_load_attr_arg,
encode_load_super_attr_arg,
},
Expand Down
Loading
Loading