LoadClassDeref -> LoadFromDictOrDeref (#6692)

This commit is contained in:
Shahar Naveh
2026-01-10 16:16:11 +02:00
committed by GitHub
parent a400386774
commit 6ff7b3ed27
5 changed files with 34 additions and 11 deletions

View File

@@ -136,7 +136,6 @@ opmap = {
'JUMP_IF_FALSE_OR_POP': 129,
'JUMP_IF_TRUE_OR_POP': 130,
'JUMP_IF_NOT_EXC_MATCH': 131,
'LOAD_CLASS_DEREF': 132,
'SET_EXC_INFO': 134,
'SUBSCRIPT': 135,
'RESUME': 149,

View File

@@ -1561,7 +1561,7 @@ impl Compiler {
NameUsage::Load => {
// Special case for class scope
if self.ctx.in_class && !self.ctx.in_func() {
Instruction::LoadClassDeref
Instruction::LoadFromDictOrDeref
} else {
Instruction::LoadDeref
}

View File

@@ -829,7 +829,7 @@ pub enum Instruction {
LoadFastLoadFast {
arg: Arg<u32>,
} = 88, // Placeholder
LoadFromDictOrDeref(Arg<NameIdx>) = 89, // Placeholder
LoadFromDictOrDeref(Arg<NameIdx>) = 89,
LoadFromDictOrGlobals(Arg<NameIdx>) = 90, // Placeholder
LoadGlobal(Arg<NameIdx>) = 91,
LoadName(Arg<NameIdx>) = 92,
@@ -932,7 +932,6 @@ pub enum Instruction {
target: Arg<Label>,
} = 130,
JumpIfNotExcMatch(Arg<Label>) = 131,
LoadClassDeref(Arg<NameIdx>) = 132,
SetExcInfo = 134,
Subscript = 135,
// ===== Pseudo Opcodes (252+) ======
@@ -997,7 +996,6 @@ impl TryFrom<u8> for Instruction {
target: Arg::marker(),
}),
u8::from(Self::JumpIfNotExcMatch(Arg::marker())),
u8::from(Self::LoadClassDeref(Arg::marker())),
u8::from(Self::SetExcInfo),
u8::from(Self::Subscript),
];
@@ -1792,14 +1790,14 @@ impl Instruction {
Nop => 0,
ImportName { .. } => -1,
ImportFrom { .. } => 1,
LoadFast(_) | LoadFastAndClear(_) | LoadName(_) | LoadGlobal(_) | LoadDeref(_)
| LoadClassDeref(_) => 1,
LoadFast(_) | LoadFastAndClear(_) | LoadName(_) | LoadGlobal(_) | LoadDeref(_) => 1,
StoreFast(_) | StoreName(_) | StoreGlobal(_) | StoreDeref(_) => -1,
StoreFastLoadFast { .. } => 0, // pop 1, push 1
DeleteFast(_) | DeleteName(_) | DeleteGlobal(_) | DeleteDeref(_) => 0,
LoadClosure(_) => 1,
Subscript => -1,
StoreSubscr => -3,
LoadFromDictOrDeref(_) => 1,
DeleteSubscr => -2,
LoadAttr { .. } => 0,
// LoadAttrMethod: pop obj, push method + self_or_null
@@ -1937,7 +1935,33 @@ impl Instruction {
UnaryNot => 0,
GetYieldFromIter => 0,
PushNull => 1, // Push NULL for call protocol
_ => 0,
Cache => 0,
BinarySlice => 0,
BinaryOpInplaceAddUnicode => 0,
EndFor => 0,
ExitInitCheck => 0,
InterpreterExit => 0,
LoadAssertionError => 0,
LoadLocals => 0,
ReturnGenerator => 0,
StoreSlice => 0,
DictMerge { .. } => 0,
BuildConstKeyMap { .. } => 0,
CopyFreeVars { .. } => 0,
EnterExecutor => 0,
JumpBackwardNoInterrupt { .. } => 0,
JumpBackward { .. } => 0,
JumpForward { .. } => 0,
ListExtend { .. } => 0,
LoadFastCheck(_) => 0,
LoadFastLoadFast { .. } => 0,
LoadFromDictOrGlobals(_) => 0,
SetUpdate { .. } => 0,
MakeCell(_) => 0,
LoadSuperAttr { .. } => 0,
StoreFastStoreFast { .. } => 0,
PopJumpIfNone { .. } => 0,
PopJumpIfNotNone { .. } => 0,
}
}
@@ -2083,7 +2107,7 @@ impl Instruction {
}
LoadAttrMethod { idx } => w!(LOAD_ATTR_METHOD, name = idx),
LoadBuildClass => w!(LOAD_BUILD_CLASS),
LoadClassDeref(idx) => w!(LOAD_CLASSDEREF, cell_name = idx),
LoadFromDictOrDeref(i) => w!(LOAD_FROM_DICT_OR_DEREF, cell_name = i),
LoadClosure(i) => w!(LOAD_CLOSURE, cell_name = i),
LoadConst { idx } => fmt_const("LOAD_CONST", arg, f, idx),
LoadDeref(idx) => w!(LOAD_DEREF, cell_name = idx),

View File

@@ -108,7 +108,7 @@ mod opcode {
&& matches!(
Instruction::try_from(opcode as u8),
Ok(Instruction::DeleteDeref(_)
| Instruction::LoadClassDeref(_)
| Instruction::LoadFromDictOrDeref(_)
| Instruction::LoadClosure(_)
| Instruction::LoadDeref(_)
| Instruction::StoreDeref(_))

View File

@@ -1108,7 +1108,7 @@ impl ExecutingFrame<'_> {
self.push_value(vm.builtins.get_attr(identifier!(vm, __build_class__), vm)?);
Ok(None)
}
bytecode::Instruction::LoadClassDeref(i) => {
bytecode::Instruction::LoadFromDictOrDeref(i) => {
let i = i.get(arg) as usize;
let name = if i < self.code.cellvars.len() {
self.code.cellvars[i]