43
43
import static com .oracle .graal .python .runtime .exception .PythonErrorType .KeyError ;
44
44
import static com .oracle .graal .python .runtime .exception .PythonErrorType .RuntimeError ;
45
45
import static com .oracle .graal .python .runtime .exception .PythonErrorType .TypeError ;
46
+ import static com .oracle .graal .python .runtime .exception .PythonErrorType .ValueError ;
46
47
47
48
import java .util .List ;
48
49
77
78
import com .oracle .graal .python .nodes .PRaiseNode ;
78
79
import com .oracle .graal .python .nodes .SpecialMethodNames ;
79
80
import com .oracle .graal .python .nodes .builtins .ListNodes ;
80
- import com .oracle .graal .python .nodes .call .CallNode ;
81
81
import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
82
82
import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
83
- import com .oracle .graal .python .nodes .call .special .LookupAndCallVarargsNode ;
84
83
import com .oracle .graal .python .nodes .control .GetIteratorExpressionNode .GetIteratorNode ;
85
84
import com .oracle .graal .python .nodes .control .GetNextNode ;
86
85
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
92
91
import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
93
92
import com .oracle .graal .python .runtime .PythonCore ;
94
93
import com .oracle .graal .python .runtime .exception .PException ;
95
- import static com .oracle .graal .python .runtime .exception .PythonErrorType .ValueError ;
96
94
import com .oracle .graal .python .runtime .sequence .PSequence ;
97
95
import com .oracle .truffle .api .CompilerDirectives ;
98
96
import com .oracle .truffle .api .dsl .Cached ;
@@ -329,10 +327,9 @@ protected abstract static class DispatchMissingNode extends Node {
329
327
protected abstract Object execute (VirtualFrame frame , Object self , Object key );
330
328
331
329
@ Specialization (guards = "hasMissing(self, lib)" , limit = "1" )
332
- protected Object misssing (Object self , Object key ,
333
- @ CachedLibrary ("self" ) PythonObjectLibrary lib ,
334
- @ Exclusive @ Cached CallNode callNode ) {
335
- return callNode .execute (lib .lookupAttribute (self , __MISSING__ ), key );
330
+ protected Object misssing (VirtualFrame frame , Object self , Object key ,
331
+ @ CachedLibrary ("self" ) PythonObjectLibrary lib ) {
332
+ return lib .lookupAndCallSpecialMethod (self , frame , __MISSING__ , key );
336
333
}
337
334
338
335
@ Specialization (guards = "!hasMissing(self, lib)" , limit = "1" )
@@ -343,7 +340,7 @@ protected Object misssing(VirtualFrame frame, Object self, Object key,
343
340
}
344
341
345
342
protected boolean hasMissing (Object self , PythonObjectLibrary lib ) {
346
- Object missing = lib .lookupAttribute (self , __MISSING__ );
343
+ Object missing = lib .lookupAttributeOnType (self , __MISSING__ );
347
344
return missing != PNone .NO_VALUE && missing instanceof PMethod ;
348
345
}
349
346
}
@@ -633,7 +630,7 @@ private HashingStorage addAll(PDict self, PDict other, GetDictStorageNode getSto
633
630
return newStorage ;
634
631
}
635
632
636
- @ Specialization (guards = {"args.length == 1" , "!isDict(args)" , "hasKeysAttr(args, libArg)" })
633
+ @ Specialization (guards = {"args.length == 1" , "!isDict(args)" , "hasKeysAttr(args, frame, libArg)" })
637
634
public Object updateMapping (VirtualFrame frame , PDict self , Object [] args , PKeyword [] kwargs ,
638
635
@ SuppressWarnings ("unused" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary libArg ,
639
636
@ CachedLibrary (limit = "3" ) HashingStorageLibrary lib ,
@@ -650,7 +647,7 @@ public Object updateMapping(VirtualFrame frame, PDict self, Object[] args, PKeyw
650
647
return PNone .NONE ;
651
648
}
652
649
653
- @ Specialization (guards = {"args.length == 1" , "!isDict(args)" , "!hasKeysAttr(args, libArg)" })
650
+ @ Specialization (guards = {"args.length == 1" , "!isDict(args)" , "!hasKeysAttr(args, frame, libArg)" })
654
651
public Object updateSequence (VirtualFrame frame , PDict self , Object [] args , PKeyword [] kwargs ,
655
652
@ SuppressWarnings ("unused" ) @ CachedLibrary (limit = "1" ) PythonObjectLibrary libArg ,
656
653
@ CachedLibrary (limit = "3" ) HashingStorageLibrary lib ,
@@ -703,8 +700,8 @@ protected boolean isSelf(PDict self, Object[] args) {
703
700
return isDict (args ) && args [0 ] == self ;
704
701
}
705
702
706
- protected boolean hasKeysAttr (Object [] args , PythonObjectLibrary lib ) {
707
- return lib .lookupAttribute (args [0 ], KEYS ) != PNone .NO_VALUE ;
703
+ protected boolean hasKeysAttr (Object [] args , VirtualFrame frame , PythonObjectLibrary lib ) {
704
+ return lib .lookupAttribute (args [0 ], frame , KEYS ) != PNone .NO_VALUE ;
708
705
}
709
706
710
707
}
@@ -714,7 +711,7 @@ protected boolean hasKeysAttr(Object[] args, PythonObjectLibrary lib) {
714
711
@ GenerateNodeFactory
715
712
public abstract static class FromKeysNode extends PythonBuiltinNode {
716
713
717
- @ Specialization (guards = {"lib.isIterable(iterable)" , "isBuiltinType(cls)" , "hasBuiltinSetItem(cls, lib)" })
714
+ @ Specialization (guards = {"lib.isIterable(iterable)" , "isBuiltinType(cls)" , "hasBuiltinSetItem(cls, frame, lib)" })
718
715
public Object doKeys (VirtualFrame frame , Object cls , Object iterable , Object value ,
719
716
@ SuppressWarnings ("unused" ) @ CachedLibrary (limit = "2" ) PythonObjectLibrary lib ,
720
717
@ CachedLibrary (limit = "2" ) HashingStorageLibrary libStorage ,
@@ -740,24 +737,23 @@ public Object doKeys(VirtualFrame frame, Object cls, Object iterable, Object val
740
737
return dict ;
741
738
}
742
739
743
- @ Specialization (guards = {"lib.isIterable(iterable)" , "!isBuiltinType(cls) || !hasBuiltinSetItem(cls, lib)" })
740
+ @ Specialization (guards = {"lib.isIterable(iterable)" , "!isBuiltinType(cls) || !hasBuiltinSetItem(cls, frame, lib)" })
744
741
public Object doKeys (VirtualFrame frame , Object cls , Object iterable , Object value ,
745
- @ CachedLibrary (limit = "2" ) PythonObjectLibrary lib ,
746
- @ Cached ("create(__CALL__)" ) LookupAndCallVarargsNode constructNode ,
747
- @ Cached CallNode callSetItemNode ,
742
+ // 2 for method calls, 2 for setitem lookups
743
+ @ CachedLibrary (limit = "4" ) PythonObjectLibrary lib ,
748
744
@ Cached GetIteratorNode getIteratorNode ,
749
745
@ Cached GetNextNode nextNode ,
750
746
@ Cached IsBuiltinClassProfile errorProfile ,
751
747
@ Cached ConditionProfile noSetItemProfile ) {
752
- Object dict = constructNode . execute ( null , cls , new Object []{ cls } );
753
- Object attrSetItem = lib .lookupAttribute (dict , __SETITEM__ );
748
+ Object dict = lib . callObject ( cls , frame );
749
+ Object setitemMethod = lib .lookupAttributeOnType (dict , __SETITEM__ );
754
750
Object val = value == PNone .NO_VALUE ? PNone .NONE : value ;
755
- if (noSetItemProfile .profile (attrSetItem != PNone .NO_VALUE )) {
751
+ if (noSetItemProfile .profile (setitemMethod != PNone .NO_VALUE )) {
756
752
Object it = getIteratorNode .executeWith (frame , iterable );
757
753
while (true ) {
758
754
try {
759
755
Object key = nextNode .execute (frame , it );
760
- callSetItemNode . execute ( frame , attrSetItem , key , val );
756
+ lib . callUnboundMethod ( setitemMethod , frame , dict , key , val );
761
757
} catch (PException e ) {
762
758
e .expectStopIteration (errorProfile );
763
759
break ;
@@ -786,8 +782,9 @@ protected boolean isBuiltinType(Object cls) {
786
782
return type == PythonBuiltinClassType .PDict ;
787
783
}
788
784
789
- protected boolean hasBuiltinSetItem (Object cls , PythonObjectLibrary lib ) {
790
- Object attr = lib .lookupAttribute (cls , __SETITEM__ );
785
+ protected boolean hasBuiltinSetItem (Object cls , VirtualFrame frame , PythonObjectLibrary lib ) {
786
+ // msimacek: this should rather use direct MRO lookup
787
+ Object attr = lib .lookupAttribute (cls , frame , __SETITEM__ );
791
788
return attr instanceof PBuiltinMethod || attr instanceof PBuiltinFunction ;
792
789
}
793
790
}
0 commit comments