Skip to content

Commit 170de60

Browse files
committed
Remove PGeneratorFunction
1 parent 8dfd2ba commit 170de60

File tree

5 files changed

+27
-82
lines changed

5 files changed

+27
-82
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,7 @@ public PCell[] getClosure() {
134134
}
135135

136136
public boolean isGeneratorFunction() {
137-
return false;
138-
}
139-
140-
public PGeneratorFunction asGeneratorFunction() {
141-
return null;
137+
return code.isGenerator();
142138
}
143139

144140
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PGeneratorFunction.java

Lines changed: 0 additions & 53 deletions
This file was deleted.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallDispatchNode.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
import com.oracle.graal.python.builtins.objects.function.PArguments;
3131
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
3232
import com.oracle.graal.python.builtins.objects.function.PFunction;
33-
import com.oracle.graal.python.builtins.objects.function.PGeneratorFunction;
3433
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetFunctionCodeNode;
34+
import com.oracle.graal.python.nodes.generator.GeneratorFunctionRootNode;
3535
import com.oracle.graal.python.runtime.PythonOptions;
3636
import com.oracle.truffle.api.Assumption;
37+
import com.oracle.truffle.api.CompilerAsserts;
3738
import com.oracle.truffle.api.RootCallTarget;
3839
import com.oracle.truffle.api.dsl.Cached;
3940
import 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);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/GeneratorFunctionDefinitionNode.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.oracle.graal.python.builtins.objects.cell.PCell;
3232
import com.oracle.graal.python.builtins.objects.code.PCode;
3333
import com.oracle.graal.python.builtins.objects.function.PArguments;
34-
import com.oracle.graal.python.builtins.objects.function.PGeneratorFunction;
34+
import com.oracle.graal.python.builtins.objects.function.PFunction;
3535
import com.oracle.graal.python.builtins.objects.function.PKeyword;
3636
import com.oracle.graal.python.nodes.PRootNode;
3737
import com.oracle.graal.python.nodes.expression.ExpressionNode;
@@ -74,7 +74,7 @@ public static GeneratorFunctionDefinitionNode create(String name, String qualnam
7474
@Override
7575
@ExplodeLoop // this should always be safe, how many syntactic defaults can one function have...
7676
// and these are constant
77-
public PGeneratorFunction execute(VirtualFrame frame) {
77+
public PFunction execute(VirtualFrame frame) {
7878
Object[] defaultValues = null;
7979
if (defaults != null) {
8080
defaultValues = new Object[defaults.length];
@@ -90,8 +90,7 @@ public PGeneratorFunction execute(VirtualFrame frame) {
9090
}
9191
}
9292
PCell[] closure = getClosureFromGeneratorOrFunctionLocals(frame);
93-
return withDocString(frame, factory().createGeneratorFunction(functionName, qualname, enclosingClassName, getGeneratorCode(), PArguments.getGlobals(frame), closure, defaultValues,
94-
kwDefaultValues));
93+
return withDocString(frame, factory().createFunction(functionName, qualname, enclosingClassName, getGeneratorCode(), PArguments.getGlobals(frame), defaultValues, kwDefaultValues, closure));
9594
}
9695

9796
public GeneratorFunctionRootNode getGeneratorFunctionRootNode(PythonContext ctx) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import com.oracle.graal.python.builtins.objects.frame.PFrame;
6666
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
6767
import com.oracle.graal.python.builtins.objects.function.PFunction;
68-
import com.oracle.graal.python.builtins.objects.function.PGeneratorFunction;
6968
import com.oracle.graal.python.builtins.objects.function.PKeyword;
7069
import com.oracle.graal.python.builtins.objects.function.Signature;
7170
import com.oracle.graal.python.builtins.objects.generator.PGenerator;
@@ -418,6 +417,11 @@ public PFunction createFunction(String name, String enclosingClassName, PCode co
418417
return trace(new PFunction(name, name, enclosingClassName, code, globals, closure));
419418
}
420419

420+
public PFunction createFunction(String name, String qualname, String enclosingClassName, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues,
421+
PCell[] closure) {
422+
return trace(new PFunction(name, qualname, enclosingClassName, code, globals, defaultValues, kwDefaultValues, closure));
423+
}
424+
421425
public PFunction createFunction(String name, String enclosingClassName, PCode code, PythonObject globals, Object[] defaultValues, PKeyword[] kwDefaultValues,
422426
PCell[] closure) {
423427
return trace(new PFunction(name, name, enclosingClassName, code, globals, defaultValues, kwDefaultValues, closure));
@@ -574,11 +578,6 @@ public PGenerator createGenerator(String name, String qualname, RootCallTarget[]
574578
return trace(PGenerator.create(name, qualname, callTargets, frameDescriptor, arguments, closure, cellSlots, generatorInfo, this, iterator));
575579
}
576580

577-
public PGeneratorFunction createGeneratorFunction(String name, String qualname, String enclosingClassName, PCode code, PythonObject globals, PCell[] closure, Object[] defaultValues,
578-
PKeyword[] kwDefaultValues) {
579-
return trace(PGeneratorFunction.create(name, qualname, enclosingClassName, code, globals, closure, defaultValues, kwDefaultValues));
580-
}
581-
582581
public PMappingproxy createMappingproxy(PythonObject object) {
583582
return trace(new PMappingproxy(PythonBuiltinClassType.PMappingproxy, PythonBuiltinClassType.PMappingproxy.newInstance(), new DynamicObjectStorage(object.getStorage())));
584583
}

0 commit comments

Comments
 (0)