3030import com .oracle .graal .python .builtins .objects .function .PArguments ;
3131import com .oracle .graal .python .builtins .objects .function .PBuiltinFunction ;
3232import com .oracle .graal .python .builtins .objects .function .PFunction ;
33- import com .oracle .graal .python .builtins .objects .function .PGeneratorFunction ;
3433import com .oracle .graal .python .nodes .builtins .FunctionNodes .GetFunctionCodeNode ;
34+ import com .oracle .graal .python .nodes .generator .GeneratorFunctionRootNode ;
3535import com .oracle .graal .python .runtime .PythonOptions ;
3636import com .oracle .truffle .api .Assumption ;
37+ import com .oracle .truffle .api .CompilerAsserts ;
3738import com .oracle .truffle .api .RootCallTarget ;
3839import com .oracle .truffle .api .dsl .Cached ;
3940import com .oracle .truffle .api .dsl .GenerateUncached ;
@@ -92,12 +93,13 @@ public final Object executeCall(VirtualFrame frame, PBuiltinFunction callee, Obj
9293
9394 // We only have a single context and this function never changed its code
9495 @ 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 ,
9697 @ 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 );
101103 }
102104 return invoke .execute (frame , arguments );
103105 }
@@ -113,10 +115,11 @@ protected Object callFunctionCachedCode(VirtualFrame frame, @SuppressWarnings("u
113115 @ SuppressWarnings ("unused" ) @ Cached ("callee" ) PFunction cachedCallee ,
114116 @ SuppressWarnings ("unused" ) @ Cached ("create()" ) GetFunctionCodeNode getFunctionCodeNode ,
115117 @ 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 );
120123 }
121124 return invoke .execute (frame , arguments );
122125 }
@@ -125,9 +128,10 @@ protected Object callFunctionCachedCode(VirtualFrame frame, @SuppressWarnings("u
125128 @ Specialization (guards = {"callee.getCallTarget() == ct" }, limit = "getCallSiteInlineCacheMaxDepth()" , replaces = "callFunctionCachedCode" )
126129 protected Object callFunctionCachedCt (VirtualFrame frame , PFunction callee , Object [] arguments ,
127130 @ 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 ) {
131135 PArguments .setGeneratorFunction (arguments , callee );
132136 }
133137 return invoke .execute (frame , callee .getGlobals (), callee .getClosure (), arguments );
@@ -151,7 +155,7 @@ protected Object callBuiltinFunctionCachedCt(VirtualFrame frame, @SuppressWarnin
151155 protected Object callFunctionUncached (Frame frame , PFunction callee , Object [] arguments ,
152156 @ Cached GenericInvokeNode invoke ,
153157 @ Cached ConditionProfile isGeneratorProfile ) {
154- if (isGeneratorProfile .profile (callee instanceof PGeneratorFunction )) {
158+ if (isGeneratorProfile .profile (callee . isGeneratorFunction () )) {
155159 PArguments .setGeneratorFunction (arguments , callee );
156160 }
157161 return invoke .executeInternal (frame , callee , arguments );
0 commit comments