Skip to content

Commit 6e48418

Browse files
author
Adam Hrbac
committed
Use new type for asyncgens and add athrow
1 parent 31152ec commit 6e48418

File tree

2 files changed

+17
-32
lines changed

2 files changed

+17
-32
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,14 +1522,14 @@ public abstract class ErrorMessages {
15221522

15231523
public static final TruffleString ASYNC_FOR_NO_AITER = tsLiteral("'async for' requires object with __aiter__ method, got %s");
15241524
public static final TruffleString ASYNC_FOR_NO_ANEXT_INITIAL = tsLiteral("'async for' received an object from __aiter__ that does not implement __anext__: %s");
1525-
public static final TruffleString ASYNC_FOR_NO_ANEXT_ITERATION = tsLiteral("'async for' requires an iterator with __anext__ method, got %s");
1525+
public static final TruffleString ASYNC_FOR_NO_ANEXT_ITERATION = tsLiteral("'async for' requires an iterator with __anext__ method, got %p");
15261526

15271527
public static final TruffleString CANNOT_REUSE_ASEND = tsLiteral("cannot reuse already awaited __anext__()/asend()");
15281528
public static final TruffleString OBJECT_NOT_ASYNCGEN = tsLiteral("'%s' object is not an async generator");
15291529
public static final TruffleString CANNOT_REUSE_ATHROW = tsLiteral("cannot reuse already awaited aclose()/athrow()");
15301530
public static final TruffleString CANNOT_REUSE_CORO = tsLiteral("cannot reuse already awaited coroutine");
15311531
public static final TruffleString AGEN_ALREADY_RUNNING = tsLiteral("anext(): asynchronous generator is already running");
15321532
public static final TruffleString CORO_ALREADY_AWAITED = tsLiteral("coroutine is being awaited already");
1533-
public static final TruffleString ANEXT_INVALID_OBJECT = tsLiteral("'async for' received an invalid object from __anext__: %s");
1533+
public static final TruffleString ANEXT_INVALID_OBJECT = tsLiteral("'async for' received an invalid object from __anext__: %p");
15341534
public static final TruffleString ASYNCGEN_RAISED_ASYNCSTOPITER = tsLiteral("async generator raised StopAsyncIteration");
15351535
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetANextNode.java

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,17 @@
4040
*/
4141
package com.oracle.graal.python.nodes.bytecode;
4242

43+
import static com.oracle.graal.python.nodes.ErrorMessages.ANEXT_INVALID_OBJECT;
44+
import static com.oracle.graal.python.nodes.ErrorMessages.ASYNC_FOR_NO_ANEXT_ITERATION;
45+
4346
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4447
import com.oracle.graal.python.builtins.objects.PNone;
4548
import com.oracle.graal.python.builtins.objects.asyncio.GetAwaitableNode;
46-
import com.oracle.graal.python.builtins.objects.object.PythonObject;
4749
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
48-
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
49-
import com.oracle.graal.python.nodes.ErrorMessages;
5050
import com.oracle.graal.python.nodes.PNodeWithContext;
5151
import com.oracle.graal.python.nodes.PRaiseNode;
52-
import com.oracle.graal.python.nodes.SpecialMethodNames;
5352
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
54-
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodNode;
5553
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodSlotNode;
56-
import com.oracle.graal.python.nodes.object.GetClassNode;
5754
import com.oracle.graal.python.nodes.object.InlinedGetClassNode;
5855
import com.oracle.graal.python.runtime.exception.PException;
5956
import com.oracle.truffle.api.dsl.Bind;
@@ -64,10 +61,6 @@
6461
import com.oracle.truffle.api.frame.Frame;
6562
import com.oracle.truffle.api.nodes.Node;
6663
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
67-
import com.oracle.truffle.api.strings.TruffleString;
68-
69-
import static com.oracle.graal.python.nodes.ErrorMessages.ANEXT_INVALID_OBJECT;
70-
import static com.oracle.graal.python.nodes.ErrorMessages.ASYNC_FOR_NO_ANEXT_ITERATION;
7164

7265
@GenerateUncached
7366
@ImportStatic(SpecialMethodSlot.class)
@@ -84,34 +77,26 @@ public static GetANextNode create() {
8477

8578
@Specialization
8679
Object doGeneric(Frame frame, Object receiver,
87-
@Bind("this") Node inliningTarget,
88-
@Cached(parameters = "ANext") LookupSpecialMethodSlotNode getANext,
89-
@Cached GetClassNode getAsyncIterType,
90-
@Cached InlinedGetClassNode.GetPythonObjectClassNode getANextType,
91-
@Cached PRaiseNode raiseNoANext,
92-
@Cached TypeNodes.GetNameNode getName,
93-
@Cached InlinedBranchProfile errorProfile,
94-
@Cached CallUnaryMethodNode callANext,
95-
@Cached PRaiseNode raiseInvalidObject,
96-
@Cached GetAwaitableNode getAwaitable) {
97-
Object type = getAsyncIterType.execute(receiver);
80+
@Bind("this") Node inliningTarget,
81+
@Cached(parameters = "ANext") LookupSpecialMethodSlotNode getANext,
82+
@Cached InlinedGetClassNode getAsyncIterType,
83+
@Cached PRaiseNode raiseNoANext,
84+
@Cached InlinedBranchProfile errorProfile,
85+
@Cached CallUnaryMethodNode callANext,
86+
@Cached PRaiseNode raiseInvalidObject,
87+
@Cached(neverDefault = true) GetAwaitableNode getAwaitable) {
88+
Object type = getAsyncIterType.execute(inliningTarget, receiver);
9889
Object getter = getANext.execute(frame, type, receiver);
9990
if (getter == PNone.NO_VALUE) {
10091
errorProfile.enter(inliningTarget);
101-
throw raiseNoANext.raise(PythonBuiltinClassType.TypeError, ASYNC_FOR_NO_ANEXT_ITERATION, getName.execute(type));
92+
throw raiseNoANext.raise(PythonBuiltinClassType.TypeError, ASYNC_FOR_NO_ANEXT_ITERATION, receiver);
10293
}
10394
Object anext = callANext.executeObject(frame, getter, receiver);
10495
try {
10596
return getAwaitable.execute(frame, anext);
106-
} catch(PException e) {
97+
} catch (PException e) {
10798
errorProfile.enter(inliningTarget);
108-
Object aNextName;
109-
if (anext instanceof PythonObject) {
110-
aNextName = getName.execute(getANextType.execute(inliningTarget, (PythonObject) anext));
111-
} else {
112-
aNextName = anext.getClass().getName();
113-
}
114-
throw raiseInvalidObject.raise(PythonBuiltinClassType.TypeError, e, ANEXT_INVALID_OBJECT, aNextName);
99+
throw raiseInvalidObject.raise(PythonBuiltinClassType.TypeError, e, ANEXT_INVALID_OBJECT, anext);
115100
}
116101
}
117102
}

0 commit comments

Comments
 (0)