diff --git a/crates/codegen/src/compile.rs b/crates/codegen/src/compile.rs index e8dc269dca..76e920311f 100644 --- a/crates/codegen/src/compile.rs +++ b/crates/codegen/src/compile.rs @@ -1351,8 +1351,6 @@ impl Compiler { .collect() }; - let module_idx = module.as_ref().map(|s| self.name(s.as_str())); - // from .... import (*fromlist) self.emit_load_const(ConstantData::Integer { value: (*level).into(), @@ -1360,11 +1358,10 @@ impl Compiler { self.emit_load_const(ConstantData::Tuple { elements: from_list, }); - if let Some(idx) = module_idx { - emit!(self, Instruction::ImportName { idx }); - } else { - emit!(self, Instruction::ImportNameless); - } + + let module_name = module.as_ref().map_or("", |s| s.as_str()); + let module_idx = self.name(module_name); + emit!(self, Instruction::ImportName { idx: module_idx }); if import_star { // from .... import * diff --git a/crates/compiler-core/src/bytecode.rs b/crates/compiler-core/src/bytecode.rs index d1482b8c8a..49c1da8b2d 100644 --- a/crates/compiler-core/src/bytecode.rs +++ b/crates/compiler-core/src/bytecode.rs @@ -662,8 +662,6 @@ pub enum Instruction { ImportFrom { idx: Arg, }, - /// Importing without name - ImportNameless, /// Importing by name ImportName { idx: Arg, @@ -1607,7 +1605,7 @@ impl Instruction { pub fn stack_effect(&self, arg: OpArg, jump: bool) -> i32 { match self { Nop => 0, - ImportName { .. } | ImportNameless => -1, + ImportName { .. } => -1, ImportFrom { .. } => 1, LoadFast(_) | LoadNameAny(_) | LoadGlobal(_) | LoadDeref(_) | LoadClassDeref(_) => 1, StoreFast(_) | StoreLocal(_) | StoreGlobal(_) | StoreDeref(_) => -1, @@ -1844,7 +1842,6 @@ impl Instruction { GetIter => w!(GetIter), GetLen => w!(GetLen), ImportFrom { idx } => w!(ImportFrom, name = idx), - ImportNameless => w!(ImportNameless), ImportName { idx } => w!(ImportName, name = idx), IsOp(inv) => w!(IS_OP, ?inv), JumpIfFalseOrPop { target } => w!(JumpIfFalseOrPop, target), diff --git a/crates/vm/src/frame.rs b/crates/vm/src/frame.rs index d6d5e42a21..4e02ca2335 100644 --- a/crates/vm/src/frame.rs +++ b/crates/vm/src/frame.rs @@ -939,10 +939,6 @@ impl ExecutingFrame<'_> { self.push_value(obj); Ok(None) } - bytecode::Instruction::ImportNameless => { - self.import(vm, None)?; - Ok(None) - } bytecode::Instruction::ImportName { idx } => { self.import(vm, Some(self.code.names[idx.get(arg) as usize]))?; Ok(None)