Skip to content

Commit 860f905

Browse files
committed
EqualSameEncodingNode is DSL inlinable node
1 parent 46b7d72 commit 860f905

File tree

6 files changed

+52
-47
lines changed

6 files changed

+52
-47
lines changed

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

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@
139139
import com.oracle.truffle.api.nodes.IndirectCallNode;
140140
import com.oracle.truffle.api.nodes.Node;
141141
import com.oracle.truffle.api.nodes.RootNode;
142-
import com.oracle.truffle.api.profiles.BranchProfile;
143-
import com.oracle.truffle.api.profiles.ConditionProfile;
144142
import com.oracle.truffle.api.source.SourceSection;
145143
import org.truffleruby.parser.RubySource;
146144

@@ -1960,14 +1958,16 @@ public abstract static class RBSprintfFormatNode extends CoreMethodArrayArgument
19601958
@Specialization(
19611959
guards = {
19621960
"libFormat.isRubyString(format)",
1963-
"equalNode.execute(libFormat, format, cachedFormat, cachedEncoding)" },
1961+
"equalNode.execute(node, libFormat, format, cachedFormat, cachedEncoding)" },
19641962
limit = "2")
1965-
protected Object typesCached(VirtualFrame frame, Object format,
1963+
1964+
protected static Object typesCached(VirtualFrame frame, Object format,
19661965
@Cached @Shared RubyStringLibrary libFormat,
19671966
@Cached("asTruffleStringUncached(format)") TruffleString cachedFormat,
19681967
@Cached("libFormat.getEncoding(format)") RubyEncoding cachedEncoding,
19691968
@Cached("compileArgTypes(cachedFormat, cachedEncoding, byteArrayNode)") RubyArray cachedTypes,
1970-
@Cached StringHelperNodes.EqualSameEncodingNode equalNode) {
1969+
@Cached StringHelperNodes.EqualSameEncodingNode equalNode,
1970+
@Bind("this") Node node) {
19711971
return cachedTypes;
19721972
}
19731973

@@ -1993,41 +1993,43 @@ protected RubyArray compileArgTypes(AbstractTruffleString format, RubyEncoding e
19931993
@ReportPolymorphism
19941994
public abstract static class RBSprintfNode extends CoreMethodArrayArgumentsNode {
19951995

1996-
@Child private TruffleString.FromByteArrayNode fromByteArrayNode;
1997-
1998-
private final BranchProfile exceptionProfile = BranchProfile.create();
1999-
private final ConditionProfile resizeProfile = ConditionProfile.create();
2000-
20011996
@Specialization(
20021997
guards = {
20031998
"libFormat.isRubyString(format)",
2004-
"equalNode.execute(libFormat, format, cachedFormat, cachedEncoding)" },
1999+
"equalNode.execute(node, libFormat, format, cachedFormat, cachedEncoding)" },
20052000
limit = "2")
2006-
protected RubyString formatCached(Object format, Object stringReader, RubyArray argArray,
2001+
protected static RubyString formatCached(Object format, Object stringReader, RubyArray argArray,
20072002
@Cached @Shared ArrayToObjectArrayNode arrayToObjectArrayNode,
20082003
@Cached @Shared RubyStringLibrary libFormat,
2004+
@Cached @Shared InlinedBranchProfile exceptionProfile,
2005+
@Cached @Shared InlinedConditionProfile resizeProfile,
2006+
@Cached @Shared TruffleString.FromByteArrayNode fromByteArrayNode,
20092007
@Cached("asTruffleStringUncached(format)") TruffleString cachedFormat,
20102008
@Cached("libFormat.getEncoding(format)") RubyEncoding cachedEncoding,
20112009
@Cached("cachedFormat.byteLength(cachedEncoding.tencoding)") int cachedFormatLength,
20122010
@Cached("create(compileFormat(cachedFormat, cachedEncoding, stringReader))") DirectCallNode formatNode,
2013-
@Cached StringHelperNodes.EqualSameEncodingNode equalNode) {
2011+
@Cached StringHelperNodes.EqualSameEncodingNode equalNode,
2012+
@Bind("this") Node node) {
20142013
final BytesResult result;
20152014
final Object[] arguments = arrayToObjectArrayNode.executeToObjectArray(argArray);
20162015
try {
20172016
result = (BytesResult) formatNode.call(new Object[]{ arguments, arguments.length, null });
20182017
} catch (FormatException e) {
2019-
exceptionProfile.enter();
2020-
throw FormatExceptionTranslator.translate(getContext(), this, e);
2018+
exceptionProfile.enter(node);
2019+
throw FormatExceptionTranslator.translate(getContext(node), node, e);
20212020
}
20222021

2023-
return finishFormat(cachedFormatLength, result);
2022+
return finishFormat(node, cachedFormatLength, result, resizeProfile, fromByteArrayNode);
20242023
}
20252024

20262025
@Specialization(
20272026
guards = "libFormat.isRubyString(format)",
20282027
replaces = "formatCached", limit = "1")
20292028
protected RubyString formatUncached(Object format, Object stringReader, RubyArray argArray,
20302029
@Cached IndirectCallNode formatNode,
2030+
@Cached @Shared InlinedBranchProfile exceptionProfile,
2031+
@Cached @Shared InlinedConditionProfile resizeProfile,
2032+
@Cached @Shared TruffleString.FromByteArrayNode fromByteArrayNode,
20312033
@Cached @Shared ArrayToObjectArrayNode arrayToObjectArrayNode,
20322034
@Cached @Shared RubyStringLibrary libFormat) {
20332035
var tstring = libFormat.getTString(format);
@@ -2038,26 +2040,23 @@ protected RubyString formatUncached(Object format, Object stringReader, RubyArra
20382040
result = (BytesResult) formatNode.call(compileFormat(tstring, encoding, stringReader),
20392041
new Object[]{ arguments, arguments.length, null });
20402042
} catch (FormatException e) {
2041-
exceptionProfile.enter();
2043+
exceptionProfile.enter(this);
20422044
throw FormatExceptionTranslator.translate(getContext(), this, e);
20432045
}
20442046

2045-
return finishFormat(tstring.byteLength(encoding.tencoding), result);
2047+
return finishFormat(this, tstring.byteLength(encoding.tencoding), result, resizeProfile, fromByteArrayNode);
20462048
}
20472049

2048-
private RubyString finishFormat(int formatLength, BytesResult result) {
2050+
private static RubyString finishFormat(Node node, int formatLength, BytesResult result,
2051+
InlinedConditionProfile resizeProfile, TruffleString.FromByteArrayNode fromByteArrayNode) {
20492052
byte[] bytes = result.getOutput();
20502053

2051-
if (resizeProfile.profile(bytes.length != result.getOutputLength())) {
2054+
if (resizeProfile.profile(node, bytes.length != result.getOutputLength())) {
20522055
bytes = Arrays.copyOf(bytes, result.getOutputLength());
20532056
}
20542057

2055-
if (fromByteArrayNode == null) {
2056-
CompilerDirectives.transferToInterpreterAndInvalidate();
2057-
fromByteArrayNode = insert(TruffleString.FromByteArrayNode.create());
2058-
}
2059-
2060-
return createString(fromByteArrayNode, bytes, result.getEncoding().getEncodingForLength(formatLength));
2058+
return createString(node, fromByteArrayNode, bytes,
2059+
result.getEncoding().getEncodingForLength(formatLength));
20612060
}
20622061

20632062
@TruffleBoundary

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ protected static RubySymbol javaStringUncached(Node node, String str) {
6161
}
6262

6363
@Specialization(
64-
guards = { "strings.isRubyString(str)", "equalNode.execute(strings, str, cachedTString, cachedEncoding)" },
64+
guards = {
65+
"strings.isRubyString(str)",
66+
"equalNode.execute(node, strings, str, cachedTString, cachedEncoding)" },
6567
limit = "getCacheLimit()")
6668
protected static RubySymbol rubyString(Node node, Object str,
6769
@Cached @Shared RubyStringLibrary strings,

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ public abstract static class EvalInternalNode extends RubyBaseNode {
727727
guards = {
728728
"libSource.isRubyString(source)",
729729
"libFile.isRubyString(file)",
730-
"codeEqualNode.execute(libSource, source, cachedSource, cachedSourceEnc)",
730+
"codeEqualNode.execute(node, libSource, source, cachedSource, cachedSourceEnc)",
731731
"fileEqualNode.execute(libFile, file, cachedFile, cachedFileEnc)",
732732
"line == cachedLine",
733733
"bindingDescriptor == getBindingDescriptor(binding)" },
@@ -1652,10 +1652,10 @@ public abstract static class SprintfNode extends CoreMethodNode {
16521652
@Specialization(
16531653
guards = {
16541654
"libFormat.isRubyString(formatAsString)",
1655-
"equalNode.execute(libFormat, formatAsString, cachedTString, cachedEncoding)",
1655+
"equalNode.execute(node, libFormat, formatAsString, cachedTString, cachedEncoding)",
16561656
"isDebug == cachedIsDebug" },
16571657
limit = "3")
1658-
protected RubyString formatCached(VirtualFrame frame, Object format, Object[] arguments,
1658+
protected static RubyString formatCached(VirtualFrame frame, Object format, Object[] arguments,
16591659
@Cached @Shared ToStrNode toStrNode,
16601660
@Cached @Shared BooleanCastNode booleanCastNode,
16611661
@Bind("isDebug(frame, booleanCastNode)") boolean isDebug,
@@ -1669,17 +1669,18 @@ protected RubyString formatCached(VirtualFrame frame, Object format, Object[] ar
16691669
@Cached StringHelperNodes.EqualSameEncodingNode equalNode,
16701670
@Cached @Shared InlinedBranchProfile exceptionProfile,
16711671
@Cached @Shared InlinedConditionProfile resizeProfile,
1672-
@Cached @Shared TruffleString.FromByteArrayNode fromByteArrayNode) {
1672+
@Cached @Shared TruffleString.FromByteArrayNode fromByteArrayNode,
1673+
@Bind("this") Node node) {
16731674
final BytesResult result;
16741675
try {
16751676
result = (BytesResult) callPackNode.call(
16761677
new Object[]{ arguments, arguments.length, null });
16771678
} catch (FormatException e) {
1678-
exceptionProfile.enter(this);
1679-
throw FormatExceptionTranslator.translate(getContext(), this, e);
1679+
exceptionProfile.enter(node);
1680+
throw FormatExceptionTranslator.translate(getContext(node), node, e);
16801681
}
16811682

1682-
return finishFormat(cachedFormatLength, result, resizeProfile, fromByteArrayNode);
1683+
return finishFormat(node, cachedFormatLength, result, resizeProfile, fromByteArrayNode);
16831684
}
16841685

16851686
@Specialization(
@@ -1707,18 +1708,18 @@ protected RubyString formatUncached(VirtualFrame frame, Object format, Object[]
17071708
throw FormatExceptionTranslator.translate(getContext(), this, e);
17081709
}
17091710

1710-
return finishFormat(tstring.byteLength(encoding.tencoding), result, resizeProfile, fromByteArrayNode);
1711+
return finishFormat(this, tstring.byteLength(encoding.tencoding), result, resizeProfile, fromByteArrayNode);
17111712
}
17121713

1713-
private RubyString finishFormat(int formatLength, BytesResult result,
1714+
private static RubyString finishFormat(Node node, int formatLength, BytesResult result,
17141715
InlinedConditionProfile resizeProfile, TruffleString.FromByteArrayNode fromByteArrayNode) {
17151716
byte[] bytes = result.getOutput();
17161717

1717-
if (resizeProfile.profile(this, bytes.length != result.getOutputLength())) {
1718+
if (resizeProfile.profile(node, bytes.length != result.getOutputLength())) {
17181719
bytes = Arrays.copyOf(bytes, result.getOutputLength());
17191720
}
17201721

1721-
return createString(this, fromByteArrayNode, bytes,
1722+
return createString(node, fromByteArrayNode, bytes,
17221723
result.getEncoding().getEncodingForLength(formatLength));
17231724
}
17241725

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,28 @@ protected boolean equal(AbstractTruffleString a, RubyEncoding encA, TruffleStrin
113113
}
114114

115115
@GenerateUncached
116+
@GenerateCached(false)
117+
@GenerateInline
116118
public abstract static class EqualSameEncodingNode extends RubyBaseNode {
117119

118-
public final boolean execute(RubyStringLibrary libString, Object rubyString,
120+
public final boolean execute(Node node, RubyStringLibrary libString, Object rubyString,
119121
TruffleString cachedString, RubyEncoding cachedEncoding) {
120-
return execute(libString.getTString(rubyString), libString.getEncoding(rubyString),
122+
return execute(node, libString.getTString(rubyString), libString.getEncoding(rubyString),
121123
cachedString, cachedEncoding);
122124
}
123125

124126
// cachedString is TruffleString to ensure correctness, caching on a MutableTruffleString is incorrect
125-
public abstract boolean execute(AbstractTruffleString tstring, RubyEncoding encoding,
127+
public abstract boolean execute(Node node, AbstractTruffleString tstring, RubyEncoding encoding,
126128
TruffleString cachedString, RubyEncoding cachedEncoding);
127129

128130
@Specialization(guards = "encA == encB")
129-
protected boolean same(AbstractTruffleString a, RubyEncoding encA, TruffleString b, RubyEncoding encB,
131+
protected static boolean same(AbstractTruffleString a, RubyEncoding encA, TruffleString b, RubyEncoding encB,
130132
@Cached StringEqualInternalNode stringEqualInternalNode) {
131133
return stringEqualInternalNode.executeInternal(a, b, encA);
132134
}
133135

134136
@Specialization(guards = "encA != encB")
135-
protected boolean diff(AbstractTruffleString a, RubyEncoding encA, TruffleString b, RubyEncoding encB) {
137+
protected static boolean diff(AbstractTruffleString a, RubyEncoding encA, TruffleString b, RubyEncoding encB) {
136138
return false;
137139
}
138140
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,18 +2557,19 @@ public abstract static class ToSymNode extends PrimitiveArrayArgumentsNode {
25572557
@Specialization(
25582558
guards = {
25592559
"!isBrokenCodeRange(tstring, encoding, codeRangeNode)",
2560-
"equalNode.execute(tstring, encoding, cachedTString, cachedEncoding)",
2560+
"equalNode.execute(node, tstring, encoding, cachedTString, cachedEncoding)",
25612561
"preserveSymbol == cachedPreserveSymbol" },
25622562
limit = "getDefaultCacheLimit()")
2563-
protected RubySymbol toSymCached(Object string, boolean preserveSymbol,
2563+
protected static RubySymbol toSymCached(Object string, boolean preserveSymbol,
25642564
@Cached @Shared RubyStringLibrary strings,
25652565
@Cached("asTruffleStringUncached(string)") TruffleString cachedTString,
25662566
@Cached("strings.getEncoding(string)") RubyEncoding cachedEncoding,
25672567
@Cached("preserveSymbol") boolean cachedPreserveSymbol,
25682568
@Cached("getSymbol(cachedTString, cachedEncoding, cachedPreserveSymbol)") RubySymbol cachedSymbol,
25692569
@Cached StringHelperNodes.EqualSameEncodingNode equalNode,
25702570
@Bind("strings.getTString(string)") AbstractTruffleString tstring,
2571-
@Bind("strings.getEncoding(string)") RubyEncoding encoding) {
2571+
@Bind("strings.getEncoding(string)") RubyEncoding encoding,
2572+
@Bind("this") Node node) {
25722573
return cachedSymbol;
25732574
}
25742575

src/main/java/org/truffleruby/core/time/TimeNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ protected Object timeSetZone(RubyTime time, Object zone,
420420
public abstract static class TimeStrftimePrimitiveNode extends PrimitiveArrayArgumentsNode {
421421

422422
@Specialization(
423-
guards = "equalNode.execute(libFormat, format, cachedFormat, cachedEncoding)",
423+
guards = "equalNode.execute(node, libFormat, format, cachedFormat, cachedEncoding)",
424424
limit = "getLanguage().options.TIME_FORMAT_CACHE")
425425
protected static RubyString timeStrftimeCached(RubyTime time, Object format,
426426
@Cached @Shared RubyStringLibrary libFormat,

0 commit comments

Comments
 (0)