Skip to content

Commit a5362be

Browse files
committed
NegotiateCompatibleEncodingNode supports DSL inlining
1 parent d43ae75 commit a5362be

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

src/main/java/org/truffleruby/core/encoding/EncodingNodes.java

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import com.oracle.truffle.api.dsl.GenerateInline;
1717
import com.oracle.truffle.api.dsl.Idempotent;
1818
import com.oracle.truffle.api.dsl.ImportStatic;
19-
import com.oracle.truffle.api.dsl.NeverDefault;
2019
import com.oracle.truffle.api.nodes.Node;
2120
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
2221
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
@@ -32,7 +31,6 @@
3231
import org.truffleruby.core.array.ArrayUtils;
3332
import org.truffleruby.core.array.RubyArray;
3433
import org.truffleruby.core.cast.ToRubyEncodingNode;
35-
import org.truffleruby.core.encoding.EncodingNodesFactory.NegotiateCompatibleEncodingNodeGen;
3634
import org.truffleruby.core.klass.RubyClass;
3735
import org.truffleruby.core.proc.RubyProc;
3836
import org.truffleruby.core.string.RubyString;
@@ -220,14 +218,11 @@ protected boolean isStandardEncoding(RubyEncoding encoding) {
220218

221219
// MRI: enc_compatible_latter
222220
/** Use {@link NegotiateCompatibleStringEncodingNode} instead if both arguments are always Strings, for footprint */
221+
@GenerateCached(false)
222+
@GenerateInline
223223
public abstract static class NegotiateCompatibleEncodingNode extends RubyBaseNode {
224224

225-
@NeverDefault
226-
public static NegotiateCompatibleEncodingNode create() {
227-
return NegotiateCompatibleEncodingNodeGen.create();
228-
}
229-
230-
public abstract RubyEncoding executeNegotiate(Object first, RubyEncoding firstEncoding, Object second,
225+
public abstract RubyEncoding execute(Node node, Object first, RubyEncoding firstEncoding, Object second,
231226
RubyEncoding secondEncoding);
232227

233228
@Specialization(
@@ -236,7 +231,7 @@ public abstract RubyEncoding executeNegotiate(Object first, RubyEncoding firstEn
236231
"secondEncoding == cachedEncoding",
237232
"cachedEncoding != null" },
238233
limit = "getCacheLimit()")
239-
protected RubyEncoding negotiateSameEncodingCached(
234+
protected static RubyEncoding negotiateSameEncodingCached(
240235
Object first, RubyEncoding firstEncoding, Object second, RubyEncoding secondEncoding,
241236
@Cached("firstEncoding") RubyEncoding cachedEncoding) {
242237
return cachedEncoding;
@@ -245,18 +240,17 @@ protected RubyEncoding negotiateSameEncodingCached(
245240
@Specialization(
246241
guards = { "firstEncoding == secondEncoding", "firstEncoding != null" },
247242
replaces = "negotiateSameEncodingCached")
248-
protected RubyEncoding negotiateSameEncodingUncached(
243+
protected static RubyEncoding negotiateSameEncodingUncached(
249244
Object first, RubyEncoding firstEncoding, Object second, RubyEncoding secondEncoding) {
250245
return firstEncoding;
251246
}
252247

253248
@Specialization(guards = { "libFirst.isRubyString(first)", "libSecond.isRubyString(second)" }, limit = "1")
254249
protected static RubyEncoding negotiateStringStringEncoding(
255-
Object first, RubyEncoding firstEncoding, Object second, RubyEncoding secondEncoding,
250+
Node node, Object first, RubyEncoding firstEncoding, Object second, RubyEncoding secondEncoding,
256251
@Cached @Shared RubyStringLibrary libFirst,
257252
@Cached @Shared RubyStringLibrary libSecond,
258-
@Cached NegotiateCompatibleStringEncodingNode negotiateNode,
259-
@Bind("this") Node node) {
253+
@Cached NegotiateCompatibleStringEncodingNode negotiateNode) {
260254
return negotiateNode.execute(
261255
node,
262256
libFirst.getTString(first),
@@ -274,12 +268,12 @@ protected static RubyEncoding negotiateStringStringEncoding(
274268
"secondEncoding == secondEncodingCached",
275269
"firstEncodingCached != secondEncodingCached" },
276270
limit = "getCacheLimit()")
277-
protected RubyEncoding negotiateStringObjectCached(
271+
protected static RubyEncoding negotiateStringObjectCached(
278272
Object first, RubyEncoding firstEncoding, Object second, RubyEncoding secondEncoding,
279273
@Cached @Shared RubyStringLibrary libFirst,
280274
@Cached("firstEncoding") RubyEncoding firstEncodingCached,
281275
@Cached("secondEncoding") RubyEncoding secondEncodingCached,
282-
@Cached @Shared TruffleString.GetByteCodeRangeNode codeRangeNode,
276+
@Cached(inline = false) @Shared TruffleString.GetByteCodeRangeNode codeRangeNode,
283277
@Bind("getCodeRange(codeRangeNode, first, libFirst)") TruffleString.CodeRange codeRange,
284278
@Cached("codeRange") TruffleString.CodeRange codeRangeCached,
285279
@Cached("negotiateStringObjectUncached(first, firstEncoding, second, secondEncoding, codeRangeNode, libFirst)") RubyEncoding negotiatedEncoding) {
@@ -292,9 +286,9 @@ protected RubyEncoding negotiateStringObjectCached(
292286
"firstEncoding != secondEncoding",
293287
"isNotRubyString(second)" },
294288
replaces = "negotiateStringObjectCached", limit = "1")
295-
protected RubyEncoding negotiateStringObjectUncached(
289+
protected static RubyEncoding negotiateStringObjectUncached(
296290
Object first, RubyEncoding firstEncoding, Object second, RubyEncoding secondEncoding,
297-
@Cached @Shared TruffleString.GetByteCodeRangeNode codeRangeNode,
291+
@Cached(inline = false) @Shared TruffleString.GetByteCodeRangeNode codeRangeNode,
298292
@Cached @Shared RubyStringLibrary libFirst) {
299293

300294
if (secondEncoding == null) {
@@ -322,10 +316,10 @@ protected RubyEncoding negotiateStringObjectUncached(
322316
"firstEncoding != secondEncoding",
323317
"isNotRubyString(first)" },
324318
limit = "1")
325-
protected RubyEncoding negotiateObjectString(
319+
protected static RubyEncoding negotiateObjectString(
326320
Object first, RubyEncoding firstEncoding, Object second, RubyEncoding secondEncoding,
327321
@Cached @Shared RubyStringLibrary libSecond,
328-
@Cached @Shared TruffleString.GetByteCodeRangeNode codeRangeNode) {
322+
@Cached(inline = false) @Shared TruffleString.GetByteCodeRangeNode codeRangeNode) {
329323
return negotiateStringObjectUncached(second, secondEncoding, first, firstEncoding, codeRangeNode,
330324
libSecond);
331325
}
@@ -340,7 +334,7 @@ protected RubyEncoding negotiateObjectString(
340334
"firstEncoding == firstEncodingCached",
341335
"secondEncoding == secondEncodingCached", },
342336
limit = "getCacheLimit()")
343-
protected RubyEncoding negotiateObjectObjectCached(
337+
protected static RubyEncoding negotiateObjectObjectCached(
344338
Object first, RubyEncoding firstEncoding, Object second, RubyEncoding secondEncoding,
345339
@Cached("firstEncoding") RubyEncoding firstEncodingCached,
346340
@Cached("secondEncoding") RubyEncoding secondEncodingCached,
@@ -354,7 +348,7 @@ protected RubyEncoding negotiateObjectObjectCached(
354348
"isNotRubyString(first)",
355349
"isNotRubyString(second)" },
356350
replaces = "negotiateObjectObjectCached")
357-
protected RubyEncoding negotiateObjectObjectUncached(
351+
protected static RubyEncoding negotiateObjectObjectUncached(
358352
Object first, RubyEncoding firstEncoding, Object second, RubyEncoding secondEncoding) {
359353
return areCompatible(firstEncoding, secondEncoding);
360354
}
@@ -381,8 +375,8 @@ protected static RubyEncoding areCompatible(RubyEncoding enc1, RubyEncoding enc2
381375
return null;
382376
}
383377

384-
protected TruffleString.CodeRange getCodeRange(TruffleString.GetByteCodeRangeNode codeRangeNode, Object string,
385-
RubyStringLibrary libString) {
378+
protected static TruffleString.CodeRange getCodeRange(TruffleString.GetByteCodeRangeNode codeRangeNode,
379+
Object string, RubyStringLibrary libString) {
386380
return codeRangeNode.execute(libString.getTString(string), libString.getTEncoding(string));
387381
}
388382

@@ -397,20 +391,18 @@ protected int getCacheLimit() {
397391
@Primitive(name = "encoding_compatible?")
398392
public abstract static class CompatibleQueryNode extends PrimitiveArrayArgumentsNode {
399393

400-
@Child private NegotiateCompatibleEncodingNode negotiateCompatibleEncodingNode = NegotiateCompatibleEncodingNode
401-
.create();
402-
403394
public static CompatibleQueryNode create() {
404395
return EncodingNodesFactory.CompatibleQueryNodeFactory.create(null);
405396
}
406397

407398
@Specialization
408399
protected Object isCompatible(Object first, Object second,
400+
@Cached NegotiateCompatibleEncodingNode negotiateCompatibleEncodingNode,
409401
@Cached ToRubyEncodingNode toRubyEncodingNode,
410402
@Cached InlinedConditionProfile noNegotiatedEncodingProfile) {
411403
final var firstEncoding = toRubyEncodingNode.execute(this, first);
412404
final var secondEncoding = toRubyEncodingNode.execute(this, second);
413-
final RubyEncoding negotiatedEncoding = negotiateCompatibleEncodingNode.executeNegotiate(first,
405+
final RubyEncoding negotiatedEncoding = negotiateCompatibleEncodingNode.execute(this, first,
414406
firstEncoding, second, secondEncoding);
415407

416408
if (noNegotiatedEncodingProfile.profile(this, negotiatedEncoding == null)) {
@@ -830,11 +822,11 @@ public abstract static class CheckEncodingNode extends RubyBaseNode {
830822
@Specialization
831823
protected static RubyEncoding checkEncoding(Node node, Object first, Object second,
832824
@Cached ToRubyEncodingNode toRubyEncodingNode,
833-
@Cached(inline = false) NegotiateCompatibleEncodingNode negotiateCompatibleEncodingNode,
825+
@Cached NegotiateCompatibleEncodingNode negotiateCompatibleEncodingNode,
834826
@Cached InlinedBranchProfile errorProfile) {
835827
final var firstEncoding = toRubyEncodingNode.execute(node, first);
836828
final var secondEncoding = toRubyEncodingNode.execute(node, second);
837-
final RubyEncoding negotiatedEncoding = negotiateCompatibleEncodingNode.executeNegotiate(first,
829+
final RubyEncoding negotiatedEncoding = negotiateCompatibleEncodingNode.execute(node, first,
838830
firstEncoding, second, secondEncoding);
839831

840832
if (negotiatedEncoding == null) {

0 commit comments

Comments
 (0)