From a16cd83ff2a9da3f9f4fc6d1be6ffc6c4f08d85c Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" Date: Tue, 3 Mar 2026 10:17:27 +0900 Subject: [PATCH 1/2] Remove unsafe ctx cast in make_class Use Context::genesis() directly in make_class to obtain &'static Context, eliminating the raw pointer cast. --- crates/vm/src/class.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/vm/src/class.rs b/crates/vm/src/class.rs index 2dc3060736f..cdfcaab7e63 100644 --- a/crates/vm/src/class.rs +++ b/crates/vm/src/class.rs @@ -210,12 +210,10 @@ pub trait PyClassImpl: PyClassDef { where Self: StaticType + Sized, { + let _ = ctx; // only used to ensure Context is initialized (*Self::static_cell().get_or_init(|| { let typ = Self::create_static_type(); - // SAFETY: Context is heap-allocated via PyRc and stored in a static cell - // (Context::genesis), so it lives for 'static. - let ctx: &'static Context = unsafe { &*(ctx as *const Context) }; - Self::extend_class(ctx, unsafe { + Self::extend_class(Context::genesis(), unsafe { // typ will be saved in static_cell let r: &Py = &typ; let r: &'static Py = core::mem::transmute(r); From 0b51d3ba75a3dcf37b0013151a4175e520b524f3 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" Date: Tue, 3 Mar 2026 22:06:24 +0900 Subject: [PATCH 2/2] make_class -> make_static_type --- crates/derive-impl/src/pymodule.rs | 4 +- crates/stdlib/src/select.rs | 6 +- crates/vm/src/class.rs | 3 +- crates/vm/src/stdlib/ast.rs | 16 +- crates/vm/src/stdlib/ast/pyast.rs | 252 ++++++++++++++--------------- crates/vm/src/stdlib/ast/python.rs | 4 +- crates/vm/src/stdlib/ast/repr.rs | 6 +- crates/vm/src/stdlib/builtins.rs | 6 +- crates/vm/src/stdlib/ctypes.rs | 32 ++-- crates/wasm/src/browser_module.rs | 4 +- 10 files changed, 166 insertions(+), 167 deletions(-) diff --git a/crates/derive-impl/src/pymodule.rs b/crates/derive-impl/src/pymodule.rs index f627e7876cc..775e6858520 100644 --- a/crates/derive-impl/src/pymodule.rs +++ b/crates/derive-impl/src/pymodule.rs @@ -753,7 +753,7 @@ impl ModuleItem for ClassItem { class_meta.class_name()? }; let class_new = quote_spanned!(ident.span() => - let new_class = <#ident as ::rustpython_vm::class::PyClassImpl>::make_class(ctx); + let new_class = <#ident as ::rustpython_vm::class::PyClassImpl>::make_static_type(); // Only set __module__ string if the class doesn't already have a // getset descriptor for __module__ (which provides instance-level // module resolution, e.g. TypeAliasType) @@ -850,7 +850,7 @@ impl ModuleItem for StructSequenceItem { // Generate the class creation code let class_new = quote_spanned!(pytype_ident.span() => - let new_class = <#pytype_ident as ::rustpython_vm::class::PyClassImpl>::make_class(ctx); + let new_class = <#pytype_ident as ::rustpython_vm::class::PyClassImpl>::make_static_type(); { let module_key = rustpython_vm::identifier!(ctx, __module__); let has_module_getset = new_class.attributes.read() diff --git a/crates/stdlib/src/select.rs b/crates/stdlib/src/select.rs index bc8aded5478..181c4573996 100644 --- a/crates/stdlib/src/select.rs +++ b/crates/stdlib/src/select.rs @@ -223,7 +223,7 @@ mod decl { #[cfg(unix)] { use crate::vm::class::PyClassImpl; - poll::PyPoll::make_class(&vm.ctx); + poll::PyPoll::make_static_type(); } __module_exec(vm, module); @@ -527,9 +527,9 @@ mod decl { #[cfg(any(target_os = "linux", target_os = "android", target_os = "redox"))] #[pyattr(name = "epoll", once)] - fn epoll(vm: &VirtualMachine) -> PyTypeRef { + fn epoll(_vm: &VirtualMachine) -> PyTypeRef { use crate::vm::class::PyClassImpl; - epoll::PyEpoll::make_class(&vm.ctx) + epoll::PyEpoll::make_static_type() } #[cfg(any(target_os = "linux", target_os = "android", target_os = "redox"))] diff --git a/crates/vm/src/class.rs b/crates/vm/src/class.rs index cdfcaab7e63..237e11abbe5 100644 --- a/crates/vm/src/class.rs +++ b/crates/vm/src/class.rs @@ -206,11 +206,10 @@ pub trait PyClassImpl: PyClassDef { class.extend_methods(class.slots.methods, ctx); } - fn make_class(ctx: &Context) -> PyTypeRef + fn make_static_type() -> PyTypeRef where Self: StaticType + Sized, { - let _ = ctx; // only used to ensure Context is initialized (*Self::static_cell().get_or_init(|| { let typ = Self::create_static_type(); Self::extend_class(Context::genesis(), unsafe { diff --git a/crates/vm/src/stdlib/ast.rs b/crates/vm/src/stdlib/ast.rs index a04864634be..1a4553c5d21 100644 --- a/crates/vm/src/stdlib/ast.rs +++ b/crates/vm/src/stdlib/ast.rs @@ -301,15 +301,15 @@ fn node_add_location( } /// Return the expected AST mod type class for a compile() mode string. -pub(crate) fn mode_type_and_name( - ctx: &Context, - mode: &str, -) -> Option<(PyRef, &'static str)> { +pub(crate) fn mode_type_and_name(mode: &str) -> Option<(PyRef, &'static str)> { match mode { - "exec" => Some((pyast::NodeModModule::make_class(ctx), "Module")), - "eval" => Some((pyast::NodeModExpression::make_class(ctx), "Expression")), - "single" => Some((pyast::NodeModInteractive::make_class(ctx), "Interactive")), - "func_type" => Some((pyast::NodeModFunctionType::make_class(ctx), "FunctionType")), + "exec" => Some((pyast::NodeModModule::make_static_type(), "Module")), + "eval" => Some((pyast::NodeModExpression::make_static_type(), "Expression")), + "single" => Some((pyast::NodeModInteractive::make_static_type(), "Interactive")), + "func_type" => Some(( + pyast::NodeModFunctionType::make_static_type(), + "FunctionType", + )), _ => None, } } diff --git a/crates/vm/src/stdlib/ast/pyast.rs b/crates/vm/src/stdlib/ast/pyast.rs index 14245a56c09..4b6e97e13fc 100644 --- a/crates/vm/src/stdlib/ast/pyast.rs +++ b/crates/vm/src/stdlib/ast/pyast.rs @@ -1523,132 +1523,132 @@ const FIELD_TYPES: &[(&str, &[(&str, FieldType)])] = &[ pub fn extend_module_nodes(vm: &VirtualMachine, module: &Py) { extend_module!(vm, module, { - "AST" => NodeAst::make_class(&vm.ctx), - "mod" => NodeMod::make_class(&vm.ctx), - "Module" => NodeModModule::make_class(&vm.ctx), - "Interactive" => NodeModInteractive::make_class(&vm.ctx), - "Expression" => NodeModExpression::make_class(&vm.ctx), - "FunctionType" => NodeModFunctionType::make_class(&vm.ctx), - "stmt" => NodeStmt::make_class(&vm.ctx), - "FunctionDef" => NodeStmtFunctionDef::make_class(&vm.ctx), - "AsyncFunctionDef" => NodeStmtAsyncFunctionDef::make_class(&vm.ctx), - "ClassDef" => NodeStmtClassDef::make_class(&vm.ctx), - "Return" => NodeStmtReturn::make_class(&vm.ctx), - "Delete" => NodeStmtDelete::make_class(&vm.ctx), - "Assign" => NodeStmtAssign::make_class(&vm.ctx), - "TypeAlias" => NodeStmtTypeAlias::make_class(&vm.ctx), - "AugAssign" => NodeStmtAugAssign::make_class(&vm.ctx), - "AnnAssign" => NodeStmtAnnAssign::make_class(&vm.ctx), - "For" => NodeStmtFor::make_class(&vm.ctx), - "AsyncFor" => NodeStmtAsyncFor::make_class(&vm.ctx), - "While" => NodeStmtWhile::make_class(&vm.ctx), - "If" => NodeStmtIf::make_class(&vm.ctx), - "With" => NodeStmtWith::make_class(&vm.ctx), - "AsyncWith" => NodeStmtAsyncWith::make_class(&vm.ctx), - "Match" => NodeStmtMatch::make_class(&vm.ctx), - "Raise" => NodeStmtRaise::make_class(&vm.ctx), - "Try" => NodeStmtTry::make_class(&vm.ctx), - "TryStar" => NodeStmtTryStar::make_class(&vm.ctx), - "Assert" => NodeStmtAssert::make_class(&vm.ctx), - "Import" => NodeStmtImport::make_class(&vm.ctx), - "ImportFrom" => NodeStmtImportFrom::make_class(&vm.ctx), - "Global" => NodeStmtGlobal::make_class(&vm.ctx), - "Nonlocal" => NodeStmtNonlocal::make_class(&vm.ctx), - "Expr" => NodeStmtExpr::make_class(&vm.ctx), - "Pass" => NodeStmtPass::make_class(&vm.ctx), - "Break" => NodeStmtBreak::make_class(&vm.ctx), - "Continue" => NodeStmtContinue::make_class(&vm.ctx), - "expr" => NodeExpr::make_class(&vm.ctx), - "BoolOp" => NodeExprBoolOp::make_class(&vm.ctx), - "NamedExpr" => NodeExprNamedExpr::make_class(&vm.ctx), - "BinOp" => NodeExprBinOp::make_class(&vm.ctx), - "UnaryOp" => NodeExprUnaryOp::make_class(&vm.ctx), - "Lambda" => NodeExprLambda::make_class(&vm.ctx), - "IfExp" => NodeExprIfExp::make_class(&vm.ctx), - "Dict" => NodeExprDict::make_class(&vm.ctx), - "Set" => NodeExprSet::make_class(&vm.ctx), - "ListComp" => NodeExprListComp::make_class(&vm.ctx), - "SetComp" => NodeExprSetComp::make_class(&vm.ctx), - "DictComp" => NodeExprDictComp::make_class(&vm.ctx), - "GeneratorExp" => NodeExprGeneratorExp::make_class(&vm.ctx), - "Await" => NodeExprAwait::make_class(&vm.ctx), - "Yield" => NodeExprYield::make_class(&vm.ctx), - "YieldFrom" => NodeExprYieldFrom::make_class(&vm.ctx), - "Compare" => NodeExprCompare::make_class(&vm.ctx), - "Call" => NodeExprCall::make_class(&vm.ctx), - "FormattedValue" => NodeExprFormattedValue::make_class(&vm.ctx), - "JoinedStr" => NodeExprJoinedStr::make_class(&vm.ctx), - "TemplateStr" => NodeExprTemplateStr::make_class(&vm.ctx), - "Interpolation" => NodeExprInterpolation::make_class(&vm.ctx), - "Constant" => NodeExprConstant::make_class(&vm.ctx), - "Attribute" => NodeExprAttribute::make_class(&vm.ctx), - "Subscript" => NodeExprSubscript::make_class(&vm.ctx), - "Starred" => NodeExprStarred::make_class(&vm.ctx), - "Name" => NodeExprName::make_class(&vm.ctx), - "List" => NodeExprList::make_class(&vm.ctx), - "Tuple" => NodeExprTuple::make_class(&vm.ctx), - "Slice" => NodeExprSlice::make_class(&vm.ctx), - "expr_context" => NodeExprContext::make_class(&vm.ctx), - "Load" => NodeExprContextLoad::make_class(&vm.ctx), - "Store" => NodeExprContextStore::make_class(&vm.ctx), - "Del" => NodeExprContextDel::make_class(&vm.ctx), - "boolop" => NodeBoolOp::make_class(&vm.ctx), - "And" => NodeBoolOpAnd::make_class(&vm.ctx), - "Or" => NodeBoolOpOr::make_class(&vm.ctx), - "operator" => NodeOperator::make_class(&vm.ctx), - "Add" => NodeOperatorAdd::make_class(&vm.ctx), - "Sub" => NodeOperatorSub::make_class(&vm.ctx), - "Mult" => NodeOperatorMult::make_class(&vm.ctx), - "MatMult" => NodeOperatorMatMult::make_class(&vm.ctx), - "Div" => NodeOperatorDiv::make_class(&vm.ctx), - "Mod" => NodeOperatorMod::make_class(&vm.ctx), - "Pow" => NodeOperatorPow::make_class(&vm.ctx), - "LShift" => NodeOperatorLShift::make_class(&vm.ctx), - "RShift" => NodeOperatorRShift::make_class(&vm.ctx), - "BitOr" => NodeOperatorBitOr::make_class(&vm.ctx), - "BitXor" => NodeOperatorBitXor::make_class(&vm.ctx), - "BitAnd" => NodeOperatorBitAnd::make_class(&vm.ctx), - "FloorDiv" => NodeOperatorFloorDiv::make_class(&vm.ctx), - "unaryop" => NodeUnaryOp::make_class(&vm.ctx), - "Invert" => NodeUnaryOpInvert::make_class(&vm.ctx), - "Not" => NodeUnaryOpNot::make_class(&vm.ctx), - "UAdd" => NodeUnaryOpUAdd::make_class(&vm.ctx), - "USub" => NodeUnaryOpUSub::make_class(&vm.ctx), - "cmpop" => NodeCmpOp::make_class(&vm.ctx), - "Eq" => NodeCmpOpEq::make_class(&vm.ctx), - "NotEq" => NodeCmpOpNotEq::make_class(&vm.ctx), - "Lt" => NodeCmpOpLt::make_class(&vm.ctx), - "LtE" => NodeCmpOpLtE::make_class(&vm.ctx), - "Gt" => NodeCmpOpGt::make_class(&vm.ctx), - "GtE" => NodeCmpOpGtE::make_class(&vm.ctx), - "Is" => NodeCmpOpIs::make_class(&vm.ctx), - "IsNot" => NodeCmpOpIsNot::make_class(&vm.ctx), - "In" => NodeCmpOpIn::make_class(&vm.ctx), - "NotIn" => NodeCmpOpNotIn::make_class(&vm.ctx), - "comprehension" => NodeComprehension::make_class(&vm.ctx), - "excepthandler" => NodeExceptHandler::make_class(&vm.ctx), - "ExceptHandler" => NodeExceptHandlerExceptHandler::make_class(&vm.ctx), - "arguments" => NodeArguments::make_class(&vm.ctx), - "arg" => NodeArg::make_class(&vm.ctx), - "keyword" => NodeKeyword::make_class(&vm.ctx), - "alias" => NodeAlias::make_class(&vm.ctx), - "withitem" => NodeWithItem::make_class(&vm.ctx), - "match_case" => NodeMatchCase::make_class(&vm.ctx), - "pattern" => NodePattern::make_class(&vm.ctx), - "MatchValue" => NodePatternMatchValue::make_class(&vm.ctx), - "MatchSingleton" => NodePatternMatchSingleton::make_class(&vm.ctx), - "MatchSequence" => NodePatternMatchSequence::make_class(&vm.ctx), - "MatchMapping" => NodePatternMatchMapping::make_class(&vm.ctx), - "MatchClass" => NodePatternMatchClass::make_class(&vm.ctx), - "MatchStar" => NodePatternMatchStar::make_class(&vm.ctx), - "MatchAs" => NodePatternMatchAs::make_class(&vm.ctx), - "MatchOr" => NodePatternMatchOr::make_class(&vm.ctx), - "type_ignore" => NodeTypeIgnore::make_class(&vm.ctx), - "TypeIgnore" => NodeTypeIgnoreTypeIgnore::make_class(&vm.ctx), - "type_param" => NodeTypeParam::make_class(&vm.ctx), - "TypeVar" => NodeTypeParamTypeVar::make_class(&vm.ctx), - "ParamSpec" => NodeTypeParamParamSpec::make_class(&vm.ctx), - "TypeVarTuple" => NodeTypeParamTypeVarTuple::make_class(&vm.ctx), + "AST" => NodeAst::make_static_type(), + "mod" => NodeMod::make_static_type(), + "Module" => NodeModModule::make_static_type(), + "Interactive" => NodeModInteractive::make_static_type(), + "Expression" => NodeModExpression::make_static_type(), + "FunctionType" => NodeModFunctionType::make_static_type(), + "stmt" => NodeStmt::make_static_type(), + "FunctionDef" => NodeStmtFunctionDef::make_static_type(), + "AsyncFunctionDef" => NodeStmtAsyncFunctionDef::make_static_type(), + "ClassDef" => NodeStmtClassDef::make_static_type(), + "Return" => NodeStmtReturn::make_static_type(), + "Delete" => NodeStmtDelete::make_static_type(), + "Assign" => NodeStmtAssign::make_static_type(), + "TypeAlias" => NodeStmtTypeAlias::make_static_type(), + "AugAssign" => NodeStmtAugAssign::make_static_type(), + "AnnAssign" => NodeStmtAnnAssign::make_static_type(), + "For" => NodeStmtFor::make_static_type(), + "AsyncFor" => NodeStmtAsyncFor::make_static_type(), + "While" => NodeStmtWhile::make_static_type(), + "If" => NodeStmtIf::make_static_type(), + "With" => NodeStmtWith::make_static_type(), + "AsyncWith" => NodeStmtAsyncWith::make_static_type(), + "Match" => NodeStmtMatch::make_static_type(), + "Raise" => NodeStmtRaise::make_static_type(), + "Try" => NodeStmtTry::make_static_type(), + "TryStar" => NodeStmtTryStar::make_static_type(), + "Assert" => NodeStmtAssert::make_static_type(), + "Import" => NodeStmtImport::make_static_type(), + "ImportFrom" => NodeStmtImportFrom::make_static_type(), + "Global" => NodeStmtGlobal::make_static_type(), + "Nonlocal" => NodeStmtNonlocal::make_static_type(), + "Expr" => NodeStmtExpr::make_static_type(), + "Pass" => NodeStmtPass::make_static_type(), + "Break" => NodeStmtBreak::make_static_type(), + "Continue" => NodeStmtContinue::make_static_type(), + "expr" => NodeExpr::make_static_type(), + "BoolOp" => NodeExprBoolOp::make_static_type(), + "NamedExpr" => NodeExprNamedExpr::make_static_type(), + "BinOp" => NodeExprBinOp::make_static_type(), + "UnaryOp" => NodeExprUnaryOp::make_static_type(), + "Lambda" => NodeExprLambda::make_static_type(), + "IfExp" => NodeExprIfExp::make_static_type(), + "Dict" => NodeExprDict::make_static_type(), + "Set" => NodeExprSet::make_static_type(), + "ListComp" => NodeExprListComp::make_static_type(), + "SetComp" => NodeExprSetComp::make_static_type(), + "DictComp" => NodeExprDictComp::make_static_type(), + "GeneratorExp" => NodeExprGeneratorExp::make_static_type(), + "Await" => NodeExprAwait::make_static_type(), + "Yield" => NodeExprYield::make_static_type(), + "YieldFrom" => NodeExprYieldFrom::make_static_type(), + "Compare" => NodeExprCompare::make_static_type(), + "Call" => NodeExprCall::make_static_type(), + "FormattedValue" => NodeExprFormattedValue::make_static_type(), + "JoinedStr" => NodeExprJoinedStr::make_static_type(), + "TemplateStr" => NodeExprTemplateStr::make_static_type(), + "Interpolation" => NodeExprInterpolation::make_static_type(), + "Constant" => NodeExprConstant::make_static_type(), + "Attribute" => NodeExprAttribute::make_static_type(), + "Subscript" => NodeExprSubscript::make_static_type(), + "Starred" => NodeExprStarred::make_static_type(), + "Name" => NodeExprName::make_static_type(), + "List" => NodeExprList::make_static_type(), + "Tuple" => NodeExprTuple::make_static_type(), + "Slice" => NodeExprSlice::make_static_type(), + "expr_context" => NodeExprContext::make_static_type(), + "Load" => NodeExprContextLoad::make_static_type(), + "Store" => NodeExprContextStore::make_static_type(), + "Del" => NodeExprContextDel::make_static_type(), + "boolop" => NodeBoolOp::make_static_type(), + "And" => NodeBoolOpAnd::make_static_type(), + "Or" => NodeBoolOpOr::make_static_type(), + "operator" => NodeOperator::make_static_type(), + "Add" => NodeOperatorAdd::make_static_type(), + "Sub" => NodeOperatorSub::make_static_type(), + "Mult" => NodeOperatorMult::make_static_type(), + "MatMult" => NodeOperatorMatMult::make_static_type(), + "Div" => NodeOperatorDiv::make_static_type(), + "Mod" => NodeOperatorMod::make_static_type(), + "Pow" => NodeOperatorPow::make_static_type(), + "LShift" => NodeOperatorLShift::make_static_type(), + "RShift" => NodeOperatorRShift::make_static_type(), + "BitOr" => NodeOperatorBitOr::make_static_type(), + "BitXor" => NodeOperatorBitXor::make_static_type(), + "BitAnd" => NodeOperatorBitAnd::make_static_type(), + "FloorDiv" => NodeOperatorFloorDiv::make_static_type(), + "unaryop" => NodeUnaryOp::make_static_type(), + "Invert" => NodeUnaryOpInvert::make_static_type(), + "Not" => NodeUnaryOpNot::make_static_type(), + "UAdd" => NodeUnaryOpUAdd::make_static_type(), + "USub" => NodeUnaryOpUSub::make_static_type(), + "cmpop" => NodeCmpOp::make_static_type(), + "Eq" => NodeCmpOpEq::make_static_type(), + "NotEq" => NodeCmpOpNotEq::make_static_type(), + "Lt" => NodeCmpOpLt::make_static_type(), + "LtE" => NodeCmpOpLtE::make_static_type(), + "Gt" => NodeCmpOpGt::make_static_type(), + "GtE" => NodeCmpOpGtE::make_static_type(), + "Is" => NodeCmpOpIs::make_static_type(), + "IsNot" => NodeCmpOpIsNot::make_static_type(), + "In" => NodeCmpOpIn::make_static_type(), + "NotIn" => NodeCmpOpNotIn::make_static_type(), + "comprehension" => NodeComprehension::make_static_type(), + "excepthandler" => NodeExceptHandler::make_static_type(), + "ExceptHandler" => NodeExceptHandlerExceptHandler::make_static_type(), + "arguments" => NodeArguments::make_static_type(), + "arg" => NodeArg::make_static_type(), + "keyword" => NodeKeyword::make_static_type(), + "alias" => NodeAlias::make_static_type(), + "withitem" => NodeWithItem::make_static_type(), + "match_case" => NodeMatchCase::make_static_type(), + "pattern" => NodePattern::make_static_type(), + "MatchValue" => NodePatternMatchValue::make_static_type(), + "MatchSingleton" => NodePatternMatchSingleton::make_static_type(), + "MatchSequence" => NodePatternMatchSequence::make_static_type(), + "MatchMapping" => NodePatternMatchMapping::make_static_type(), + "MatchClass" => NodePatternMatchClass::make_static_type(), + "MatchStar" => NodePatternMatchStar::make_static_type(), + "MatchAs" => NodePatternMatchAs::make_static_type(), + "MatchOr" => NodePatternMatchOr::make_static_type(), + "type_ignore" => NodeTypeIgnore::make_static_type(), + "TypeIgnore" => NodeTypeIgnoreTypeIgnore::make_static_type(), + "type_param" => NodeTypeParam::make_static_type(), + "TypeVar" => NodeTypeParamTypeVar::make_static_type(), + "ParamSpec" => NodeTypeParamParamSpec::make_static_type(), + "TypeVarTuple" => NodeTypeParamTypeVarTuple::make_static_type(), }); // Populate _field_types with real Python type objects diff --git a/crates/vm/src/stdlib/ast/python.rs b/crates/vm/src/stdlib/ast/python.rs index acc36202cd1..c8883212a0c 100644 --- a/crates/vm/src/stdlib/ast/python.rs +++ b/crates/vm/src/stdlib/ast/python.rs @@ -366,7 +366,7 @@ Support for arbitrary keyword arguments is deprecated and will be removed in Pyt field_types.map(|ft| ft.downcast::()) { let expr_ctx_type: PyObjectRef = - super::super::pyast::NodeExprContext::make_class(&vm.ctx).into(); + super::super::pyast::NodeExprContext::make_static_type().into(); for field in &fields { if set_fields.contains(field.as_str()) { @@ -382,7 +382,7 @@ Support for arbitrary keyword arguments is deprecated and will be removed in Pyt } else if ftype.is(&expr_ctx_type) { // expr_context — default to Load() let load_type = - super::super::pyast::NodeExprContextLoad::make_class(&vm.ctx); + super::super::pyast::NodeExprContextLoad::make_static_type(); let load_instance = load_type .get_attr(vm.ctx.intern_str("_instance")) .unwrap_or_else(|| { diff --git a/crates/vm/src/stdlib/ast/repr.rs b/crates/vm/src/stdlib/ast/repr.rs index 0b7f903f807..47fceb2386e 100644 --- a/crates/vm/src/stdlib/ast/repr.rs +++ b/crates/vm/src/stdlib/ast/repr.rs @@ -20,7 +20,7 @@ fn repr_ast_list(vm: &VirtualMachine, items: Vec, depth: usize) -> if idx == 1 && items.len() == 1 { break; } - let repr = if item.fast_isinstance(&NodeAst::make_class(&vm.ctx)) { + let repr = if item.fast_isinstance(&NodeAst::make_static_type()) { repr_ast_node(vm, item, depth.saturating_sub(1))? } else { item.repr(vm)?.as_wtf8().to_owned() @@ -62,7 +62,7 @@ fn repr_ast_tuple(vm: &VirtualMachine, items: Vec, depth: usize) -> if idx == 1 && items.len() == 1 { break; } - let repr = if item.fast_isinstance(&NodeAst::make_class(&vm.ctx)) { + let repr = if item.fast_isinstance(&NodeAst::make_static_type()) { repr_ast_node(vm, item, depth.saturating_sub(1))? } else { item.repr(vm)?.as_wtf8().to_owned() @@ -136,7 +136,7 @@ pub(crate) fn repr_ast_node( .downcast::() .expect("tuple type should downcast"); repr_ast_tuple(vm, tuple.as_slice().to_vec(), depth)? - } else if value.fast_isinstance(&NodeAst::make_class(&vm.ctx)) { + } else if value.fast_isinstance(&NodeAst::make_static_type()) { repr_ast_node(vm, &value, depth.saturating_sub(1))? } else { value.repr(vm)?.as_wtf8().to_owned() diff --git a/crates/vm/src/stdlib/builtins.rs b/crates/vm/src/stdlib/builtins.rs index 2d81f01f305..528bd4a50a3 100644 --- a/crates/vm/src/stdlib/builtins.rs +++ b/crates/vm/src/stdlib/builtins.rs @@ -277,7 +277,7 @@ mod builtins { if args .source - .fast_isinstance(&ast::NodeAst::make_class(&vm.ctx)) + .fast_isinstance(&ast::NodeAst::make_static_type()) { let flags: i32 = args.flags.map_or(Ok(0), |v| v.try_to_primitive(vm))?; let is_ast_only = !(flags & ast::PY_CF_ONLY_AST).is_zero(); @@ -291,7 +291,7 @@ mod builtins { // compile(ast_node, ..., PyCF_ONLY_AST) returns the AST after validation if is_ast_only { - let (expected_type, expected_name) = ast::mode_type_and_name(&vm.ctx, mode_str) + let (expected_type, expected_name) = ast::mode_type_and_name(mode_str) .ok_or_else(|| { vm.new_value_error( "compile() mode must be 'exec', 'eval', 'single' or 'func_type'" @@ -1344,7 +1344,7 @@ mod builtins { pub fn init_module(vm: &VirtualMachine, module: &Py) { let ctx = &vm.ctx; - crate::protocol::VecBuffer::make_class(&vm.ctx); + crate::protocol::VecBuffer::make_static_type(); module.__init_methods(vm).unwrap(); builtins::module_exec(vm, module).unwrap(); diff --git a/crates/vm/src/stdlib/ctypes.rs b/crates/vm/src/stdlib/ctypes.rs index b358d04a6e8..8ab52f3bcef 100644 --- a/crates/vm/src/stdlib/ctypes.rs +++ b/crates/vm/src/stdlib/ctypes.rs @@ -1300,26 +1300,26 @@ pub(crate) mod _ctypes { __module_exec(vm, module); let ctx = &vm.ctx; - PyCSimpleType::make_class(ctx); - array::PyCArrayType::make_class(ctx); - pointer::PyCPointerType::make_class(ctx); - structure::PyCStructType::make_class(ctx); - union::PyCUnionType::make_class(ctx); - function::PyCFuncPtrType::make_class(ctx); - function::RawMemoryBuffer::make_class(ctx); + PyCSimpleType::make_static_type(); + array::PyCArrayType::make_static_type(); + pointer::PyCPointerType::make_static_type(); + structure::PyCStructType::make_static_type(); + union::PyCUnionType::make_static_type(); + function::PyCFuncPtrType::make_static_type(); + function::RawMemoryBuffer::make_static_type(); extend_module!(vm, module, { - "_CData" => PyCData::make_class(ctx), - "_SimpleCData" => PyCSimple::make_class(ctx), - "Array" => PyCArray::make_class(ctx), - "CField" => PyCField::make_class(ctx), - "CFuncPtr" => function::PyCFuncPtr::make_class(ctx), - "_Pointer" => PyCPointer::make_class(ctx), + "_CData" => PyCData::make_static_type(), + "_SimpleCData" => PyCSimple::make_static_type(), + "Array" => PyCArray::make_static_type(), + "CField" => PyCField::make_static_type(), + "CFuncPtr" => function::PyCFuncPtr::make_static_type(), + "_Pointer" => PyCPointer::make_static_type(), "_pointer_type_cache" => ctx.new_dict(), "_array_type_cache" => ctx.new_dict(), - "Structure" => PyCStructure::make_class(ctx), - "CThunkObject" => function::PyCThunk::make_class(ctx), - "Union" => PyCUnion::make_class(ctx), + "Structure" => PyCStructure::make_static_type(), + "CThunkObject" => function::PyCThunk::make_static_type(), + "Union" => PyCUnion::make_static_type(), }); Ok(()) diff --git a/crates/wasm/src/browser_module.rs b/crates/wasm/src/browser_module.rs index 3ec319e10d0..59ca55f45c7 100644 --- a/crates/wasm/src/browser_module.rs +++ b/crates/wasm/src/browser_module.rs @@ -177,12 +177,12 @@ mod _browser { } #[pyattr] - fn document(vm: &VirtualMachine) -> PyRef { + fn document(_vm: &VirtualMachine) -> PyRef { PyRef::new_ref( Document { doc: window().document().expect("Document missing from window"), }, - Document::make_class(&vm.ctx), + Document::make_static_type(), None, ) }