◐ Shell
reader mode source ↗
Skip to content

Remove cells_frees duplicate storage from Frame#7351

Closed
youknowone wants to merge 2 commits into
RustPython:mainfrom
youknowone:worktree-frame-datastack
Closed

Remove cells_frees duplicate storage from Frame#7351
youknowone wants to merge 2 commits into
RustPython:mainfrom
youknowone:worktree-frame-datastack

Conversation

@youknowone

@youknowone youknowone commented Mar 4, 2026

Copy link
Copy Markdown
Member

Cell/free variable objects were stored in both a separate Box<[PyCellRef]> (cells_frees field) and in the localsplus fastlocals array. Remove the redundant cells_frees field and access cell objects directly through localsplus, eliminating one Box allocation and N clone operations per frame creation.

Summary by CodeRabbit

  • Refactor
    • Optimized VM frame variable storage mechanism by consolidating cell and free variable management for improved internal efficiency and code maintainability.

Cell/free variable objects were stored in both a separate
`Box<[PyCellRef]>` (cells_frees field) and in the localsplus
fastlocals array. Remove the redundant cells_frees field and
access cell objects directly through localsplus, eliminating
one Box allocation and N clone operations per frame creation.
@coderabbitai

coderabbitai Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Frame's cell and free variable storage refactored from a separate cells_frees buffer to inline placement within LocalsPlus.fastlocals array. Frame initialization, accessors, and instruction implementations updated accordingly to use new ExecutingFrame.cell_ref() helper method.

Changes

Cohort / File(s) Summary
Cell/Free Variable Storage Refactoring
crates/vm/src/frame.rs
Removed cells_frees field from Frame struct; cell and free variables now stored directly in LocalsPlus.fastlocals at positions after nlocals. Introduced ExecutingFrame.cell_ref() method for accessing cells. Updated Frame initialization, set_cell_contents(), get_cell_contents(), and Traverse implementation. Updated instruction implementations (DeleteDeref, LoadDeref, StoreDeref, etc.) to use cell_ref() instead of direct cells_frees access.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through fastlocals with glee,
Cell variables inline where they belong to be,
No separate buffer to hop around,
Storage unified—efficiency found! 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: removing the redundant cells_frees field from Frame that was duplicating cell/free variable storage.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Code has been automatically formatted

The code in this PR has been formatted using:

  • cargo fmt --all
    Please pull the latest changes before pushing again:
git pull origin worktree-frame-datastack

@youknowone youknowone marked this pull request as ready for review March 5, 2026 00:14
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@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.

Hide comment

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/vm/src/frame.rs`:
- Around line 743-744: Rename the misleading method clear_stack_and_cells() to
clear_stack() and update its docstring to state it only clears the value stack
(delegating cell/free clearing to clear_locals_and_stack()); inside the function
keep calling stack_clear() as before, and update all callsites and references
(including any uses alongside clear_locals_and_stack()) to the new name to
maintain behavior; ensure public API/export names are adjusted and tests/uses
compile.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 97256480-8c7b-4237-bb71-6049292ef84a

📥 Commits

Reviewing files that changed from the base of the PR and between 5c29074 and 577f474.

📒 Files selected for processing (1)
  • crates/vm/src/frame.rs

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