Skip to content

Commit 6d5da24

Browse files
committed
No need to store the sourceLocation in Backtrace anymore
1 parent 855dca9 commit 6d5da24

File tree

3 files changed

+9
-39
lines changed

3 files changed

+9
-39
lines changed

src/main/java/org/truffleruby/core/exception/ExceptionOperations.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2222
import com.oracle.truffle.api.nodes.Node;
2323
import com.oracle.truffle.api.object.Shape;
24-
import com.oracle.truffle.api.source.SourceSection;
2524
import org.truffleruby.language.library.RubyStringLibrary;
2625

2726
public abstract class ExceptionOperations {
@@ -68,12 +67,7 @@ public static String messageToString(RubyContext context, RubyException exceptio
6867

6968
public static RubyException createRubyException(RubyContext context, RubyClass rubyClass, Object message,
7069
Node node, Throwable javaException) {
71-
return createRubyException(context, rubyClass, message, node, null, javaException);
72-
}
73-
74-
public static RubyException createRubyException(RubyContext context, RubyClass rubyClass, Object message,
75-
Node node, SourceSection sourceLocation, Throwable javaException) {
76-
final Backtrace backtrace = context.getCallStack().getBacktrace(node, sourceLocation, javaException);
70+
final Backtrace backtrace = context.getCallStack().getBacktrace(node, 0, javaException);
7771
return createRubyException(context, rubyClass, message, backtrace);
7872
}
7973

src/main/java/org/truffleruby/language/CallStackManager.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,21 @@ private static InternalMethod getMethod(Frame frame) {
189189
// Backtraces
190190

191191
public Backtrace getBacktrace(Node currentNode) {
192-
return getBacktrace(currentNode, null, 0, null);
192+
return getBacktrace(currentNode, 0, null);
193193
}
194194

195195
public Backtrace getBacktrace(Node currentNode, int omit) {
196-
return getBacktrace(currentNode, null, omit, null);
196+
return getBacktrace(currentNode, omit, null);
197197
}
198198

199-
public Backtrace getBacktrace(Node currentNode, SourceSection sourceLocation, Throwable javaThrowable) {
200-
return getBacktrace(currentNode, sourceLocation, 0, javaThrowable);
201-
}
202-
203-
public Backtrace getBacktrace(Node currentNode, SourceSection sourceLocation, int omit, Throwable javaThrowable) {
199+
public Backtrace getBacktrace(Node currentNode, int omit, Throwable javaThrowable) {
204200
if (context.getOptions().EXCEPTIONS_STORE_JAVA || context.getOptions().BACKTRACES_INTERLEAVE_JAVA) {
205201
if (javaThrowable == null) {
206202
javaThrowable = newException();
207203
}
208204
}
209205

210-
return new Backtrace(currentNode, sourceLocation, omit, javaThrowable);
206+
return new Backtrace(currentNode, omit, javaThrowable);
211207
}
212208

213209
@SuppressFBWarnings("ES")

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

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
import java.util.ArrayList;
1313
import java.util.List;
1414

15-
import com.oracle.truffle.api.CompilerDirectives;
1615
import com.oracle.truffle.api.exception.AbstractTruffleException;
17-
import com.oracle.truffle.api.interop.InteropLibrary;
18-
import com.oracle.truffle.api.interop.UnsupportedMessageException;
1916
import org.truffleruby.RubyContext;
2017
import org.truffleruby.RubyLanguage;
2118
import org.truffleruby.core.array.ArrayHelpers;
@@ -32,7 +29,6 @@
3229
import com.oracle.truffle.api.TruffleStackTraceElement;
3330
import com.oracle.truffle.api.nodes.Node;
3431
import com.oracle.truffle.api.nodes.RootNode;
35-
import com.oracle.truffle.api.source.SourceSection;
3632
import org.truffleruby.language.objects.AllocationTracing;
3733

3834
/** Represents a backtrace: a list of activations (~ call sites).
@@ -75,7 +71,6 @@ public class Backtrace {
7571
// See accessors for info on most undocumented fields.
7672

7773
private final Node location;
78-
private final SourceSection sourceLocation;
7974
private final int omitted;
8075
private RaiseException raiseException;
8176
private final Throwable javaThrowable;
@@ -86,25 +81,17 @@ public class Backtrace {
8681
// region Constructors
8782

8883
/** Fully explicit constructor. */
89-
public Backtrace(Node location, SourceSection sourceLocation, int omitted, Throwable javaThrowable) {
84+
public Backtrace(Node location, int omitted, Throwable javaThrowable) {
9085
this.location = location;
91-
this.sourceLocation = sourceLocation;
9286
this.omitted = omitted;
9387
this.javaThrowable = javaThrowable;
9488
}
9589

96-
/** Creates a backtrace for the given foreign exception, setting the {@link #getLocation() location} and
97-
* {@link #getSourceLocation() source location} accordingly, and computing the activations eagerly (since the
98-
* exception itself is not retained). */
90+
/** Creates a backtrace for the given foreign exception, setting the {@link #getLocation() location} accordingly,
91+
* and computing the activations eagerly (since the exception itself is not retained). */
9992
public Backtrace(AbstractTruffleException exception) {
10093
assert !(exception instanceof RaiseException);
10194
this.location = exception.getLocation();
102-
try {
103-
final InteropLibrary interop = InteropLibrary.getUncached();
104-
this.sourceLocation = interop.hasSourceLocation(exception) ? interop.getSourceLocation(exception) : null;
105-
} catch (UnsupportedMessageException e) {
106-
throw CompilerDirectives.shouldNotReachHere(e);
107-
}
10895
this.omitted = 0;
10996
this.javaThrowable = null;
11097
this.stackTrace = getStackTrace(exception);
@@ -114,7 +101,6 @@ public Backtrace(AbstractTruffleException exception) {
114101
* retrieved. The activations are computed eagerly, since the exception itself is not retained. */
115102
public Backtrace(Throwable exception) {
116103
this.location = null;
117-
this.sourceLocation = null;
118104
this.omitted = 0;
119105
this.javaThrowable = null;
120106
this.stackTrace = getStackTrace(exception);
@@ -128,12 +114,6 @@ public Node getLocation() {
128114
return location;
129115
}
130116

131-
/** Only set for {@code SyntaxError}, where it represents where the error occurred (while {@link #getLocation()}
132-
* does not). */
133-
public SourceSection getSourceLocation() {
134-
return sourceLocation;
135-
}
136-
137117
/** Returns the wrapper for the Ruby exception associated with this backtrace, if any, and null otherwise. */
138118
public RaiseException getRaiseException() {
139119
return raiseException;
@@ -192,7 +172,7 @@ private static String getRootName(RootNode root) {
192172
/** Used to copy the backtrace when copying {@code exception}. */
193173
@TruffleBoundary
194174
public Backtrace copy(RubyContext context, RubyException exception) {
195-
Backtrace copy = new Backtrace(location, sourceLocation, omitted, javaThrowable);
175+
Backtrace copy = new Backtrace(location, omitted, javaThrowable);
196176
// A Backtrace is 1-1-1 with a RaiseException and a Ruby exception.
197177
// Copy the RaiseException
198178
RaiseException newRaiseException = new RaiseException(this.raiseException, exception);

0 commit comments

Comments
 (0)