Skip to content

Clean up compiler parity leftovers#8174

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowone:bytecode-parity
Jun 26, 2026
Merged

Clean up compiler parity leftovers#8174
youknowone merged 1 commit into
RustPython:mainfrom
youknowone:bytecode-parity

Conversation

@youknowone

@youknowone youknowone commented Jun 26, 2026

Copy link
Copy Markdown
Member

follow-up #8138

Summary by CodeRabbit

  • Bug Fixes
    • Improved error reporting for invalid code generation and symbol-related issues by including the original source context and more precise locations.
    • Nonlocal and related scope errors now point to the correct source position more reliably.
    • Removed an outdated “feature not implemented yet” error case from code generation.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR removes one codegen error variant, adds optional source locations to symbols, records them for global and nonlocal declarations, uses them in symbol-table validation, and passes synthesized source text into AST compile syntax errors.

Changes

Source-location error reporting

Layer / File(s) Summary
Codegen error variant cleanup
crates/codegen/src/error.rs
CodegenErrorType removes NotImplementedYet, and its Display arm is deleted.
Symbol location plumbing
crates/codegen/src/symboltable.rs
Symbol gains location: Option<SourceLocation>, starts at None, and register_name stores declaration locations for global and nonlocal names.
Nonlocal validation locations
crates/codegen/src/symboltable.rs
analyze_symbol now uses symbol.location in nonlocal and free-variable errors, and analyze_symbol_comprehension is removed.
AST compile source text
crates/vm/src/stdlib/_ast.rs
compile clones synthesized text into source and passes it to syntax-error construction.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ShaharNaveh

Poem

🐇 I dug through symbols under moonlit code,
and found the paths where errors rode.
With source in paw, the compiler sings,
and nonlocals land on proper springs.
Thump, thump—tiny bugs take wing.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the PR’s compiler-parity cleanup theme and accurately reflects the overall changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone
youknowone marked this pull request as ready for review June 26, 2026 12:38

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 3361-3363: The global/nonlocal handling in symbol registration is
using the statement-wide range instead of each identifier’s own range, so errors
for later names point to the wrong place. Update the `Stmt::Global` and
`Stmt::Nonlocal` call sites in `symboltable.rs` to pass each name’s range (or
use `register_ident(name, ...)` for per-name registration) rather than
`statement.range()`. Keep the change aligned with the
`register_ident`/`symbol.location` flow so each declared name gets its own
location.
🪄 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: d89dab1f-1a63-483d-9e25-0a7e4d36bab9

📥 Commits

Reviewing files that changed from the base of the PR and between c449564 and 3b9bbbb.

📒 Files selected for processing (3)
  • crates/codegen/src/error.rs
  • crates/codegen/src/symboltable.rs
  • crates/vm/src/stdlib/_ast.rs
💤 Files with no reviewable changes (1)
  • crates/codegen/src/error.rs

Comment on lines +3361 to +3363
if matches!(role, SymbolUsage::Global | SymbolUsage::Nonlocal) {
symbol.location = location;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Store the per-name range for global/nonlocal declarations.

Line 3361 now persists the passed location, but the Stmt::Global/Stmt::Nonlocal callers pass statement.range() for every declared name. For nonlocal a, b, an error for b will point at the statement start instead of the offending identifier. Prefer calling register_ident(name, ...) or passing name.range.

Suggested fix
- self.register_name(name.as_str(), SymbolUsage::Global, statement.range())?;
+ self.register_ident(name, SymbolUsage::Global)?;

- self.register_name(
-     name.as_str(),
-     SymbolUsage::Nonlocal,
-     statement.range(),
- )?;
+ self.register_ident(name, SymbolUsage::Nonlocal)?;
🤖 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 3361 - 3363, The
global/nonlocal handling in symbol registration is using the statement-wide
range instead of each identifier’s own range, so errors for later names point to
the wrong place. Update the `Stmt::Global` and `Stmt::Nonlocal` call sites in
`symboltable.rs` to pass each name’s range (or use `register_ident(name, ...)`
for per-name registration) rather than `statement.range()`. Keep the change
aligned with the `register_ident`/`symbol.location` flow so each declared name
gets its own location.

@youknowone
youknowone merged commit 0009dd6 into RustPython:main Jun 26, 2026
26 checks passed
@youknowone
youknowone deleted the bytecode-parity branch June 26, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant