Skip to content
Draft
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
Auto-format: cargo fmt --all
  • Loading branch information
github-actions[bot] committed Jan 29, 2026
commit 94b06a427a207c81f1c4ca7ad55af2f85c548640
12 changes: 9 additions & 3 deletions crates/compiler-core/src/marshal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,15 @@ pub fn deserialize_code<R: Read, Bag: ConstantBag>(
let mut ncellvars: u32 = 0;
let mut nfreevars: u32 = 0;
for &kind in localspluskinds.iter() {
if kind.contains(LocalKind::LOCAL) { nlocals += 1; }
if kind.contains(LocalKind::CELL) { ncellvars += 1; }
if kind.contains(LocalKind::FREE) { nfreevars += 1; }
if kind.contains(LocalKind::LOCAL) {
nlocals += 1;
}
if kind.contains(LocalKind::CELL) {
ncellvars += 1;
}
if kind.contains(LocalKind::FREE) {
nfreevars += 1;
}
}

// Read linetable and exceptiontable
Expand Down
10 changes: 8 additions & 2 deletions crates/vm/src/builtins/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,10 @@ impl PyCode {

#[pygetset]
pub fn co_cellvars(&self, vm: &VirtualMachine) -> PyTupleRef {
let cellvars: Vec<PyObjectRef> = self.code.localsplusnames.iter()
let cellvars: Vec<PyObjectRef> = self
.code
.localsplusnames
.iter()
.zip(self.code.localspluskinds.iter())
.filter(|&(_, kind)| kind.contains(bytecode::LocalKind::CELL))
.map(|(name, _)| name.to_object())
Expand Down Expand Up @@ -1032,7 +1035,10 @@ impl PyCode {
.into_iter()
.map(|o| o.as_interned_str(vm).unwrap())
.collect(),
OptionalArg::Missing => self.code.localsplusnames.iter()
OptionalArg::Missing => self
.code
.localsplusnames
.iter()
.zip(self.code.localspluskinds.iter())
.filter(|&(_, kind)| kind.contains(bytecode::LocalKind::CELL))
.map(|(name, _)| *name)
Expand Down
11 changes: 8 additions & 3 deletions crates/vm/src/builtins/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,16 @@ impl PyFunction {
}

{
let total_args = (code.arg_count + code.kwonlyarg_count
let total_args = (code.arg_count
+ code.kwonlyarg_count
+ code.flags.contains(bytecode::CodeFlags::VARARGS) as u32
+ code.flags.contains(bytecode::CodeFlags::VARKEYWORDS) as u32) as usize;
+ code.flags.contains(bytecode::CodeFlags::VARKEYWORDS) as u32)
as usize;
let mut cell_idx = 0;
for (i, &kind) in code.localspluskinds[..code.nlocals as usize].iter().enumerate() {
for (i, &kind) in code.localspluskinds[..code.nlocals as usize]
.iter()
.enumerate()
{
if kind.contains(bytecode::LocalKind::CELL) {
if i < total_args {
let arg = fastlocals[i].take();
Expand Down
10 changes: 7 additions & 3 deletions crates/vm/src/builtins/super.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ See also [CPython source code.](https://github.com/python/cpython/blob/50b48572d

use super::{PyStr, PyType, PyTypeRef};
use crate::{
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
bytecode,
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, bytecode,
class::PyClassImpl,
common::lock::PyRwLock,
function::{FuncArgs, IntoFuncArgs, OptionalArg},
Expand Down Expand Up @@ -89,7 +88,12 @@ impl Initializer for PySuper {
let obj = frame.fastlocals.lock()[0]
.clone()
.or_else(|| {
if frame.code.localspluskinds.first().map_or(false, |k| k.contains(bytecode::LocalKind::CELL)) {
if frame
.code
.localspluskinds
.first()
.map_or(false, |k| k.contains(bytecode::LocalKind::CELL))
{
// First argument (self) is captured as a cell
frame.cells_frees[0].get()
} else {
Expand Down
14 changes: 12 additions & 2 deletions crates/vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,12 @@ impl ExecutingFrame<'_> {
// Find the i-th cell/free variable name
let mut count = 0;
let mut found_name = None;
for (name, &kind) in self.code.localsplusnames.iter().zip(self.code.localspluskinds.iter()) {
for (name, &kind) in self
.code
.localsplusnames
.iter()
.zip(self.code.localspluskinds.iter())
{
if kind.intersects(bytecode::LocalKind::CELL | bytecode::LocalKind::FREE) {
if count == i {
found_name = Some(name);
Expand Down Expand Up @@ -1215,7 +1220,12 @@ impl ExecutingFrame<'_> {
// Find the i-th cell/free variable name
let mut count = 0;
let mut name = self.code.localsplusnames[0]; // placeholder
for (n, &kind) in self.code.localsplusnames.iter().zip(self.code.localspluskinds.iter()) {
for (n, &kind) in self
.code
.localsplusnames
.iter()
.zip(self.code.localspluskinds.iter())
{
if kind.intersects(bytecode::LocalKind::CELL | bytecode::LocalKind::FREE) {
if count == i {
name = *n;
Expand Down
Loading