Skip to content

Commit 9f1dbea

Browse files
qunaibitsteve-s
authored andcommitted
address comments
1 parent 4a78fe8 commit 9f1dbea

File tree

6 files changed

+15
-39
lines changed

6 files changed

+15
-39
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ToNativeTypeNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetItemSizeNode;
8080
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroStorageNode;
8181
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetSubclassesNode;
82-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetSuperClassNode;
8382
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetTypeFlagsNode;
8483
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetWeakListOffsetNode;
8584
import com.oracle.graal.python.builtins.objects.type.TypeNodesFactory.GetDictOffsetNodeGen;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public static void executeUncached(HashingStorage self, Object key, PHashingColl
486486
HashingStorageDelItemNodeGen.getUncached().executeWithAsserts(null, null, self, key, false, toUpdate);
487487
}
488488

489-
public static void delWithHash(EconomicMapStorage storage, Object key, long hash) {
489+
public static void executeUncachedWithHash(EconomicMapStorage storage, Object key, long hash) {
490490
ObjectHashMapFactory.RemoveNodeGen.getUncached().execute(null, null, storage.map, key, hash);
491491
}
492492

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@
3434
import com.oracle.graal.python.builtins.objects.PNone;
3535
import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyDef;
3636
import com.oracle.graal.python.builtins.objects.cext.hpy.HPyTypeExtra;
37-
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
38-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetItemWithHash;
39-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetIterator;
40-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageIterator;
41-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageIteratorKey;
42-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageIteratorKeyHash;
43-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageIteratorNext;
44-
import com.oracle.graal.python.builtins.objects.dict.PDict;
4537
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetSubclassesAsArrayNode;
4638
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromDynamicObjectNode;
4739
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
@@ -369,18 +361,6 @@ private void updateMroShapeSubTypes(PythonLanguage lang) {
369361
}
370362
}
371363

372-
private static void addToProcess(ArrayDeque<Object> toProcess, PythonManagedClass klass) {
373-
PDict subclasses = klass.getSubClasses();
374-
HashingStorage storage = subclasses.getDictStorage();
375-
HashingStorageIterator it = HashingStorageGetIterator.executeUncached(storage);
376-
while (HashingStorageIteratorNext.executeUncached(storage, it)) {
377-
long hash = HashingStorageIteratorKeyHash.executeUncached(storage, it);
378-
Object key = HashingStorageIteratorKey.executeUncached(storage, it);
379-
Object clazz = HashingStorageGetItemWithHash.getItemWithHash(storage, key, hash);
380-
toProcess.add(clazz);
381-
}
382-
}
383-
384364
/**
385365
* Can be used to update MRO shapes in inheritance hierarchy of a builtin.
386366
*/

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___DOC__;
3030
import static com.oracle.graal.python.nodes.truffle.TruffleStringMigrationHelpers.assertNoJavaString;
3131

32-
import java.util.ArrayList;
33-
3432
import com.oracle.graal.python.PythonLanguage;
3533
import com.oracle.graal.python.builtins.objects.PNone;
3634
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PCallCapiFunction;
@@ -50,6 +48,7 @@
5048
import com.oracle.graal.python.nodes.PRaiseNode;
5149
import com.oracle.graal.python.runtime.PythonContext;
5250
import com.oracle.graal.python.runtime.exception.PException;
51+
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5352
import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
5453
import com.oracle.truffle.api.Assumption;
5554
import com.oracle.truffle.api.CompilerAsserts;
@@ -128,7 +127,7 @@ protected PythonManagedClass(PythonLanguage lang, Object typeClass, Shape classS
128127
this.instanceShape = lang.getShapeForClass(this);
129128
}
130129

131-
this.subClasses = new PDict(lang);
130+
this.subClasses = PythonObjectFactory.getUncached().createDict();
132131
}
133132

134133
public boolean isMROInitialized() {
@@ -288,10 +287,10 @@ private void unsafeSetSuperClass(PythonAbstractClass... newBaseClasses) {
288287

289288
@TruffleBoundary
290289
public final void setBases(Object newBaseClass, PythonAbstractClass[] newBaseClasses) {
291-
ArrayList<Set<PythonAbstractClass>> newBasesSubclasses = new ArrayList<>(newBaseClasses.length);
292-
for (PythonAbstractClass type : newBaseClasses) {
293-
HashingStorage storage = GetSubclassesNode.executeUncached(newBase).getDictStorage();
294-
newBasesSubclasses.add(HashingStorageCopy.executeUncached(storage));
290+
HashingStorage[] newBasesSubclasses = new HashingStorage[newBaseClasses.length];
291+
for (int i = 0; i < newBaseClasses.length; i++) {
292+
HashingStorage storage = GetSubclassesNode.executeUncached(newBaseClasses[i]).getDictStorage();
293+
newBasesSubclasses[i++] = HashingStorageCopy.executeUncached(storage);
295294
}
296295

297296
Object oldBase = getBase();
@@ -353,7 +352,7 @@ public final void setBases(Object newBaseClass, PythonAbstractClass[] newBaseCla
353352
PythonAbstractClass base = newBaseClasses[i];
354353
if (base != null) {
355354
PDict dict = GetSubclassesNode.executeUncached(base);
356-
dict.setDictStorage(newBasesSubclasses.get(i));
355+
dict.setDictStorage(newBasesSubclasses[i]);
357356
}
358357
}
359358
if (this.baseClasses == newBaseClasses) {

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
@@ -1069,11 +1069,11 @@ Object hook(VirtualFrame frame, Object cls, Object subclass) {
10691069
abstract static class SubclassesNode extends PythonUnaryBuiltinNode {
10701070

10711071
@Specialization
1072-
PList getSubclasses(VirtualFrame frame, Object cls,
1072+
PList getSubclasses(Object cls,
10731073
@Bind("this") Node inliningTarget,
10741074
@Cached(inline = true) GetSubclassesAsArrayNode getSubclassesNode) {
10751075
// TODO: missing: keep track of subclasses
1076-
PythonAbstractClass[] array = getSubclassesNode.execute(frame, inliningTarget, cls);
1076+
PythonAbstractClass[] array = getSubclassesNode.execute(inliningTarget, cls);
10771077
Object[] classes = new Object[array.length];
10781078
PythonUtils.arraycopy(array, 0, classes, 0, array.length);
10791079
return factory().createList(classes);

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ protected static void unsafeRemoveSubclass(Object base, Object subclass) {
761761
PDict dict = executeUncached(base);
762762
HashingStorage storage = dict.getDictStorage();
763763
if (storage instanceof EconomicMapStorage ems) {
764-
HashingStorageDelItem.delWithHash(ems, subclass, hash);
764+
HashingStorageDelItem.executeUncachedWithHash(ems, subclass, hash);
765765
} else {
766766
assert storage == EmptyStorage.INSTANCE : "Unexpected storage type!";
767767
}
@@ -786,8 +786,6 @@ static PDict doNativeClass(Node inliningTarget, PythonNativeClass obj,
786786
Object profiled = profile.profile(inliningTarget, tpSubclasses);
787787
if (profiled instanceof PDict dict) {
788788
return dict;
789-
// } else if (profiled instanceof PNone) {
790-
// return Collections.emptySet();
791789
}
792790
CompilerDirectives.transferToInterpreterAndInvalidate();
793791
throw new IllegalStateException("invalid subclasses dict " + profiled.getClass().getName());
@@ -801,10 +799,10 @@ public abstract static class GetSubclassesAsArrayNode extends Node {
801799

802800
private static final PythonAbstractClass[] EMPTY = new PythonAbstractClass[0];
803801

804-
abstract PythonAbstractClass[] execute(Frame frame, Node inliningTarget, Object clazz);
802+
abstract PythonAbstractClass[] execute(Node inliningTarget, Object clazz);
805803

806804
public static PythonAbstractClass[] executeUncached(Object clazz) {
807-
return GetSubclassesAsArrayNodeGen.getUncached().execute(null, null, clazz);
805+
return GetSubclassesAsArrayNodeGen.getUncached().execute(null, clazz);
808806
}
809807

810808
static final class PythonAbstractClassList {
@@ -841,7 +839,7 @@ static PythonAbstractClassList doIt(Frame frame, Node inliningTarget, HashingSto
841839
}
842840

843841
@Specialization
844-
static PythonAbstractClass[] doTpSubclasses(Frame frame, Node inliningTarget, PythonAbstractClass object,
842+
static PythonAbstractClass[] doTpSubclasses(Node inliningTarget, PythonAbstractClass object,
845843
@Cached GetSubclassesNode getSubclassesNode,
846844
@Cached EachSubclassAdd eachNode,
847845
@Cached HashingStorageLen dictLen,
@@ -858,7 +856,7 @@ static PythonAbstractClass[] doTpSubclasses(Frame frame, Node inliningTarget, Py
858856

859857
int size = dictLen.execute(inliningTarget, storage);
860858
PythonAbstractClassList list = new PythonAbstractClassList(new PythonAbstractClass[size]);
861-
forEachNode.execute(frame, inliningTarget, storage, eachNode, list);
859+
forEachNode.execute(null, inliningTarget, storage, eachNode, list);
862860
return list.subclasses;
863861
}
864862
}

0 commit comments

Comments
 (0)