Skip to content

Commit bbb9c5b

Browse files
committed
remove qualified_path
1 parent dbd2887 commit bbb9c5b

File tree

1 file changed

+9
-44
lines changed

1 file changed

+9
-44
lines changed

compiler/codegen/src/compile.rs

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ struct Compiler<'src> {
7474
source_code: SourceCode<'src>,
7575
// current_source_location: SourceLocation,
7676
current_source_range: TextRange,
77-
qualified_path: Vec<String>,
7877
done_with_future_stmts: DoneWithFuture,
7978
future_annotations: bool,
8079
ctx: CompileContext,
@@ -326,7 +325,6 @@ impl<'src> Compiler<'src> {
326325
source_code,
327326
// current_source_location: SourceLocation::default(),
328327
current_source_range: TextRange::default(),
329-
qualified_path: Vec::new(),
330328
done_with_future_stmts: DoneWithFuture::No,
331329
future_annotations: false,
332330
ctx: CompileContext {
@@ -401,12 +399,8 @@ impl Compiler<'_> {
401399
.map(|(var, _)| var.clone())
402400
.collect();
403401

404-
// Calculate qualname based on the current qualified path
405-
let qualname = if self.qualified_path.is_empty() {
406-
Some(obj_name.clone())
407-
} else {
408-
Some(self.qualified_path.join("."))
409-
};
402+
// Qualname will be set later by set_qualname
403+
let qualname = None;
410404

411405
// Get the private name from current scope if exists
412406
let private = self.code_stack.last().and_then(|info| info.private.clone());
@@ -539,24 +533,21 @@ impl Compiler<'_> {
539533
&& !parent_obj_name.starts_with("<") // Not a special scope like <lambda>, <listcomp>, etc.
540534
&& parent_obj_name != "<module>"; // Not the module scope
541535

542-
let path_len = self.qualified_path.len();
543-
544536
if is_function_parent {
545537
// For functions, append .<locals> to parent qualname
546538
// Use parent's qualname if available, otherwise use parent_obj_name
547539
let parent_qualname = parent.qualname.as_ref().unwrap_or(parent_obj_name);
548540
format!("{parent_qualname}.<locals>.{current_obj_name}")
549541
} else {
550-
// For classes and other scopes, use qualified_path without current name
551-
// (since current name is already pushed to qualified_path)
552-
if path_len > 0 && self.qualified_path[path_len - 1] == current_obj_name {
553-
// Current name is already in qualified_path, just join
554-
self.qualified_path.join(".")
555-
} else if self.qualified_path.is_empty() {
542+
// For classes and other scopes, use parent's qualname directly
543+
// Use parent's qualname if available, otherwise use parent_obj_name
544+
let parent_qualname = parent.qualname.as_ref().unwrap_or(parent_obj_name);
545+
if parent_qualname == "<module>" {
546+
// Module level, just use the name
556547
current_obj_name
557548
} else {
558-
// Append current name to qualified_path
559-
format!("{}.{}", self.qualified_path.join("."), current_obj_name)
549+
// Concatenate parent qualname with current name
550+
format!("{parent_qualname}.{current_obj_name}")
560551
}
561552
}
562553
}
@@ -1642,13 +1633,9 @@ impl Compiler<'_> {
16421633
},
16431634
};
16441635

1645-
self.push_qualified_path(name);
1646-
16471636
// Set qualname using the new method
16481637
let qualname = self.set_qualname();
16491638

1650-
self.push_qualified_path("<locals>");
1651-
16521639
let (doc_str, body) = split_doc(body, &self.opts);
16531640

16541641
self.current_code_info()
@@ -1676,8 +1663,6 @@ impl Compiler<'_> {
16761663
}
16771664

16781665
let code = self.pop_code_object();
1679-
self.qualified_path.pop();
1680-
self.qualified_path.pop();
16811666
self.ctx = prev_ctx;
16821667

16831668
// Prepare generic type parameters:
@@ -1852,19 +1837,6 @@ impl Compiler<'_> {
18521837
loop_data: None,
18531838
};
18541839

1855-
// Check if the class is declared global
1856-
let symbol_table = self.symbol_table_stack.last().unwrap();
1857-
let symbol = unwrap_internal(
1858-
self,
1859-
symbol_table
1860-
.lookup(name.as_ref())
1861-
.ok_or_else(|| InternalError::MissingSymbol(name.to_owned())),
1862-
);
1863-
let mut global_path_prefix = Vec::new();
1864-
if symbol.scope == SymbolScope::GlobalExplicit {
1865-
global_path_prefix.append(&mut self.qualified_path);
1866-
}
1867-
self.push_qualified_path(name);
18681840

18691841
// If there are type params, we need to push a special symbol table just for them
18701842
if let Some(type_params) = type_params {
@@ -1941,9 +1913,6 @@ impl Compiler<'_> {
19411913
self.emit_return_value();
19421914

19431915
let code = self.pop_code_object();
1944-
1945-
self.qualified_path.pop();
1946-
self.qualified_path.append(global_path_prefix.as_mut());
19471916
self.ctx = prev_ctx;
19481917

19491918
emit!(self, Instruction::LoadBuildClass);
@@ -4429,10 +4398,6 @@ impl Compiler<'_> {
44294398
.line_index(self.current_source_range.start())
44304399
}
44314400

4432-
fn push_qualified_path(&mut self, name: &str) {
4433-
self.qualified_path.push(name.to_owned());
4434-
}
4435-
44364401
fn mark_generator(&mut self) {
44374402
self.current_code_info().flags |= bytecode::CodeFlags::IS_GENERATOR
44384403
}

0 commit comments

Comments
 (0)