55
55
import com .oracle .graal .python .builtins .objects .traceback .GetTracebackNode ;
56
56
import com .oracle .graal .python .builtins .objects .traceback .PTraceback ;
57
57
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
58
- import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
59
58
import com .oracle .graal .python .nodes .ErrorMessages ;
60
59
import com .oracle .graal .python .nodes .PGuards ;
61
60
import com .oracle .graal .python .nodes .PRaiseNode ;
@@ -102,7 +101,7 @@ public class GeneratorBuiltins extends PythonBuiltins {
102
101
* we now use the same arguments array every time, the next invocation would think that there is
103
102
* not excepion but in fact, the a subsequent call ot {@code next} may have a different
104
103
* exception state.
105
- *
104
+ *
106
105
* <pre>
107
106
* g = my_generator()
108
107
*
@@ -302,23 +301,25 @@ PBaseException doException(@SuppressWarnings("unused") PBaseException exc, @Supp
302
301
throw raise .raise (PythonBuiltinClassType .TypeError , ErrorMessages .INSTANCE_EX_MAY_NOT_HAVE_SEP_VALUE );
303
302
}
304
303
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 ,
307
306
@ Cached BuiltinFunctions .IsInstanceNode isInstanceNode ,
308
307
@ Cached BranchProfile isNotInstanceProfile ,
309
- @ Cached ("create(__CALL__)" ) LookupAndCallVarargsNode callConstructor ) {
308
+ @ Cached ("create(__CALL__)" ) LookupAndCallVarargsNode callConstructor ,
309
+ @ CachedLibrary (limit = "2" ) PythonObjectLibrary lib ) {
310
310
if (isInstanceNode .executeWith (frame , value , type )) {
311
311
checkExceptionClass (type );
312
312
return value ;
313
313
} else {
314
314
isNotInstanceProfile .enter ();
315
- return doCreateObject (frame , type , value , callConstructor );
315
+ return doCreateObject (frame , type , value , callConstructor , lib );
316
316
}
317
317
}
318
318
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 ) {
322
323
checkExceptionClass (type );
323
324
Object instance = callConstructor .execute (frame , type , new Object []{type });
324
325
if (instance instanceof PBaseException ) {
@@ -328,10 +329,11 @@ PBaseException doCreate(VirtualFrame frame, LazyPythonClass type, @SuppressWarni
328
329
}
329
330
}
330
331
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 ,
333
334
@ Cached GetObjectArrayNode getObjectArrayNode ,
334
- @ Cached ("create(__CALL__)" ) LookupAndCallVarargsNode callConstructor ) {
335
+ @ Cached ("create(__CALL__)" ) LookupAndCallVarargsNode callConstructor ,
336
+ @ SuppressWarnings ("unused" ) @ CachedLibrary (limit = "2" ) PythonObjectLibrary lib ) {
335
337
checkExceptionClass (type );
336
338
Object [] array = getObjectArrayNode .execute (value );
337
339
Object [] args = new Object [array .length + 1 ];
@@ -345,9 +347,10 @@ PBaseException doCreateTuple(VirtualFrame frame, LazyPythonClass type, PTuple va
345
347
}
346
348
}
347
349
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 ) {
351
354
checkExceptionClass (type );
352
355
Object instance = callConstructor .execute (frame , type , new Object []{type , value });
353
356
if (instance instanceof PBaseException ) {
@@ -370,7 +373,7 @@ private PRaiseNode raise() {
370
373
return raiseNode ;
371
374
}
372
375
373
- private void checkExceptionClass (LazyPythonClass type ) {
376
+ private void checkExceptionClass (Object type ) {
374
377
if (isSubtypeNode == null ) {
375
378
CompilerDirectives .transferToInterpreterAndInvalidate ();
376
379
isSubtypeNode = insert (IsSubtypeNode .create ());
0 commit comments