Skip to content

Commit 669bf09

Browse files
committed
[GR-70898] Pass location to boundary code that raises errors.
PullRequest: graalpython/4063
2 parents 8cc272c + 99fc40a commit 669bf09

File tree

17 files changed

+69
-74
lines changed

17 files changed

+69
-74
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsTruffleModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private static PythonClass initClass(TruffleString className, TruffleString supe
165165
}
166166

167167
private static PythonClass initClass(TruffleString className, PythonAbstractClass superClass, BuiltinDescr[] descrs, PythonModule codecsTruffleModule, PythonLanguage language) {
168-
PythonClass clazz = PFactory.createPythonClassAndFixupSlots(language, className, superClass, new PythonAbstractClass[]{superClass});
168+
PythonClass clazz = PFactory.createPythonClassAndFixupSlots(null, language, className, superClass, new PythonAbstractClass[]{superClass});
169169
for (BuiltinDescr d : descrs) {
170170
PythonUtils.createMethod(language, clazz, d.nodeFactory(), d.enclosingType ? clazz : null, 1);
171171
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ast/AstTypeFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ final class AstTypeFactory {
7171
}
7272

7373
PythonClass makeType(TruffleString name, PythonAbstractClass base, TruffleString[] fields, TruffleString[] attributes, TruffleString[] optional, TruffleString docString) {
74-
PythonClass newType = PFactory.createPythonClassAndFixupSlots(language, name, base, new PythonAbstractClass[]{base});
74+
PythonClass newType = PFactory.createPythonClassAndFixupSlots(null, language, name, base, new PythonAbstractClass[]{base});
7575
newType.setAttribute(T___MODULE__, T_AST);
7676
newType.setAttribute(T___DOC__, docString);
7777
newType.setAttribute(T__FIELDS, PFactory.createTuple(language, convertToObjectArray(fields)));

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,14 +688,14 @@ public String toString() {
688688
public String toDisassembledString(boolean quickened) {
689689
RootNode rootNode = getRootCallTarget().getRootNode();
690690
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER && rootNode instanceof PBytecodeDSLRootNode dslRoot) {
691-
return dslRoot.getCodeUnit().toString(quickened);
691+
return dslRoot.getCodeUnit().toString(quickened, dslRoot);
692692
} else if (rootNode instanceof PBytecodeGeneratorRootNode r) {
693693
rootNode = r.getBytecodeRootNode();
694694
} else if (rootNode instanceof PBytecodeGeneratorFunctionRootNode r) {
695695
rootNode = r.getBytecodeRootNode();
696696
}
697697
if (rootNode instanceof PBytecodeRootNode bytecodeRootNode) {
698-
return bytecodeRootNode.getCodeUnit().toString(quickened);
698+
return bytecodeRootNode.getCodeUnit().toString(quickened, bytecodeRootNode);
699699
}
700700
return J_EMPTY_STRING;
701701
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLOperationNode.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ public void read(VirtualFrame frame, Node inliningTarget, PSSLSocket socket, Byt
120120
* Errors are wrapped into Python exceptions. Requests for IO in non-blocking modes are
121121
* indicated using Python exceptions ({@code SSLErrorWantRead}, {@code SSLErrorWantWrite}).
122122
*/
123-
public void handshake(VirtualFrame frame, Node inliningTarget, PSSLSocket socket) {
123+
public void handshake(VirtualFrame frame, Node inliningTarget, PConstructAndRaiseNode.Lazy constructAndRaiseNode, PSSLSocket socket) {
124124
if (!socket.isHandshakeComplete()) {
125125
try {
126126
beginHandshake(socket);
127127
} catch (SSLException e) {
128-
throw handleSSLException(e);
128+
throw handleSSLException(inliningTarget, e, constructAndRaiseNode);
129129
}
130130
execute(frame, inliningTarget, socket, SSLOperationNode.EMPTY_BUFFER, SSLOperationNode.EMPTY_BUFFER, SSLOperation.HANDSHAKE);
131131
}
@@ -268,7 +268,7 @@ static void doSocket(VirtualFrame frame, Node inliningTarget, PSSLSocket socket,
268268
break;
269269
}
270270
} catch (SSLException e) {
271-
throw handleSSLException(e);
271+
throw handleSSLException(inliningTarget, e, constructAndRaiseNode);
272272
} catch (OverflowException | OutOfMemoryError node) {
273273
throw raiseNode.raise(inliningTarget, MemoryError);
274274
}
@@ -310,7 +310,7 @@ static void doMemory(VirtualFrame frame, Node inliningTarget, PSSLSocket socket,
310310
throw CompilerDirectives.shouldNotReachHere("MemoryBIO-based socket operation returned WANTS_WRITE");
311311
}
312312
} catch (SSLException e) {
313-
throw handleSSLException(e);
313+
throw handleSSLException(inliningTarget, e, constructAndRaiseNode);
314314
} catch (OverflowException | OutOfMemoryError node) {
315315
throw raiseNode.raise(inliningTarget, MemoryError);
316316
}
@@ -550,10 +550,10 @@ private static SSLEngineResult doWrap(SSLEngine engine, ByteBuffer appInput, PMe
550550
}
551551

552552
@TruffleBoundary
553-
private static PException handleSSLException(SSLException e) {
553+
private static PException handleSSLException(Node inliningTarget, SSLException e, PConstructAndRaiseNode.Lazy raiseNode) {
554554
if (e.getCause() instanceof CertificateException) {
555-
throw PConstructAndRaiseNode.raiseUncachedSSLError(SSLErrorCode.ERROR_CERT_VERIFICATION, ErrorMessages.CERTIFICATE_VERIFY_FAILED, e.toString());
555+
throw raiseNode.get(inliningTarget).raiseSSLError(null, SSLErrorCode.ERROR_CERT_VERIFICATION, ErrorMessages.CERTIFICATE_VERIFY_FAILED, e.toString());
556556
}
557-
throw PConstructAndRaiseNode.raiseUncachedSSLError(SSLErrorCode.ERROR_SSL, toTruffleStringUncached(e.toString()));
557+
throw raiseNode.get(inliningTarget).raiseSSLError(null, SSLErrorCode.ERROR_SSL, toTruffleStringUncached(e.toString()));
558558
}
559559
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/SSLSocketBuiltins.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAcquireLibrary;
6969
import com.oracle.graal.python.builtins.objects.dict.PDict;
7070
import com.oracle.graal.python.nodes.ErrorMessages;
71+
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
7172
import com.oracle.graal.python.nodes.PRaiseNode;
7273
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
7374
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -196,8 +197,9 @@ abstract static class DoHandshakeNode extends PythonUnaryBuiltinNode {
196197
@Specialization
197198
Object doHandshake(VirtualFrame frame, PSSLSocket self,
198199
@Bind Node inliningTarget,
200+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode,
199201
@Cached SSLOperationNode sslOperationNode) {
200-
sslOperationNode.handshake(frame, inliningTarget, self);
202+
sslOperationNode.handshake(frame, inliningTarget, constructAndRaiseNode, self);
201203
return PNone.NONE;
202204
}
203205
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public final class PythonBuiltinClass extends PythonManagedClass {
6767

6868
@TruffleBoundary
6969
public PythonBuiltinClass(PythonLanguage lang, PythonBuiltinClassType builtinClass, PythonAbstractClass base) {
70-
super(lang, builtinClass.getType(), builtinClass.getType().getInstanceShape(lang), builtinClass.getInstanceShape(lang), builtinClass.getName(), base, new PythonAbstractClass[]{base},
70+
super(null, lang, builtinClass.getType(), builtinClass.getType().getInstanceShape(lang), builtinClass.getInstanceShape(lang), builtinClass.getName(), base, new PythonAbstractClass[]{base},
7171
builtinClass.getSlots());
7272
this.type = builtinClass;
7373
}

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

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.lang.ref.WeakReference;
2929
import java.util.ArrayDeque;
3030
import java.util.Arrays;
31-
import java.util.concurrent.atomic.AtomicReference;
3231

3332
import com.oracle.graal.python.PythonLanguage;
3433
import com.oracle.graal.python.builtins.objects.PNone;
@@ -41,9 +40,7 @@
4140
import com.oracle.graal.python.runtime.GilNode;
4241
import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
4342
import com.oracle.graal.python.util.SuppressFBWarnings;
44-
import com.oracle.truffle.api.Assumption;
4543
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
46-
import com.oracle.truffle.api.Truffle;
4744
import com.oracle.truffle.api.dsl.Bind;
4845
import com.oracle.truffle.api.dsl.Cached;
4946
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -69,7 +66,6 @@ public final class PythonClass extends PythonManagedClass {
6966
private static final int MRO_SUBTYPES_MAX = 64;
7067
private static final int MRO_SHAPE_INVALIDATIONS_MAX = 5;
7168

72-
private final AtomicReference<Assumption> slotsFinalAssumption = new AtomicReference<>();
7369
private MroShape mroShape; // only set if there's no inheritance from native types
7470
/**
7571
* Array of all classes that contain this class in their MRO and that have non-null mroShape,
@@ -80,30 +76,12 @@ public final class PythonClass extends PythonManagedClass {
8076
private TruffleWeakReference<PythonClass>[] mroShapeSubTypes;
8177
private byte mroShapeInvalidationsCount;
8278

83-
public PythonClass(PythonLanguage lang, Object typeClass, Shape classShape, TruffleString name, Object base, PythonAbstractClass[] baseClasses) {
84-
super(lang, typeClass, classShape, null, name, base, baseClasses, null);
79+
public PythonClass(Node location, PythonLanguage lang, Object typeClass, Shape classShape, TruffleString name, Object base, PythonAbstractClass[] baseClasses) {
80+
super(location, lang, typeClass, classShape, null, name, base, baseClasses, null);
8581
}
8682

87-
public PythonClass(PythonLanguage lang, Object typeClass, Shape classShape, TruffleString name, boolean invokeMro, Object base, PythonAbstractClass[] baseClasses) {
88-
super(lang, typeClass, classShape, null, name, invokeMro, false, base, baseClasses, null);
89-
}
90-
91-
public Assumption getSlotsFinalAssumption() {
92-
Assumption result = slotsFinalAssumption.get();
93-
if (result == null) {
94-
result = Truffle.getRuntime().createAssumption("slots");
95-
if (!slotsFinalAssumption.compareAndSet(null, result)) {
96-
result = slotsFinalAssumption.get();
97-
}
98-
}
99-
return result;
100-
}
101-
102-
public void invalidateSlotsFinalAssumption() {
103-
Assumption assumption = slotsFinalAssumption.get();
104-
if (assumption != null) {
105-
assumption.invalidate();
106-
}
83+
public PythonClass(Node location, PythonLanguage lang, Object typeClass, Shape classShape, TruffleString name, boolean invokeMro, Object base, PythonAbstractClass[] baseClasses) {
84+
super(location, lang, typeClass, classShape, null, name, invokeMro, false, base, baseClasses, null);
10785
}
10886

10987
public void setTpSlots(TpSlots tpSlots) {
@@ -114,10 +92,6 @@ public void setTpSlots(TpSlots tpSlots) {
11492
@TruffleBoundary
11593
@SuppressFBWarnings(value = "UR_UNINIT_READ_CALLED_FROM_SUPER_CONSTRUCTOR")
11694
public void setAttribute(TruffleString key, Object value) {
117-
if (slotsFinalAssumption != null) {
118-
// It is OK when slotsFinalAssumption is null during the super ctor call
119-
invalidateSlotsFinalAssumption();
120-
}
12195
super.setAttribute(key, value);
12296
invalidateMroShapeSubTypes();
12397
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@ public abstract class PythonManagedClass extends PythonObject implements PythonA
7979
public PTuple basesTuple;
8080

8181
@TruffleBoundary
82-
protected PythonManagedClass(PythonLanguage lang, Object typeClass, Shape classShape, Shape instanceShape, TruffleString name, Object base, PythonAbstractClass[] baseClasses, TpSlots slots) {
83-
this(lang, typeClass, classShape, instanceShape, name, true, true, base, baseClasses, slots);
82+
protected PythonManagedClass(Node location, PythonLanguage lang, Object typeClass, Shape classShape, Shape instanceShape, TruffleString name, Object base, PythonAbstractClass[] baseClasses,
83+
TpSlots slots) {
84+
this(location, lang, typeClass, classShape, instanceShape, name, true, true, base, baseClasses, slots);
8485
}
8586

8687
@TruffleBoundary
8788
@SuppressWarnings("this-escape")
88-
protected PythonManagedClass(PythonLanguage lang, Object typeClass, Shape classShape, Shape instanceShape, TruffleString name, boolean invokeMro, boolean initDocAttr,
89+
protected PythonManagedClass(Node location, PythonLanguage lang, Object typeClass, Shape classShape, Shape instanceShape, TruffleString name, boolean invokeMro, boolean initDocAttr,
8990
Object base, PythonAbstractClass[] baseClasses, TpSlots slots) {
9091
super(typeClass, classShape);
9192
this.name = name;
@@ -101,8 +102,7 @@ protected PythonManagedClass(PythonLanguage lang, Object typeClass, Shape classS
101102
unsafeSetSuperClass(baseClasses);
102103
}
103104

104-
// TODO should pass node for exception location
105-
this.setMRO(ComputeMroNode.doSlowPath(null, this, invokeMro));
105+
this.setMRO(ComputeMroNode.doSlowPath(location, this, invokeMro));
106106
if (invokeMro) {
107107
mroInitialized = true;
108108
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ static PythonClass typeMetaclass(VirtualFrame frame, TruffleString name, PTuple
21722172

21732173
// 1.) create class, but avoid calling mro method - it might try to access __dict__ so
21742174
// we have to copy dict slots first
2175-
PythonClass pythonClass = PFactory.createPythonClass(language, metaclass, getInstanceShape.execute(metaclass), name, false, base, basesArray);
2175+
PythonClass pythonClass = PFactory.createPythonClass(inliningTarget, language, metaclass, getInstanceShape.execute(metaclass), name, false, base, basesArray);
21762176

21772177
// 2.) copy the dictionary slots
21782178
copyDictSlots(frame, inliningTarget, language, ctx, pythonClass, namespace, setHashingStorageItem,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BytecodeCodeUnit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.oracle.truffle.api.CompilerDirectives;
6060
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
6161
import com.oracle.truffle.api.nodes.Node;
62+
import com.oracle.truffle.api.nodes.RootNode;
6263
import com.oracle.truffle.api.strings.TruffleString;
6364

6465
public final class BytecodeCodeUnit extends CodeUnit {
@@ -149,7 +150,7 @@ public void generalizeInputs(int bci) {
149150
}
150151

151152
@Override
152-
protected void dumpBytecode(StringBuilder sb, boolean quickened) {
153+
protected void dumpBytecode(StringBuilder sb, boolean quickened, RootNode rootNode) {
153154
int bci = 0;
154155
int oparg = 0;
155156
SourceMap map = getSourceMap();

0 commit comments

Comments
 (0)