Skip to content
Merged
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
opcodes dis repr like cpython. POP-> POP_TOP
  • Loading branch information
ShaharNaveh committed Dec 25, 2025
commit 9b67d416748e7eb129f7de4c85737aa913492f46
202 changes: 101 additions & 101 deletions crates/compiler-core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,6 @@ pub enum Instruction {
MatchMapping,
MatchSequence,
Nop,
Pop,
PopBlock,
PopException,
/// Pop the top of the stack, and jump if this value is false.
Expand All @@ -793,6 +792,7 @@ pub enum Instruction {
PopJumpIfTrue {
target: Arg<Label>,
},
PopTop,
Raise {
kind: Arg<RaiseKind>,
},
Expand Down Expand Up @@ -1685,7 +1685,7 @@ impl Instruction {
BinaryOp { .. } | CompareOperation { .. } => -1,
BinarySubscript => -1,
CopyItem { .. } => 1,
Pop => -1,
PopTop => -1,
Swap { .. } => 0,
ToBool => 0,
GetIter => 0,
Expand Down Expand Up @@ -1860,112 +1860,112 @@ impl Instruction {
};

match self {
BeforeAsyncWith => w!(BeforeAsyncWith),
BeforeAsyncWith => w!(BEFORE_ASYNC_WITH),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there reason to change the convention?

Copy link
Copy Markdown
Contributor Author

@ShaharNaveh ShaharNaveh Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Some tests are checking for the presents/absent of certain opcodes by name like:

def test_no_wraparound_jump(self):
# See https://bugs.python.org/issue46724
def while_not_chained(a, b, c):
while not (a < b < c):
pass
for instr in dis.Bytecode(while_not_chained):
self.assertNotEqual(instr.opname, "EXTENDED_ARG")

And pretty much all tests under test_dis.py (which we have a VERY outdated version of ATM), aligning the names of the opcodes just increases our test coverage

BinaryOp { op } => write!(f, "{:pad$}({})", "BINARY_OP", op.get(arg)),
BinarySubscript => w!(BinarySubscript),
Break { target } => w!(Break, target),
BuildListFromTuples { size } => w!(BuildListFromTuples, size),
BuildList { size } => w!(BuildList, size),
BuildMapForCall { size } => w!(BuildMapForCall, size),
BuildMap { size } => w!(BuildMap, size),
BuildSetFromTuples { size } => w!(BuildSetFromTuples, size),
BuildSet { size } => w!(BuildSet, size),
BuildSlice { argc } => w!(BuildSlice, ?argc),
BuildString { size } => w!(BuildString, size),
BuildTupleFromIter => w!(BuildTupleFromIter),
BuildTupleFromTuples { size } => w!(BuildTupleFromTuples, size),
BuildTuple { size } => w!(BuildTuple, size),
CallFunctionEx { has_kwargs } => w!(CallFunctionEx, has_kwargs),
CallFunctionKeyword { nargs } => w!(CallFunctionKeyword, nargs),
CallFunctionPositional { nargs } => w!(CallFunctionPositional, nargs),
CallIntrinsic1 { func } => w!(CallIntrinsic1, ?func),
CallIntrinsic2 { func } => w!(CallIntrinsic2, ?func),
CallMethodEx { has_kwargs } => w!(CallMethodEx, has_kwargs),
CallMethodKeyword { nargs } => w!(CallMethodKeyword, nargs),
CallMethodPositional { nargs } => w!(CallMethodPositional, nargs),
CompareOperation { op } => w!(CompareOperation, ?op),
BinarySubscript => w!(BINARY_SUBSCRIPT),
Break { target } => w!(BREAK, target),
BuildListFromTuples { size } => w!(BUILD_LIST_FROM_TUPLES, size),
BuildList { size } => w!(BUILD_LIST, size),
BuildMapForCall { size } => w!(BUILD_MAP_FOR_CALL, size),
BuildMap { size } => w!(BUILD_MAP, size),
BuildSetFromTuples { size } => w!(BUILD_SET_FROM_TUPLES, size),
BuildSet { size } => w!(BUILD_SET, size),
BuildSlice { argc } => w!(BUILD_SLICE, ?argc),
BuildString { size } => w!(BUILD_STRING, size),
BuildTupleFromIter => w!(BUILD_TUPLE_FROM_ITER),
BuildTupleFromTuples { size } => w!(BUILD_TUPLE_FROM_TUPLES, size),
BuildTuple { size } => w!(BUILD_TUPLE, size),
CallFunctionEx { has_kwargs } => w!(CALL_FUNCTION_EX, has_kwargs),
CallFunctionKeyword { nargs } => w!(CALL_FUNCTION_KEYWORD, nargs),
CallFunctionPositional { nargs } => w!(CALL_FUNCTION_POSITIONAL, nargs),
CallIntrinsic1 { func } => w!(CALL_INTRINSIC_1, ?func),
CallIntrinsic2 { func } => w!(CALL_INTRINSIC_2, ?func),
CallMethodEx { has_kwargs } => w!(CALL_METHOD_EX, has_kwargs),
CallMethodKeyword { nargs } => w!(CALL_METHOD_KEYWORD, nargs),
CallMethodPositional { nargs } => w!(CALL_METHOD_POSITIONAL, nargs),
CompareOperation { op } => w!(COMPARE_OPERATION, ?op),
ContainsOp(inv) => w!(CONTAINS_OP, ?inv),
Continue { target } => w!(Continue, target),
Continue { target } => w!(CONTINUE, target),
ConvertValue { oparg } => write!(f, "{:pad$}{}", "CONVERT_VALUE", oparg.get(arg)),
CopyItem { index } => w!(CopyItem, index),
DeleteAttr { idx } => w!(DeleteAttr, name = idx),
DeleteDeref(idx) => w!(DeleteDeref, cell_name = idx),
DeleteFast(idx) => w!(DeleteFast, varname = idx),
DeleteGlobal(idx) => w!(DeleteGlobal, name = idx),
DeleteLocal(idx) => w!(DeleteLocal, name = idx),
DeleteSubscript => w!(DeleteSubscript),
DictUpdate { index } => w!(DictUpdate, index),
EndAsyncFor => w!(EndAsyncFor),
EndFinally => w!(EndFinally),
EnterFinally => w!(EnterFinally),
ExtendedArg => w!(ExtendedArg, Arg::<u32>::marker()),
ForIter { target } => w!(ForIter, target),
CopyItem { index } => w!(COPY, index),
DeleteAttr { idx } => w!(DELETE_ATTR, name = idx),
DeleteDeref(idx) => w!(DELETE_DEREF, cell_name = idx),
DeleteFast(idx) => w!(DELETE_FAST, varname = idx),
DeleteGlobal(idx) => w!(DELETE_GLOBAL, name = idx),
DeleteLocal(idx) => w!(DELETE_LOCAL, name = idx),
DeleteSubscript => w!(DELETE_SUBSCRIPT),
DictUpdate { index } => w!(DICT_UPDATE, index),
EndAsyncFor => w!(END_ASYNC_FOR),
EndFinally => w!(END_FINALLY),
EnterFinally => w!(ENTER_FINALLY),
ExtendedArg => w!(EXTENDED_ARG, Arg::<u32>::marker()),
ForIter { target } => w!(FOR_ITER, target),
FormatSimple => w!(FORMAT_SIMPLE),
FormatWithSpec => w!(FORMAT_WITH_SPEC),
GetAIter => w!(GetAIter),
GetANext => w!(GetANext),
GetAwaitable => w!(GetAwaitable),
GetIter => w!(GetIter),
GetLen => w!(GetLen),
ImportFrom { idx } => w!(ImportFrom, name = idx),
ImportName { idx } => w!(ImportName, name = idx),
GetAIter => w!(GET_AITER),
GetANext => w!(GET_ANEXT),
GetAwaitable => w!(GET_AWAITABLE),
GetIter => w!(GET_ITER),
GetLen => w!(GET_LEN),
ImportFrom { idx } => w!(IMPORT_FROM, name = idx),
ImportName { idx } => w!(IMPORT_NAME, name = idx),
IsOp(inv) => w!(IS_OP, ?inv),
JumpIfFalseOrPop { target } => w!(JumpIfFalseOrPop, target),
JumpIfFalseOrPop { target } => w!(JUMP_IF_FALSE_OR_POP, target),
JumpIfNotExcMatch(target) => w!(JUMP_IF_NOT_EXC_MATCH, target),
JumpIfTrueOrPop { target } => w!(JumpIfTrueOrPop, target),
Jump { target } => w!(Jump, target),
ListAppend { i } => w!(ListAppend, i),
LoadAttr { idx } => w!(LoadAttr, name = idx),
LoadBuildClass => w!(LoadBuildClass),
LoadClassDeref(idx) => w!(LoadClassDeref, cell_name = idx),
LoadClosure(i) => w!(LoadClosure, cell_name = i),
LoadConst { idx } => fmt_const("LoadConst", arg, f, idx),
LoadDeref(idx) => w!(LoadDeref, cell_name = idx),
LoadFast(idx) => w!(LoadFast, varname = idx),
LoadGlobal(idx) => w!(LoadGlobal, name = idx),
LoadMethod { idx } => w!(LoadMethod, name = idx),
LoadNameAny(idx) => w!(LoadNameAny, name = idx),
MakeFunction => w!(MakeFunction),
MapAdd { i } => w!(MapAdd, i),
MatchClass(arg) => w!(MatchClass, arg),
MatchKeys => w!(MatchKeys),
MatchMapping => w!(MatchMapping),
MatchSequence => w!(MatchSequence),
Nop => w!(Nop),
Pop => w!(Pop),
PopBlock => w!(PopBlock),
PopException => w!(PopException),
PopJumpIfFalse { target } => w!(PopJumpIfFalse, target),
PopJumpIfTrue { target } => w!(PopJumpIfTrue, target),
Raise { kind } => w!(Raise, ?kind),
Resume { arg } => w!(Resume, arg),
ReturnConst { idx } => fmt_const("ReturnConst", arg, f, idx),
ReturnValue => w!(ReturnValue),
Reverse { amount } => w!(Reverse, amount),
SetAdd { i } => w!(SetAdd, i),
SetFunctionAttribute { attr } => w!(SetFunctionAttribute, ?attr),
SetupAnnotation => w!(SetupAnnotation),
SetupAsyncWith { end } => w!(SetupAsyncWith, end),
SetupExcept { handler } => w!(SetupExcept, handler),
SetupFinally { handler } => w!(SetupFinally, handler),
SetupLoop => w!(SetupLoop),
SetupWith { end } => w!(SetupWith, end),
StoreAttr { idx } => w!(StoreAttr, name = idx),
StoreDeref(idx) => w!(StoreDeref, cell_name = idx),
StoreFast(idx) => w!(StoreFast, varname = idx),
StoreGlobal(idx) => w!(StoreGlobal, name = idx),
StoreLocal(idx) => w!(StoreLocal, name = idx),
StoreSubscript => w!(StoreSubscript),
Subscript => w!(Subscript),
Swap { index } => w!(Swap, index),
ToBool => w!(ToBool),
UnaryOperation { op } => w!(UnaryOperation, ?op),
UnpackEx { args } => w!(UnpackEx, args),
UnpackSequence { size } => w!(UnpackSequence, size),
WithCleanupFinish => w!(WithCleanupFinish),
WithCleanupStart => w!(WithCleanupStart),
YieldFrom => w!(YieldFrom),
YieldValue => w!(YieldValue),
JumpIfTrueOrPop { target } => w!(JUMP_IF_TRUE_OR_POP, target),
Jump { target } => w!(JUMP, target),
ListAppend { i } => w!(LIST_APPEND, i),
LoadAttr { idx } => w!(LOAD_ATTR, name = idx),
LoadBuildClass => w!(LOAD_BUILD_CLASS),
LoadClassDeref(idx) => w!(LOAD_CLASS_DEREF, cell_name = idx),
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),
LoadFast(idx) => w!(LOAD_FAST, varname = idx),
LoadGlobal(idx) => w!(LOAD_GLOBAL, name = idx),
LoadMethod { idx } => w!(LOAD_METHOD, name = idx),
LoadNameAny(idx) => w!(LOAD_NAME_ANY, name = idx),
MakeFunction => w!(MAKE_FUNCTION),
MapAdd { i } => w!(MAP_ADD, i),
MatchClass(arg) => w!(MATCH_CLASS, arg),
MatchKeys => w!(MATCH_KEYS),
MatchMapping => w!(MATCH_MAPPING),
MatchSequence => w!(MATCH_SEQUENCE),
Nop => w!(NOP),
PopBlock => w!(POP_BLOCK),
PopException => w!(POP_EXCEPTION),
PopJumpIfFalse { target } => w!(POP_JUMP_IF_FALSE, target),
PopJumpIfTrue { target } => w!(POP_JUMP_IF_TRUE, target),
PopTop => w!(POP_TOP),
Raise { kind } => w!(RAISE, ?kind),
Resume { arg } => w!(RESUME, arg),
ReturnConst { idx } => fmt_const("RETURN_CONST", arg, f, idx),
ReturnValue => w!(RETURN_VALUE),
Reverse { amount } => w!(REVERSE, amount),
SetAdd { i } => w!(SET_ADD, i),
SetFunctionAttribute { attr } => w!(SET_FUNCTION_ATTRIBUTE, ?attr),
SetupAnnotation => w!(SETUP_ANNOTATION),
SetupAsyncWith { end } => w!(SETUP_ASYNC_WITH, end),
SetupExcept { handler } => w!(SETUP_EXCEPT, handler),
SetupFinally { handler } => w!(SETUP_FINALLY, handler),
SetupLoop => w!(SETUP_LOOP),
SetupWith { end } => w!(SETUP_WITH, end),
StoreAttr { idx } => w!(STORE_ATTR, name = idx),
StoreDeref(idx) => w!(STORE_DEREF, cell_name = idx),
StoreFast(idx) => w!(STORE_FAST, varname = idx),
StoreGlobal(idx) => w!(STORE_GLOBAL, name = idx),
StoreLocal(idx) => w!(STORE_LOCAL, name = idx),
StoreSubscript => w!(STORE_SUBSCRIPT),
Subscript => w!(SUBSCRIPT),
Swap { index } => w!(SWAP, index),
ToBool => w!(TO_BOOL),
UnaryOperation { op } => w!(UNARY_OPERATION, ?op),
UnpackEx { args } => w!(UNPACK_EX, args),
UnpackSequence { size } => w!(UNPACK_SEQUENCE, size),
WithCleanupFinish => w!(WITH_CLEANUP_FINISH),
WithCleanupStart => w!(WITH_CLEANUP_START),
YieldFrom => w!(YIELD_FROM),
YieldValue => w!(YIELD_VALUE),
}
}
}
Expand Down