100
100
import com .oracle .graal .python .builtins .objects .bytes .PByteArray ;
101
101
import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
102
102
import com .oracle .graal .python .builtins .objects .bytes .PBytesLike ;
103
- import com .oracle .graal .python .builtins .objects .code .PCode ;
104
103
import com .oracle .graal .python .builtins .objects .code .CodeNodes ;
104
+ import com .oracle .graal .python .builtins .objects .code .PCode ;
105
105
import com .oracle .graal .python .builtins .objects .common .HashingCollectionNodes ;
106
106
import com .oracle .graal .python .builtins .objects .common .HashingStorageLibrary ;
107
107
import com .oracle .graal .python .builtins .objects .common .SequenceNodes .GetObjectArrayNode ;
185
185
import com .oracle .graal .python .nodes .function .builtins .PythonVarargsBuiltinNode ;
186
186
import com .oracle .graal .python .nodes .function .builtins .clinic .ArgumentClinicProvider ;
187
187
import com .oracle .graal .python .nodes .object .GetClassNode ;
188
+ import com .oracle .graal .python .nodes .object .GetOrCreateDictNode ;
188
189
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
189
190
import com .oracle .graal .python .nodes .subscript .SetItemNode ;
190
191
import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
@@ -553,6 +554,7 @@ public abstract static class EvalNode extends PythonBuiltinNode {
553
554
@ Child protected CompileNode compileNode ;
554
555
@ Child private GenericInvokeNode invokeNode = GenericInvokeNode .create ();
555
556
@ Child private HasInheritedAttributeNode hasGetItemNode ;
557
+ @ Child private GetOrCreateDictNode getOrCreateDictNode ;
556
558
557
559
private HasInheritedAttributeNode getHasGetItemNode () {
558
560
if (hasGetItemNode == null ) {
@@ -607,28 +609,19 @@ private static void setCustomLocals(Object[] args, Object locals) {
607
609
PArguments .setCustomLocals (args , locals );
608
610
}
609
611
610
- private void setBuiltinsInGlobals (VirtualFrame frame , PDict globals , HashingCollectionNodes .SetItemNode setBuiltins , PythonModule builtins , PythonObjectLibrary lib ) {
612
+ private void setBuiltinsInGlobals (VirtualFrame frame , PDict globals , HashingCollectionNodes .SetItemNode setBuiltins , PythonModule builtins ) {
611
613
if (builtins != null ) {
612
- PDict builtinsDict = lib .getDict (builtins );
613
- if (builtinsDict == null ) {
614
- builtinsDict = factory ().createDictFixedStorage (builtins );
615
- try {
616
- lib .setDict (builtins , builtinsDict );
617
- } catch (UnsupportedMessageException e ) {
618
- CompilerDirectives .transferToInterpreterAndInvalidate ();
619
- throw new IllegalStateException (e );
620
- }
621
- }
614
+ PDict builtinsDict = getOrCreateDictNode (builtins );
622
615
setBuiltins .execute (frame , globals , __BUILTINS__ , builtinsDict );
623
616
} else {
624
617
// This happens during context initialization
625
618
return ;
626
619
}
627
620
}
628
621
629
- private void setCustomGlobals (VirtualFrame frame , PDict globals , HashingCollectionNodes .SetItemNode setBuiltins , Object [] args , PythonObjectLibrary lib ) {
622
+ private void setCustomGlobals (VirtualFrame frame , PDict globals , HashingCollectionNodes .SetItemNode setBuiltins , Object [] args ) {
630
623
PythonModule builtins = getContext ().getBuiltins ();
631
- setBuiltinsInGlobals (frame , globals , setBuiltins , builtins , lib );
624
+ setBuiltinsInGlobals (frame , globals , setBuiltins , builtins );
632
625
PArguments .setGlobals (args , globals );
633
626
}
634
627
@@ -648,12 +641,11 @@ Object execInheritGlobalsInheritLocals(VirtualFrame frame, Object source, @Suppr
648
641
649
642
@ Specialization
650
643
Object execCustomGlobalsGlobalLocals (VirtualFrame frame , Object source , PDict globals , @ SuppressWarnings ("unused" ) PNone locals ,
651
- @ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ,
652
644
@ Cached HashingCollectionNodes .SetItemNode setBuiltins ,
653
645
@ Shared ("getCt" ) @ Cached CodeNodes .GetCodeCallTargetNode getCt ) {
654
646
PCode code = createAndCheckCode (frame , source );
655
647
Object [] args = PArguments .create ();
656
- setCustomGlobals (frame , globals , setBuiltins , args , lib );
648
+ setCustomGlobals (frame , globals , setBuiltins , args );
657
649
// here, we don't need to set any locals, since the {Write,Read,Delete}NameNodes will
658
650
// fall back (like their CPython counterparts) to writing to the globals. We only need
659
651
// to ensure that the `locals()` call still gives us the globals dict
@@ -681,12 +673,11 @@ Object execInheritGlobalsCustomLocals(VirtualFrame frame, Object source, @Suppre
681
673
682
674
@ Specialization (guards = {"isMapping(locals)" })
683
675
Object execCustomGlobalsCustomLocals (VirtualFrame frame , Object source , PDict globals , Object locals ,
684
- @ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ,
685
676
@ Cached HashingCollectionNodes .SetItemNode setBuiltins ,
686
677
@ Shared ("getCt" ) @ Cached CodeNodes .GetCodeCallTargetNode getCt ) {
687
678
PCode code = createAndCheckCode (frame , source );
688
679
Object [] args = PArguments .create ();
689
- setCustomGlobals (frame , globals , setBuiltins , args , lib );
680
+ setCustomGlobals (frame , globals , setBuiltins , args );
690
681
setCustomLocals (args , locals );
691
682
692
683
return invokeNode .execute (frame , getCt .execute (code ), args );
@@ -710,6 +701,14 @@ private CompileNode getCompileNode() {
710
701
return compileNode ;
711
702
}
712
703
704
+ private PDict getOrCreateDictNode (PythonObject object ) {
705
+ if (getOrCreateDictNode == null ) {
706
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
707
+ getOrCreateDictNode = insert (GetOrCreateDictNode .create ());
708
+ }
709
+ return getOrCreateDictNode .execute (object );
710
+ }
711
+
713
712
protected boolean shouldStripLeadingWhitespace () {
714
713
return true ;
715
714
}
@@ -1943,22 +1942,11 @@ public abstract static class GlobalsNode extends PythonBuiltinNode {
1943
1942
1944
1943
@ Specialization
1945
1944
public Object globals (VirtualFrame frame ,
1946
- @ CachedLibrary ( limit = "1" ) PythonObjectLibrary lib ) {
1945
+ @ Cached GetOrCreateDictNode getDict ) {
1947
1946
PFrame callerFrame = readCallerFrameNode .executeWith (frame , 0 );
1948
1947
PythonObject globals = callerFrame .getGlobals ();
1949
1948
if (condProfile .profile (globals instanceof PythonModule )) {
1950
- PDict dict = lib .getDict (globals );
1951
- if (dict == null ) {
1952
- CompilerDirectives .transferToInterpreter ();
1953
- dict = factory ().createDictFixedStorage (globals );
1954
- try {
1955
- lib .setDict (globals , dict );
1956
- } catch (UnsupportedMessageException e ) {
1957
- CompilerDirectives .transferToInterpreterAndInvalidate ();
1958
- throw new IllegalStateException (e );
1959
- }
1960
- }
1961
- return dict ;
1949
+ return getDict .execute (globals );
1962
1950
} else {
1963
1951
return globals ;
1964
1952
}
0 commit comments