Skip to content

Commit 3fc2c33

Browse files
committed
DeleteBangStringsNode supports DSL inlining
1 parent 3777336 commit 3fc2c33

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ public RubyException argumentErrorMinMaxArity(int passed, int minArity, int maxA
243243
}
244244
}
245245

246-
public RubyException argumentErrorEmptyVarargs(RubyBaseNode currentNode) {
247-
return argumentError(coreStrings().WRONG_ARGS_ZERO_PLUS_ONE.createInstance(currentNode.getContext()),
246+
public RubyException argumentErrorEmptyVarargs(Node currentNode) {
247+
return argumentError(coreStrings().WRONG_ARGS_ZERO_PLUS_ONE.createInstance(RubyContext.get(currentNode)),
248248
currentNode, null);
249249
}
250250

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ protected int countFast(Object string, TStringWithEncoding[] args,
206206
@Cached("libString.getEncoding(string)") RubyEncoding cachedEncoding,
207207
@Cached(value = "squeeze()", dimensions = 1) boolean[] squeeze,
208208
@Cached("findEncoding(libString.getTString(string), libString.getEncoding(string), cachedArgs, checkEncodingNode)") RubyEncoding compatEncoding,
209-
@Cached("makeTables(cachedArgs, squeeze, compatEncoding)") StringSupport.TrTables tables,
209+
@Cached("makeTables(this, cachedArgs, squeeze, compatEncoding)") StringSupport.TrTables tables,
210210
@Cached @Shared TruffleString.GetInternalByteArrayNode byteArrayNode,
211211
@Cached @Shared TruffleString.GetByteCodeRangeNode getByteCodeRangeNode) {
212212
var byteArray = byteArrayNode.execute(tstring, encoding.tencoding);
@@ -239,7 +239,7 @@ protected int count(Object string, TStringWithEncoding[] tstringsWithEncs,
239239
private int countSlow(InternalByteArray byteArray, TruffleString.CodeRange codeRange,
240240
TStringWithEncoding[] tstringsWithEncs, RubyEncoding enc) {
241241
final boolean[] table = squeeze();
242-
final StringSupport.TrTables tables = makeTables(tstringsWithEncs, table, enc);
242+
final StringSupport.TrTables tables = makeTables(this, tstringsWithEncs, table, enc);
243243
return StringSupport.strCount(byteArray, codeRange, table, tables, enc.jcoding, this);
244244
}
245245
}
@@ -250,7 +250,7 @@ protected boolean[] squeeze() {
250250
return new boolean[StringSupport.TRANS_SIZE + 1];
251251
}
252252

253-
protected RubyEncoding findEncoding(AbstractTruffleString tstring, RubyEncoding encoding,
253+
protected static RubyEncoding findEncoding(AbstractTruffleString tstring, RubyEncoding encoding,
254254
TStringWithEncoding[] tstringsWithEncs, EncodingNodes.CheckStringEncodingNode checkEncodingNode) {
255255
RubyEncoding enc = checkEncodingNode.executeCheckEncoding(tstring, encoding, tstringsWithEncs[0].tstring,
256256
tstringsWithEncs[0].encoding);
@@ -261,8 +261,8 @@ protected RubyEncoding findEncoding(AbstractTruffleString tstring, RubyEncoding
261261
return enc;
262262
}
263263

264-
protected StringSupport.TrTables makeTables(TStringWithEncoding[] tstringsWithEncs, boolean[] squeeze,
265-
RubyEncoding enc) {
264+
protected static StringSupport.TrTables makeTables(Node node, TStringWithEncoding[] tstringsWithEncs,
265+
boolean[] squeeze, RubyEncoding enc) {
266266
// The trSetupTable method will consume the bytes from the rope one encoded character at a time and
267267
// build a TrTable from this. Previously we started with the encoding of rope zero, and at each
268268
// stage found a compatible encoding to build that TrTable with. Although we now calculate a single
@@ -275,12 +275,12 @@ protected StringSupport.TrTables makeTables(TStringWithEncoding[] tstringsWithEn
275275
null,
276276
true,
277277
enc.jcoding,
278-
this);
278+
node);
279279

280280
for (int i = 1; i < tstringsWithEncs.length; i++) {
281281
tables = StringSupport
282282
.trSetupTable(tstringsWithEncs[i].tstring, tstringsWithEncs[i].encoding, squeeze, tables, false,
283-
enc.jcoding, this);
283+
enc.jcoding, node);
284284
}
285285
return tables;
286286
}
@@ -312,15 +312,17 @@ protected Object deleteBangEmpty(RubyString string, Object[] args) {
312312
@Specialization
313313
protected Object deleteBangString(RubyString string, TStringWithEncoding[] args,
314314
@Cached DeleteBangStringsNode deleteBangStringsNode) {
315-
return deleteBangStringsNode.execute(string, args);
315+
return deleteBangStringsNode.execute(this, string, args);
316316
}
317317
}
318318

319319

320320
@ImportStatic(StringGuards.class)
321+
@GenerateCached(false)
322+
@GenerateInline
321323
public abstract static class DeleteBangStringsNode extends TrTableNode {
322324

323-
public abstract Object execute(RubyString string, TStringWithEncoding[] tstringsWithEncs);
325+
public abstract Object execute(Node node, RubyString string, TStringWithEncoding[] tstringsWithEncs);
324326

325327
@Specialization(
326328
guards = {
@@ -330,17 +332,16 @@ public abstract static class DeleteBangStringsNode extends TrTableNode {
330332
"argsMatch(cachedArgs, args, equalNode)",
331333
"libString.getEncoding(string) == cachedEncoding" },
332334
limit = "getDefaultCacheLimit()")
333-
protected static Object deleteBangFast(RubyString string, TStringWithEncoding[] args,
335+
protected static Object deleteBangFast(Node node, RubyString string, TStringWithEncoding[] args,
334336
@Cached(value = "args", dimensions = 1) TStringWithEncoding[] cachedArgs,
335337
@Cached TruffleString.EqualNode equalNode,
336338
@Cached @Shared EncodingNodes.CheckStringEncodingNode checkEncodingNode,
337339
@Cached @Shared RubyStringLibrary libString,
338340
@Cached("libString.getEncoding(string)") RubyEncoding cachedEncoding,
339341
@Cached(value = "squeeze()", dimensions = 1) boolean[] squeeze,
340342
@Cached("findEncoding(libString.getTString(string), libString.getEncoding(string), cachedArgs, checkEncodingNode)") RubyEncoding compatEncoding,
341-
@Cached("makeTables(cachedArgs, squeeze, compatEncoding)") StringSupport.TrTables tables,
342-
@Cached @Exclusive InlinedBranchProfile nullProfile,
343-
@Bind("this") Node node) {
343+
@Cached("makeTables(node, cachedArgs, squeeze, compatEncoding)") StringSupport.TrTables tables,
344+
@Cached @Exclusive InlinedBranchProfile nullProfile) {
344345
var processedTString = processStr(node, string, squeeze, compatEncoding, tables);
345346
if (processedTString == null) {
346347
nullProfile.enter(node);
@@ -352,28 +353,28 @@ protected static Object deleteBangFast(RubyString string, TStringWithEncoding[]
352353
}
353354

354355
@Specialization(guards = "!string.tstring.isEmpty()", replaces = "deleteBangFast")
355-
protected Object deleteBangSlow(RubyString string, TStringWithEncoding[] args,
356+
protected static Object deleteBangSlow(Node node, RubyString string, TStringWithEncoding[] args,
356357
@Cached @Shared RubyStringLibrary libString,
357358
@Cached @Shared EncodingNodes.CheckStringEncodingNode checkEncodingNode,
358359
@Cached @Exclusive InlinedBranchProfile errorProfile) {
359360
if (args.length == 0) {
360-
errorProfile.enter(this);
361-
throw new RaiseException(getContext(), coreExceptions().argumentErrorEmptyVarargs(this));
361+
errorProfile.enter(node);
362+
throw new RaiseException(getContext(node), coreExceptions(node).argumentErrorEmptyVarargs(node));
362363
}
363364

364365
RubyEncoding enc = findEncoding(string.tstring, libString.getEncoding(string), args, checkEncodingNode);
365366

366-
return deleteBangSlow(string, args, enc);
367+
return deleteBangSlow(node, string, args, enc);
367368
}
368369

369370
@TruffleBoundary
370-
private Object deleteBangSlow(RubyString string, TStringWithEncoding[] tstringsWithEncs,
371+
private static Object deleteBangSlow(Node node, RubyString string, TStringWithEncoding[] tstringsWithEncs,
371372
RubyEncoding enc) {
372373
final boolean[] squeeze = new boolean[StringSupport.TRANS_SIZE + 1];
373374

374-
final StringSupport.TrTables tables = makeTables(tstringsWithEncs, squeeze, enc);
375+
final StringSupport.TrTables tables = makeTables(node, tstringsWithEncs, squeeze, enc);
375376

376-
var processedTString = processStr(this, string, squeeze, enc, tables);
377+
var processedTString = processStr(node, string, squeeze, enc, tables);
377378
if (processedTString == null) {
378379
return nil;
379380
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ protected static Object deleteBang(Node node, RubyString string, Object[] args,
10071007
@Cached("args.length") int size) {
10081008
final TStringWithEncoding[] tstringsWithEncs = argTStringsWithEncs(node, args, size, toStrNode,
10091009
asTruffleStringNode, rubyStringLibrary);
1010-
return deleteBangStringsNode.execute(string, tstringsWithEncs);
1010+
return deleteBangStringsNode.execute(node, string, tstringsWithEncs);
10111011
}
10121012

10131013
@Specialization(replaces = "deleteBang")
@@ -1018,7 +1018,7 @@ protected static Object deleteBangSlow(Node node, RubyString string, Object[] ar
10181018
@Cached @Shared ToStrNode toStrNode) {
10191019
final TStringWithEncoding[] tstrings = argTStringsWithEncsSlow(node, args, toStrNode, asTruffleStringNode,
10201020
rubyStringLibrary);
1021-
return deleteBangStringsNode.execute(string, tstrings);
1021+
return deleteBangStringsNode.execute(node, string, tstrings);
10221022
}
10231023

10241024
@ExplodeLoop

0 commit comments

Comments
 (0)