Skip to content
Closed
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
Next Next commit
Set tp_new slot when build heap/static type
Signed-off-by: snowapril <sinjihng@gmail.com>
  • Loading branch information
Snowapril authored and youknowone committed Dec 15, 2025
commit 61d7d66624c4acb9b9e8d6a2a5f02a3314e71fbd
30 changes: 27 additions & 3 deletions crates/vm/src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ impl PyType {
None,
);

Self::set_new(&new_type.slots, &new_type.base);

let weakref_type = super::PyWeak::static_type();
for base in new_type.bases.read().iter() {
base.subclasses.write().push(
Expand All @@ -420,9 +422,6 @@ impl PyType {

for cls in self.mro.read().iter() {
for &name in cls.attributes.read().keys() {
if name == identifier!(ctx, __new__) {
continue;
}
if name.as_bytes().starts_with(b"__") && name.as_bytes().ends_with(b"__") {
slot_name_set.insert(name);
}
Expand All @@ -436,6 +435,31 @@ impl PyType {
for attr_name in slot_name_set {
self.update_slot::<true>(attr_name, ctx);
}

Self::set_new(&self.slots, &self.base);
}

fn set_new(slots: &PyTypeSlots, base: &Option<PyTypeRef>) {
// if self.slots.new.load().is_none()
// && self
// .base
// .as_ref()
// .map(|base| base.class().is(ctx.types.object_type))
// .unwrap_or(false)
// && self.slots.flags.contains(PyTypeFlags::HEAPTYPE)
// {
// self.slots.flags |= PyTypeFlags::DISALLOW_INSTANTIATION;
// }

if slots.flags.contains(PyTypeFlags::DISALLOW_INSTANTIATION) {
slots.new.store(None)
} else if slots.new.load().is_none() {
slots.new.store(
base.as_ref()
.map(|base| base.slots.new.load())
.unwrap_or(None),
)
}
}

// This is used for class initialization where the vm is not yet available.
Expand Down