@@ -74,7 +74,6 @@ struct Compiler<'src> {
74
74
source_code : SourceCode < ' src > ,
75
75
// current_source_location: SourceLocation,
76
76
current_source_range : TextRange ,
77
- qualified_path : Vec < String > ,
78
77
done_with_future_stmts : DoneWithFuture ,
79
78
future_annotations : bool ,
80
79
ctx : CompileContext ,
@@ -326,7 +325,6 @@ impl<'src> Compiler<'src> {
326
325
source_code,
327
326
// current_source_location: SourceLocation::default(),
328
327
current_source_range : TextRange :: default ( ) ,
329
- qualified_path : Vec :: new ( ) ,
330
328
done_with_future_stmts : DoneWithFuture :: No ,
331
329
future_annotations : false ,
332
330
ctx : CompileContext {
@@ -401,12 +399,8 @@ impl Compiler<'_> {
401
399
. map ( |( var, _) | var. clone ( ) )
402
400
. collect ( ) ;
403
401
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 ;
410
404
411
405
// Get the private name from current scope if exists
412
406
let private = self . code_stack . last ( ) . and_then ( |info| info. private . clone ( ) ) ;
@@ -539,24 +533,21 @@ impl Compiler<'_> {
539
533
&& !parent_obj_name. starts_with ( "<" ) // Not a special scope like <lambda>, <listcomp>, etc.
540
534
&& parent_obj_name != "<module>" ; // Not the module scope
541
535
542
- let path_len = self . qualified_path . len ( ) ;
543
-
544
536
if is_function_parent {
545
537
// For functions, append .<locals> to parent qualname
546
538
// Use parent's qualname if available, otherwise use parent_obj_name
547
539
let parent_qualname = parent. qualname . as_ref ( ) . unwrap_or ( parent_obj_name) ;
548
540
format ! ( "{parent_qualname}.<locals>.{current_obj_name}" )
549
541
} 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
556
547
current_obj_name
557
548
} 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}" )
560
551
}
561
552
}
562
553
}
@@ -1642,13 +1633,9 @@ impl Compiler<'_> {
1642
1633
} ,
1643
1634
} ;
1644
1635
1645
- self . push_qualified_path ( name) ;
1646
-
1647
1636
// Set qualname using the new method
1648
1637
let qualname = self . set_qualname ( ) ;
1649
1638
1650
- self . push_qualified_path ( "<locals>" ) ;
1651
-
1652
1639
let ( doc_str, body) = split_doc ( body, & self . opts ) ;
1653
1640
1654
1641
self . current_code_info ( )
@@ -1676,8 +1663,6 @@ impl Compiler<'_> {
1676
1663
}
1677
1664
1678
1665
let code = self . pop_code_object ( ) ;
1679
- self . qualified_path . pop ( ) ;
1680
- self . qualified_path . pop ( ) ;
1681
1666
self . ctx = prev_ctx;
1682
1667
1683
1668
// Prepare generic type parameters:
@@ -1852,19 +1837,6 @@ impl Compiler<'_> {
1852
1837
loop_data : None ,
1853
1838
} ;
1854
1839
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) ;
1868
1840
1869
1841
// If there are type params, we need to push a special symbol table just for them
1870
1842
if let Some ( type_params) = type_params {
@@ -1941,9 +1913,6 @@ impl Compiler<'_> {
1941
1913
self . emit_return_value ( ) ;
1942
1914
1943
1915
let code = self . pop_code_object ( ) ;
1944
-
1945
- self . qualified_path . pop ( ) ;
1946
- self . qualified_path . append ( global_path_prefix. as_mut ( ) ) ;
1947
1916
self . ctx = prev_ctx;
1948
1917
1949
1918
emit ! ( self , Instruction :: LoadBuildClass ) ;
@@ -4429,10 +4398,6 @@ impl Compiler<'_> {
4429
4398
. line_index ( self . current_source_range . start ( ) )
4430
4399
}
4431
4400
4432
- fn push_qualified_path ( & mut self , name : & str ) {
4433
- self . qualified_path . push ( name. to_owned ( ) ) ;
4434
- }
4435
-
4436
4401
fn mark_generator ( & mut self ) {
4437
4402
self . current_code_info ( ) . flags |= bytecode:: CodeFlags :: IS_GENERATOR
4438
4403
}
0 commit comments