Skip to content

Commit 7a90daa

Browse files
committed
Refactor getNode calls. For exceptions only called once in CallStackManager
1 parent a7f2a0f commit 7a90daa

File tree

11 files changed

+24
-22
lines changed

11 files changed

+24
-22
lines changed

src/main/java/org/truffleruby/cext/UnwrapNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ protected static ValueWrapper genericToWrapper(Node node, Object value,
183183
} catch (UnsupportedMessageException e) {
184184
unsupportedProfile.enter(node);
185185
throw new RaiseException(getContext(node),
186-
coreExceptions(node).argumentError(e.getMessage(), getNode(node), e));
186+
coreExceptions(node).argumentError(e.getMessage(), node, e));
187187
}
188188
return nativeToWrapperNode.execute(node, handle);
189189
}
@@ -281,7 +281,7 @@ protected static Object unwrapGeneric(Node node, Object value,
281281
} catch (UnsupportedMessageException e) {
282282
unsupportedProfile.enter(node);
283283
throw new RaiseException(getContext(node),
284-
coreExceptions(node).argumentError(e.getMessage(), getNode(node), e));
284+
coreExceptions(node).argumentError(e.getMessage(), node, e));
285285
}
286286
return unwrapNativeNode.execute(node, handle);
287287
}

src/main/java/org/truffleruby/cext/ValueWrapperManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ protected long allocateHandle(ValueWrapper wrapper, RubyContext context, RubyLan
336336
}
337337

338338
if (context.getOptions().BACKTRACE_ON_TO_NATIVE) {
339-
context.getDefaultBacktraceFormatter().printBacktraceOnEnvStderr("ValueWrapper#toNative: ", getNode());
339+
context.getDefaultBacktraceFormatter().printBacktraceOnEnvStderr("ValueWrapper#toNative: ", this);
340340
}
341341

342342
if (block == null || block.isFull()) {

src/main/java/org/truffleruby/core/cast/NameToJavaStringNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected static String nameToJavaString(Object object,
8484
if (e.getException().getLogicalClass() == coreLibrary(node).noMethodErrorClass) {
8585
throw new RaiseException(getContext(node), coreExceptions(node).typeError(
8686
Utils.concat(object, " is not a symbol nor a string"),
87-
getNode(node)));
87+
node));
8888
} else {
8989
throw e;
9090
}
@@ -99,7 +99,7 @@ protected static String nameToJavaString(Object object,
9999
"String",
100100
"to_str",
101101
coerced,
102-
getNode(node)));
102+
node));
103103
}
104104
}
105105

src/main/java/org/truffleruby/core/cast/ToSymbolNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected static RubySymbol toStr(Object object,
9090
"String",
9191
"to_str",
9292
coerced,
93-
getNode(node)));
93+
node));
9494
}
9595
}
9696

src/main/java/org/truffleruby/core/inlined/AlwaysInlinedMethodNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public abstract class AlwaysInlinedMethodNode extends RubyBaseNode {
4141
public abstract Object execute(Frame callerFrame, Object self, Object[] rubyArgs, RootCallTarget target);
4242

4343
protected void needCallerFrame(Frame callerFrame, RootCallTarget target) {
44-
needCallerFrame(getNode(), callerFrame, target);
44+
needCallerFrame(this, callerFrame, target);
4545
}
4646

4747
protected static void needCallerFrame(Node node, Frame callerFrame, RootCallTarget target) {
@@ -56,7 +56,7 @@ protected static void needCallerFrame(Node node, Frame callerFrame, RootCallTarg
5656
protected void needCallerFrame(Frame callerFrame, String method) {
5757
if (callerFrame == null) {
5858
CompilerDirectives.transferToInterpreterAndInvalidate();
59-
throw buildException(getNode(), method);
59+
throw buildException(this, method);
6060
}
6161

6262
assert CallStackManager.isRubyFrame(callerFrame);
@@ -71,7 +71,7 @@ private static RaiseException buildException(Node node, RootCallTarget target) {
7171
private static RaiseException buildException(Node node, String method) {
7272
return new RaiseException(getContext(node), coreExceptions(node).runtimeError(
7373
method + " needs the caller frame but it was not passed (cannot be called directly from a foreign language)",
74-
getNode(node)));
74+
node));
7575
}
7676

7777
public static boolean isBlockProvided(Object[] rubyArgs) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public abstract static class BindingNode extends AlwaysInlinedMethodNode {
363363
@Specialization
364364
protected RubyBinding binding(Frame callerFrame, Object self, Object[] rubyArgs, RootCallTarget target,
365365
@Cached(
366-
value = "getNode().getEncapsulatingSourceSection()",
366+
value = "getNode(this).getEncapsulatingSourceSection()",
367367
allowUncached = true, neverDefault = false) SourceSection sourceSection) {
368368
needCallerFrame(callerFrame, target);
369369
return BindingNodes.createBinding(getContext(), getLanguage(), callerFrame.materialize(), sourceSection);
@@ -700,7 +700,7 @@ protected Object eval(Frame callerFrame, Object callerSelf, Object[] rubyArgs, R
700700
errorProfile.enter(this);
701701
throw new RaiseException(
702702
getContext(),
703-
coreExceptions().typeErrorWrongArgumentType(bindingArg, "binding", getNode()));
703+
coreExceptions().typeErrorWrongArgumentType(bindingArg, "binding", this));
704704
}
705705
binding = (RubyBinding) bindingArg;
706706
self = RubyArguments.getSelf(binding.getFrame());

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ protected Object[] generateAccessors(Frame callerFrame, RubyModule module, Objec
481481
@TruffleBoundary
482482
private Object[] createAccessors(RubyModule module, Object[] names, Accessor accessor,
483483
Visibility visibility) {
484-
final Node currentNode = getNode();
484+
final Node currentNode = getNode(this);
485485
final SourceSection sourceSection;
486486
if (currentNode != null) {
487487
sourceSection = currentNode.getEncapsulatingSourceSection();
@@ -732,7 +732,7 @@ protected static Object evalWithString(
732732

733733
if (count == 0) {
734734
wrongNumberOfArgumentsProfile.enter(node);
735-
throw new RaiseException(getContext(node), coreExceptions(node).argumentError(0, 1, 2, getNode(node)));
735+
throw new RaiseException(getContext(node), coreExceptions(node).argumentError(0, 1, 2, node));
736736
}
737737

738738
sourceCode = toStrNode.execute(node, RubyArguments.getArgument(rubyArgs, 0));

src/main/java/org/truffleruby/core/string/StringNodes.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,8 +1410,7 @@ protected static RubyString forceEncodingString(RubyString string, Object newEnc
14101410
errorProfile.enter(node);
14111411
throw new RaiseException(
14121412
getContext(node),
1413-
coreExceptions(node).argumentError(Utils.concat("unknown encoding name - ", stringName),
1414-
getNode(node)));
1413+
coreExceptions(node).argumentError(Utils.concat("unknown encoding name - ", stringName), node));
14151414
}
14161415

14171416
return forceEncodingNode.execute(string, rubyEncoding);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ public Backtrace getBacktrace(Node currentNode, int omit, Throwable javaThrowabl
227227
}
228228
}
229229

230-
return new Backtrace(currentNode, omit, javaThrowable);
230+
var adoptableNode = RubyNode.getNode(currentNode);
231+
return new Backtrace(adoptableNode, omit, javaThrowable);
231232
}
232233

233234
@SuppressFBWarnings("ES")

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,7 @@ protected void reportLongLoopCount(long count) {
117117
LoopNode.reportLoopCount(this, count > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) count);
118118
// Checkstyle: resume
119119
}
120-
121-
protected Node getNode() {
122-
return getNode(this);
123-
}
124-
120+
125121
protected static Node getNode(Node node) {
126122
boolean adoptable = node != null && node.isAdoptable();
127123
CompilerAsserts.partialEvaluationConstant(adoptable);

0 commit comments

Comments
 (0)