16
16
import com .oracle .truffle .api .dsl .GenerateInline ;
17
17
import com .oracle .truffle .api .dsl .Idempotent ;
18
18
import com .oracle .truffle .api .dsl .ImportStatic ;
19
- import com .oracle .truffle .api .dsl .NeverDefault ;
20
19
import com .oracle .truffle .api .nodes .Node ;
21
20
import com .oracle .truffle .api .profiles .InlinedBranchProfile ;
22
21
import com .oracle .truffle .api .profiles .InlinedConditionProfile ;
32
31
import org .truffleruby .core .array .ArrayUtils ;
33
32
import org .truffleruby .core .array .RubyArray ;
34
33
import org .truffleruby .core .cast .ToRubyEncodingNode ;
35
- import org .truffleruby .core .encoding .EncodingNodesFactory .NegotiateCompatibleEncodingNodeGen ;
36
34
import org .truffleruby .core .klass .RubyClass ;
37
35
import org .truffleruby .core .proc .RubyProc ;
38
36
import org .truffleruby .core .string .RubyString ;
@@ -220,14 +218,11 @@ protected boolean isStandardEncoding(RubyEncoding encoding) {
220
218
221
219
// MRI: enc_compatible_latter
222
220
/** Use {@link NegotiateCompatibleStringEncodingNode} instead if both arguments are always Strings, for footprint */
221
+ @ GenerateCached (false )
222
+ @ GenerateInline
223
223
public abstract static class NegotiateCompatibleEncodingNode extends RubyBaseNode {
224
224
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 ,
231
226
RubyEncoding secondEncoding );
232
227
233
228
@ Specialization (
@@ -236,7 +231,7 @@ public abstract RubyEncoding executeNegotiate(Object first, RubyEncoding firstEn
236
231
"secondEncoding == cachedEncoding" ,
237
232
"cachedEncoding != null" },
238
233
limit = "getCacheLimit()" )
239
- protected RubyEncoding negotiateSameEncodingCached (
234
+ protected static RubyEncoding negotiateSameEncodingCached (
240
235
Object first , RubyEncoding firstEncoding , Object second , RubyEncoding secondEncoding ,
241
236
@ Cached ("firstEncoding" ) RubyEncoding cachedEncoding ) {
242
237
return cachedEncoding ;
@@ -245,18 +240,17 @@ protected RubyEncoding negotiateSameEncodingCached(
245
240
@ Specialization (
246
241
guards = { "firstEncoding == secondEncoding" , "firstEncoding != null" },
247
242
replaces = "negotiateSameEncodingCached" )
248
- protected RubyEncoding negotiateSameEncodingUncached (
243
+ protected static RubyEncoding negotiateSameEncodingUncached (
249
244
Object first , RubyEncoding firstEncoding , Object second , RubyEncoding secondEncoding ) {
250
245
return firstEncoding ;
251
246
}
252
247
253
248
@ Specialization (guards = { "libFirst.isRubyString(first)" , "libSecond.isRubyString(second)" }, limit = "1" )
254
249
protected static RubyEncoding negotiateStringStringEncoding (
255
- Object first , RubyEncoding firstEncoding , Object second , RubyEncoding secondEncoding ,
250
+ Node node , Object first , RubyEncoding firstEncoding , Object second , RubyEncoding secondEncoding ,
256
251
@ Cached @ Shared RubyStringLibrary libFirst ,
257
252
@ Cached @ Shared RubyStringLibrary libSecond ,
258
- @ Cached NegotiateCompatibleStringEncodingNode negotiateNode ,
259
- @ Bind ("this" ) Node node ) {
253
+ @ Cached NegotiateCompatibleStringEncodingNode negotiateNode ) {
260
254
return negotiateNode .execute (
261
255
node ,
262
256
libFirst .getTString (first ),
@@ -274,12 +268,12 @@ protected static RubyEncoding negotiateStringStringEncoding(
274
268
"secondEncoding == secondEncodingCached" ,
275
269
"firstEncodingCached != secondEncodingCached" },
276
270
limit = "getCacheLimit()" )
277
- protected RubyEncoding negotiateStringObjectCached (
271
+ protected static RubyEncoding negotiateStringObjectCached (
278
272
Object first , RubyEncoding firstEncoding , Object second , RubyEncoding secondEncoding ,
279
273
@ Cached @ Shared RubyStringLibrary libFirst ,
280
274
@ Cached ("firstEncoding" ) RubyEncoding firstEncodingCached ,
281
275
@ Cached ("secondEncoding" ) RubyEncoding secondEncodingCached ,
282
- @ Cached @ Shared TruffleString .GetByteCodeRangeNode codeRangeNode ,
276
+ @ Cached ( inline = false ) @ Shared TruffleString .GetByteCodeRangeNode codeRangeNode ,
283
277
@ Bind ("getCodeRange(codeRangeNode, first, libFirst)" ) TruffleString .CodeRange codeRange ,
284
278
@ Cached ("codeRange" ) TruffleString .CodeRange codeRangeCached ,
285
279
@ Cached ("negotiateStringObjectUncached(first, firstEncoding, second, secondEncoding, codeRangeNode, libFirst)" ) RubyEncoding negotiatedEncoding ) {
@@ -292,9 +286,9 @@ protected RubyEncoding negotiateStringObjectCached(
292
286
"firstEncoding != secondEncoding" ,
293
287
"isNotRubyString(second)" },
294
288
replaces = "negotiateStringObjectCached" , limit = "1" )
295
- protected RubyEncoding negotiateStringObjectUncached (
289
+ protected static RubyEncoding negotiateStringObjectUncached (
296
290
Object first , RubyEncoding firstEncoding , Object second , RubyEncoding secondEncoding ,
297
- @ Cached @ Shared TruffleString .GetByteCodeRangeNode codeRangeNode ,
291
+ @ Cached ( inline = false ) @ Shared TruffleString .GetByteCodeRangeNode codeRangeNode ,
298
292
@ Cached @ Shared RubyStringLibrary libFirst ) {
299
293
300
294
if (secondEncoding == null ) {
@@ -322,10 +316,10 @@ protected RubyEncoding negotiateStringObjectUncached(
322
316
"firstEncoding != secondEncoding" ,
323
317
"isNotRubyString(first)" },
324
318
limit = "1" )
325
- protected RubyEncoding negotiateObjectString (
319
+ protected static RubyEncoding negotiateObjectString (
326
320
Object first , RubyEncoding firstEncoding , Object second , RubyEncoding secondEncoding ,
327
321
@ Cached @ Shared RubyStringLibrary libSecond ,
328
- @ Cached @ Shared TruffleString .GetByteCodeRangeNode codeRangeNode ) {
322
+ @ Cached ( inline = false ) @ Shared TruffleString .GetByteCodeRangeNode codeRangeNode ) {
329
323
return negotiateStringObjectUncached (second , secondEncoding , first , firstEncoding , codeRangeNode ,
330
324
libSecond );
331
325
}
@@ -340,7 +334,7 @@ protected RubyEncoding negotiateObjectString(
340
334
"firstEncoding == firstEncodingCached" ,
341
335
"secondEncoding == secondEncodingCached" , },
342
336
limit = "getCacheLimit()" )
343
- protected RubyEncoding negotiateObjectObjectCached (
337
+ protected static RubyEncoding negotiateObjectObjectCached (
344
338
Object first , RubyEncoding firstEncoding , Object second , RubyEncoding secondEncoding ,
345
339
@ Cached ("firstEncoding" ) RubyEncoding firstEncodingCached ,
346
340
@ Cached ("secondEncoding" ) RubyEncoding secondEncodingCached ,
@@ -354,7 +348,7 @@ protected RubyEncoding negotiateObjectObjectCached(
354
348
"isNotRubyString(first)" ,
355
349
"isNotRubyString(second)" },
356
350
replaces = "negotiateObjectObjectCached" )
357
- protected RubyEncoding negotiateObjectObjectUncached (
351
+ protected static RubyEncoding negotiateObjectObjectUncached (
358
352
Object first , RubyEncoding firstEncoding , Object second , RubyEncoding secondEncoding ) {
359
353
return areCompatible (firstEncoding , secondEncoding );
360
354
}
@@ -381,8 +375,8 @@ protected static RubyEncoding areCompatible(RubyEncoding enc1, RubyEncoding enc2
381
375
return null ;
382
376
}
383
377
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 ) {
386
380
return codeRangeNode .execute (libString .getTString (string ), libString .getTEncoding (string ));
387
381
}
388
382
@@ -397,20 +391,18 @@ protected int getCacheLimit() {
397
391
@ Primitive (name = "encoding_compatible?" )
398
392
public abstract static class CompatibleQueryNode extends PrimitiveArrayArgumentsNode {
399
393
400
- @ Child private NegotiateCompatibleEncodingNode negotiateCompatibleEncodingNode = NegotiateCompatibleEncodingNode
401
- .create ();
402
-
403
394
public static CompatibleQueryNode create () {
404
395
return EncodingNodesFactory .CompatibleQueryNodeFactory .create (null );
405
396
}
406
397
407
398
@ Specialization
408
399
protected Object isCompatible (Object first , Object second ,
400
+ @ Cached NegotiateCompatibleEncodingNode negotiateCompatibleEncodingNode ,
409
401
@ Cached ToRubyEncodingNode toRubyEncodingNode ,
410
402
@ Cached InlinedConditionProfile noNegotiatedEncodingProfile ) {
411
403
final var firstEncoding = toRubyEncodingNode .execute (this , first );
412
404
final var secondEncoding = toRubyEncodingNode .execute (this , second );
413
- final RubyEncoding negotiatedEncoding = negotiateCompatibleEncodingNode .executeNegotiate ( first ,
405
+ final RubyEncoding negotiatedEncoding = negotiateCompatibleEncodingNode .execute ( this , first ,
414
406
firstEncoding , second , secondEncoding );
415
407
416
408
if (noNegotiatedEncodingProfile .profile (this , negotiatedEncoding == null )) {
@@ -830,11 +822,11 @@ public abstract static class CheckEncodingNode extends RubyBaseNode {
830
822
@ Specialization
831
823
protected static RubyEncoding checkEncoding (Node node , Object first , Object second ,
832
824
@ Cached ToRubyEncodingNode toRubyEncodingNode ,
833
- @ Cached ( inline = false ) NegotiateCompatibleEncodingNode negotiateCompatibleEncodingNode ,
825
+ @ Cached NegotiateCompatibleEncodingNode negotiateCompatibleEncodingNode ,
834
826
@ Cached InlinedBranchProfile errorProfile ) {
835
827
final var firstEncoding = toRubyEncodingNode .execute (node , first );
836
828
final var secondEncoding = toRubyEncodingNode .execute (node , second );
837
- final RubyEncoding negotiatedEncoding = negotiateCompatibleEncodingNode .executeNegotiate ( first ,
829
+ final RubyEncoding negotiatedEncoding = negotiateCompatibleEncodingNode .execute ( node , first ,
838
830
firstEncoding , second , secondEncoding );
839
831
840
832
if (negotiatedEncoding == null ) {
0 commit comments