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
8 changes: 1 addition & 7 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from _opcode import get_executor


__all__ = ["code_info", "dis", "disassemble", "distb", "disco",
"findlinestarts", "findlabels", "show_code",
"get_instructions", "Instruction", "Bytecode"] + _opcodes_all
Expand Down Expand Up @@ -1052,9 +1051,6 @@ def dis(self):
return output.getvalue()


from _dis import * # TODO: RUSTPYTHON; Remove this import (and module)


def main(args=None):
import argparse

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

if __name__ == "__main__":
main()
10 changes: 0 additions & 10 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,11 +971,9 @@ def test_bug_1333982(self):

self.do_disassembly_test(bug1333982, dis_bug1333982)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_bug_42562(self):
self.do_disassembly_test(bug42562, dis_bug42562)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_bug_45757(self):
# Extended arg followed by NOP
self.do_disassembly_test(code_bug_45757, dis_bug_45757)
Expand All @@ -997,7 +995,6 @@ def test_intrinsic_1(self):
self.do_disassembly_test("+a", dis_intrinsic_1_5)
self.do_disassembly_test("(*a,)", dis_intrinsic_1_6)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_intrinsic_2(self):
self.assertIn("CALL_INTRINSIC_2 1 (INTRINSIC_PREP_RERAISE_STAR)",
self.get_disassembly("try: pass\nexcept* Exception: x"))
Expand Down Expand Up @@ -1059,19 +1056,16 @@ def test_disassemble_static_method(self):
def test_disassemble_class_method(self):
self.do_disassembly_test(_C.cm, dis_c_class_method)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_disassemble_generator(self):
gen_func_disas = self.get_disassembly(_g) # Generator function
gen_disas = self.get_disassembly(_g(1)) # Generator iterator
self.assertEqual(gen_disas, gen_func_disas)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_disassemble_async_generator(self):
agen_func_disas = self.get_disassembly(_ag) # Async generator function
agen_disas = self.get_disassembly(_ag(1)) # Async generator iterator
self.assertEqual(agen_disas, agen_func_disas)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_disassemble_coroutine(self):
coro_func_disas = self.get_disassembly(_co) # Coroutine function
coro = _co(1) # Coroutine object
Expand All @@ -1096,7 +1090,6 @@ def test_disassemble_try_finally(self):
self.do_disassembly_test(_tryfinally, dis_tryfinally)
self.do_disassembly_test(_tryfinallyconst, dis_tryfinallyconst)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_dis_none(self):
try:
del sys.last_exc
Expand All @@ -1108,7 +1101,6 @@ def test_dis_none(self):
pass
self.assertRaises(RuntimeError, dis.dis, None)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_dis_traceback(self):
self.maxDiff = None
try:
Expand Down Expand Up @@ -2198,14 +2190,12 @@ def test_assert_not_in_with_op_not_in_bytecode(self):
self.assertNotInBytecode(code, "LOAD_NAME")
self.assertNotInBytecode(code, "LOAD_NAME", "a")

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_assert_not_in_with_arg_not_in_bytecode(self):
code = compile("a = 1", "<string>", "exec")
self.assertInBytecode(code, "LOAD_CONST")
self.assertInBytecode(code, "LOAD_CONST", 1)
self.assertNotInBytecode(code, "LOAD_CONST", 2)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_assert_not_in_with_arg_in_bytecode(self):
code = compile("a = 1", "<string>", "exec")
with self.assertRaises(AssertionError):
Expand Down
4 changes: 1 addition & 3 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,6 @@ def do_something_static():

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

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_isawaitable(self):
def gen(): yield
self.assertFalse(inspect.isawaitable(gen()))
Expand Down Expand Up @@ -6748,4 +6746,4 @@ def f():


if __name__ == "__main__":
unittest.main()
unittest.main()
2 changes: 0 additions & 2 deletions Lib/test/test_unittest/testmock/testasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,6 @@ def __aiter__(self): pass

async def __anext__(self): pass

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


@unittest.expectedFailure # TODO: RUSTPYTHON
def test_mock_async_for(self):
async def iterate(iterator):
accumulator = []
Expand Down
30 changes: 15 additions & 15 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ enum CollectionType {
impl Compiler {
fn new(opts: CompileOpts, source_file: SourceFile, code_name: String) -> Self {
let module_code = ir::CodeInfo {
flags: bytecode::CodeFlags::NEW_LOCALS,
flags: bytecode::CodeFlags::NEWLOCALS,
source_path: source_file.name().to_owned(),
private: None,
blocks: vec![ir::Block::default()],
Expand Down Expand Up @@ -749,19 +749,19 @@ impl Compiler {
CompilerScope::Module => (bytecode::CodeFlags::empty(), 0, 0, 0),
CompilerScope::Class => (bytecode::CodeFlags::empty(), 0, 0, 0),
CompilerScope::Function | CompilerScope::AsyncFunction | CompilerScope::Lambda => (
bytecode::CodeFlags::NEW_LOCALS | bytecode::CodeFlags::IS_OPTIMIZED,
bytecode::CodeFlags::NEWLOCALS | bytecode::CodeFlags::OPTIMIZED,
0, // Will be set later in enter_function
0, // Will be set later in enter_function
0, // Will be set later in enter_function
),
CompilerScope::Comprehension => (
bytecode::CodeFlags::NEW_LOCALS | bytecode::CodeFlags::IS_OPTIMIZED,
bytecode::CodeFlags::NEWLOCALS | bytecode::CodeFlags::OPTIMIZED,
0,
1, // comprehensions take one argument (.0)
0,
),
CompilerScope::TypeParams => (
bytecode::CodeFlags::NEW_LOCALS | bytecode::CodeFlags::IS_OPTIMIZED,
bytecode::CodeFlags::NEWLOCALS | bytecode::CodeFlags::OPTIMIZED,
0,
0,
0,
Expand Down Expand Up @@ -1298,7 +1298,7 @@ impl Compiler {
let parent_obj_name = &parent.metadata.name;

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

Expand Down Expand Up @@ -1914,7 +1914,7 @@ impl Compiler {
&& self
.current_code_info()
.flags
.contains(bytecode::CodeFlags::IS_GENERATOR)
.contains(bytecode::CodeFlags::GENERATOR)
{
return Err(self.error_ranged(
CodegenErrorType::AsyncReturnValue,
Expand Down Expand Up @@ -2062,7 +2062,7 @@ impl Compiler {
}

self.push_output(
bytecode::CodeFlags::NEW_LOCALS | bytecode::CodeFlags::IS_OPTIMIZED,
bytecode::CodeFlags::NEWLOCALS | bytecode::CodeFlags::OPTIMIZED,
parameters.posonlyargs.len().to_u32(),
(parameters.posonlyargs.len() + parameters.args.len()).to_u32(),
parameters.kwonlyargs.len().to_u32(),
Expand All @@ -2080,11 +2080,11 @@ impl Compiler {
}

if let Some(name) = parameters.vararg.as_deref() {
self.current_code_info().flags |= bytecode::CodeFlags::HAS_VARARGS;
self.current_code_info().flags |= bytecode::CodeFlags::VARARGS;
self.varname(name.name.as_str())?;
}
if let Some(name) = parameters.kwarg.as_deref() {
self.current_code_info().flags |= bytecode::CodeFlags::HAS_VARKEYWORDS;
self.current_code_info().flags |= bytecode::CodeFlags::VARKEYWORDS;
self.varname(name.name.as_str())?;
}

Expand Down Expand Up @@ -3103,7 +3103,7 @@ impl Compiler {
self.enter_function(name, parameters)?;
self.current_code_info()
.flags
.set(bytecode::CodeFlags::IS_COROUTINE, is_async);
.set(bytecode::CodeFlags::COROUTINE, is_async);

// Set up context
let prev_ctx = self.ctx;
Expand Down Expand Up @@ -3233,7 +3233,7 @@ impl Compiler {
// Enter type params scope
let type_params_name = format!("<generic parameters of {name}>");
self.push_output(
bytecode::CodeFlags::IS_OPTIMIZED | bytecode::CodeFlags::NEW_LOCALS,
bytecode::CodeFlags::OPTIMIZED | bytecode::CodeFlags::NEWLOCALS,
0,
num_typeparam_args as u32,
0,
Expand Down Expand Up @@ -3664,7 +3664,7 @@ impl Compiler {
if is_generic {
let type_params_name = format!("<generic parameters of {name}>");
self.push_output(
bytecode::CodeFlags::IS_OPTIMIZED | bytecode::CodeFlags::NEW_LOCALS,
bytecode::CodeFlags::OPTIMIZED | bytecode::CodeFlags::NEWLOCALS,
0,
0,
0,
Expand Down Expand Up @@ -6371,9 +6371,9 @@ impl Compiler {
in_async_scope: prev_ctx.in_async_scope || is_async,
};

let flags = bytecode::CodeFlags::NEW_LOCALS | bytecode::CodeFlags::IS_OPTIMIZED;
let flags = bytecode::CodeFlags::NEWLOCALS | bytecode::CodeFlags::OPTIMIZED;
let flags = if is_async {
flags | bytecode::CodeFlags::IS_COROUTINE
flags | bytecode::CodeFlags::COROUTINE
} else {
flags
};
Expand Down Expand Up @@ -7040,7 +7040,7 @@ impl Compiler {
}

fn mark_generator(&mut self) {
self.current_code_info().flags |= bytecode::CodeFlags::IS_GENERATOR
self.current_code_info().flags |= bytecode::CodeFlags::GENERATOR
}

/// Whether the expression contains an await expression and
Expand Down
4 changes: 2 additions & 2 deletions crates/codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ impl CodeInfo {

let total_args = self.metadata.argcount
+ self.metadata.kwonlyargcount
+ self.flags.contains(CodeFlags::HAS_VARARGS) as u32
+ self.flags.contains(CodeFlags::HAS_VARKEYWORDS) as u32;
+ self.flags.contains(CodeFlags::VARARGS) as u32
+ self.flags.contains(CodeFlags::VARKEYWORDS) as u32;

let mut found_cellarg = false;
let cell2arg = self
Expand Down
29 changes: 8 additions & 21 deletions crates/compiler-core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,28 +371,15 @@ pub struct CodeObject<C: Constant = ConstantData> {
bitflags! {
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct CodeFlags: u16 {
const NEW_LOCALS = 0x01;
const IS_GENERATOR = 0x02;
const IS_COROUTINE = 0x04;
const HAS_VARARGS = 0x08;
const HAS_VARKEYWORDS = 0x10;
const IS_OPTIMIZED = 0x20;
const OPTIMIZED = 0x0001;
const NEWLOCALS = 0x0002;
const VARARGS = 0x0004;
const VARKEYWORDS = 0x0008;
const GENERATOR = 0x0020;
const COROUTINE = 0x0080;
}
}

impl CodeFlags {
pub const NAME_MAPPING: &'static [(&'static str, Self)] = &[
("GENERATOR", Self::IS_GENERATOR),
("COROUTINE", Self::IS_COROUTINE),
(
"ASYNC_GENERATOR",
Self::from_bits_truncate(Self::IS_GENERATOR.bits() | Self::IS_COROUTINE.bits()),
),
("VARARGS", Self::HAS_VARARGS),
("VARKEYWORDS", Self::HAS_VARKEYWORDS),
];
}

/// an opcode argument that may be extended by a prior ExtendedArg
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(transparent)]
Expand Down Expand Up @@ -1564,14 +1551,14 @@ impl<C: Constant> CodeObject<C> {
let args = &self.varnames[..nargs];
let kwonlyargs = &self.varnames[nargs..varargs_pos];

let vararg = if self.flags.contains(CodeFlags::HAS_VARARGS) {
let vararg = if self.flags.contains(CodeFlags::VARARGS) {
let vararg = &self.varnames[varargs_pos];
varargs_pos += 1;
Some(vararg)
} else {
None
};
let varkwarg = if self.flags.contains(CodeFlags::HAS_VARKEYWORDS) {
let varkwarg = if self.flags.contains(CodeFlags::VARKEYWORDS) {
Some(&self.varnames[varargs_pos])
} else {
None
Expand Down
58 changes: 0 additions & 58 deletions crates/stdlib/src/dis.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/stdlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mod bisect;
mod cmath;
mod contextvars;
mod csv;
mod dis;
mod gc;

mod bz2;
Expand Down Expand Up @@ -132,7 +131,6 @@ pub fn get_module_inits() -> impl Iterator<Item = (Cow<'static, str>, StdlibInit
"cmath" => cmath::make_module,
"_contextvars" => contextvars::make_module,
"_csv" => csv::make_module,
"_dis" => dis::make_module,
"faulthandler" => faulthandler::make_module,
"gc" => gc::make_module,
"_hashlib" => hashlib::make_module,
Expand Down
Loading
Loading