Skip to content

Commit 3a0b82f

Browse files
committed
Properly type the RaiseException stored in Backtrace
* Use another API for the one case we don't use a RaiseException.
1 parent 4c6e975 commit 3a0b82f

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

src/main/java/org/truffleruby/core/VMPrimitiveNodes.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,21 +218,21 @@ public static abstract class VMRaiseExceptionNode extends PrimitiveArrayArgument
218218
public DynamicObject vmRaiseException(DynamicObject exception, boolean internal,
219219
@Cached("createBinaryProfile()") ConditionProfile reRaiseProfile) {
220220
final Backtrace backtrace = Layouts.EXCEPTION.getBacktrace(exception);
221-
if (reRaiseProfile.profile(backtrace != null && backtrace.getTruffleException() != null)) {
222-
// We need to rethrow the existing TruffleException, otherwise we would lose the
221+
if (reRaiseProfile.profile(backtrace != null && backtrace.getRaiseException() != null)) {
222+
// We need to rethrow the existing RaiseException, otherwise we would lose the
223223
// TruffleStackTrace stored in it.
224-
throw (RaiseException) backtrace.getTruffleException();
224+
throw backtrace.getRaiseException();
225225
} else {
226226
throw new RaiseException(getContext(), exception, internal);
227227
}
228228
}
229229

230230
public static void reRaiseException(RubyContext context, DynamicObject exception) {
231231
final Backtrace backtrace = Layouts.EXCEPTION.getBacktrace(exception);
232-
if (backtrace != null && backtrace.getTruffleException() != null) {
233-
// We need to rethrow the existing TruffleException, otherwise we would lose the
232+
if (backtrace != null && backtrace.getRaiseException() != null) {
233+
// We need to rethrow the existing RaiseException, otherwise we would lose the
234234
// TruffleStackTrace stored in it.
235-
throw (RaiseException) backtrace.getTruffleException();
235+
throw backtrace.getRaiseException();
236236
} else {
237237
throw new RaiseException(context, exception, false);
238238
}

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,7 @@ private DynamicObject innerCallerLocations(int omit, int length) {
310310
final Backtrace backtrace = getContext().getCallStack().getBacktrace(this, omitted);
311311
final int limit = (length == GetBacktraceException.UNLIMITED) ? GetBacktraceException.UNLIMITED : omitted + length;
312312

313-
backtrace.setTruffleException(new GetBacktraceException(this, limit));
314-
315-
int locationsCount = backtrace.getActivations().length;
313+
int locationsCount = backtrace.getActivations(new GetBacktraceException(this, limit)).length;
316314

317315
if (length != GetBacktraceException.UNLIMITED && length < locationsCount) {
318316
locationsCount = length;

src/main/java/org/truffleruby/core/thread/ThreadManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ private static void setException(RubyContext context, DynamicObject thread, Dyna
280280

281281
// We materialize the backtrace eagerly here, as the exception escapes the thread and needs
282282
// to capture the backtrace from this thread.
283-
final TruffleException truffleException = Layouts.EXCEPTION.getBacktrace(exception).getTruffleException();
283+
final TruffleException truffleException = Layouts.EXCEPTION.getBacktrace(exception).getRaiseException();
284284
if (truffleException != null) {
285285
TruffleStackTraceElement.fillIn((Throwable) truffleException);
286286
}

src/main/java/org/truffleruby/language/backtrace/Backtrace.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.truffleruby.core.exception.GetBacktraceException;
2222
import org.truffleruby.language.CallStackManager;
2323
import org.truffleruby.language.arguments.RubyArguments;
24+
import org.truffleruby.language.control.RaiseException;
2425
import org.truffleruby.language.methods.InternalMethod;
2526

2627
import java.util.ArrayList;
@@ -30,7 +31,7 @@ public class Backtrace {
3031

3132
private final Node location;
3233
private SourceSection sourceLocation;
33-
private TruffleException truffleException;
34+
private RaiseException raiseException;
3435
private Activation[] activations;
3536
private final int omitted;
3637
private final Throwable javaThrowable;
@@ -51,22 +52,23 @@ public SourceSection getSourceLocation() {
5152
return sourceLocation;
5253
}
5354

54-
public TruffleException getTruffleException() {
55-
return truffleException;
55+
public RaiseException getRaiseException() {
56+
return raiseException;
5657
}
5758

58-
public void setTruffleException(TruffleException truffleException) {
59-
assert this.truffleException == null : "the TruffleException of a Backtrace must not be set again, otherwise the original backtrace is lost";
60-
this.truffleException = truffleException;
59+
public void setRaiseException(RaiseException raiseException) {
60+
assert this.raiseException == null : "the RaiseException of a Backtrace must not be set again, otherwise the original backtrace is lost";
61+
this.raiseException = raiseException;
6162
}
6263

63-
@TruffleBoundary
6464
public Activation[] getActivations() {
65+
return getActivations(this.raiseException);
66+
}
67+
68+
@TruffleBoundary
69+
public Activation[] getActivations(TruffleException truffleException) {
6570
if (this.activations == null) {
66-
final TruffleException truffleException;
67-
if (this.truffleException != null) {
68-
truffleException = this.truffleException;
69-
} else {
71+
if (truffleException == null) {
7072
truffleException = new GetBacktraceException(location, GetBacktraceException.UNLIMITED);
7173
}
7274

src/main/java/org/truffleruby/language/control/RaiseException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public RaiseException(RubyContext context, DynamicObject exception, boolean inte
4242

4343
final Backtrace backtrace = Layouts.EXCEPTION.getBacktrace(exception);
4444
if (backtrace != null) { // The backtrace could be null if for example a user backtrace was passed to Kernel#raise
45-
backtrace.setTruffleException(this);
45+
backtrace.setRaiseException(this);
4646
}
4747

4848
assert !isSyntaxError() || getSourceLocation() != null;

0 commit comments

Comments
 (0)