@@ -11,7 +11,7 @@ use crate::{
11
11
IndexMap , IndexSet , ToPythonName ,
12
12
error:: { CodegenError , CodegenErrorType , PatternUnreachableReason } ,
13
13
ir:: { self , BlockIdx } ,
14
- symboltable:: { self , SymbolFlags , SymbolScope , SymbolTable , SymbolTableType } ,
14
+ symboltable:: { self , CompilerScope , SymbolFlags , SymbolScope , SymbolTable } ,
15
15
unparse:: unparse_expr,
16
16
} ;
17
17
@@ -409,7 +409,7 @@ impl Compiler<'_> {
409
409
fn enter_scope (
410
410
& mut self ,
411
411
name : & str ,
412
- scope_type : SymbolTableType ,
412
+ scope_type : CompilerScope ,
413
413
key : usize , // In RustPython, we use the index in symbol_table_stack as key
414
414
lineno : u32 ,
415
415
) -> CompileResult < ( ) > {
@@ -452,14 +452,14 @@ impl Compiler<'_> {
452
452
// Handle implicit __class__ cell if needed
453
453
if ste. needs_class_closure {
454
454
// Cook up an implicit __class__ cell
455
- debug_assert_eq ! ( scope_type, SymbolTableType :: Class ) ;
455
+ debug_assert_eq ! ( scope_type, CompilerScope :: Class ) ;
456
456
cellvar_cache. insert ( "__class__" . to_string ( ) ) ;
457
457
}
458
458
459
459
// Handle implicit __classdict__ cell if needed
460
460
if ste. needs_classdict {
461
461
// Cook up an implicit __classdict__ cell
462
- debug_assert_eq ! ( scope_type, SymbolTableType :: Class ) ;
462
+ debug_assert_eq ! ( scope_type, CompilerScope :: Class ) ;
463
463
cellvar_cache. insert ( "__classdict__" . to_string ( ) ) ;
464
464
}
465
465
@@ -480,21 +480,21 @@ impl Compiler<'_> {
480
480
481
481
// Initialize u_metadata fields
482
482
let ( flags, posonlyarg_count, arg_count, kwonlyarg_count) = match scope_type {
483
- SymbolTableType :: Module => ( bytecode:: CodeFlags :: empty ( ) , 0 , 0 , 0 ) ,
484
- SymbolTableType :: Class => ( bytecode:: CodeFlags :: empty ( ) , 0 , 0 , 0 ) ,
485
- SymbolTableType :: Function | SymbolTableType :: Lambda => (
483
+ CompilerScope :: Module => ( bytecode:: CodeFlags :: empty ( ) , 0 , 0 , 0 ) ,
484
+ CompilerScope :: Class => ( bytecode:: CodeFlags :: empty ( ) , 0 , 0 , 0 ) ,
485
+ CompilerScope :: Function | CompilerScope :: AsyncFunction | CompilerScope :: Lambda => (
486
486
bytecode:: CodeFlags :: NEW_LOCALS | bytecode:: CodeFlags :: IS_OPTIMIZED ,
487
487
0 , // Will be set later in enter_function
488
488
0 , // Will be set later in enter_function
489
489
0 , // Will be set later in enter_function
490
490
) ,
491
- SymbolTableType :: Comprehension => (
491
+ CompilerScope :: Comprehension => (
492
492
bytecode:: CodeFlags :: NEW_LOCALS | bytecode:: CodeFlags :: IS_OPTIMIZED ,
493
493
0 ,
494
494
1 , // comprehensions take one argument (.0)
495
495
0 ,
496
496
) ,
497
- SymbolTableType :: TypeParams => (
497
+ CompilerScope :: TypeParams => (
498
498
bytecode:: CodeFlags :: NEW_LOCALS | bytecode:: CodeFlags :: IS_OPTIMIZED ,
499
499
0 ,
500
500
0 ,
@@ -530,7 +530,7 @@ impl Compiler<'_> {
530
530
kwonlyargcount : kwonlyarg_count,
531
531
firstlineno : OneIndexed :: new ( lineno as usize ) . unwrap_or ( OneIndexed :: MIN ) ,
532
532
} ,
533
- static_attributes : if scope_type == SymbolTableType :: Class {
533
+ static_attributes : if scope_type == CompilerScope :: Class {
534
534
Some ( IndexSet :: default ( ) )
535
535
} else {
536
536
None
@@ -544,12 +544,12 @@ impl Compiler<'_> {
544
544
self . code_stack . push ( code_info) ;
545
545
546
546
// Set qualname after pushing (uses compiler_set_qualname logic)
547
- if scope_type != SymbolTableType :: Module {
547
+ if scope_type != CompilerScope :: Module {
548
548
self . set_qualname ( ) ;
549
549
}
550
550
551
551
// Emit RESUME instruction
552
- let _resume_loc = if scope_type == SymbolTableType :: Module {
552
+ let _resume_loc = if scope_type == CompilerScope :: Module {
553
553
// Module scope starts with lineno 0
554
554
ruff_source_file:: SourceLocation {
555
555
row : OneIndexed :: MIN ,
@@ -569,7 +569,7 @@ impl Compiler<'_> {
569
569
}
570
570
) ;
571
571
572
- if scope_type == SymbolTableType :: Module {
572
+ if scope_type == CompilerScope :: Module {
573
573
// This would be loc.lineno = -1 in CPython
574
574
// We handle this differently in RustPython
575
575
}
@@ -950,11 +950,7 @@ impl Compiler<'_> {
950
950
cache = & mut info. metadata . cellvars ;
951
951
NameOpType :: Deref
952
952
} // TODO: is this right?
953
- SymbolScope :: TypeParams => {
954
- // Type parameters are always cell variables
955
- cache = & mut info. metadata . cellvars ;
956
- NameOpType :: Deref
957
- } // SymbolScope::Unknown => NameOpType::Global,
953
+ // SymbolScope::Unknown => NameOpType::Global,
958
954
} ;
959
955
960
956
if NameUsage :: Load == usage && name == "__debug__" {
@@ -1999,7 +1995,7 @@ impl Compiler<'_> {
1999
1995
let table = self . symbol_table_stack . last ( ) . unwrap ( ) ;
2000
1996
match table. lookup ( name) {
2001
1997
Some ( symbol) => match symbol. scope {
2002
- SymbolScope :: Cell | SymbolScope :: TypeParams => Ok ( SymbolScope :: Cell ) ,
1998
+ SymbolScope :: Cell => Ok ( SymbolScope :: Cell ) ,
2003
1999
SymbolScope :: Free => Ok ( SymbolScope :: Free ) ,
2004
2000
_ if symbol. flags . contains ( SymbolFlags :: FREE_CLASS ) => Ok ( SymbolScope :: Free ) ,
2005
2001
_ => Err ( CodegenErrorType :: SyntaxError ( format ! (
@@ -2204,7 +2200,7 @@ impl Compiler<'_> {
2204
2200
// Use enter_scope instead of push_output to match CPython
2205
2201
let key = self . symbol_table_stack . len ( ) ;
2206
2202
self . push_symbol_table ( ) ;
2207
- self . enter_scope ( name, SymbolTableType :: Class , key, firstlineno) ?;
2203
+ self . enter_scope ( name, CompilerScope :: Class , key, firstlineno) ?;
2208
2204
2209
2205
// Set qualname using the new method
2210
2206
let qualname = self . set_qualname ( ) ;
0 commit comments