Skip to content

Commit b757f03

Browse files
author
Franziska Geiger
committed
- Added Binary multiplication specializations
- Added custom String subclass handling in HashingStorageNodes, - Changed one ginstall dependency - Added boolean value handling in string formatting variable %i
1 parent ed39066 commit b757f03

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,20 @@ public Object mul(PBytes self, int times,
291291
return factory().createBytes(res);
292292
}
293293

294+
@Specialization
295+
public Object mul(PBytes self, double times,
296+
@Cached("create()") SequenceStorageNodes.RepeatNode repeatNode) {
297+
SequenceStorage res = repeatNode.execute(self.getSequenceStorage(), (int) times);
298+
return factory().createBytes(res);
299+
}
300+
301+
@Specialization
302+
public Object mul(PBytes self, long times,
303+
@Cached("create()") SequenceStorageNodes.RepeatNode repeatNode) {
304+
SequenceStorage res = repeatNode.execute(self.getSequenceStorage(), (int) times);
305+
return factory().createBytes(res);
306+
}
307+
294308
@SuppressWarnings("unused")
295309
@Fallback
296310
public Object mul(Object self, Object other) {

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,19 @@ protected boolean contains(EmptyStorage storage, Object key) {
516516

517517
@Specialization(guards = "isHashable(frame, key)")
518518
protected boolean contains(@SuppressWarnings("unused") VirtualFrame frame, KeywordsStorage storage, Object key,
519-
@Cached("createClassProfile()") ValueProfile keyTypeProfile) {
519+
@Cached("createClassProfile()") ValueProfile keyTypeProfile,
520+
@Cached LookupInheritedAttributeNode.Dynamic lookupHash,
521+
@Cached LookupAttributeInMRONode.Dynamic lookupStringHash) {
520522
Object profileKey = keyTypeProfile.profile(key);
521523
if (profileKey instanceof String) {
522524
return storage.hasKey(profileKey, DEFAULT_EQIVALENCE);
523-
} else if (profileKey instanceof PString && wrappedString((PString) profileKey)) {
524-
return storage.hasKey(((PString) profileKey).getValue(), DEFAULT_EQIVALENCE);
525+
} else if (profileKey instanceof PString) {
526+
if(wrappedString((PString) profileKey) || lookupHash.execute(key, __HASH__) == lookupStringHash.execute(PythonBuiltinClassType.PString, __HASH__)){
527+
return storage.hasKey(((PString) profileKey).getValue(), DEFAULT_EQIVALENCE);
528+
}
529+
CompilerDirectives.transferToInterpreter();
530+
// see GR-17389
531+
throw new RuntimeException("String subclasses with custom hash in dict not implemented.");
525532
}
526533
return false;
527534
}
@@ -626,6 +633,11 @@ protected boolean contains(VirtualFrame frame, HashMapStorage storage, Object ke
626633
}
627634
}
628635

636+
@Specialization(guards = "isHashable(frame, key)")
637+
protected boolean contains(@SuppressWarnings("unused") VirtualFrame frame, LocalsStorage storage, PString key) {
638+
return storage.hasKey(key.getValue(), HashingStorage.DEFAULT_EQIVALENCE);
639+
}
640+
629641
@Specialization(guards = "isHashable(frame, key)")
630642
protected boolean contains(@SuppressWarnings("unused") VirtualFrame frame, LocalsStorage storage, Object key) {
631643
return storage.hasKey(key, HashingStorage.DEFAULT_EQIVALENCE);
@@ -870,7 +882,7 @@ protected HashingStorage doKeywordsGeneralize(VirtualFrame frame, KeywordsStorag
870882
newStorage.addAll(storage, getEquivalence());
871883
newStorage.setItem(key, value, getEquivalence());
872884
}
873-
return storage;
885+
return newStorage;
874886
}
875887

876888
@Specialization(guards = "isHashable(frame, key)")
@@ -1185,6 +1197,19 @@ Object doLocalsString(LocalsStorage storage, PString key) {
11851197
return storage.getItem(key.getValue(), DEFAULT_EQIVALENCE);
11861198
}
11871199

1200+
@Specialization(guards = {"!isJavaString(key)", "isHashable(frame, key)"})
1201+
Object doLocalsObject(VirtualFrame frame, LocalsStorage storage, PString key,
1202+
@Cached LookupInheritedAttributeNode.Dynamic lookupHash,
1203+
@Cached LookupAttributeInMRONode.Dynamic lookupStringHash,
1204+
@Cached GetItemNode recursiveNode) {
1205+
if (lookupHash.execute(key, __HASH__) == lookupStringHash.execute(PythonBuiltinClassType.PString, __HASH__)) {
1206+
return recursiveNode.execute(frame, storage, key.getValue());
1207+
}
1208+
CompilerDirectives.transferToInterpreter();
1209+
// see GR-17389
1210+
throw new RuntimeException("String subclasses with custom hash in dict not implemented.");
1211+
}
1212+
11881213
@Specialization(guards = {"!isJavaString(key)", "isHashable(frame, key)"})
11891214
@SuppressWarnings("unused")
11901215
Object doLocalsObject(VirtualFrame frame, LocalsStorage storage, Object key) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ private static Object asNumber(Object arg, CallNode callNode, BiFunction<Object,
123123
} else if (arg instanceof Double) {
124124
// A common case where it is safe to return arg.__int__()
125125
return ((Double) arg).intValue();
126+
} else if(arg instanceof Boolean) {
127+
return (Boolean)arg ? 1 : 0;
126128
} else if (arg instanceof PFloat) {
127129
return (int) ((PFloat) arg).getValue();
128130
} else if (arg instanceof PythonAbstractObject) {

graalpython/lib-graalpython/modules/ginstall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def gast(**kwargs):
8484
def astor(**kwargs):
8585
install_from_pypi("astor==0.8.0", **kwargs)
8686

87-
def absl_py(**kwargs):
87+
def absl-py(**kwargs):
8888
install_from_pypi("absl-py==0.7.1", **kwargs)
8989

9090
def mock(**kwargs):

0 commit comments

Comments
 (0)