Skip to content

Commit 9531bae

Browse files
committed
Remove unnecessary usages of RubyContextSourceNode
1 parent e356d67 commit 9531bae

File tree

10 files changed

+27
-26
lines changed

10 files changed

+27
-26
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public RubyException argumentError(Rope message, RubyEncoding encoding, Node cur
266266
return ExceptionOperations.createRubyException(
267267
context,
268268
exceptionClass,
269-
StringOperations.createString(context, language, message, encoding),
269+
StringOperations.createString(currentNode, message, encoding),
270270
currentNode,
271271
javaThrowable);
272272
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public InterpolatedStringNode(ToSNode[] children, Encoding encoding, boolean fro
4545
public Object execute(VirtualFrame frame) {
4646

4747
// Start with an empty string to ensure the result has class String and the proper encoding.
48-
RubyString builder = StringOperations.createString(getContext(), getLanguage(), emptyRope, encoding);
48+
RubyString builder = StringOperations.createString(this, emptyRope, encoding);
4949

5050
// TODO (nirvdrum 11-Jan-16) Rewrite to avoid massively unbalanced trees.
5151
for (ToSNode child : children) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ protected Object concatMany(RubyString string, Object first, Object[] rest,
596596
Object result = argConcatNode.executeConcat(string, first, EMPTY_ARGUMENTS);
597597
for (int i = 0; i < cachedLength; ++i) {
598598
final Object argOrCopy = selfArgProfile.profile(rest[i] == string)
599-
? createString(getContext(), getLanguage(), rope, string.encoding)
599+
? createString(this, rope, string.encoding)
600600
: rest[i];
601601
result = argConcatNode.executeConcat(string, argOrCopy, EMPTY_ARGUMENTS);
602602
}
@@ -612,7 +612,7 @@ protected Object concatManyGeneral(RubyString string, Object first, Object[] res
612612
Object result = argConcatNode.executeConcat(string, first, EMPTY_ARGUMENTS);
613613
for (Object arg : rest) {
614614
if (selfArgProfile.profile(arg == string)) {
615-
Object copy = createString(getContext(), getLanguage(), rope, string.encoding);
615+
Object copy = createString(this, rope, string.encoding);
616616
result = argConcatNode.executeConcat(string, copy, EMPTY_ARGUMENTS);
617617
} else {
618618
result = argConcatNode.executeConcat(string, arg, EMPTY_ARGUMENTS);

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.nio.CharBuffer;
2929
import java.nio.charset.Charset;
3030

31+
import com.oracle.truffle.api.nodes.Node;
3132
import org.jcodings.Encoding;
3233
import org.jcodings.specific.ASCIIEncoding;
3334
import org.truffleruby.RubyContext;
@@ -41,33 +42,32 @@
4142
import org.truffleruby.core.rope.RopeOperations;
4243

4344
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
44-
import org.truffleruby.language.RubyContextSourceNode;
4545
import org.truffleruby.language.objects.AllocationTracing;
4646

4747
public abstract class StringOperations {
4848

49-
public static RubyString createString(RubyContextSourceNode node, Rope rope, RubyEncoding encoding) {
49+
public static RubyString createUTF8String(RubyContext context, RubyLanguage language, Rope rope) {
5050
final RubyString instance = new RubyString(
51-
node.getContext().getCoreLibrary().stringClass,
52-
node.getLanguage().stringShape,
51+
context.getCoreLibrary().stringClass,
52+
language.stringShape,
5353
false,
5454
rope,
55-
encoding);
56-
AllocationTracing.trace(instance, node);
55+
Encodings.UTF_8);
5756
return instance;
5857
}
5958

60-
public static RubyString createUTF8String(RubyContext context, RubyLanguage language, Rope rope) {
59+
public static RubyString createString(Node node, Rope rope, RubyEncoding encoding) {
6160
final RubyString instance = new RubyString(
62-
context.getCoreLibrary().stringClass,
63-
language.stringShape,
61+
RubyContext.get(node).getCoreLibrary().stringClass,
62+
RubyLanguage.get(node).stringShape,
6463
false,
6564
rope,
66-
Encodings.UTF_8);
65+
encoding);
66+
AllocationTracing.trace(instance, node);
6767
return instance;
6868
}
6969

70-
// TODO BJF Aug-3-2020 Trace more allocations of RubyString
70+
/** Only use when there is no Node to report the allocation */
7171
public static RubyString createString(RubyContext context, RubyLanguage language, Rope rope,
7272
RubyEncoding encoding) {
7373
final RubyString instance = new RubyString(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import com.oracle.truffle.api.frame.VirtualFrame;
1616

17-
/** Has both context and source methods. */
17+
/** See {@link RubyNode} */
1818
public abstract class RubyContextSourceNode extends RubyNode {
1919

2020
private int sourceCharIndex = NO_SOURCE;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public Object execute(VirtualFrame frame) {
4444
.send(
4545
interactiveBinding,
4646
"eval",
47-
StringOperations.createString(context, language, sourceRope, Encodings.UTF_8));
47+
StringOperations.createString(this, sourceRope, Encodings.UTF_8));
4848
}
4949

5050
@Override

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939

4040
import static org.truffleruby.debug.RubyScope.RECEIVER_MEMBER;
4141

42-
/** RubyNode has source, execute, and is instrument-able. However, it does not have any fields which would prevent
43-
* using @GenerateUncached. It should never be subclassed directly, either use {@link RubyContextSourceNode} or
44-
* {@link RubySourceNode}. SourceRubyNode is not defined since there was no use for it for now. */
42+
/** RubyNode has source, execute, and is instrument-able. If there is no need for source and instrument-able,
43+
* {@link RubyBaseNode} or {@link RubyBaseNodeWithExecute} should be used instead to save footprint. RubyNode does not
44+
* have any fields which would prevent using @GenerateUncached. It should never be subclassed directly, either use
45+
* {@link RubyContextSourceNode} (cannot be uncached, but avoids the DSL generating 6 field accessors for each subclass)
46+
* or {@link RubySourceNode} (can be uncached). SourceRubyNode is not defined since there was no use for it for now. */
4547
@GenerateWrapper
4648
@ExportLibrary(NodeLibrary.class)
4749
public abstract class RubyNode extends RubyBaseNodeWithExecute implements InstrumentableNode {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import com.oracle.truffle.api.frame.VirtualFrame;
1616
import org.truffleruby.RubyLanguage;
1717

18-
/** Can be used as a parent of Ruby nodes which need @GenerateUncached. */
18+
/** Can be used as a parent of Ruby nodes which need source and @GenerateUncached. */
1919
@NodeField(name = "sourceCharIndex", type = int.class)
2020
@NodeField(name = "sourceLength", type = int.class)
2121
@NodeField(name = "flags", type = byte.class)

src/main/java/org/truffleruby/language/objects/AllocationTracing.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.truffleruby.core.string.RubyString;
2222
import org.truffleruby.core.string.StringOperations;
2323
import org.truffleruby.language.LexicalScope;
24-
import org.truffleruby.language.RubyContextSourceNode;
2524
import org.truffleruby.language.RubyDynamicObject;
2625
import org.truffleruby.language.arguments.RubyArguments;
2726

@@ -88,7 +87,7 @@ private static void traceBoundary(RubyContext context, RubyDynamicObject object,
8887

8988
@TruffleBoundary
9089
private static void traceInlineBoundary(RubyContext context, RubyDynamicObject instance, String className,
91-
String allocatingMethod, RubyContextSourceNode node) {
90+
String allocatingMethod, Node node) {
9291
final ObjectSpaceManager objectSpaceManager = context.getObjectSpaceManager();
9392
if (!objectSpaceManager.isTracingPaused()) {
9493
objectSpaceManager.setTracingPaused(true);
@@ -125,7 +124,7 @@ private static void callTraceAllocation(RubyContext context, RubyDynamicObject o
125124

126125
@TruffleBoundary
127126
private static void callTraceInlineAllocation(RubyContext context, RubyDynamicObject instance, String className,
128-
String allocatingMethod, RubyContextSourceNode node) {
127+
String allocatingMethod, Node node) {
129128
final SourceSection allocatingSourceSection = context
130129
.getCallStack()
131130
.getTopMostUserSourceSection(node.getEncapsulatingSourceSection());

src/main/java/org/truffleruby/stdlib/digest/DigestNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.truffleruby.core.rope.Rope;
2323
import org.truffleruby.core.string.RubyString;
2424
import org.truffleruby.core.string.StringNodes;
25-
import org.truffleruby.language.RubyContextSourceNode;
25+
import org.truffleruby.language.RubyBaseNode;
2626
import org.truffleruby.language.library.RubyStringLibrary;
2727
import org.truffleruby.language.objects.AllocationTracing;
2828

@@ -41,7 +41,7 @@ private static MessageDigest getMessageDigestInstance(String name) {
4141
}
4242
}
4343

44-
private static RubyDigest createDigest(RubyContextSourceNode node, DigestAlgorithm algorithm) {
44+
private static RubyDigest createDigest(RubyBaseNode node, DigestAlgorithm algorithm) {
4545
final RubyDigest instance = new RubyDigest(
4646
node.getContext().getCoreLibrary().digestClass,
4747
node.getLanguage().digestShape,

0 commit comments

Comments
 (0)