@@ -103,64 +103,39 @@ public final class PException extends AbstractTruffleException {
103103 private boolean skipFirstTracebackFrame ;
104104 private int tracebackFrameCount ;
105105
106- /**
107- * We create new {@link PException} instances wrapping the same {@link PBaseException} as the
108- * stack is unwound when the exception is reraised. See {@link MaterializeLazyTracebackNode} for
109- * more details.
110- * <p>
111- * Since the new {@link PException} for reraise will be thrown from different frame than the
112- * initial {@link PException}, Truffle will think that it belongs to that frame and not to the
113- * original frame. Truffle expects the {@link AbstractTruffleException#getLocation()} to belong
114- * the (AST of the root node of) frame where the exception was thrown. If we just copy the
115- * location from the initial {@link PException} to the {@link PException} constructed for
116- * reraise, the location would not satisfy that property, but at the same time we like to keep
117- * the original location to use it in {@link InteropLibrary#getSourceLocation} message.
118- */
119- private final Node originalLocation ;
120-
121106 private PException (Object pythonException , Node node ) {
122107 super (node );
123108 this .pythonException = pythonException ;
124- this .originalLocation = node ;
125109 }
126110
127- private PException (Object pythonException , Node location , Node originalLocation , Throwable wrapped ) {
128- super (null , wrapped , UNLIMITED_STACK_TRACE , location );
111+ private PException (Object pythonException , Node node , Throwable wrapped ) {
112+ super (null , wrapped , UNLIMITED_STACK_TRACE , node );
129113 this .pythonException = pythonException ;
130- this .originalLocation = originalLocation ;
131114 assert PyExceptionInstanceCheckNode .executeUncached (pythonException );
132115 }
133116
134- public static PException fromObject (Object pythonException , Node location , boolean withJavaStacktrace ) {
135- return fromObject (pythonException , location , location , withJavaStacktrace );
136- }
137-
138- public static PException fromObject (Object pythonException , Node location , Node originalLocation , boolean withJavaStacktrace ) {
117+ public static PException fromObject (Object pythonException , Node node , boolean withJavaStacktrace ) {
139118 Throwable wrapped = null ;
140119 if (withJavaStacktrace ) {
141120 // Create a carrier for the java stacktrace as PException cannot have one
142121 wrapped = createStacktraceCarrier ();
143122 }
144- return fromObject (pythonException , location , originalLocation , wrapped );
123+ return fromObject (pythonException , node , wrapped );
145124 }
146125
147126 @ TruffleBoundary
148127 private static RuntimeException createStacktraceCarrier () {
149128 return new RuntimeException ();
150129 }
151130
152- public static PException fromObject (Object pythonException , Node location , Throwable wrapped ) {
153- return fromObject (pythonException , location , location , wrapped );
154- }
155-
156131 /*
157132 * Note: we use this method to convert a Java StackOverflowError into a Python RecursionError.
158133 * At the time when this is done, some Java stack frames were already unwinded but there is no
159134 * guarantee on how many. Therefore, it is important that this method is simple. In particular,
160135 * do not add calls if that can be avoided.
161136 */
162- public static PException fromObject (Object pythonException , Node node , Node originalLocation , Throwable wrapped ) {
163- PException pException = new PException (pythonException , node , originalLocation , wrapped );
137+ public static PException fromObject (Object pythonException , Node node , Throwable wrapped ) {
138+ PException pException = new PException (pythonException , node , wrapped );
164139 if (pythonException instanceof PBaseException managedException ) {
165140 managedException .setException (pException );
166141 }
@@ -173,7 +148,7 @@ public static PException fromExceptionInfo(Object pythonException, boolean withJ
173148 // Create a carrier for the java stacktrace as PException cannot have one
174149 wrapped = createStacktraceCarrier ();
175150 }
176- PException pException = new PException (pythonException , null , null , wrapped );
151+ PException pException = new PException (pythonException , null , wrapped );
177152 pException .reified = true ;
178153 if (pythonException instanceof PBaseException managedException ) {
179154 managedException .setException (pException );
@@ -423,7 +398,7 @@ public void notifyAddedTracebackFrame(boolean visible) {
423398 */
424399 public PException getExceptionForReraise (boolean rootNodeVisible ) {
425400 ensureReified ();
426- PException pe = PException .fromObject (pythonException , null , getLocation (), false );
401+ PException pe = PException .fromObject (pythonException , getLocation (), false );
427402 if (rootNodeVisible ) {
428403 pe .skipFirstTracebackFrame ();
429404 }
@@ -467,15 +442,15 @@ RuntimeException throwException(@Exclusive @Cached GilNode gil) {
467442 @ ExportMessage
468443 @ SuppressWarnings ("static-method" )
469444 boolean hasSourceLocation () {
470- return originalLocation != null && originalLocation .getEncapsulatingSourceSection () != null ;
445+ return getLocation () != null && getLocation () .getEncapsulatingSourceSection () != null ;
471446 }
472447
473448 @ ExportMessage (name = "getSourceLocation" )
474449 SourceSection getExceptionSourceLocation (
475450 @ Bind ("$node" ) Node inliningTarget ,
476451 @ Cached InlinedBranchProfile unsupportedProfile ) throws UnsupportedMessageException {
477452 if (hasSourceLocation ()) {
478- return originalLocation .getEncapsulatingSourceSection ();
453+ return getLocation () .getEncapsulatingSourceSection ();
479454 }
480455 unsupportedProfile .enter (inliningTarget );
481456 throw UnsupportedMessageException .create ();
0 commit comments