Skip to content

Commit 8517f1f

Browse files
committed
Fix uncached execution
* Fix missing None guard in ArrayBuiltins * Use EncapsulatingNodeReference.get().get() for exception location if the current location is null or not adoptable unless unadoptable location is intended
1 parent 9f333d1 commit 8517f1f

8 files changed

Lines changed: 22 additions & 18 deletions

File tree

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2026, Oracle and/or its affiliates.
33
* Copyright (c) 2014, Regents of the University of California
44
*
55
* All rights reserved.
@@ -323,7 +323,7 @@ static PArray arraySequenceInitializer(VirtualFrame frame, Node inliningTarget,
323323
}
324324
}
325325

326-
@Specialization(guards = {"!isBytes(initializer)", "!isString(initializer)", "!isPSequence(initializer)"})
326+
@Specialization(guards = {"!isBytes(initializer)", "!isString(initializer)", "!isPSequence(initializer)", "!isNoValue(initializer)"})
327327
@InliningCutoff
328328
static PArray arrayIteratorInitializer(VirtualFrame frame, Node inliningTarget, Object cls, TruffleString typeCode, Object initializer,
329329
@Cached PyObjectGetIter getIter,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -2230,7 +2230,7 @@ static Object doGeneric(PythonThreadState state, @SuppressWarnings("unused") Tru
22302230
if (currentException == PNone.NO_VALUE) {
22312231
throw raiseNode.raise(inliningTarget, PythonBuiltinClassType.StopIteration);
22322232
} else {
2233-
throw PException.fromObject(currentException, inliningTarget, false);
2233+
throw PException.fromObjectFixUncachedLocation(currentException, inliningTarget, false);
22342234
}
22352235
}
22362236
return result;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -617,7 +617,7 @@ private static void checkFunctionResultSlowpath(Node inliningTarget, TruffleStri
617617
if (indicatesError) {
618618
if (errOccurred) {
619619
assert currentException != PNone.NO_VALUE;
620-
throw PException.fromObject(currentException, inliningTarget, false);
620+
throw PException.fromObjectFixUncachedLocation(currentException, inliningTarget, false);
621621
} else if (strict) {
622622
assert currentException == PNone.NO_VALUE;
623623
throw raiseNullButNoError(inliningTarget, name, nullButNoErrorMessage);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotIterNext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -194,7 +194,7 @@ static Object callNative(VirtualFrame frame, Node inliningTarget, TpSlotCExtNati
194194
if (pythonResult == PNone.NO_VALUE) {
195195
Object currentException = readAndClearNativeException.execute(inliningTarget, state);
196196
if (currentException != PNone.NO_VALUE) {
197-
throw PException.fromObject(currentException, inliningTarget, false);
197+
throw PException.fromObjectFixUncachedLocation(currentException, inliningTarget, false);
198198
} else {
199199
throw TpIterNextBuiltin.iteratorExhausted();
200200
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRaiseNode.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import com.oracle.truffle.api.dsl.GenerateInline;
5959
import com.oracle.truffle.api.dsl.GenerateUncached;
6060
import com.oracle.truffle.api.dsl.Specialization;
61-
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
6261
import com.oracle.truffle.api.nodes.Node;
6362
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
6463
import com.oracle.truffle.api.strings.TruffleString;
@@ -275,11 +274,7 @@ private static PException raiseExceptionObjectStatic(Node raisingNode, Object ex
275274

276275
// No @InliningCutoff, done in callers already
277276
public static PException raiseExceptionObjectStatic(Node raisingNode, Object exc, boolean withJavaStacktrace) {
278-
if (raisingNode != null && raisingNode.isAdoptable()) {
279-
throw PException.fromObject(exc, raisingNode, withJavaStacktrace);
280-
} else {
281-
throw PException.fromObject(exc, EncapsulatingNodeReference.getCurrent().get(), withJavaStacktrace);
282-
}
277+
throw PException.fromObjectFixUncachedLocation(exc, raisingNode, withJavaStacktrace);
283278
}
284279

285280
public static PRaiseNode getUncached() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetSendValueNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -62,7 +62,7 @@ Object doNext(@SuppressWarnings("unused") Object specialArgument) {
6262

6363
@Specialization
6464
Object doThrow(ThrowData throwData) {
65-
throw PException.fromObject(throwData.pythonException, this, throwData.withJavaStacktrace);
65+
throw PException.fromObjectFixUncachedLocation(throwData.pythonException, this, throwData.withJavaStacktrace);
6666
}
6767

6868
@Fallback

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/SequenceFromArrayNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public abstract static class ListFromArrayNode extends SequenceFromArrayNode imp
189189
private static final ListFromArrayNode UNCACHED = new ListFromArrayNode() {
190190
@Override
191191
public PList execute(PythonLanguage language, Object[] elements) {
192-
return PFactory.createList(language, elements);
192+
return PFactory.createList(language, SequenceStorageFactory.createStorage(elements));
193193
}
194194
};
195195

@@ -252,7 +252,7 @@ public abstract static class TupleFromArrayNode extends SequenceFromArrayNode {
252252
private static final TupleFromArrayNode UNCACHED = new TupleFromArrayNode() {
253253
@Override
254254
public PTuple execute(PythonLanguage language, Object[] elements) {
255-
return PFactory.createTuple(language, elements);
255+
return PFactory.createTuple(language, SequenceStorageFactory.createStorage(elements));
256256
}
257257
};
258258

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/PException.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import com.oracle.truffle.api.library.CachedLibrary;
7777
import com.oracle.truffle.api.library.ExportLibrary;
7878
import com.oracle.truffle.api.library.ExportMessage;
79+
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
7980
import com.oracle.truffle.api.nodes.Node;
8081
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
8182
import com.oracle.truffle.api.source.SourceSection;
@@ -137,6 +138,14 @@ private PException(Object pythonException, Node node, Throwable wrapped) {
137138
assert PyExceptionInstanceCheckNode.executeUncached(pythonException);
138139
}
139140

141+
public static PException fromObjectFixUncachedLocation(Object pythonException, Node location, boolean withJavaStacktrace) {
142+
Node n = location;
143+
if (n == null || !n.isAdoptable()) {
144+
n = EncapsulatingNodeReference.getCurrent().get();
145+
}
146+
return fromObject(pythonException, n, withJavaStacktrace);
147+
}
148+
140149
public static PException fromObject(Object pythonException, Node node, boolean withJavaStacktrace) {
141150
Throwable wrapped = null;
142151
if (withJavaStacktrace) {

0 commit comments

Comments
 (0)