FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Align symtable flag names with CPython (#8184) · RustPython/RustPython@b39bec4 · GitHub

Repository navigation

Commit b39bec4

Browse files
authored
Align symtable flag names with CPython (#8184)
* ASSIGNED -> DEF_LOCAL * GLOBAL -> DEF_GLOBAL * REFERENCED -> USE * PARAMETER -> DEF_PARAM * expose symbol flags directly as a pyattr * FREE_CLASS -> DEF_FREE_CLASS * IMPORTED -> DEF_IMPORT * ANNOTATED -> DEF_ANNOT * DEF_COMP_ITER DEF_COMP_CELL DEF_TYPE_PARAM * DEF_NONLOCAL DEF_BOUND * Align flag values * unmark passing tests
1 parent 6a3d4e8 commit b39bec4

4 files changed

Lines changed: 115 additions & 105 deletions

File tree

‎Lib/test/test_symtable.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ def test_globals(self):
269269
self.assertTrue(self.top.lookup("some_non_assigned_global_var").is_global())
270270
self.assertTrue(self.top.lookup("some_assigned_global_var").is_global())
271271

272-
@unittest.expectedFailure # TODO: RUSTPYTHON
273272
def test_nonlocal(self):
274273
self.assertFalse(self.spam.lookup("some_var").is_nonlocal())
275274
self.assertTrue(self.other_internal.lookup("some_var").is_nonlocal())
@@ -288,7 +287,6 @@ def test_local(self):
288287
def test_free(self):
289288
self.assertTrue(self.internal.lookup("x").is_free())
290289

291-
@unittest.expectedFailure # TODO: RUSTPYTHON
292290
def test_referenced(self):
293291
self.assertTrue(self.internal.lookup("x").is_referenced())
294292
self.assertTrue(self.spam.lookup("internal").is_referenced())
@@ -358,7 +356,6 @@ def test_annotated(self):
358356
' x: int',
359357
'test', 'exec')
360358

361-
@unittest.expectedFailure # TODO: RUSTPYTHON
362359
def test_imported(self):
363360
self.assertTrue(self.top.lookup("sys").is_imported())
364361

‎crates/codegen/src/compile.rs‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ impl<'warnings> Compiler<'warnings> {
14731473
self.symbol_table_stack
14741474
.first()
14751475
.and_then(|table| table.symbols.get(name))
1476-
.is_some_and(|sym| sym.flags.contains(SymbolFlags::IMPORTED))
1476+
.is_some_and(|sym| sym.flags.contains(SymbolFlags::DEF_IMPORT))
14771477
}
14781478

14791479
/// Get the cell-relative index of a free variable.
@@ -1751,10 +1751,10 @@ impl<'warnings> Compiler<'warnings> {
17511751
}
17521752

17531753
// Check if __class__ is available as a cell/free variable
1754-
// The scope must be Free (from enclosing class) or have FREE_CLASS flag
1754+
// The scope must be Free (from enclosing class) or have DEF_FREE_CLASS flag
17551755
if let Some(symbol) = table.lookup("__class__") {
17561756
if symbol.scope != SymbolScope::Free
1757-
&& !symbol.flags.contains(SymbolFlags::FREE_CLASS)
1757+
&& !symbol.flags.contains(SymbolFlags::DEF_FREE_CLASS)
17581758
{
17591759
return None;
17601760
}
@@ -1872,7 +1872,7 @@ impl<'warnings> Compiler<'warnings> {
18721872
.symbols
18731873
.iter()
18741874
.filter(|(_, s)| {
1875-
s.scope == SymbolScope::Cell || s.flags.contains(SymbolFlags::COMP_CELL)
1875+
s.scope == SymbolScope::Cell || s.flags.contains(SymbolFlags::DEF_COMP_CELL)
18761876
})
18771877
.map(|(name, _)| name.clone())
18781878
.collect();
@@ -1920,9 +1920,9 @@ impl<'warnings> Compiler<'warnings> {
19201920
.filter(|(_, s)| {
19211921
s.scope == SymbolScope::Free
19221922
|| (scope_type != CompilerScope::Class
1923-
&& s.flags.contains(SymbolFlags::FREE_CLASS))
1923+
&& s.flags.contains(SymbolFlags::DEF_FREE_CLASS))
19241924
|| (scope_type == CompilerScope::Class
1925-
&& s.flags.contains(SymbolFlags::FREE_CLASS)
1925+
&& s.flags.contains(SymbolFlags::DEF_FREE_CLASS)
19261926
&& self.has_enclosing_non_module_code_scope())
19271927
})
19281928
.filter(|(name, symbol)| {
@@ -3132,7 +3132,7 @@ impl<'warnings> Compiler<'warnings> {
31323132
.rev()
31333133
.find(|table| table.typ == CompilerScope::Class)
31343134
.and_then(|table| table.lookup(name.as_ref()))
3135-
.is_some_and(|symbol| symbol.flags.contains(SymbolFlags::GLOBAL));
3135+
.is_some_and(|symbol| symbol.flags.contains(SymbolFlags::DEF_GLOBAL));
31363136

31373137
(
31383138
symbol.map(|s| s.scope),
@@ -5597,7 +5597,7 @@ impl<'warnings> Compiler<'warnings> {
55975597
Some(symbol) => match symbol.scope {
55985598
SymbolScope::Cell => Ok(SymbolScope::Cell),
55995599
SymbolScope::Free => Ok(SymbolScope::Free),
5600-
_ if symbol.flags.contains(SymbolFlags::FREE_CLASS) => Ok(SymbolScope::Free),
5600+
_ if symbol.flags.contains(SymbolFlags::DEF_FREE_CLASS) => Ok(SymbolScope::Free),
56015601
_ => Err(CodegenErrorType::SyntaxError(format!(
56025602
"get_ref_type: invalid scope for '{name}'"
56035603
))),
@@ -10888,13 +10888,13 @@ impl<'warnings> Compiler<'warnings> {
1088810888
let mut pushed_locals: Vec<String> = Vec::new();
1088910889
let mut fast_hidden_locals: Vec<String> = Vec::new();
1089010890
for (name, sym) in &comp_table.symbols {
10891-
if sym.flags.contains(SymbolFlags::PARAMETER) {
10891+
if sym.flags.contains(SymbolFlags::DEF_PARAM) {
1089210892
continue; // skip .0
1089310893
}
1089410894
let is_local = sym
1089510895
.flags
10896-
.intersects(SymbolFlags::ASSIGNED | SymbolFlags::ITER)
10897-
&& !sym.flags.contains(SymbolFlags::NONLOCAL);
10896+
.intersects(SymbolFlags::DEF_LOCAL | SymbolFlags::ITER)
10897+
&& !sym.flags.contains(SymbolFlags::DEF_NONLOCAL);
1089810898
if is_local {
1089910899
pushed_locals.push(name.clone());
1090010900
}
@@ -10908,7 +10908,7 @@ impl<'warnings> Compiler<'warnings> {
1090810908
// module/class scopes, also enable temporary fast locals for
1090910909
// comprehension-bound names only.
1091010910
for (name, comp_sym) in &comp_table.symbols {
10911-
if comp_sym.flags.contains(SymbolFlags::PARAMETER) {
10911+
if comp_sym.flags.contains(SymbolFlags::DEF_PARAM) {
1091210912
continue; // skip .0
1091310913
}
1091410914
let comp_scope = comp_sym.scope;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL