Skip to content

Commit 4d7900e

Browse files
committed
add another couple of state bits
1 parent 5f461b0 commit 4d7900e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AbstractImportNode.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ abstract static class ResolveName extends Node {
347347
private static final byte PKG_IS_NULL = 0b01;
348348
private static final byte SPEC_IS_STH = 0b001;
349349
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;
350352
@CompilationFinal private byte branchStates = 0;
351353

352354
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,
373375
try {
374376
pkgString = castPackageNode.execute(pkg);
375377
} catch (CannotCastException e) {
378+
if ((branchStates & CANNOT_CAST) == 0) {
379+
CompilerDirectives.transferToInterpreterAndInvalidate();
380+
branchStates |= CANNOT_CAST;
381+
}
376382
throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.TypeError, "package must be a string");
377383
}
378384
if (spec != null && spec != PNone.NONE) {
@@ -394,6 +400,10 @@ String resolveName(VirtualFrame frame, String name, Object globals, int level,
394400
try {
395401
pkgString = castPackageNode.execute(pkg);
396402
} catch (CannotCastException e) {
403+
if ((branchStates & CANNOT_CAST) == 0) {
404+
CompilerDirectives.transferToInterpreterAndInvalidate();
405+
branchStates |= CANNOT_CAST;
406+
}
397407
throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.TypeError, "__spec__.parent must be a string");
398408
}
399409
} else {
@@ -410,11 +420,19 @@ String resolveName(VirtualFrame frame, String name, Object globals, int level,
410420
// footprint when use the same node for __package__, __name__, and __path__ lookup
411421
pkg = getPackageOrNameNode.execute(frame, globalsDict, SpecialAttributeNames.__NAME__);
412422
if (pkg == null) {
423+
if ((branchStates & GOT_NO_NAME) == 0) {
424+
CompilerDirectives.transferToInterpreterAndInvalidate();
425+
branchStates |= GOT_NO_NAME;
426+
}
413427
PRaiseNode.raiseUncached(this, PythonBuiltinClassType.KeyError, "'__name__' not in globals");
414428
}
415429
try {
416430
pkgString = castPackageNode.execute(pkg);
417431
} catch (CannotCastException e) {
432+
if ((branchStates & CANNOT_CAST) == 0) {
433+
CompilerDirectives.transferToInterpreterAndInvalidate();
434+
branchStates |= CANNOT_CAST;
435+
}
418436
throw PRaiseNode.raiseUncached(this, PythonBuiltinClassType.TypeError, "__name__ must be a string");
419437
}
420438
Object path = getPackageOrNameNode.execute(frame, globalsDict, SpecialAttributeNames.__PATH__);

0 commit comments

Comments
 (0)