Skip to content

Commit 4c0e900

Browse files
committed
Convert ToRubyIntegerNode to DSL inlinable
1 parent 98d791a commit 4c0e900

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

src/main/java/org/truffleruby/core/VMPrimitiveNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ protected Object startHashNotNumber(Object salt,
475475
@Cached InlinedConditionProfile isIntegerProfile,
476476
@Cached InlinedConditionProfile isLongProfile,
477477
@Cached InlinedConditionProfile isBignumProfile) {
478-
Object result = toRubyInteger.execute(salt);
478+
Object result = toRubyInteger.execute(this, salt);
479479
if (isIntegerProfile.profile(this, result instanceof Integer)) {
480480
return getContext().getHashing(this).start((int) result);
481481
} else if (isLongProfile.profile(this, result instanceof Long)) {
@@ -508,7 +508,7 @@ protected Object updateHash(long hash, Object value,
508508
@Cached InlinedConditionProfile isIntegerProfile,
509509
@Cached InlinedConditionProfile isLongProfile,
510510
@Cached InlinedConditionProfile isBignumProfile) {
511-
Object result = toRubyInteger.execute(value);
511+
Object result = toRubyInteger.execute(this, value);
512512
if (isIntegerProfile.profile(this, result instanceof Integer)) {
513513
return Hashing.update(hash, (int) result);
514514
} else if (isLongProfile.profile(this, result instanceof Long)) {

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
*/
1010
package org.truffleruby.core.cast;
1111

12+
import com.oracle.truffle.api.dsl.GenerateCached;
13+
import com.oracle.truffle.api.dsl.GenerateInline;
1214
import com.oracle.truffle.api.dsl.GenerateUncached;
13-
import com.oracle.truffle.api.dsl.NeverDefault;
15+
import com.oracle.truffle.api.nodes.Node;
1416
import org.truffleruby.core.numeric.RubyBignum;
1517
import org.truffleruby.language.RubyBaseNode;
1618
import org.truffleruby.language.dispatch.DispatchNode;
@@ -20,33 +22,30 @@
2022

2123
/** See {@link ToIntNode} for a comparison of different integer conversion nodes. */
2224
@GenerateUncached
25+
@GenerateInline
26+
@GenerateCached(false)
2327
public abstract class ToRubyIntegerNode extends RubyBaseNode {
2428

25-
@NeverDefault
26-
public static ToRubyIntegerNode create() {
27-
return ToRubyIntegerNodeGen.create();
28-
}
29-
30-
public abstract Object execute(Object object);
29+
public abstract Object execute(Node node, Object object);
3130

3231
@Specialization
33-
protected int coerceInt(int value) {
32+
protected static int coerceInt(int value) {
3433
return value;
3534
}
3635

3736
@Specialization
38-
protected long coerceLong(long value) {
37+
protected static long coerceLong(long value) {
3938
return value;
4039
}
4140

4241
@Specialization
43-
protected RubyBignum coerceRubyBignum(RubyBignum value) {
42+
protected static RubyBignum coerceRubyBignum(RubyBignum value) {
4443
return value;
4544
}
4645

4746
@Specialization(guards = "!isRubyInteger(object)")
48-
protected Object coerceObject(Object object,
47+
protected static Object coerceObject(Node node, Object object,
4948
@Cached DispatchNode toIntNode) {
50-
return toIntNode.call(coreLibrary().truffleTypeModule, "rb_to_int_fallback", object);
49+
return toIntNode.call(coreLibrary(node).truffleTypeModule, "rb_to_int_fallback", object);
5150
}
5251
}

src/main/java/org/truffleruby/core/hash/HashingNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ protected static int castBignum(RubyBignum hashed) {
167167
}
168168

169169
@Specialization(guards = "!isRubyInteger(hashed)")
170-
protected static int castOther(Object hashed,
170+
protected static int castOther(Node node, Object hashed,
171171
@Cached ToRubyIntegerNode toRubyInteger,
172172
//recursive inlining is not supported
173173
@Cached(inline = false) HashCastResultNode hashCastResult) {
174-
return hashCastResult.executeCached(toRubyInteger.execute(hashed));
174+
return hashCastResult.executeCached(toRubyInteger.execute(node, hashed));
175175
}
176176
}
177177
}

src/main/java/org/truffleruby/core/numeric/IntegerNodes.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
import java.math.BigInteger;
1414
import java.math.RoundingMode;
1515

16+
import com.oracle.truffle.api.dsl.Bind;
1617
import com.oracle.truffle.api.dsl.Cached.Shared;
1718
import com.oracle.truffle.api.dsl.Cached.Exclusive;
1819
import com.oracle.truffle.api.dsl.Fallback;
1920
import com.oracle.truffle.api.dsl.Idempotent;
2021
import com.oracle.truffle.api.dsl.NeverDefault;
22+
import com.oracle.truffle.api.nodes.Node;
2123
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
2224
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
2325
import com.oracle.truffle.api.profiles.InlinedLoopConditionProfile;
@@ -1261,10 +1263,11 @@ protected Object leftShiftNeg(Object a, RubyBignum b) {
12611263
// Coercion
12621264

12631265
@Specialization(guards = "!isRubyInteger(b)")
1264-
protected Object leftShiftCoerced(Object a, Object b,
1266+
protected static Object leftShiftCoerced(Object a, Object b,
12651267
@Cached ToRubyIntegerNode toRubyIntNode,
1266-
@Cached LeftShiftNode leftShiftNode) {
1267-
return leftShiftNode.executeLeftShift(a, toRubyIntNode.execute(b));
1268+
@Cached LeftShiftNode leftShiftNode,
1269+
@Bind("this") Node node) {
1270+
return leftShiftNode.executeLeftShift(a, toRubyIntNode.execute(node, b));
12681271
}
12691272

12701273
private Object negateAndRightShift(Object a, Object b) {
@@ -1380,10 +1383,11 @@ protected Object rightShiftNeg(Object a, RubyBignum b) {
13801383
// Coercion
13811384

13821385
@Specialization(guards = "!isRubyInteger(b)")
1383-
protected Object rightShiftCoerced(Object a, Object b,
1386+
protected static Object rightShiftCoerced(Object a, Object b,
13841387
@Cached ToRubyIntegerNode toRubyIntNode,
1385-
@Cached RightShiftNode rightShiftNode) {
1386-
return rightShiftNode.executeRightShift(a, toRubyIntNode.execute(b));
1388+
@Cached RightShiftNode rightShiftNode,
1389+
@Bind("this") Node node) {
1390+
return rightShiftNode.executeRightShift(a, toRubyIntNode.execute(node, b));
13871391
}
13881392

13891393
private Object negateAndLeftShift(Object a, Object b) {

src/main/java/org/truffleruby/core/support/TypeNodes.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,11 @@ protected int numToInt(Object value) {
426426

427427
@Primitive(name = "rb_to_int")
428428
public abstract static class RbToIntNode extends PrimitiveArrayArgumentsNode {
429-
@Child private ToRubyIntegerNode toRubyInteger = ToRubyIntegerNode.create();
430429

431430
@Specialization
432-
protected Object toRubyInteger(Object value) {
433-
return toRubyInteger.execute(value);
431+
protected Object toRubyInteger(Object value,
432+
@Cached ToRubyIntegerNode toRubyInteger) {
433+
return toRubyInteger.execute(this, value);
434434
}
435435
}
436436

0 commit comments

Comments
 (0)