Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unify FastLocals and BoxVec stack into LocalsPlus
Replace separate FastLocals (Box<[Option<PyObjectRef>]>) and
BoxVec<Option<PyStackRef>> with a single LocalsPlus struct that
stores both in a contiguous Box<[usize]> array. The first
nlocalsplus slots are fastlocals and the rest is the evaluation
stack. Typed access is provided through transmute-based methods.

Remove BoxVec import from frame.rs.
  • Loading branch information
youknowone committed Mar 4, 2026
commit e286597ac2e99f7de68fb0b3cc09bd810c05ef09
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ impl Py<Frame> {
// Clear fastlocals
// SAFETY: Frame is not executing (detached or stopped).
{
let fastlocals = unsafe { self.fastlocals.borrow_mut() };
let fastlocals = unsafe { self.fastlocals_mut() };
for slot in fastlocals.iter_mut() {
*slot = None;
}
Expand Down
6 changes: 3 additions & 3 deletions crates/vm/src/builtins/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl PyFunction {
// https://github.com/python/cpython/blob/main/Python/ceval.c#L3681

// SAFETY: Frame was just created and not yet executing.
let fastlocals = unsafe { frame.fastlocals.borrow_mut() };
let fastlocals = unsafe { frame.fastlocals_mut() };

let mut args_iter = func_args.args.into_iter();

Expand Down Expand Up @@ -671,15 +671,15 @@ impl Py<PyFunction> {

// Move args directly into fastlocals (no clone/refcount needed)
{
let fastlocals = unsafe { frame.fastlocals.borrow_mut() };
let fastlocals = unsafe { frame.fastlocals_mut() };
for (slot, arg) in fastlocals.iter_mut().zip(args.drain(..)) {
*slot = Some(arg);
}
}

// Handle cell2arg
if let Some(cell2arg) = code.cell2arg.as_deref() {
let fastlocals = unsafe { frame.fastlocals.borrow_mut() };
let fastlocals = unsafe { frame.fastlocals_mut() };
for (cell_idx, arg_idx) in cell2arg.iter().enumerate().filter(|(_, i)| **i != -1) {
let x = fastlocals[*arg_idx as usize].take();
frame.set_cell_contents(cell_idx, x);
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/super.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Initializer for PySuper {
return Err(vm.new_runtime_error("super(): no arguments"));
}
// SAFETY: Frame is current and not concurrently mutated.
let obj = unsafe { frame.fastlocals.borrow() }[0]
let obj = unsafe { frame.fastlocals() }[0]
.clone()
.or_else(|| {
if let Some(cell2arg) = frame.code.cell2arg.as_deref() {
Expand Down
Loading