Skip to content

Commit b004600

Browse files
committed
added GetBestBasesNode
1 parent 530c800 commit b004600

File tree

5 files changed

+264
-45
lines changed

5 files changed

+264
-45
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
7575
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
7676
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
77-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetSuperClassNode;
78-
import com.oracle.graal.python.builtins.objects.type.TypeNodesFactory.GetSuperClassNodeGen;
77+
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBaseClassNode;
78+
import com.oracle.graal.python.builtins.objects.type.TypeNodesFactory.GetBaseClassNodeGen;
7979
import com.oracle.graal.python.nodes.BuiltinNames;
8080
import com.oracle.graal.python.nodes.ErrorMessages;
8181
import com.oracle.graal.python.nodes.PGuards;
@@ -115,7 +115,6 @@
115115
import com.oracle.truffle.api.nodes.UnexpectedResultException;
116116
import com.oracle.truffle.api.profiles.BranchProfile;
117117
import com.oracle.truffle.api.profiles.ConditionProfile;
118-
import java.util.Arrays;
119118

120119
@CoreFunctions(extendClasses = PythonBuiltinClassType.PythonObject)
121120
public class ObjectBuiltins extends PythonBuiltins {
@@ -133,7 +132,7 @@ abstract static class ClassNode extends PythonBinaryBuiltinNode {
133132
@Child private TypeNodes.GetNameNode getTypeNameNode;
134133

135134
@Child private LookupAttributeInMRONode lookupNewNode;
136-
@Child private GetSuperClassNode getBaseClassNode;
135+
@Child private GetBaseClassNode getBaseClassNode;
137136
@Child private GetDictStorageNode getDictStorageNode;
138137
@Child private LookupAndCallBinaryNode getDictNode;
139138
@Child private HashingStorageLibrary hashingStorageLib;
@@ -189,17 +188,16 @@ private boolean compatibleForAssignment(VirtualFrame frame, Object self, PythonA
189188
Object newBase = other;
190189
Object oldBase = self;
191190

192-
// TODO getBaseClassNode tends to fail with "get bestBase case not yet implemented"
193-
Object newParent = getSuperClassNode().execute(newBase);
191+
Object newParent = getBaseClassNode().execute(frame, newBase);
194192
while (newParent != null && compatibleWithBase(frame, newBase, newParent)) {
195193
newBase = newParent;
196-
newParent = getSuperClassNode().execute(newBase);
194+
newParent = getBaseClassNode().execute(frame, newBase);
197195
}
198196

199-
Object oldParent = getSuperClassNode().execute(oldBase);
197+
Object oldParent = getBaseClassNode().execute(frame, oldBase);
200198
while (oldParent != null && compatibleWithBase(frame, oldBase, oldParent)) {
201199
oldBase = oldParent;
202-
oldParent = getSuperClassNode().execute(oldBase);
200+
oldParent = getBaseClassNode().execute(frame, oldBase);
203201
}
204202

205203
if (newBase != oldBase && (newParent != oldParent || !compareSlotsFromDict(frame, newBase, oldBase))) {
@@ -257,7 +255,6 @@ private boolean compareSlotsFromDict(VirtualFrame frame, Object a, Object b) {
257255
return compareSlots(a, b, aSlots, bSlots);
258256
}
259257

260-
@TruffleBoundary
261258
private boolean compareSlots(Object aType, Object bType, Object aSlotsArg, Object bSlotsArg) {
262259
Object aSlots = aSlotsArg;
263260
Object bSlots = bSlotsArg;
@@ -267,24 +264,7 @@ private boolean compareSlots(Object aType, Object bType, Object aSlotsArg, Objec
267264
}
268265

269266
if (aSlots != null && bSlots != null) {
270-
Object[] aArray = getObjectArrayNode().execute(aSlots);
271-
Object[] bArray = getObjectArrayNode().execute(bSlots);
272-
if (bArray.length != aArray.length) {
273-
return false;
274-
}
275-
aArray = Arrays.copyOf(aArray, aArray.length);
276-
bArray = Arrays.copyOf(bArray, bArray.length);
277-
// what cpython does in same_slots_added() is a compare on a sorted slots list
278-
// ((PyHeapTypeObject *)a)->ht_slots which is populated in type_new() and
279-
// NOT the same like the unsorted __slots__ attribute.
280-
Arrays.sort(bArray);
281-
Arrays.sort(aArray);
282-
for (int i = 0; i < aArray.length; i++) {
283-
if (!aArray[i].equals(bArray[i])) {
284-
return false;
285-
}
286-
}
287-
return true;
267+
return TypeNodes.compareSortedSlots(aSlots, bSlots, getObjectArrayNode());
288268
}
289269

290270
aSlots = getLookupSlots().execute(aType);
@@ -355,10 +335,10 @@ private LookupAttributeInMRONode getLookupSlots() {
355335
return lookupSlotsNode;
356336
}
357337

358-
private GetSuperClassNode getSuperClassNode() {
338+
private GetBaseClassNode getBaseClassNode() {
359339
if (getBaseClassNode == null) {
360340
CompilerDirectives.transferToInterpreterAndInvalidate();
361-
getBaseClassNode = insert(GetSuperClassNodeGen.create());
341+
getBaseClassNode = insert(GetBaseClassNodeGen.create());
362342
}
363343
return getBaseClassNode;
364344
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,9 @@ Object setBuiltin(@SuppressWarnings("unused") PythonBuiltinClass cls, @SuppressW
589589
@GenerateNodeFactory
590590
abstract static class BaseNode extends PythonBuiltinNode {
591591
@Specialization
592-
static Object base(Object self,
592+
static Object base(VirtualFrame frame, Object self,
593593
@Cached TypeNodes.GetBaseClassNode getBaseClassNode) {
594-
Object baseClass = getBaseClassNode.execute(self);
594+
Object baseClass = getBaseClassNode.execute(frame, self);
595595
return baseClass != null ? baseClass : PNone.NONE;
596596
}
597597
}

0 commit comments

Comments
 (0)