Skip to content

Commit a307328

Browse files
committed
[GR-44210] Minor cleanups.
PullRequest: graalpython/2759
2 parents 794a5d3 + bcd5d92 commit a307328

File tree

9 files changed

+86
-156
lines changed

9 files changed

+86
-156
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_gc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ def test_native_class(self):
129129
b = GCTestClass.getCounters()
130130
assert b == (1,1,0,0)
131131
del o
132-
gc.collect()
133-
time.sleep(1)
134-
gc.collect()
132+
for i in range(4):
133+
gc.collect()
134+
time.sleep(1)
135135
c = GCTestClass.getCounters()
136136
assert c == (1,1,1,1)
137137

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyDebugModuleBuiltins.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -127,11 +127,6 @@ static final class NotAvailable extends PythonBuiltinNode {
127127
public Object execute(VirtualFrame frame) {
128128
throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_DEBUG_MODE_NOT_AVAILABLE);
129129
}
130-
131-
@Override
132-
protected ReadArgumentNode[] getArguments() {
133-
return EMPTY_ARGS;
134-
}
135130
}
136131

137132
@TruffleBoundary

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/AbstractCallMethodNode.java

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -72,7 +72,6 @@
7272
import com.oracle.truffle.api.CompilerDirectives;
7373
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7474
import com.oracle.truffle.api.RootCallTarget;
75-
import com.oracle.truffle.api.dsl.GeneratedBy;
7675
import com.oracle.truffle.api.dsl.ImportStatic;
7776
import com.oracle.truffle.api.dsl.NodeFactory;
7877
import com.oracle.truffle.api.dsl.NodeField;
@@ -94,29 +93,6 @@ abstract class AbstractCallMethodNode extends PNodeWithContext {
9493

9594
protected abstract void setMaxSizeExceeded(boolean value);
9695

97-
/**
98-
* Returns a new instanceof the builtin if it's a subclass of the given class, and null
99-
* otherwise.
100-
*/
101-
private <T extends PythonBuiltinBaseNode> T getBuiltin(VirtualFrame frame, PBuiltinFunction func, Class<T> clazz) {
102-
CompilerAsserts.neverPartOfCompilation();
103-
NodeFactory<? extends PythonBuiltinBaseNode> builtinNodeFactory = func.getBuiltinNodeFactory();
104-
if (builtinNodeFactory == null) {
105-
return null; // see for example MethodDescriptorRoot and subclasses
106-
}
107-
assert builtinNodeFactory.getNodeClass().getAnnotationsByType(Builtin.class).length > 0 : "PBuiltinFunction " + func + " is expected to have a Builtin annotated node.";
108-
if (builtinNodeFactory.getNodeClass().getAnnotationsByType(Builtin.class)[0].needsFrame() && frame == null) {
109-
return null;
110-
}
111-
if (clazz.isAssignableFrom(builtinNodeFactory.getNodeClass())) {
112-
T builtinNode = clazz.cast(func.getBuiltinNodeFactory().createNode());
113-
if (!callerExceedsMaxSize(builtinNode)) {
114-
return builtinNode;
115-
}
116-
}
117-
return null;
118-
}
119-
12096
protected PythonBuiltinBaseNode getBuiltin(VirtualFrame frame, PBuiltinFunction func, int nargs) {
12197
CompilerAsserts.neverPartOfCompilation();
12298
NodeFactory<? extends PythonBuiltinBaseNode> builtinNodeFactory = func.getBuiltinNodeFactory();
@@ -220,13 +196,23 @@ private <T extends PythonBuiltinBaseNode> boolean callerExceedsMaxSize(T builtin
220196
return true;
221197
}
222198

223-
protected static boolean frameIsUnused(PythonBuiltinBaseNode builtinNode) {
224-
return builtinNode == null || !builtinNode.getClass().getAnnotation(GeneratedBy.class).value().getAnnotationsByType(Builtin.class)[0].needsFrame();
225-
}
226-
227199
PythonVarargsBuiltinNode getVarargs(VirtualFrame frame, Object func) {
228-
if (func instanceof PBuiltinFunction) {
229-
return getBuiltin(frame, (PBuiltinFunction) func, PythonVarargsBuiltinNode.class);
200+
CompilerAsserts.neverPartOfCompilation();
201+
if (func instanceof PBuiltinFunction builtinFunc) {
202+
NodeFactory<? extends PythonBuiltinBaseNode> builtinNodeFactory = builtinFunc.getBuiltinNodeFactory();
203+
if (builtinNodeFactory == null) {
204+
return null; // see for example MethodDescriptorRoot and subclasses
205+
}
206+
assert builtinNodeFactory.getNodeClass().getAnnotationsByType(Builtin.class).length > 0 : "PBuiltinFunction " + builtinFunc + " is expected to have a Builtin annotated node.";
207+
if (builtinNodeFactory.getNodeClass().getAnnotationsByType(Builtin.class)[0].needsFrame() && frame == null) {
208+
return null;
209+
}
210+
if (PythonVarargsBuiltinNode.class.isAssignableFrom(builtinNodeFactory.getNodeClass())) {
211+
PythonVarargsBuiltinNode builtinNode = (PythonVarargsBuiltinNode) builtinFunc.getBuiltinNodeFactory().createNode();
212+
if (!callerExceedsMaxSize(builtinNode)) {
213+
return builtinNode;
214+
}
215+
}
230216
}
231217
return null;
232218
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallBinaryMethodNode.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -133,73 +133,62 @@ Object callSpecialMethodSlotCallTarget(VirtualFrame frame, BuiltinMethodDescript
133133
return invokeNode.execute(frame, callTarget, arguments);
134134
}
135135

136-
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null",
137-
"frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()")
136+
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null"}, limit = "getCallSiteInlineCacheMaxDepth()")
138137
static Object callObjectSingleContext(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2,
139138
@SuppressWarnings("unused") @Cached("func") PBuiltinFunction cachedFunc,
140139
@SuppressWarnings("unused") @Cached("isForReverseBinaryOperation(func.getCallTarget())") boolean isReverse,
141-
@Cached("getBuiltin(frame, func, 2)") PythonBuiltinBaseNode builtinNode,
142-
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
140+
@Cached("getBuiltin(frame, func, 2)") PythonBuiltinBaseNode builtinNode) {
143141
if (isReverse) {
144142
return callBinaryBuiltin(frame, builtinNode, arg2, arg1);
145143
} else {
146144
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
147145
}
148146
}
149147

150-
@Specialization(guards = {"func.getCallTarget() == ct", "builtinNode != null", "frame != null || unusedFrame"}, //
148+
@Specialization(guards = {"func.getCallTarget() == ct", "builtinNode != null"}, //
151149
limit = "getCallSiteInlineCacheMaxDepth()")
152150
static Object callObject(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2,
153151
@SuppressWarnings("unused") @Cached("func.getCallTarget()") RootCallTarget ct,
154152
@SuppressWarnings("unused") @Cached("isForReverseBinaryOperation(func.getCallTarget())") boolean isReverse,
155-
@Cached("getBuiltin(frame, func, 2)") PythonBuiltinBaseNode builtinNode,
156-
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
153+
@Cached("getBuiltin(frame, func, 2)") PythonBuiltinBaseNode builtinNode) {
157154
if (isReverse) {
158155
return callBinaryBuiltin(frame, builtinNode, arg2, arg1);
159156
} else {
160157
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
161158
}
162159
}
163160

164-
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null", "!takesSelfArg",
165-
"frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()")
161+
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
166162
static Object callMethodSingleContext(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2,
167163
@SuppressWarnings("unused") @Cached("func") PBuiltinMethod cachedFunc,
168164
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
169-
@Cached("getBuiltin(frame, func.getFunction(), 2)") PythonBuiltinBaseNode builtinNode,
170-
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
165+
@Cached("getBuiltin(frame, func.getFunction(), 2)") PythonBuiltinBaseNode builtinNode) {
171166
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
172167
}
173168

174-
@Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "!takesSelfArg",
175-
"frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()")
169+
@Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
176170
static Object callMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2,
177171
@SuppressWarnings("unused") @Cached GetCallTargetNode getCt,
178172
@SuppressWarnings("unused") @Cached("getCallTarget(func, getCt)") RootCallTarget ct,
179173
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
180-
@Cached("getBuiltin(frame, func.getFunction(), 2)") PythonBuiltinBaseNode builtinNode,
181-
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
174+
@Cached("getBuiltin(frame, func.getFunction(), 2)") PythonBuiltinBaseNode builtinNode) {
182175
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
183176
}
184177

185-
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null", "takesSelfArg",
186-
"frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()")
178+
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
187179
static Object callMethodSingleContextSelf(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2,
188180
@SuppressWarnings("unused") @Cached(value = "func", weak = true) PBuiltinMethod cachedFunc,
189181
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
190-
@Cached("getBuiltin(frame, func.getFunction(), 3)") PythonBuiltinBaseNode builtinNode,
191-
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
182+
@Cached("getBuiltin(frame, func.getFunction(), 3)") PythonBuiltinBaseNode builtinNode) {
192183
return callTernaryBuiltin(frame, builtinNode, cachedFunc.getSelf(), arg1, arg2);
193184
}
194185

195-
@Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "takesSelfArg",
196-
"frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()")
186+
@Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
197187
static Object callMethodSelf(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2,
198188
@SuppressWarnings("unused") @Cached GetCallTargetNode getCt,
199189
@SuppressWarnings("unused") @Cached("getCallTarget(func, getCt)") RootCallTarget ct,
200190
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
201-
@Cached("getBuiltin(frame, func.getFunction(), 3)") PythonBuiltinBaseNode builtinNode,
202-
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
191+
@Cached("getBuiltin(frame, func.getFunction(), 3)") PythonBuiltinBaseNode builtinNode) {
203192
return callTernaryBuiltin(frame, builtinNode, func.getSelf(), arg1, arg2);
204193
}
205194

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallQuaternaryMethodNode.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,42 +69,36 @@ public static CallQuaternaryMethodNode getUncached() {
6969

7070
public abstract Object execute(Frame frame, Object callable, Object arg1, Object arg2, Object arg3, Object arg4);
7171

72-
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null", "frame != null || unusedFrame"}, //
72+
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null"}, //
7373
limit = "getCallSiteInlineCacheMaxDepth()")
7474
Object callSingle(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2, Object arg3, Object arg4,
7575
@SuppressWarnings("unused") @Cached("func") PBuiltinFunction cachedFunc,
76-
@Cached("getBuiltin(frame, func, 4)") PythonBuiltinBaseNode builtinNode,
77-
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
76+
@Cached("getBuiltin(frame, func, 4)") PythonBuiltinBaseNode builtinNode) {
7877
return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4);
7978
}
8079

81-
@Specialization(guards = {"func.getCallTarget() == ct", "builtinNode != null", "frame != null || unusedFrame"}, //
80+
@Specialization(guards = {"func.getCallTarget() == ct", "builtinNode != null"}, //
8281
limit = "getCallSiteInlineCacheMaxDepth()")
8382
Object call(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2, Object arg3, Object arg4,
8483
@SuppressWarnings("unused") @Cached("func.getCallTarget()") RootCallTarget ct,
85-
@Cached("getBuiltin(frame, func, 4)") PythonBuiltinBaseNode builtinNode,
86-
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
84+
@Cached("getBuiltin(frame, func, 4)") PythonBuiltinBaseNode builtinNode) {
8785
return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4);
8886
}
8987

90-
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null", "!takesSelfArg",
91-
"frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()")
88+
@Specialization(guards = {"isSingleContext()", "func == cachedFunc", "builtinNode != null", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
9289
Object callMethodSingle(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3, Object arg4,
9390
@SuppressWarnings("unused") @Cached("func") PBuiltinMethod cachedFunc,
9491
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
95-
@Cached("getBuiltin(frame, func.getFunction(), 4)") PythonBuiltinBaseNode builtinNode,
96-
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
92+
@Cached("getBuiltin(frame, func.getFunction(), 4)") PythonBuiltinBaseNode builtinNode) {
9793
return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4);
9894
}
9995

100-
@Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "!takesSelfArg",
101-
"frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()")
96+
@Specialization(guards = {"builtinNode != null", "getCallTarget(func, getCt) == ct", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
10297
Object callMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3, Object arg4,
10398
@SuppressWarnings("unused") @Cached GetCallTargetNode getCt,
10499
@SuppressWarnings("unused") @Cached("getCallTarget(func, getCt)") RootCallTarget ct,
105100
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
106-
@Cached("getBuiltin(frame, func.getFunction(), 4)") PythonBuiltinBaseNode builtinNode,
107-
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
101+
@Cached("getBuiltin(frame, func.getFunction(), 4)") PythonBuiltinBaseNode builtinNode) {
108102
return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4);
109103
}
110104

0 commit comments

Comments
 (0)