Skip to content

Commit f9e7260

Browse files
committed
Inherit flags in case of user classes.
1 parent 1e96001 commit f9e7260

File tree

1 file changed

+25
-3
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type

1 file changed

+25
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
8888
import com.oracle.graal.python.builtins.objects.common.SequenceNodes.GetObjectArrayNode;
8989
import com.oracle.graal.python.builtins.objects.common.SequenceNodesFactory.GetObjectArrayNodeGen;
90+
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
9091
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetInternalObjectArrayNode;
9192
import com.oracle.graal.python.builtins.objects.dict.PDict;
9293
import com.oracle.graal.python.builtins.objects.function.PFunction;
@@ -126,6 +127,7 @@
126127
import com.oracle.truffle.api.CompilerDirectives;
127128
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
128129
import com.oracle.truffle.api.dsl.Cached;
130+
import com.oracle.truffle.api.dsl.Cached.Shared;
129131
import com.oracle.truffle.api.dsl.CachedContext;
130132
import com.oracle.truffle.api.dsl.Fallback;
131133
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -224,16 +226,36 @@ static long doBuiltinClass(PythonBuiltinClass clazz) {
224226
}
225227

226228
@Specialization
227-
static long doOther(PythonClass clazz) {
229+
static long doPythonClass(PythonClass clazz,
230+
@Cached GetMroStorageNode getMroStorageNode,
231+
@Cached SequenceStorageNodes.LenNode lenNode,
232+
@Cached SequenceStorageNodes.GetItemDynamicNode getItemNode,
233+
@Shared("getTpFlagsNode") @Cached CExtNodes.GetTypeMemberNode getTpFlagsNode) {
234+
228235
// according to 'type_new' in 'typeobject.c', all have DEFAULT, HEAPTYPE, and BASETYPE.
229236
// The HAVE_GC is inherited. But we do not mimic this behavior in every detail, so it
230237
// should be fine to just set it.
231-
return DEFAULT | HEAPTYPE | BASETYPE | HAVE_GC;
238+
long result = DEFAULT | HEAPTYPE | BASETYPE | HAVE_GC;
239+
240+
// flags are inherited
241+
MroSequenceStorage mroStorage = getMroStorageNode.execute(clazz);
242+
int n = lenNode.execute(mroStorage);
243+
for (int i = 0; i < n; i++) {
244+
Object mroEntry = getItemNode.execute(mroStorage, i);
245+
if (mroEntry instanceof PythonBuiltinClass) {
246+
result |= doBuiltinClass((PythonBuiltinClass) mroEntry);
247+
} else if (mroEntry instanceof PythonBuiltinClassType) {
248+
result |= doBuiltinClassType((PythonBuiltinClassType) mroEntry);
249+
} else if (mroEntry instanceof PythonAbstractNativeObject) {
250+
result |= doNative((PythonAbstractNativeObject) mroEntry, CExtNodes.GetTypeMemberNode.getUncached());
251+
}
252+
}
253+
return result;
232254
}
233255

234256
@Specialization
235257
static long doNative(PythonNativeClass clazz,
236-
@Cached CExtNodes.GetTypeMemberNode getTpFlagsNode) {
258+
@Shared("getTpFlagsNode") @Cached CExtNodes.GetTypeMemberNode getTpFlagsNode) {
237259
return (long) getTpFlagsNode.execute(clazz, NativeMember.TP_FLAGS);
238260
}
239261
}

0 commit comments

Comments
 (0)