Skip to content

Commit 3d4614e

Browse files
committed
Remove LazyPythonClass use in GeneratorBuiltins
1 parent 8fa2206 commit 3d4614e

File tree

1 file changed

+19
-16
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator

1 file changed

+19
-16
lines changed

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import com.oracle.graal.python.builtins.objects.traceback.GetTracebackNode;
5656
import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
5757
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
58-
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
5958
import com.oracle.graal.python.nodes.ErrorMessages;
6059
import com.oracle.graal.python.nodes.PGuards;
6160
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -102,7 +101,7 @@ public class GeneratorBuiltins extends PythonBuiltins {
102101
* we now use the same arguments array every time, the next invocation would think that there is
103102
* not excepion but in fact, the a subsequent call ot {@code next} may have a different
104103
* exception state.
105-
*
104+
*
106105
* <pre>
107106
* g = my_generator()
108107
*
@@ -302,23 +301,25 @@ PBaseException doException(@SuppressWarnings("unused") PBaseException exc, @Supp
302301
throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.INSTANCE_EX_MAY_NOT_HAVE_SEP_VALUE);
303302
}
304303

305-
@Specialization
306-
PBaseException doException(VirtualFrame frame, LazyPythonClass type, PBaseException value,
304+
@Specialization(guards = "lib.isLazyPythonClass(type)")
305+
PBaseException doException(VirtualFrame frame, Object type, PBaseException value,
307306
@Cached BuiltinFunctions.IsInstanceNode isInstanceNode,
308307
@Cached BranchProfile isNotInstanceProfile,
309-
@Cached("create(__CALL__)") LookupAndCallVarargsNode callConstructor) {
308+
@Cached("create(__CALL__)") LookupAndCallVarargsNode callConstructor,
309+
@CachedLibrary(limit = "2") PythonObjectLibrary lib) {
310310
if (isInstanceNode.executeWith(frame, value, type)) {
311311
checkExceptionClass(type);
312312
return value;
313313
} else {
314314
isNotInstanceProfile.enter();
315-
return doCreateObject(frame, type, value, callConstructor);
315+
return doCreateObject(frame, type, value, callConstructor, lib);
316316
}
317317
}
318318

319-
@Specialization
320-
PBaseException doCreate(VirtualFrame frame, LazyPythonClass type, @SuppressWarnings("unused") PNone value,
321-
@Cached("create(__CALL__)") LookupAndCallVarargsNode callConstructor) {
319+
@Specialization(guards = "lib.isLazyPythonClass(type)")
320+
PBaseException doCreate(VirtualFrame frame, Object type, @SuppressWarnings("unused") PNone value,
321+
@Cached("create(__CALL__)") LookupAndCallVarargsNode callConstructor,
322+
@SuppressWarnings("unused") @CachedLibrary(limit = "2") PythonObjectLibrary lib) {
322323
checkExceptionClass(type);
323324
Object instance = callConstructor.execute(frame, type, new Object[]{type});
324325
if (instance instanceof PBaseException) {
@@ -328,10 +329,11 @@ PBaseException doCreate(VirtualFrame frame, LazyPythonClass type, @SuppressWarni
328329
}
329330
}
330331

331-
@Specialization
332-
PBaseException doCreateTuple(VirtualFrame frame, LazyPythonClass type, PTuple value,
332+
@Specialization(guards = "lib.isLazyPythonClass(type)")
333+
PBaseException doCreateTuple(VirtualFrame frame, Object type, PTuple value,
333334
@Cached GetObjectArrayNode getObjectArrayNode,
334-
@Cached("create(__CALL__)") LookupAndCallVarargsNode callConstructor) {
335+
@Cached("create(__CALL__)") LookupAndCallVarargsNode callConstructor,
336+
@SuppressWarnings("unused") @CachedLibrary(limit = "2") PythonObjectLibrary lib) {
335337
checkExceptionClass(type);
336338
Object[] array = getObjectArrayNode.execute(value);
337339
Object[] args = new Object[array.length + 1];
@@ -345,9 +347,10 @@ PBaseException doCreateTuple(VirtualFrame frame, LazyPythonClass type, PTuple va
345347
}
346348
}
347349

348-
@Specialization(guards = {"!isPNone(value)", "!isPTuple(value)", "!isPBaseException(value)"})
349-
PBaseException doCreateObject(VirtualFrame frame, LazyPythonClass type, Object value,
350-
@Cached("create(__CALL__)") LookupAndCallVarargsNode callConstructor) {
350+
@Specialization(guards = {"lib.isLazyPythonClass(type)", "!isPNone(value)", "!isPTuple(value)", "!isPBaseException(value)"})
351+
PBaseException doCreateObject(VirtualFrame frame, Object type, Object value,
352+
@Cached("create(__CALL__)") LookupAndCallVarargsNode callConstructor,
353+
@SuppressWarnings("unused") @CachedLibrary(limit = "2") PythonObjectLibrary lib) {
351354
checkExceptionClass(type);
352355
Object instance = callConstructor.execute(frame, type, new Object[]{type, value});
353356
if (instance instanceof PBaseException) {
@@ -370,7 +373,7 @@ private PRaiseNode raise() {
370373
return raiseNode;
371374
}
372375

373-
private void checkExceptionClass(LazyPythonClass type) {
376+
private void checkExceptionClass(Object type) {
374377
if (isSubtypeNode == null) {
375378
CompilerDirectives.transferToInterpreterAndInvalidate();
376379
isSubtypeNode = insert(IsSubtypeNode.create());

0 commit comments

Comments
 (0)