@@ -347,6 +347,8 @@ abstract static class ResolveName extends Node {
347
347
private static final byte PKG_IS_NULL = 0b01;
348
348
private static final byte SPEC_IS_STH = 0b001;
349
349
private static final byte NO_SPEC_PKG = 0b0001;
350
+ private static final byte CANNOT_CAST = 0b00001;
351
+ private static final byte GOT_NO_NAME = 0b000001;
350
352
@ CompilationFinal private byte branchStates = 0 ;
351
353
352
354
abstract String execute (VirtualFrame frame , String name , Object globals , int level );
@@ -373,6 +375,10 @@ String resolveName(VirtualFrame frame, String name, Object globals, int level,
373
375
try {
374
376
pkgString = castPackageNode .execute (pkg );
375
377
} catch (CannotCastException e ) {
378
+ if ((branchStates & CANNOT_CAST ) == 0 ) {
379
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
380
+ branchStates |= CANNOT_CAST ;
381
+ }
376
382
throw PRaiseNode .raiseUncached (this , PythonBuiltinClassType .TypeError , "package must be a string" );
377
383
}
378
384
if (spec != null && spec != PNone .NONE ) {
@@ -394,6 +400,10 @@ String resolveName(VirtualFrame frame, String name, Object globals, int level,
394
400
try {
395
401
pkgString = castPackageNode .execute (pkg );
396
402
} catch (CannotCastException e ) {
403
+ if ((branchStates & CANNOT_CAST ) == 0 ) {
404
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
405
+ branchStates |= CANNOT_CAST ;
406
+ }
397
407
throw PRaiseNode .raiseUncached (this , PythonBuiltinClassType .TypeError , "__spec__.parent must be a string" );
398
408
}
399
409
} else {
@@ -410,11 +420,19 @@ String resolveName(VirtualFrame frame, String name, Object globals, int level,
410
420
// footprint when use the same node for __package__, __name__, and __path__ lookup
411
421
pkg = getPackageOrNameNode .execute (frame , globalsDict , SpecialAttributeNames .__NAME__ );
412
422
if (pkg == null ) {
423
+ if ((branchStates & GOT_NO_NAME ) == 0 ) {
424
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
425
+ branchStates |= GOT_NO_NAME ;
426
+ }
413
427
PRaiseNode .raiseUncached (this , PythonBuiltinClassType .KeyError , "'__name__' not in globals" );
414
428
}
415
429
try {
416
430
pkgString = castPackageNode .execute (pkg );
417
431
} catch (CannotCastException e ) {
432
+ if ((branchStates & CANNOT_CAST ) == 0 ) {
433
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
434
+ branchStates |= CANNOT_CAST ;
435
+ }
418
436
throw PRaiseNode .raiseUncached (this , PythonBuiltinClassType .TypeError , "__name__ must be a string" );
419
437
}
420
438
Object path = getPackageOrNameNode .execute (frame , globalsDict , SpecialAttributeNames .__PATH__ );
0 commit comments