Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 0 additions & 21 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,11 +1021,9 @@ def test_widths(self):
width += 1 + dis._OPARG_WIDTH
self.assertLessEqual(len(opname), width)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_dis(self):
self.do_disassembly_test(_f, dis_f)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_dis_with_offsets(self):
self.do_disassembly_test(_f, dis_f_with_offsets, show_offsets=True)

Expand Down Expand Up @@ -1105,7 +1103,6 @@ def f():
])
self.do_disassembly_test(f, expect, show_positions=True)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_bug_708901(self):
self.do_disassembly_test(bug708901, dis_bug708901)

Expand All @@ -1125,7 +1122,6 @@ def test_bug_45757(self):
# Extended arg followed by NOP
self.do_disassembly_test(code_bug_45757, dis_bug_45757)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_bug_46724(self):
# Test that negative operargs are handled properly
self.do_disassembly_test(bug46724, dis_bug46724)
Expand Down Expand Up @@ -1179,23 +1175,19 @@ def test_disassemble_str(self):
def test_disassemble_bytes(self):
self.do_disassembly_test(_f.__code__.co_code, dis_f_co_code)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_disassemble_class(self):
self.do_disassembly_test(_C, dis_c)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_disassemble_instance_method(self):
self.do_disassembly_test(_C(1).__init__, dis_c_instance_method)

def test_disassemble_instance_method_bytes(self):
method_bytecode = _C(1).__init__.__code__.co_code
self.do_disassembly_test(method_bytecode, dis_c_instance_method_bytes)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_disassemble_static_method(self):
self.do_disassembly_test(_C.sm, dis_c_static_method)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_disassemble_class_method(self):
self.do_disassembly_test(_C.cm, dis_c_class_method)

Expand All @@ -1216,7 +1208,6 @@ def test_disassemble_coroutine(self):
coro_disas = self.get_disassembly(coro)
self.assertEqual(coro_disas, coro_func_disas)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_disassemble_fstring(self):
self.do_disassembly_test(_fstring, dis_fstring)

Expand Down Expand Up @@ -1284,7 +1275,6 @@ def test__try_compile_no_context_exc_on_error(self):
except Exception as e:
self.assertIsNone(e.__context__)

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: No END_ASYNC_FOR in disassembly of async for
def test_async_for_presentation(self):

async def afunc():
Expand Down Expand Up @@ -1469,10 +1459,6 @@ def get_disassembly(self, func, lasti=-1, wrapper=True, **kwargs):
dis.disassemble(func, lasti, file=output, **kwargs)
return output.getvalue()

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: No END_ASYNC_FOR in disassembly of async for
def test_async_for_presentation(self):
return super().test_async_for_presentation()


if dis.code_info.__doc__ is None:
code_info_consts = "0: None"
Expand Down Expand Up @@ -2164,7 +2150,6 @@ def test_baseopname_and_baseopcode(self):
self.assertIn(name, opcode._specializations[baseopname])
self.assertEqual(opcode.opmap[baseopname], baseopcode)

@unittest.expectedFailure # TODO: RUSTPYTHON; - JUMP_BACKWARD/JUMP_FORWARD are placeholders
def test_jump_target(self):
# Non-jump instructions should return None
instruction = make_inst(opname="NOP", arg=None, argval=None,
Expand All @@ -2190,7 +2175,6 @@ def test_jump_target(self):
positions=None)
self.assertEqual(10 + 2 + 1*2 + 100*2, instruction.jump_target)

@unittest.expectedFailure # TODO: RUSTPYTHON; - JUMP_BACKWARD is a placeholder
def test_argval_argrepr(self):
def f(opcode, oparg, offset, *init_args):
arg_resolver = dis.ArgResolver(*init_args)
Expand All @@ -2211,7 +2195,6 @@ def f(opcode, oparg, offset, *init_args):
self.assertEqual(f(opcode.opmap["BINARY_OP"], 3, *args), (3, '<<'))
self.assertEqual(f(opcode.opmap["CALL_INTRINSIC_1"], 2, *args), (2, 'INTRINSIC_IMPORT_STAR'))

@unittest.expectedFailure # TODO: RUSTPYTHON; - JUMP_BACKWARD is a placeholder
def test_custom_arg_resolver(self):
class MyArgResolver(dis.ArgResolver):
def offset_from_jump_arg(self, op, arg, offset):
Expand Down Expand Up @@ -2354,7 +2337,6 @@ def test_info(self):
b = dis.Bytecode(x)
self.assertRegex(b.info(), expected)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_disassembled(self):
actual = dis.Bytecode(_f).dis()
self.do_disassembly_compare(actual, dis_f)
Expand All @@ -2366,7 +2348,6 @@ def test_from_traceback(self):

self.assertEqual(b.current_offset, tb.tb_lasti)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_from_traceback_dis(self):
self.maxDiff = None
tb = get_tb()
Expand Down Expand Up @@ -2472,7 +2453,6 @@ def test_distb_empty(self):
with self.assertRaises(RuntimeError):
dis.distb()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_distb_last_traceback(self):
self.maxDiff = None
# We need to have an existing last traceback in `sys`:
Expand All @@ -2481,7 +2461,6 @@ def test_distb_last_traceback(self):

self.do_disassembly_compare(self.get_disassembly(None), dis_traceback)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_distb_explicit_arg(self):
self.maxDiff = None
tb = get_tb()
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_peepholer.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ def f():
self.check_jump_targets(f)
self.check_lnotab(f)

@unittest.expectedFailure # TODO: RUSTPYTHON; KeyError: 38
def test_elim_jump_to_uncond_jump2(self):
# POP_JUMP_IF_FALSE to JUMP_BACKWARD --> POP_JUMP_IF_FALSE to non-jump
def f():
Expand Down Expand Up @@ -598,7 +597,6 @@ def f(a, b, c):
self.assertEqual(count_instr_recursively(f, 'POP_JUMP_IF_FALSE'), 1)
self.assertEqual(count_instr_recursively(f, 'POP_JUMP_IF_TRUE'), 1)

@unittest.expectedFailure # TODO: RUSTPYTHON; KeyError: 6
def test_elim_jump_to_uncond_jump4(self):
def f():
for i in range(5):
Expand Down
43 changes: 37 additions & 6 deletions crates/stdlib/src/_opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ mod _opcode {
| Opcode::ImportFrom
| Opcode::ImportName
| Opcode::LoadAttr
| Opcode::LoadFromDictOrGlobals
| Opcode::LoadGlobal
| Opcode::LoadName
| Opcode::LoadSuperAttr
| Opcode::StoreAttr
| Opcode::StoreGlobal
| Opcode::StoreName
| Opcode::InstrumentedLoadSuperAttr
))
)
}
Expand All @@ -135,8 +138,24 @@ mod _opcode {
matches!(
try_from_i32(opcode),
Ok(AnyOpcode::Real(
Opcode::ForIter | Opcode::PopJumpIfFalse | Opcode::PopJumpIfTrue | Opcode::Send
) | AnyOpcode::Pseudo(PseudoOpcode::Jump))
Opcode::EndAsyncFor
| Opcode::ForIter
| Opcode::JumpBackward
| Opcode::JumpBackwardNoInterrupt
| Opcode::JumpForward
| Opcode::PopJumpIfFalse
| Opcode::PopJumpIfNone
| Opcode::PopJumpIfNotNone
| Opcode::PopJumpIfTrue
| Opcode::Send
| Opcode::InstrumentedForIter
| Opcode::InstrumentedEndAsyncFor
) | AnyOpcode::Pseudo(
PseudoOpcode::Jump
| PseudoOpcode::JumpIfFalse
| PseudoOpcode::JumpIfTrue
| PseudoOpcode::JumpNoInterrupt
))
)
}

Expand All @@ -147,7 +166,7 @@ mod _opcode {
Ok(AnyOpcode::Real(
Opcode::DeleteDeref
| Opcode::LoadFromDictOrDeref
| Opcode::LoadDeref
| Opcode::MakeCell
| Opcode::StoreDeref
))
)
Expand All @@ -159,20 +178,32 @@ mod _opcode {
try_from_i32(opcode),
Ok(AnyOpcode::Real(
Opcode::DeleteFast
| Opcode::LoadDeref
| Opcode::LoadFast
| Opcode::LoadFastAndClear
| Opcode::LoadFastBorrow
| Opcode::LoadFastBorrowLoadFastBorrow
| Opcode::LoadFastCheck
| Opcode::LoadFastLoadFast
| Opcode::StoreFast
| Opcode::StoreFastLoadFast
))
| Opcode::StoreFastStoreFast
) | AnyOpcode::Pseudo(PseudoOpcode::LoadClosure | PseudoOpcode::StoreFastMaybeNull))
)
}

#[pyfunction]
fn has_exc(opcode: i32) -> bool {
// No instructions have exception info in RustPython
// (exception handling is done via exception table)
let _ = opcode;
false
// This is for compatibility with CPython

matches!(
try_from_i32(opcode),
Ok(AnyOpcode::Pseudo(
PseudoOpcode::SetupCleanup | PseudoOpcode::SetupFinally | PseudoOpcode::SetupWith
))
)
}

#[pyfunction]
Expand Down
Loading