Skip to content

codegen: module seed CodeInfo emits empty flags#7782

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowone:fix/module-seed-codeflags-empty
May 5, 2026
Merged

codegen: module seed CodeInfo emits empty flags#7782
youknowone merged 1 commit into
RustPython:mainfrom
youknowone:fix/module-seed-codeflags-empty

Conversation

@youknowone
Copy link
Copy Markdown
Member

@youknowone youknowone commented May 5, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Corrected code flag initialization to properly reflect local variable binding semantics across different execution contexts.

CPython convention: top-level module / interactive / expression code
does not carry CO_NEWLOCALS or CO_OPTIMIZED. The per-scope mapping at
enter_scope::CompilerScope::Module already returns empty flags, but
Compiler::new seeded the root CodeInfo with CodeFlags::NEWLOCALS,
forcing module code into the NEWLOCALS arm of frame.rs:725-731 so
locals were allocated as a fresh empty dict instead of being bound to
globals (the correct semantics for exec(code, globals)).

Restore the seed to empty() so it matches the per-scope mapping and
CPython's compiler_enter_scope for module scope.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: f9934ad7-c055-44a9-986a-4c9ae99e49ae

📥 Commits

Reviewing files that changed from the base of the PR and between d877c30 and 7980213.

📒 Files selected for processing (1)
  • crates/codegen/src/compile.rs

📝 Walkthrough

Walkthrough

The ir::CodeInfo initialization in compile.rs changes from using CodeFlags::NEWLOCALS to CodeFlags::empty() to align module, interactive, and expression code semantics with CPython conventions. Supporting inline comments explain the rationale.

Changes

Code Generation Flag Alignment

Layer / File(s) Summary
Core Logic & Documentation
crates/codegen/src/compile.rs
ir::CodeInfo flags field initialization changes from CodeFlags::NEWLOCALS to CodeFlags::empty(), with inline comments detailing CPython module/interactive/expression semantics and per-scope flag mapping behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit hops through flags so bright,
NEWLOCALS bows out of sight,
Now empty() leads the way,
CPython rules the code today! 🐰✨

✨ 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 and usage tips.

@youknowone youknowone marked this pull request as ready for review May 5, 2026 07:22
@youknowone youknowone merged commit ae7ff9c into RustPython:main May 5, 2026
24 of 25 checks passed
@youknowone youknowone deleted the fix/module-seed-codeflags-empty branch May 5, 2026 07:22
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