Align symtable flag names with CPython#8184
Conversation
📝 WalkthroughWalkthroughThis PR renames symbol-table flags to the new ChangesSymbol flag migration across analyzer, codegen, and symtable API
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/symtable.py dependencies:
dependent tests: (2 tests)
Legend:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/codegen/src/symboltable.rs`:
- Around line 311-317: `SymbolFlags::DEF_BOUND` is currently mixing in the
RustPython-only `ITER` bit, which leaks into the public `_symtable.DEF_BOUND`
export and breaks CPython compatibility. Update the `DEF_BOUND` definition in
`symboltable.rs` to include only the CPython-aligned flags, and keep `ITER`
restricted to internal bound-check logic elsewhere in the symbol table handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 4c981d47-0be7-4e02-802a-f6f0517ef402
⛔ Files ignored due to path filters (1)
Lib/test/test_symtable.pyis excluded by!Lib/**
📒 Files selected for processing (3)
crates/codegen/src/compile.rscrates/codegen/src/symboltable.rscrates/vm/src/stdlib/_symtable.rs
| const DEF_BOUND = ( | ||
| Self::DEF_LOCAL.bits() | ||
| | Self::DEF_PARAM.bits() | ||
| | Self::DEF_IMPORT.bits() | ||
| | Self::ITER.bits() | ||
| | Self::DEF_TYPE_PARAM.bits() | ||
| ); |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Keep RustPython-only ITER out of the CPython DEF_BOUND mask.
Line 315 folds the internal ITER bit into DEF_BOUND, and _symtable now exports SymbolFlags::DEF_BOUND.bits() directly. That makes the public _symtable.DEF_BOUND value include a RustPython-specific flag, breaking the CPython-aligned flag contract. Keep DEF_BOUND CPython-compatible and include ITER only in internal bound checks.
Suggested fix
const DEF_BOUND = (
Self::DEF_LOCAL.bits()
| Self::DEF_PARAM.bits()
| Self::DEF_IMPORT.bits()
- | Self::ITER.bits()
| Self::DEF_TYPE_PARAM.bits()
); pub const fn is_bound(&self) -> bool {
- self.flags.intersects(SymbolFlags::DEF_BOUND)
+ self.flags
+ .intersects(SymbolFlags::DEF_BOUND | SymbolFlags::ITER)
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const DEF_BOUND = ( | |
| Self::DEF_LOCAL.bits() | |
| | Self::DEF_PARAM.bits() | |
| | Self::DEF_IMPORT.bits() | |
| | Self::ITER.bits() | |
| | Self::DEF_TYPE_PARAM.bits() | |
| ); | |
| const DEF_BOUND = ( | |
| Self::DEF_LOCAL.bits() | |
| | Self::DEF_PARAM.bits() | |
| | Self::DEF_IMPORT.bits() | |
| | Self::DEF_TYPE_PARAM.bits() | |
| ); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/codegen/src/symboltable.rs` around lines 311 - 317,
`SymbolFlags::DEF_BOUND` is currently mixing in the RustPython-only `ITER` bit,
which leaks into the public `_symtable.DEF_BOUND` export and breaks CPython
compatibility. Update the `DEF_BOUND` definition in `symboltable.rs` to include
only the CPython-aligned flags, and keep `ITER` restricted to internal
bound-check logic elsewhere in the symbol table handling.
| const DEF_GLOBAL = 1; | ||
| const DEF_LOCAL = 2; | ||
| const DEF_PARAM = 2 << 1; | ||
| const DEF_NONLOCAL = 2 << 2; | ||
| const USE = 2 << 3; |
There was a problem hiding this comment.
| const DEF_GLOBAL = 1; | |
| const DEF_LOCAL = 2; | |
| const DEF_PARAM = 2 << 1; | |
| const DEF_NONLOCAL = 2 << 2; | |
| const USE = 2 << 3; | |
| const DEF_GLOBAL = 1 << 0; | |
| const DEF_LOCAL = 1 << 1; | |
| const DEF_PARAM = 1 << 2; | |
| const DEF_NONLOCAL = 1 << 3; | |
| const USE = 1 << 4; |
if 2 << n better than this?
There was a problem hiding this comment.
I've matched those values to be 1:1 like they're defined over at CPython for it to not be confusing. I'd rather keep it like this if you're okay with it
Summary
Summary by CodeRabbit