Skip to content

Commit a91d687

Browse files
author
Adam Hrbac
committed
Avoid passing profiles everywhere
1 parent bdf78bd commit a91d687

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
package com.oracle.graal.python.builtins.objects.generator;
4242

4343
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.GeneratorExit;
44-
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PAsyncGenerator;
45-
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.PCoroutine;
4644
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.StopAsyncIteration;
4745
import static com.oracle.graal.python.runtime.exception.PythonErrorType.RuntimeError;
4846
import static com.oracle.graal.python.runtime.exception.PythonErrorType.StopIteration;
@@ -144,9 +142,9 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
144142
return CommonGeneratorBuiltinsFactory.getFactories();
145143
}
146144

147-
private static void checkResumable(PythonBuiltinBaseNode node, PGenerator self, boolean isAsyncGen) {
145+
private static void checkResumable(PythonBuiltinBaseNode node, PGenerator self) {
148146
if (self.isFinished()) {
149-
if (isAsyncGen) {
147+
if (self.isAsyncGen()) {
150148
throw node.raise(StopAsyncIteration);
151149
}
152150
if (self.isCoroutine()) {
@@ -183,7 +181,7 @@ Object cached(VirtualFrame frame, PGenerator self, Object sendValue,
183181
throw handleException(self, inliningTarget, errorProfile, raiseNode, e);
184182
} catch (GeneratorReturnException e) {
185183
returnProfile.enter(inliningTarget);
186-
throw handleReturn(self, inliningTarget, e, raiseNode, profile);
184+
throw handleReturn(self, e, raiseNode);
187185
} finally {
188186
self.setRunning(false);
189187
}
@@ -216,7 +214,7 @@ Object generic(VirtualFrame frame, PGenerator self, Object sendValue,
216214
throw handleException(self, inliningTarget, errorProfile, raiseNode, e);
217215
} catch (GeneratorReturnException e) {
218216
returnProfile.enter(inliningTarget);
219-
throw handleReturn(self, inliningTarget, e, raiseNode, profile);
217+
throw handleReturn(self, e, raiseNode);
220218
} finally {
221219
self.setRunning(false);
222220
}
@@ -225,7 +223,7 @@ Object generic(VirtualFrame frame, PGenerator self, Object sendValue,
225223

226224
private PException handleException(PGenerator self, Node inliningTarget, IsBuiltinObjectProfile profile, PRaiseNode raiseNode, PException e) {
227225
self.markAsFinished();
228-
if (profile.profileObject(inliningTarget, self, PAsyncGenerator)) {
226+
if (self.isAsyncGen()) {
229227
// Async generators need to wrap StopAsyncIteration in a runtime error
230228
if (profile.profileException(inliningTarget, e, StopAsyncIteration)) {
231229
throw raiseNode.raise(RuntimeError, e.getEscapedException(), ErrorMessages.ASYNCGEN_RAISED_ASYNCSTOPITER);
@@ -242,9 +240,9 @@ private Object handleResult(PGenerator self, GeneratorYieldResult result) {
242240
return result.yieldValue;
243241
}
244242

245-
private static PException handleReturn(PGenerator self, Node inliningTarget, GeneratorReturnException e, PRaiseNode raiseNode, IsBuiltinObjectProfile profile) {
243+
private static PException handleReturn(PGenerator self, GeneratorReturnException e, PRaiseNode raiseNode) {
246244
self.markAsFinished();
247-
if (profile.profileObject(inliningTarget, self, PAsyncGenerator)) {
245+
if (self.isAsyncGen()) {
248246
throw raiseNode.raise(StopAsyncIteration);
249247
}
250248
if (e.value != PNone.NONE) {
@@ -270,11 +268,10 @@ public abstract static class SendNode extends PythonBinaryBuiltinNode {
270268
@Specialization
271269
Object send(VirtualFrame frame, PGenerator self, Object value,
272270
@Bind("this") Node inliningTarget,
273-
@Cached ResumeGeneratorNode resumeGeneratorNode,
274-
@Cached IsBuiltinObjectProfile isAsyncGen) {
271+
@Cached ResumeGeneratorNode resumeGeneratorNode) {
275272
// even though this isn't a builtin for async generators, SendNode is used on async
276273
// generators by PAsyncGenSend
277-
checkResumable(this, self, isAsyncGen.profileObject(inliningTarget, self, PAsyncGenerator));
274+
checkResumable(this, self);
278275
if (!self.isStarted() && value != PNone.NONE) {
279276
throw raise(TypeError, ErrorMessages.SEND_NON_NONE_TO_UNSTARTED_GENERATOR);
280277
}
@@ -422,7 +419,7 @@ Object sendThrow(VirtualFrame frame, PGenerator self, Object typ, Object val, PT
422419

423420
private Object doThrow(VirtualFrame frame, ResumeGeneratorNode resumeGeneratorNode, PGenerator self, PBaseException instance, PythonLanguage language) {
424421
instance.setContext(null); // Will be filled when caught
425-
if (self.isFinished() && self.isCoroutine()) {
422+
if (self.isCoroutine() && self.isFinished()) {
426423
throw raise(PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_REUSE_CORO);
427424
}
428425
if (self.isStarted() && !self.isFinished()) {

0 commit comments

Comments
 (0)