30
30
import com .oracle .graal .python .builtins .objects .function .PArguments ;
31
31
import com .oracle .graal .python .builtins .objects .function .PBuiltinFunction ;
32
32
import com .oracle .graal .python .builtins .objects .function .PFunction ;
33
- import com .oracle .graal .python .builtins .objects .function .PGeneratorFunction ;
34
33
import com .oracle .graal .python .nodes .builtins .FunctionNodes .GetFunctionCodeNode ;
34
+ import com .oracle .graal .python .nodes .generator .GeneratorFunctionRootNode ;
35
35
import com .oracle .graal .python .runtime .PythonOptions ;
36
36
import com .oracle .truffle .api .Assumption ;
37
+ import com .oracle .truffle .api .CompilerAsserts ;
37
38
import com .oracle .truffle .api .RootCallTarget ;
38
39
import com .oracle .truffle .api .dsl .Cached ;
39
40
import com .oracle .truffle .api .dsl .GenerateUncached ;
@@ -92,12 +93,13 @@ public final Object executeCall(VirtualFrame frame, PBuiltinFunction callee, Obj
92
93
93
94
// We only have a single context and this function never changed its code
94
95
@ Specialization (guards = {"callee == cachedCallee" }, limit = "getCallSiteInlineCacheMaxDepth()" , assumptions = {"singleContextAssumption()" , "cachedCallee.getCodeStableAssumption()" })
95
- protected Object callFunctionCached (VirtualFrame frame , PFunction callee , Object [] arguments ,
96
+ protected Object callFunctionCached (VirtualFrame frame , @ SuppressWarnings ( "unused" ) PFunction callee , Object [] arguments ,
96
97
@ SuppressWarnings ("unused" ) @ Cached ("callee" ) PFunction cachedCallee ,
97
- @ Cached ("createInvokeNode(cachedCallee)" ) FunctionInvokeNode invoke ,
98
- @ Cached ConditionProfile isGeneratorProfile ) {
99
- if (isGeneratorProfile .profile (callee instanceof PGeneratorFunction )) {
100
- PArguments .setGeneratorFunction (arguments , callee );
98
+ @ Cached ("createInvokeNode(cachedCallee)" ) FunctionInvokeNode invoke ) {
99
+ boolean isGenerator = cachedCallee .getFunctionRootNode () instanceof GeneratorFunctionRootNode ;
100
+ CompilerAsserts .partialEvaluationConstant (isGenerator );
101
+ if (isGenerator ) {
102
+ PArguments .setGeneratorFunction (arguments , cachedCallee );
101
103
}
102
104
return invoke .execute (frame , arguments );
103
105
}
@@ -113,10 +115,11 @@ protected Object callFunctionCachedCode(VirtualFrame frame, @SuppressWarnings("u
113
115
@ SuppressWarnings ("unused" ) @ Cached ("callee" ) PFunction cachedCallee ,
114
116
@ SuppressWarnings ("unused" ) @ Cached ("create()" ) GetFunctionCodeNode getFunctionCodeNode ,
115
117
@ SuppressWarnings ("unused" ) @ Cached ("getCode(getFunctionCodeNode, callee)" ) PCode cachedCode ,
116
- @ Cached ("createInvokeNode(cachedCallee)" ) FunctionInvokeNode invoke ,
117
- @ Cached ConditionProfile isGeneratorProfile ) {
118
- if (isGeneratorProfile .profile (callee instanceof PGeneratorFunction )) {
119
- PArguments .setGeneratorFunction (arguments , callee );
118
+ @ Cached ("createInvokeNode(cachedCallee)" ) FunctionInvokeNode invoke ) {
119
+ boolean isGenerator = cachedCode .getRootNode () instanceof GeneratorFunctionRootNode ;
120
+ CompilerAsserts .partialEvaluationConstant (isGenerator );
121
+ if (isGenerator ) {
122
+ PArguments .setGeneratorFunction (arguments , cachedCallee );
120
123
}
121
124
return invoke .execute (frame , arguments );
122
125
}
@@ -125,9 +128,10 @@ protected Object callFunctionCachedCode(VirtualFrame frame, @SuppressWarnings("u
125
128
@ Specialization (guards = {"callee.getCallTarget() == ct" }, limit = "getCallSiteInlineCacheMaxDepth()" , replaces = "callFunctionCachedCode" )
126
129
protected Object callFunctionCachedCt (VirtualFrame frame , PFunction callee , Object [] arguments ,
127
130
@ SuppressWarnings ("unused" ) @ Cached ("callee.getCallTarget()" ) RootCallTarget ct ,
128
- @ Cached ("createCtInvokeNode(callee)" ) CallTargetInvokeNode invoke ,
129
- @ Cached ConditionProfile isGeneratorProfile ) {
130
- if (isGeneratorProfile .profile (callee instanceof PGeneratorFunction )) {
131
+ @ Cached ("createCtInvokeNode(callee)" ) CallTargetInvokeNode invoke ) {
132
+ boolean isGenerator = ct .getRootNode () instanceof GeneratorFunctionRootNode ;
133
+ CompilerAsserts .partialEvaluationConstant (isGenerator );
134
+ if (isGenerator ) {
131
135
PArguments .setGeneratorFunction (arguments , callee );
132
136
}
133
137
return invoke .execute (frame , callee .getGlobals (), callee .getClosure (), arguments );
@@ -151,7 +155,7 @@ protected Object callBuiltinFunctionCachedCt(VirtualFrame frame, @SuppressWarnin
151
155
protected Object callFunctionUncached (Frame frame , PFunction callee , Object [] arguments ,
152
156
@ Cached GenericInvokeNode invoke ,
153
157
@ Cached ConditionProfile isGeneratorProfile ) {
154
- if (isGeneratorProfile .profile (callee instanceof PGeneratorFunction )) {
158
+ if (isGeneratorProfile .profile (callee . isGeneratorFunction () )) {
155
159
PArguments .setGeneratorFunction (arguments , callee );
156
160
}
157
161
return invoke .executeInternal (frame , callee , arguments );
0 commit comments