Visitar URL original
Bytecode oparg optimization by ShaharNaveh · Pull Request #7032 · RustPython/RustPython · GitHub
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
Prev Previous commit
Next Next commit
Don't use as u32
  • Loading branch information
ShaharNaveh committed Feb 6, 2026
commit d2c98f0991015ba54803dca32a883bf197c53d80
12 changes: 6 additions & 6 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ impl Compiler {
arg: OpArgMarker::marker(),
}
.into(),
arg: OpArg(bytecode::ResumeType::AtFuncStart as u32),
arg: OpArg(u32::from(bytecode::ResumeType::AtFuncStart)),
target: BlockIdx::NULL,
location,
end_location,
Expand Down Expand Up @@ -6555,9 +6555,9 @@ impl Compiler {
self,
Instruction::Resume {
arg: if is_await {
bytecode::ResumeType::AfterAwait as u32
u32::from(bytecode::ResumeType::AfterAwait)
} else {
bytecode::ResumeType::AfterYieldFrom as u32
u32::from(bytecode::ResumeType::AfterYieldFrom)
}
}
);
Expand Down Expand Up @@ -6710,7 +6710,7 @@ impl Compiler {
emit!(
self,
Instruction::Resume {
arg: bytecode::ResumeType::AfterYield as u32
arg: u32::from(bytecode::ResumeType::AfterYield)
}
);
}
Expand Down Expand Up @@ -6932,7 +6932,7 @@ impl Compiler {
emit!(
compiler,
Instruction::Resume {
arg: bytecode::ResumeType::AfterYield as u32
arg: u32::from(bytecode::ResumeType::AfterYield)
}
);
emit!(compiler, Instruction::PopTop);
Expand Down Expand Up @@ -8420,7 +8420,7 @@ impl Compiler {

// Emit BUILD_INTERPOLATION
// oparg encoding: (conversion << 2) | has_format_spec
let oparg = (conversion << 2) | (has_format_spec as u32);
let oparg = (conversion << 2) | u32::from(has_format_spec);
emit!(self, Instruction::BuildInterpolation { oparg });

*interp_count += 1;
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler-core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ bitflags! {
}
}

#[derive(Copy, Clone)]
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct CodeUnit {
pub op: Instruction,
pub arg: OpArgByte,
Expand All @@ -330,7 +330,7 @@ impl TryFrom<&[u8]> for CodeUnit {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct CodeUnits(Box<[CodeUnit]>);

impl TryFrom<&[u8]> for CodeUnits {
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler-core/src/bytecode/oparg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ macro_rules! impl_oparg_enum {

impl OpArgType for $name {}

const _: () = assert!(::core::mem::size_of::<$name>() == ::core::mem::size_of::<u8>());
// const _: () = assert!(::core::mem::size_of::<$name>() == ::core::mem::size_of::<u8>());
};
}

Expand Down