Skip to content

Commit cd61162

Browse files
committed
GR-12492: access dict.getDictStorage via a node (avoids generating an invoke node due the several types of HashingCollections available)
stylefix
1 parent 1cf3837 commit cd61162

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodesFactory.LenNodeGen;
4444
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodesFactory.SetItemNodeGen;
45+
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodesFactory.GetDictStorageNodeGen;
4546
import com.oracle.graal.python.nodes.PGuards;
4647
import com.oracle.graal.python.nodes.PNodeWithContext;
4748
import com.oracle.truffle.api.dsl.Cached;
@@ -83,4 +84,20 @@ public static SetItemNode create() {
8384
return SetItemNodeGen.create();
8485
}
8586
}
87+
88+
@ImportStatic({PGuards.class})
89+
public abstract static class GetDictStorageNode extends PNodeWithContext {
90+
91+
public abstract HashingStorage execute(PHashingCollection c);
92+
93+
@Specialization(limit = "4", guards = {"c.getClass() == cachedClass"})
94+
HashingStorage doWithStorage(PHashingCollection c,
95+
@Cached("c.getClass()") Class<? extends PHashingCollection> cachedClass) {
96+
return cachedClass.cast(c).getDictStorage();
97+
}
98+
99+
public static GetDictStorageNode create() {
100+
return GetDictStorageNodeGen.create();
101+
}
102+
}
86103
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/ObjectAttributeNode.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@
4141
package com.oracle.graal.python.nodes.attributes;
4242

4343
import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage;
44+
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes;
4445
import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
4546
import com.oracle.graal.python.builtins.objects.object.PythonObject;
4647
import com.oracle.graal.python.builtins.objects.str.PString;
4748
import com.oracle.graal.python.nodes.PGuards;
4849
import com.oracle.graal.python.nodes.PNodeWithContext;
4950
import com.oracle.graal.python.runtime.PythonOptions;
51+
import com.oracle.truffle.api.CompilerDirectives;
5052
import com.oracle.truffle.api.dsl.ImportStatic;
5153
import com.oracle.truffle.api.object.HiddenKey;
5254
import com.oracle.truffle.api.object.Location;
@@ -55,6 +57,16 @@
5557

5658
@ImportStatic({PGuards.class, PythonOptions.class})
5759
public abstract class ObjectAttributeNode extends PNodeWithContext {
60+
private @Child HashingCollectionNodes.GetDictStorageNode getDictStorageNode;
61+
62+
public HashingCollectionNodes.GetDictStorageNode getGetDictStorageNode() {
63+
if (getDictStorageNode == null) {
64+
CompilerDirectives.transferToInterpreterAndInvalidate();
65+
getDictStorageNode = insert(HashingCollectionNodes.GetDictStorageNode.create());
66+
}
67+
return getDictStorageNode;
68+
}
69+
5870
protected Object attrKey(Object key) {
5971
if (key instanceof PString) {
6072
return ((PString) key).getValue();
@@ -68,7 +80,7 @@ protected boolean isDictUnsetOrSameAsStorage(PythonObject object, ValueProfile d
6880
if (dict == null) {
6981
return true;
7082
} else {
71-
return dict.getDictStorage() instanceof DynamicObjectStorage.PythonObjectDictStorage;
83+
return getGetDictStorageNode().execute(dict) instanceof DynamicObjectStorage.PythonObjectDictStorage;
7284
}
7385
}
7486

0 commit comments

Comments
 (0)