Skip to content

Commit e034ebe

Browse files
ShaharNavehterryluan12
authored andcommitted
Remove _dis module (RustPython#6690)
* Remove `_dis` module * Adjust CodeFlag
1 parent f43bcbf commit e034ebe

12 files changed

Lines changed: 36 additions & 133 deletions

File tree

‎Lib/dis.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
from _opcode import get_executor
2121

22-
2322
__all__ = ["code_info", "dis", "disassemble", "distb", "disco",
2423
"findlinestarts", "findlabels", "show_code",
2524
"get_instructions", "Instruction", "Bytecode"] + _opcodes_all
@@ -1052,9 +1051,6 @@ def dis(self):
10521051
return output.getvalue()
10531052

10541053

1055-
from _dis import * # TODO: RUSTPYTHON; Remove this import (and module)
1056-
1057-
10581054
def main(args=None):
10591055
import argparse
10601056

@@ -1073,9 +1069,7 @@ def main(args=None):
10731069
with open(args.infile, 'rb') as infile:
10741070
source = infile.read()
10751071
code = compile(source, name, "exec")
1076-
# TODO: RUSTPYTHON; Add support for `show_caches` & `show_offsets` arguments
1077-
# dis(code, show_caches=args.show_caches, show_offsets=args.show_offsets)
1078-
dis(code)
1072+
dis(code, show_caches=args.show_caches, show_offsets=args.show_offsets)
10791073

10801074
if __name__ == "__main__":
10811075
main()

‎Lib/test/test_dis.py‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -971,11 +971,9 @@ def test_bug_1333982(self):
971971

972972
self.do_disassembly_test(bug1333982, dis_bug1333982)
973973

974-
@unittest.expectedFailure # TODO: RUSTPYTHON
975974
def test_bug_42562(self):
976975
self.do_disassembly_test(bug42562, dis_bug42562)
977976

978-
@unittest.expectedFailure # TODO: RUSTPYTHON
979977
def test_bug_45757(self):
980978
# Extended arg followed by NOP
981979
self.do_disassembly_test(code_bug_45757, dis_bug_45757)
@@ -997,7 +995,6 @@ def test_intrinsic_1(self):
997995
self.do_disassembly_test("+a", dis_intrinsic_1_5)
998996
self.do_disassembly_test("(*a,)", dis_intrinsic_1_6)
999997

1000-
@unittest.expectedFailure # TODO: RUSTPYTHON
1001998
def test_intrinsic_2(self):
1002999
self.assertIn("CALL_INTRINSIC_2 1 (INTRINSIC_PREP_RERAISE_STAR)",
10031000
self.get_disassembly("try: pass\nexcept* Exception: x"))
@@ -1059,19 +1056,16 @@ def test_disassemble_static_method(self):
10591056
def test_disassemble_class_method(self):
10601057
self.do_disassembly_test(_C.cm, dis_c_class_method)
10611058

1062-
@unittest.expectedFailure # TODO: RUSTPYTHON
10631059
def test_disassemble_generator(self):
10641060
gen_func_disas = self.get_disassembly(_g) # Generator function
10651061
gen_disas = self.get_disassembly(_g(1)) # Generator iterator
10661062
self.assertEqual(gen_disas, gen_func_disas)
10671063

1068-
@unittest.expectedFailure # TODO: RUSTPYTHON
10691064
def test_disassemble_async_generator(self):
10701065
agen_func_disas = self.get_disassembly(_ag) # Async generator function
10711066
agen_disas = self.get_disassembly(_ag(1)) # Async generator iterator
10721067
self.assertEqual(agen_disas, agen_func_disas)
10731068

1074-
@unittest.expectedFailure # TODO: RUSTPYTHON
10751069
def test_disassemble_coroutine(self):
10761070
coro_func_disas = self.get_disassembly(_co) # Coroutine function
10771071
coro = _co(1) # Coroutine object
@@ -1096,7 +1090,6 @@ def test_disassemble_try_finally(self):
10961090
self.do_disassembly_test(_tryfinally, dis_tryfinally)
10971091
self.do_disassembly_test(_tryfinallyconst, dis_tryfinallyconst)
10981092

1099-
@unittest.expectedFailure # TODO: RUSTPYTHON
11001093
def test_dis_none(self):
11011094
try:
11021095
del sys.last_exc
@@ -1108,7 +1101,6 @@ def test_dis_none(self):
11081101
pass
11091102
self.assertRaises(RuntimeError, dis.dis, None)
11101103

1111-
@unittest.expectedFailure # TODO: RUSTPYTHON
11121104
def test_dis_traceback(self):
11131105
self.maxDiff = None
11141106
try:
@@ -2198,14 +2190,12 @@ def test_assert_not_in_with_op_not_in_bytecode(self):
21982190
self.assertNotInBytecode(code, "LOAD_NAME")
21992191
self.assertNotInBytecode(code, "LOAD_NAME", "a")
22002192

2201-
@unittest.expectedFailure # TODO: RUSTPYTHON
22022193
def test_assert_not_in_with_arg_not_in_bytecode(self):
22032194
code = compile("a = 1", "<string>", "exec")
22042195
self.assertInBytecode(code, "LOAD_CONST")
22052196
self.assertInBytecode(code, "LOAD_CONST", 1)
22062197
self.assertNotInBytecode(code, "LOAD_CONST", 2)
22072198

2208-
@unittest.expectedFailure # TODO: RUSTPYTHON
22092199
def test_assert_not_in_with_arg_in_bytecode(self):
22102200
code = compile("a = 1", "<string>", "exec")
22112201
with self.assertRaises(AssertionError):

‎Lib/test/test_inspect/test_inspect.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,6 @@ def do_something_static():
384384

385385
coro.close(); gen_coro.close(); # silence warnings
386386

387-
# TODO: RUSTPYTHON
388-
@unittest.expectedFailure
389387
def test_isawaitable(self):
390388
def gen(): yield
391389
self.assertFalse(inspect.isawaitable(gen()))
@@ -6748,4 +6746,4 @@ def f():
67486746

67496747

67506748
if __name__ == "__main__":
6751-
unittest.main()
6749+
unittest.main()

‎Lib/test/test_unittest/testmock/testasync.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,6 @@ def __aiter__(self): pass
734734

735735
async def __anext__(self): pass
736736

737-
@unittest.expectedFailure # TODO: RUSTPYTHON
738737
def test_aiter_set_return_value(self):
739738
mock_iter = AsyncMock(name="tester")
740739
mock_iter.__aiter__.return_value = [1, 2, 3]
@@ -760,7 +759,6 @@ def inner_test(mock_type):
760759
inner_test(mock_type)
761760

762761

763-
@unittest.expectedFailure # TODO: RUSTPYTHON
764762
def test_mock_async_for(self):
765763
async def iterate(iterator):
766764
accumulator = []

‎crates/codegen/src/compile.rs‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ enum CollectionType {
377377
impl Compiler {
378378
fn new(opts: CompileOpts, source_file: SourceFile, code_name: String) -> Self {
379379
let module_code = ir::CodeInfo {
380-
flags: bytecode::CodeFlags::NEW_LOCALS,
380+
flags: bytecode::CodeFlags::NEWLOCALS,
381381
source_path: source_file.name().to_owned(),
382382
private: None,
383383
blocks: vec![ir::Block::default()],
@@ -749,19 +749,19 @@ impl Compiler {
749749
CompilerScope::Module => (bytecode::CodeFlags::empty(), 0, 0, 0),
750750
CompilerScope::Class => (bytecode::CodeFlags::empty(), 0, 0, 0),
751751
CompilerScope::Function | CompilerScope::AsyncFunction | CompilerScope::Lambda => (
752-
bytecode::CodeFlags::NEW_LOCALS | bytecode::CodeFlags::IS_OPTIMIZED,
752+
bytecode::CodeFlags::NEWLOCALS | bytecode::CodeFlags::OPTIMIZED,
753753
0, // Will be set later in enter_function
754754
0, // Will be set later in enter_function
755755
0, // Will be set later in enter_function
756756
),
757757
CompilerScope::Comprehension => (
758-
bytecode::CodeFlags::NEW_LOCALS | bytecode::CodeFlags::IS_OPTIMIZED,
758+
bytecode::CodeFlags::NEWLOCALS | bytecode::CodeFlags::OPTIMIZED,
759759
0,
760760
1, // comprehensions take one argument (.0)
761761
0,
762762
),
763763
CompilerScope::TypeParams => (
764-
bytecode::CodeFlags::NEW_LOCALS | bytecode::CodeFlags::IS_OPTIMIZED,
764+
bytecode::CodeFlags::NEWLOCALS | bytecode::CodeFlags::OPTIMIZED,
765765
0,
766766
0,
767767
0,
@@ -1298,7 +1298,7 @@ impl Compiler {
12981298
let parent_obj_name = &parent.metadata.name;
12991299

13001300
// Determine if parent is a function-like scope
1301-
let is_function_parent = parent.flags.contains(bytecode::CodeFlags::IS_OPTIMIZED)
1301+
let is_function_parent = parent.flags.contains(bytecode::CodeFlags::OPTIMIZED)
13021302
&& !parent_obj_name.starts_with("<") // Not a special scope like <lambda>, <listcomp>, etc.
13031303
&& parent_obj_name != "<module>"; // Not the module scope
13041304

@@ -1914,7 +1914,7 @@ impl Compiler {
19141914
&& self
19151915
.current_code_info()
19161916
.flags
1917-
.contains(bytecode::CodeFlags::IS_GENERATOR)
1917+
.contains(bytecode::CodeFlags::GENERATOR)
19181918
{
19191919
return Err(self.error_ranged(
19201920
CodegenErrorType::AsyncReturnValue,
@@ -2062,7 +2062,7 @@ impl Compiler {
20622062
}
20632063

20642064
self.push_output(
2065-
bytecode::CodeFlags::NEW_LOCALS | bytecode::CodeFlags::IS_OPTIMIZED,
2065+
bytecode::CodeFlags::NEWLOCALS | bytecode::CodeFlags::OPTIMIZED,
20662066
parameters.posonlyargs.len().to_u32(),
20672067
(parameters.posonlyargs.len() + parameters.args.len()).to_u32(),
20682068
parameters.kwonlyargs.len().to_u32(),
@@ -2080,11 +2080,11 @@ impl Compiler {
20802080
}
20812081

20822082
if let Some(name) = parameters.vararg.as_deref() {
2083-
self.current_code_info().flags |= bytecode::CodeFlags::HAS_VARARGS;
2083+
self.current_code_info().flags |= bytecode::CodeFlags::VARARGS;
20842084
self.varname(name.name.as_str())?;
20852085
}
20862086
if let Some(name) = parameters.kwarg.as_deref() {
2087-
self.current_code_info().flags |= bytecode::CodeFlags::HAS_VARKEYWORDS;
2087+
self.current_code_info().flags |= bytecode::CodeFlags::VARKEYWORDS;
20882088
self.varname(name.name.as_str())?;
20892089
}
20902090

@@ -3103,7 +3103,7 @@ impl Compiler {
31033103
self.enter_function(name, parameters)?;
31043104
self.current_code_info()
31053105
.flags
3106-
.set(bytecode::CodeFlags::IS_COROUTINE, is_async);
3106+
.set(bytecode::CodeFlags::COROUTINE, is_async);
31073107

31083108
// Set up context
31093109
let prev_ctx = self.ctx;
@@ -3233,7 +3233,7 @@ impl Compiler {
32333233
// Enter type params scope
32343234
let type_params_name = format!("<generic parameters of {name}>");
32353235
self.push_output(
3236-
bytecode::CodeFlags::IS_OPTIMIZED | bytecode::CodeFlags::NEW_LOCALS,
3236+
bytecode::CodeFlags::OPTIMIZED | bytecode::CodeFlags::NEWLOCALS,
32373237
0,
32383238
num_typeparam_args as u32,
32393239
0,
@@ -3664,7 +3664,7 @@ impl Compiler {
36643664
if is_generic {
36653665
let type_params_name = format!("<generic parameters of {name}>");
36663666
self.push_output(
3667-
bytecode::CodeFlags::IS_OPTIMIZED | bytecode::CodeFlags::NEW_LOCALS,
3667+
bytecode::CodeFlags::OPTIMIZED | bytecode::CodeFlags::NEWLOCALS,
36683668
0,
36693669
0,
36703670
0,
@@ -6371,9 +6371,9 @@ impl Compiler {
63716371
in_async_scope: prev_ctx.in_async_scope || is_async,
63726372
};
63736373

6374-
let flags = bytecode::CodeFlags::NEW_LOCALS | bytecode::CodeFlags::IS_OPTIMIZED;
6374+
let flags = bytecode::CodeFlags::NEWLOCALS | bytecode::CodeFlags::OPTIMIZED;
63756375
let flags = if is_async {
6376-
flags | bytecode::CodeFlags::IS_COROUTINE
6376+
flags | bytecode::CodeFlags::COROUTINE
63776377
} else {
63786378
flags
63796379
};
@@ -7040,7 +7040,7 @@ impl Compiler {
70407040
}
70417041

70427042
fn mark_generator(&mut self) {
7043-
self.current_code_info().flags |= bytecode::CodeFlags::IS_GENERATOR
7043+
self.current_code_info().flags |= bytecode::CodeFlags::GENERATOR
70447044
}
70457045

70467046
/// Whether the expression contains an await expression and

‎crates/codegen/src/ir.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ impl CodeInfo {
332332

333333
let total_args = self.metadata.argcount
334334
+ self.metadata.kwonlyargcount
335-
+ self.flags.contains(CodeFlags::HAS_VARARGS) as u32
336-
+ self.flags.contains(CodeFlags::HAS_VARKEYWORDS) as u32;
335+
+ self.flags.contains(CodeFlags::VARARGS) as u32
336+
+ self.flags.contains(CodeFlags::VARKEYWORDS) as u32;
337337

338338
let mut found_cellarg = false;
339339
let cell2arg = self

‎crates/compiler-core/src/bytecode.rs‎

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -371,28 +371,15 @@ pub struct CodeObject<C: Constant = ConstantData> {
371371
bitflags! {
372372
#[derive(Copy, Clone, Debug, PartialEq)]
373373
pub struct CodeFlags: u16 {
374-
const NEW_LOCALS = 0x01;
375-
const IS_GENERATOR = 0x02;
376-
const IS_COROUTINE = 0x04;
377-
const HAS_VARARGS = 0x08;
378-
const HAS_VARKEYWORDS = 0x10;
379-
const IS_OPTIMIZED = 0x20;
374+
const OPTIMIZED = 0x0001;
375+
const NEWLOCALS = 0x0002;
376+
const VARARGS = 0x0004;
377+
const VARKEYWORDS = 0x0008;
378+
const GENERATOR = 0x0020;
379+
const COROUTINE = 0x0080;
380380
}
381381
}
382382

383-
impl CodeFlags {
384-
pub const NAME_MAPPING: &'static [(&'static str, Self)] = &[
385-
("GENERATOR", Self::IS_GENERATOR),
386-
("COROUTINE", Self::IS_COROUTINE),
387-
(
388-
"ASYNC_GENERATOR",
389-
Self::from_bits_truncate(Self::IS_GENERATOR.bits() | Self::IS_COROUTINE.bits()),
390-
),
391-
("VARARGS", Self::HAS_VARARGS),
392-
("VARKEYWORDS", Self::HAS_VARKEYWORDS),
393-
];
394-
}
395-
396383
/// an opcode argument that may be extended by a prior ExtendedArg
397384
#[derive(Copy, Clone, PartialEq, Eq)]
398385
#[repr(transparent)]
@@ -1564,14 +1551,14 @@ impl<C: Constant> CodeObject<C> {
15641551
let args = &self.varnames[..nargs];
15651552
let kwonlyargs = &self.varnames[nargs..varargs_pos];
15661553

1567-
let vararg = if self.flags.contains(CodeFlags::HAS_VARARGS) {
1554+
let vararg = if self.flags.contains(CodeFlags::VARARGS) {
15681555
let vararg = &self.varnames[varargs_pos];
15691556
varargs_pos += 1;
15701557
Some(vararg)
15711558
} else {
15721559
None
15731560
};
1574-
let varkwarg = if self.flags.contains(CodeFlags::HAS_VARKEYWORDS) {
1561+
let varkwarg = if self.flags.contains(CodeFlags::VARKEYWORDS) {
15751562
Some(&self.varnames[varargs_pos])
15761563
} else {
15771564
None

‎crates/stdlib/src/dis.rs‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎crates/stdlib/src/lib.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ mod bisect;
1414
mod cmath;
1515
mod contextvars;
1616
mod csv;
17-
mod dis;
1817
mod gc;
1918

2019
mod bz2;
@@ -132,7 +131,6 @@ pub fn get_module_inits() -> impl Iterator<Item = (Cow<'static, str>, StdlibInit
132131
"cmath" => cmath::make_module,
133132
"_contextvars" => contextvars::make_module,
134133
"_csv" => csv::make_module,
135-
"_dis" => dis::make_module,
136134
"faulthandler" => faulthandler::make_module,
137135
"gc" => gc::make_module,
138136
"_hashlib" => hashlib::make_module,

0 commit comments

Comments
 (0)