Skip to content

Commit 21273f7

Browse files
youknowonearihant2math
authored andcommitted
initial slot inheritance
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
1 parent 974c54e commit 21273f7

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

vm/src/builtins/type.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl PyType {
214214
if slots.basicsize == 0 {
215215
slots.basicsize = base.slots.basicsize;
216216
}
217+
slots.inherits(&mro);
217218

218219
if let Some(qualname) = attrs.get(identifier!(ctx, __qualname__)) {
219220
if !qualname.fast_isinstance(ctx.types.str_type) {

vm/src/types/slot.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,46 @@ impl PyTypeSlots {
110110
..Default::default()
111111
}
112112
}
113+
114+
pub fn inherits(&mut self, mro: &[PyTypeRef]) {
115+
macro_rules! inherit {
116+
($name:ident) => {
117+
if self.$name.is_none() {
118+
for ty in mro {
119+
if let Some(func) = ty.slots.$name {
120+
self.$name = Some(func);
121+
break;
122+
}
123+
}
124+
}
125+
};
126+
($name:ident, "atomic") => {
127+
if self.$name.load().is_none() {
128+
for ty in mro {
129+
if let Some(func) = ty.slots.$name.load() {
130+
self.$name.store(Some(func));
131+
break;
132+
}
133+
}
134+
}
135+
};
136+
}
137+
inherit!(as_sequence, "atomic");
138+
inherit!(as_mapping, "atomic");
139+
inherit!(hash, "atomic");
140+
inherit!(call, "atomic");
141+
inherit!(getattro, "atomic");
142+
inherit!(setattro, "atomic");
143+
inherit!(as_buffer);
144+
inherit!(richcompare, "atomic");
145+
inherit!(iter, "atomic");
146+
inherit!(iternext, "atomic");
147+
inherit!(descr_get, "atomic");
148+
inherit!(descr_set, "atomic");
149+
inherit!(init, "atomic");
150+
inherit!(new, "atomic");
151+
inherit!(del, "atomic");
152+
}
113153
}
114154

115155
impl std::fmt::Debug for PyTypeSlots {

0 commit comments

Comments
 (0)