Skip to content

Commit 1a2d65f

Browse files
author
Franziska Geiger
committed
Add new specializaton to isSuperSet node.
Add baseClass support to IsBuiltinClassProfile Rework IsBuiltinClassProfile
1 parent b57d855 commit 1a2d65f

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_set.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ def test_sub_and_super():
187187
assert not set('cbs').issuperset('a')
188188

189189

190+
def test_superset_list():
191+
set = {1, 2, 3, 4}
192+
list = [1, 2, 3, 4]
193+
visited= False
194+
if set.issuperset(list):
195+
visited = True
196+
assert visited
197+
198+
190199
def test_intersection():
191200
word = 'simsalabim'
192201
otherword = 'madagascar'

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
@@ -266,7 +266,7 @@ protected boolean wrappedString(PString s) {
266266
CompilerDirectives.transferToInterpreterAndInvalidate();
267267
isBuiltinClassProfile = IsBuiltinClassProfile.create();
268268
}
269-
return isBuiltinClassProfile.profileClass(getClass(s), PythonBuiltinClassType.PString);
269+
return isBuiltinClassProfile.profileClassWithBaseClasses(getClass(s), PythonBuiltinClassType.PString);
270270
}
271271

272272
protected EconomicMapStorage switchToEconomicMap(HashingStorage storage) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/FrozenSetBuiltins.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import com.oracle.graal.python.runtime.PythonContext;
7373
import com.oracle.graal.python.runtime.exception.PException;
7474
import com.oracle.graal.python.runtime.exception.PythonErrorType;
75+
import com.oracle.graal.python.runtime.sequence.PSequence;
7576
import com.oracle.truffle.api.CompilerDirectives;
7677
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
7778
import com.oracle.truffle.api.dsl.Cached;
@@ -489,7 +490,15 @@ boolean isSuperSet(VirtualFrame frame, PBaseSet self, PBaseSet other,
489490
}
490491

491492
@Specialization
492-
boolean isSuperSet(VirtualFrame frame, PBaseSet self, String other,
493+
boolean isSuperSetPSequence(VirtualFrame frame, PBaseSet self, PSequence other,
494+
@Cached("create()") SetNodes.ConstructSetNode constructSetNode,
495+
@Cached("create()") HashingStorageNodes.KeysIsSupersetNode isSupersetNode) {
496+
PSet otherSet = constructSetNode.executeWith(frame, other);
497+
return isSupersetNode.execute(frame, self.getDictStorage(), otherSet.getDictStorage());
498+
}
499+
500+
@Specialization
501+
boolean isSuperSetString(VirtualFrame frame, PBaseSet self, String other,
493502
@Cached("create()") SetNodes.ConstructSetNode constructSetNode,
494503
@Cached("create()") HashingStorageNodes.KeysIsSupersetNode isSupersetNode) {
495504
PSet otherSet = constructSetNode.executeWith(frame, other);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/IsBuiltinClassProfile.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
4646
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
4747
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
48+
import com.oracle.graal.python.builtins.objects.type.PythonClass;
4849
import com.oracle.graal.python.runtime.exception.PException;
4950
import com.oracle.truffle.api.CompilerDirectives;
5051
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
@@ -205,6 +206,20 @@ public boolean profileClass(LazyPythonClass clazz, PythonBuiltinClassType type)
205206
}
206207
}
207208

209+
public boolean profileClassWithBaseClasses(LazyPythonClass clazz, PythonBuiltinClassType type){
210+
if (!profileClass(clazz,type)) {
211+
PythonAbstractClass [] baseClasses = ((PythonClass) clazz).getBaseClasses();
212+
for (PythonAbstractClass baseClazz : baseClasses) {
213+
if (profileClass(baseClazz, type)) {
214+
return true;
215+
}
216+
}
217+
return false;
218+
} else {
219+
return true;
220+
}
221+
}
222+
208223
public boolean profileClass(PythonAbstractClass clazz, PythonBuiltinClassType type) {
209224
if (clazz instanceof PythonBuiltinClass) {
210225
if (!isBuiltinClass) {

0 commit comments

Comments
 (0)