Skip to content

Commit ba67acc

Browse files
committed
function builtins: cache GetFunctionCodeNode in specializations
- fix guards on getCodeCached specialization
1 parent 12e1ad1 commit ba67acc

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/code/GetFunctionCodeNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
public abstract class GetFunctionCodeNode extends PNodeWithContext {
5151
public abstract PCode execute(PFunction function);
5252

53-
@Specialization(guards = {"self.getCode() == cachedCode"}, assumptions = {"codeStableAssumption"})
53+
@Specialization(guards = {"self == cachedSelf"}, assumptions = {"codeStableAssumption"})
5454
PCode getCodeCached(@SuppressWarnings("unused") PFunction self,
55+
@SuppressWarnings("unused") @Cached("self") PFunction cachedSelf,
5556
@Cached("self.getCode()") PCode cachedCode,
5657
@SuppressWarnings("unused") @Cached("self.getCodeStableAssumption()") Assumption codeStableAssumption) {
5758
return cachedCode;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/code/GetSignatureNode.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,17 @@
4646
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
4747
import com.oracle.graal.python.builtins.objects.method.PMethod;
4848
import com.oracle.graal.python.nodes.PNodeWithContext;
49-
import com.oracle.truffle.api.CompilerDirectives;
49+
import com.oracle.truffle.api.dsl.Cached;
5050
import com.oracle.truffle.api.dsl.Specialization;
5151

5252
public abstract class GetSignatureNode extends PNodeWithContext {
53-
@Child private GetFunctionCodeNode getCodeNode;
54-
55-
private GetFunctionCodeNode getGetCodeNode() {
56-
if (getCodeNode == null) {
57-
CompilerDirectives.transferToInterpreterAndInvalidate();
58-
getCodeNode = GetFunctionCodeNode.create();
59-
}
60-
return getCodeNode;
61-
}
62-
63-
private Signature doFunctionInternal(PFunction function) {
64-
return getGetCodeNode().execute(function).getSignature();
53+
private Signature doFunctionInternal(GetFunctionCodeNode getFunctionCodeNode, PFunction function) {
54+
return getFunctionCodeNode.execute(function).getSignature();
6555
}
6656

67-
private Signature doMethodInternal(Object function) {
57+
private Signature doMethodInternal(GetFunctionCodeNode getFunctionCodeNode, Object function) {
6858
if (function instanceof PFunction) {
69-
return doFunctionInternal((PFunction) function);
59+
return doFunctionInternal(getFunctionCodeNode, (PFunction) function);
7060
} else if (function instanceof PBuiltinFunction) {
7161
return ((PBuiltinFunction) function).getSignature();
7262
}
@@ -76,8 +66,9 @@ private Signature doMethodInternal(Object function) {
7666
public abstract Signature execute(Object function);
7767

7868
@Specialization
79-
Signature doFunction(PFunction function) {
80-
return doFunctionInternal(function);
69+
Signature doFunction(PFunction function,
70+
@Cached("create()") GetFunctionCodeNode getFunctionCodeNode) {
71+
return doFunctionInternal(getFunctionCodeNode, function);
8172
}
8273

8374
@Specialization
@@ -86,13 +77,15 @@ Signature doBuiltinFunction(PBuiltinFunction builtinFunction) {
8677
}
8778

8879
@Specialization
89-
Signature doMethod(PMethod method) {
90-
return doMethodInternal(method.getFunction());
80+
Signature doMethod(PMethod method,
81+
@Cached("create()") GetFunctionCodeNode getFunctionCodeNode) {
82+
return doMethodInternal(getFunctionCodeNode, method.getFunction());
9183
}
9284

9385
@Specialization
94-
Signature doBuiltinMethod(PBuiltinMethod builtinMethod) {
95-
return doMethodInternal(builtinMethod.getFunction());
86+
Signature doBuiltinMethod(PBuiltinMethod builtinMethod,
87+
@Cached("create()") GetFunctionCodeNode getFunctionCodeNode) {
88+
return doMethodInternal(getFunctionCodeNode, builtinMethod.getFunction());
9689
}
9790

9891
public static GetSignatureNode create() {

0 commit comments

Comments
 (0)