Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 0 additions & 15 deletions .claude/settings.json

This file was deleted.

41 changes: 16 additions & 25 deletions crates/vm/src/builtins/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ fn format_missing_args(
#[pyclass(module = false, name = "function", traverse = "manual")]
#[derive(Debug)]
pub struct PyFunction {
code: PyAtomicRef<PyCode>,
globals: PyDictRef,
builtins: PyObjectRef,
pub(crate) code: PyAtomicRef<PyCode>,
pub(crate) globals: PyDictRef,
pub(crate) builtins: PyObjectRef,
pub(crate) closure: Option<PyRef<PyTuple<PyCellRef>>>,
defaults_and_kwdefaults: PyMutex<(Option<PyTupleRef>, Option<PyDictRef>)>,
name: PyMutex<PyStrRef>,
Expand Down Expand Up @@ -617,11 +617,6 @@ impl Py<PyFunction> {

// Fast path: stack-allocated InterpreterFrame, no FrameObject.
// No refcount inc for code — it's alive via self.code for the call duration.
let nlocalsplus = code.localspluskinds.len();
let max_stackdepth = code.max_stackdepth as usize;
let localsplus =
crate::frame::LocalsPlus::new_on_datastack(nlocalsplus, max_stackdepth, vm);

let locals = if code.flags.contains(bytecode::CodeFlags::NEWLOCALS) {
crate::frame::FrameLocals::lazy()
} else if let Some(locals) = locals {
Expand All @@ -634,22 +629,21 @@ impl Py<PyFunction> {

// Use self.as_object() as raw pointer — no refcount inc/dec.
// The function is alive on the caller's stack for the call duration.
let mut iframe = crate::frame::InterpreterFrame::new(
let iframe = crate::frame::InterpreterFrame::new_on_datastack(
&self.code,
&self.globals,
&self.builtins,
Some(self.as_object()),
localsplus,
locals,
self.closure.as_ref().map_or(&[], |c| c.as_slice()),
crate::frame::FrameOwner::Thread,
vm,
);
let result = self
.fill_locals_from_args_iframe(&mut iframe, func_args, vm)
.and_then(|()| vm.run_frame_fast(&mut iframe));
.fill_locals_from_args_iframe(iframe, func_args, vm)
.and_then(|()| vm.run_frame_fast(iframe));
// Release data stack memory — must happen on both success and error.
unsafe {
if let Some(base) = iframe.localsplus.release_datastack() {
if let Some(base) = iframe.release_datastack_frame() {
vm.datastack_pop(base);
}
}
Expand Down Expand Up @@ -797,10 +791,6 @@ impl Py<PyFunction> {
vm: &VirtualMachine,
) -> PyResult {
let code = &*self.code;
let nlocalsplus = code.localspluskinds.len();
let max_stackdepth = code.max_stackdepth as usize;
let localsplus =
crate::frame::LocalsPlus::new_on_datastack(nlocalsplus, max_stackdepth, vm);

let locals = if code.flags.contains(bytecode::CodeFlags::NEWLOCALS) {
crate::frame::FrameLocals::lazy()
Expand All @@ -810,15 +800,14 @@ impl Py<PyFunction> {
))
};

let mut iframe = crate::frame::InterpreterFrame::new(
let iframe = crate::frame::InterpreterFrame::new_on_datastack(
code,
&self.globals,
&self.builtins,
Some(self.as_object()),
localsplus,
locals,
self.closure.as_ref().map_or(&[], |c| c.as_slice()),
crate::frame::FrameOwner::Thread,
vm,
);

// Fill arguments directly into fastlocals
Expand All @@ -829,9 +818,9 @@ impl Py<PyFunction> {
}
}

let result = vm.run_frame_fast(&mut iframe);
let result = vm.run_frame_fast(iframe);
unsafe {
if let Some(base) = iframe.localsplus.release_datastack() {
if let Some(base) = iframe.release_datastack_frame() {
vm.datastack_pop(base);
}
}
Expand Down Expand Up @@ -887,8 +876,10 @@ pub(crate) fn datastack_frame_size_bytes_for_code(code: &Py<PyCode>) -> Option<u
return None;
}
let nlocalsplus = code.localspluskinds.len();
let capacity = nlocalsplus.checked_add(code.max_stackdepth as usize)?;
capacity.checked_mul(core::mem::size_of::<usize>())
Some(crate::frame::datastack_iframe_total_bytes(
nlocalsplus,
code.max_stackdepth as usize,
))
}

impl PyPayload for PyFunction {
Expand Down
2 changes: 2 additions & 0 deletions crates/vm/src/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl ExecutionResult {
};
PyIterReturn::StopIteration(arg)
}
Self::TailCall => unreachable!("TailCall in generator/coroutine"),
}
}
}
Expand Down Expand Up @@ -104,6 +105,7 @@ impl Coro {
self.clear_frame_locals_on_close();
}
Ok(ExecutionResult::Yield(_)) => {}
Ok(ExecutionResult::TailCall) => unreachable!("TailCall in generator/coroutine"),
}
}

Expand Down
Loading
Loading