Skip to content

Commit 5e4bc6d

Browse files
committed
index normalization may be called without a frame
1 parent 65240fd commit 5e4bc6d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ abstract static class NormalizingNode extends PNodeWithContext {
463463
@Child private NormalizeIndexNode normalizeIndexNode;
464464
@Child private PythonObjectLibrary lib;
465465
@CompilationFinal private ValueProfile storeProfile;
466+
@CompilationFinal private ConditionProfile gotFrameProfile;
466467

467468
protected NormalizingNode(NormalizeIndexNode normalizeIndexNode) {
468469
this.normalizeIndexNode = normalizeIndexNode;
@@ -477,7 +478,16 @@ private PythonObjectLibrary getLibrary() {
477478
}
478479

479480
protected final int normalizeIndex(VirtualFrame frame, Object idx, SequenceStorage store) {
480-
int intIdx = getLibrary().asSizeWithState(idx, PythonBuiltinClassType.IndexError, PArguments.getThreadState(frame));
481+
if (gotFrameProfile == null) {
482+
CompilerDirectives.transferToInterpreterAndInvalidate();
483+
gotFrameProfile = ConditionProfile.createBinaryProfile();
484+
}
485+
int intIdx;
486+
if (gotFrameProfile.profile(frame != null)) {
487+
intIdx = getLibrary().asSizeWithState(idx, PythonBuiltinClassType.IndexError, PArguments.getThreadState(frame));
488+
} else {
489+
intIdx = getLibrary().asSize(idx, PythonBuiltinClassType.IndexError);
490+
}
481491
if (normalizeIndexNode != null) {
482492
return normalizeIndexNode.execute(intIdx, getStoreProfile().profile(store).length());
483493
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PArguments.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public static PDict getGeneratorFrameLocals(Object[] arguments) {
352352
}
353353

354354
public static ThreadState getThreadState(VirtualFrame frame) {
355-
assert frame != null;
355+
assert frame != null : "cannot get thread state without a frame";
356356
return new ThreadState(PArguments.getCurrentFrameInfo(frame), PArguments.getException(frame));
357357
}
358358

0 commit comments

Comments
 (0)