@@ -516,12 +516,19 @@ protected boolean contains(EmptyStorage storage, Object key) {
516
516
517
517
@ Specialization (guards = "isHashable(frame, key)" )
518
518
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 ) {
520
522
Object profileKey = keyTypeProfile .profile (key );
521
523
if (profileKey instanceof String ) {
522
524
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." );
525
532
}
526
533
return false ;
527
534
}
@@ -626,6 +633,11 @@ protected boolean contains(VirtualFrame frame, HashMapStorage storage, Object ke
626
633
}
627
634
}
628
635
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
+
629
641
@ Specialization (guards = "isHashable(frame, key)" )
630
642
protected boolean contains (@ SuppressWarnings ("unused" ) VirtualFrame frame , LocalsStorage storage , Object key ) {
631
643
return storage .hasKey (key , HashingStorage .DEFAULT_EQIVALENCE );
@@ -870,7 +882,7 @@ protected HashingStorage doKeywordsGeneralize(VirtualFrame frame, KeywordsStorag
870
882
newStorage .addAll (storage , getEquivalence ());
871
883
newStorage .setItem (key , value , getEquivalence ());
872
884
}
873
- return storage ;
885
+ return newStorage ;
874
886
}
875
887
876
888
@ Specialization (guards = "isHashable(frame, key)" )
@@ -1185,6 +1197,19 @@ Object doLocalsString(LocalsStorage storage, PString key) {
1185
1197
return storage .getItem (key .getValue (), DEFAULT_EQIVALENCE );
1186
1198
}
1187
1199
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
+
1188
1213
@ Specialization (guards = {"!isJavaString(key)" , "isHashable(frame, key)" })
1189
1214
@ SuppressWarnings ("unused" )
1190
1215
Object doLocalsObject (VirtualFrame frame , LocalsStorage storage , Object key ) {
0 commit comments