Skip to content

Commit dc9809e

Browse files
committed
BooleanCastNode is DSL inlinable node
1 parent ed38ea4 commit dc9809e

27 files changed

+185
-184
lines changed

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,6 @@ private static class State {
17961796
}
17971797

17981798
@Child private ArrayBuilderNode arrayBuilder = ArrayBuilderNode.create();
1799-
@Child private BooleanCastNode booleanCastNode = BooleanCastNode.create();
18001799

18011800
@Specialization
18021801
protected Object reject(RubyArray array, RubyProc block,
@@ -1816,7 +1815,7 @@ public void accept(Node node, CallBlockNode yieldNode, RubyArray array, Object s
18161815
int index, BooleanCastNode booleanCastNode) {
18171816
final State state = (State) stateObject;
18181817

1819-
if (!booleanCastNode.execute(yieldNode.yield(state.block, element))) {
1818+
if (!booleanCastNode.execute(node, yieldNode.yield(state.block, element))) {
18201819
arrayBuilder.appendValue(state.builderState, state.newArraySize, element);
18211820
state.newArraySize++;
18221821
}
@@ -2007,7 +2006,6 @@ private static class State {
20072006
}
20082007

20092008
@Child private ArrayBuilderNode arrayBuilder = ArrayBuilderNode.create();
2010-
@Child private BooleanCastNode booleanCastNode = BooleanCastNode.create();
20112009

20122010
@Specialization
20132011
protected Object select(RubyArray array, RubyProc block,
@@ -2027,7 +2025,7 @@ public void accept(Node node, CallBlockNode yieldNode, RubyArray array, Object s
20272025
int index, BooleanCastNode booleanCastNode) {
20282026
final State state = (State) stateObject;
20292027

2030-
if (booleanCastNode.execute(yieldNode.yield(state.block, element))) {
2028+
if (booleanCastNode.execute(node, yieldNode.yield(state.block, element))) {
20312029
arrayBuilder.appendValue(state.builderState, state.selectedSize, element);
20322030
state.selectedSize++;
20332031
}

src/main/java/org/truffleruby/core/basicobject/BasicObjectNodes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public abstract static class NotNode extends CoreMethodArrayArgumentsNode {
9999
@Specialization
100100
protected boolean not(Object value,
101101
@Cached BooleanCastNode cast) {
102-
return !cast.execute(value);
102+
return !cast.execute(this, value);
103103
}
104104

105105
}
@@ -108,11 +108,11 @@ protected boolean not(Object value,
108108
public abstract static class NotEqualNode extends CoreMethodArrayArgumentsNode {
109109

110110
@Child private DispatchNode equalNode = DispatchNode.create();
111-
@Child private BooleanCastNode booleanCastNode = BooleanCastNode.create();
112111

113112
@Specialization
114-
protected boolean equal(VirtualFrame frame, Object a, Object b) {
115-
return !booleanCastNode.execute(equalNode.call(a, "==", b));
113+
protected boolean equal(VirtualFrame frame, Object a, Object b,
114+
@Cached BooleanCastNode booleanCastNode) {
115+
return !booleanCastNode.execute(this, equalNode.call(a, "==", b));
116116
}
117117

118118
}

src/main/java/org/truffleruby/core/bool/FalseClassNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract static class OrXorNode extends CoreMethodArrayArgumentsNode {
3535
@Specialization
3636
protected boolean orXor(Object other,
3737
@Cached BooleanCastNode cast) {
38-
return cast.execute(other);
38+
return cast.execute(this, other);
3939
}
4040

4141
}

src/main/java/org/truffleruby/core/bool/TrueClassNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public abstract static class AndNode extends CoreMethodArrayArgumentsNode {
2626
@Specialization
2727
protected boolean and(Object other,
2828
@Cached BooleanCastNode cast) {
29-
return cast.execute(other);
29+
return cast.execute(this, other);
3030
}
3131
}
3232

@@ -45,7 +45,7 @@ public abstract static class XorNode extends CoreMethodArrayArgumentsNode {
4545
@Specialization
4646
protected boolean xor(Object other,
4747
@Cached BooleanCastNode cast) {
48-
return !cast.execute(other);
48+
return !cast.execute(this, other);
4949
}
5050
}
5151

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

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,86 +9,76 @@
99
*/
1010
package org.truffleruby.core.cast;
1111

12-
import com.oracle.truffle.api.dsl.Bind;
13-
import com.oracle.truffle.api.dsl.NeverDefault;
12+
import com.oracle.truffle.api.dsl.GenerateCached;
13+
import com.oracle.truffle.api.dsl.GenerateInline;
1414
import com.oracle.truffle.api.nodes.Node;
1515
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
1616
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
1717
import org.truffleruby.language.ImmutableRubyObject;
1818
import org.truffleruby.language.Nil;
1919
import org.truffleruby.language.RubyBaseNode;
2020
import org.truffleruby.language.RubyDynamicObject;
21-
import org.truffleruby.language.RubyNode;
2221

2322
import com.oracle.truffle.api.dsl.Cached;
2423
import com.oracle.truffle.api.dsl.GenerateUncached;
25-
import com.oracle.truffle.api.dsl.NodeChild;
2624
import com.oracle.truffle.api.dsl.Specialization;
27-
import com.oracle.truffle.api.frame.VirtualFrame;
2825
import com.oracle.truffle.api.interop.InteropLibrary;
2926
import com.oracle.truffle.api.interop.UnsupportedMessageException;
3027
import com.oracle.truffle.api.library.CachedLibrary;
3128

3229
/** Casts a value into a boolean. */
3330
@GenerateUncached
34-
@NodeChild(value = "valueNode", type = RubyNode.class)
31+
@GenerateCached(false)
32+
@GenerateInline
3533
public abstract class BooleanCastNode extends RubyBaseNode {
3634

37-
@NeverDefault
38-
public static BooleanCastNode create() {
39-
return BooleanCastNodeGen.create(null);
35+
public static boolean executeUncached(Object value) {
36+
return BooleanCastNodeGen.getUncached().execute(null, value);
4037
}
4138

42-
/** Execute with child node */
43-
public abstract boolean execute(VirtualFrame frame);
44-
45-
public abstract RubyNode getValueNode();
46-
47-
/** Execute with given value */
48-
public abstract boolean execute(Object value);
39+
public abstract boolean execute(Node node, Object value);
4940

5041
@Specialization
51-
protected boolean doNil(Nil nil) {
42+
protected static boolean doNil(Nil nil) {
5243
return false;
5344
}
5445

5546
@Specialization
56-
protected boolean doBoolean(boolean value) {
47+
protected static boolean doBoolean(boolean value) {
5748
return value;
5849
}
5950

6051
@Specialization
61-
protected boolean doInt(int value) {
52+
protected static boolean doInt(int value) {
6253
return true;
6354
}
6455

6556
@Specialization
66-
protected boolean doLong(long value) {
57+
protected static boolean doLong(long value) {
6758
return true;
6859
}
6960

7061
@Specialization
71-
protected boolean doFloat(double value) {
62+
protected static boolean doFloat(double value) {
7263
return true;
7364
}
7465

7566
@Specialization
76-
protected boolean doBasicObject(RubyDynamicObject object) {
67+
protected static boolean doBasicObject(RubyDynamicObject object) {
7768
return true;
7869
}
7970

8071
@Specialization(guards = "!isNil(object)")
81-
protected boolean doImmutableObject(ImmutableRubyObject object) {
72+
protected static boolean doImmutableObject(ImmutableRubyObject object) {
8273
return true;
8374
}
8475

8576
@Specialization(guards = "isForeignObject(object)", limit = "getCacheLimit()")
86-
protected static boolean doForeignObject(Object object,
77+
protected static boolean doForeignObject(Node node, Object object,
8778
@CachedLibrary("object") InteropLibrary objects,
8879
@Cached InlinedConditionProfile isNullProfile,
8980
@Cached InlinedConditionProfile isBooleanProfile,
90-
@Cached InlinedBranchProfile failed,
91-
@Bind("this") Node node) {
81+
@Cached InlinedBranchProfile failed) {
9282

9383
if (isNullProfile.profile(node, objects.isNull(object))) {
9484
return false;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ protected static boolean doDefault(NotProvided value, boolean defaultValue) {
3232
}
3333

3434
@Fallback
35-
protected static boolean fallback(Object value, boolean defaultValue,
35+
protected static boolean fallback(Node node, Object value, boolean defaultValue,
3636
@Cached BooleanCastNode booleanCastNode) {
37-
return booleanCastNode.execute(value);
37+
return booleanCastNode.execute(node, value);
3838
}
3939
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
package org.truffleruby.core.cast;
2222

23+
import com.oracle.truffle.api.dsl.Bind;
24+
import com.oracle.truffle.api.nodes.Node;
2325
import org.truffleruby.core.numeric.RubyBignum;
2426
import org.truffleruby.core.string.StringUtils;
2527
import org.truffleruby.language.Nil;
@@ -78,17 +80,18 @@ private String formatMessage(Object receiver, Object other) {
7880
}
7981

8082
@Specialization(guards = { "!isRubyInteger(value)", "!isNil(value)" })
81-
protected int cmpObject(Object value, Object receiver, Object other,
83+
protected static int cmpObject(Object value, Object receiver, Object other,
8284
@Cached DispatchNode gtNode,
8385
@Cached DispatchNode ltNode,
8486
@Cached BooleanCastNode gtCastNode,
85-
@Cached BooleanCastNode ltCastNode) {
87+
@Cached BooleanCastNode ltCastNode,
88+
@Bind("this") Node node) {
8689

87-
if (gtCastNode.execute(gtNode.call(value, ">", 0))) {
90+
if (gtCastNode.execute(node, gtNode.call(value, ">", 0))) {
8891
return 1;
8992
}
9093

91-
if (ltCastNode.execute(ltNode.call(value, "<", 0))) {
94+
if (ltCastNode.execute(node, ltNode.call(value, "<", 0))) {
9295
return -1;
9396
}
9497

src/main/java/org/truffleruby/core/hash/library/PackedHashStoreLibrary.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ public abstract static class SmallHashLiteralNode extends HashLiteralNode {
484484

485485
@Child private HashingNodes.ToHashByHashCode hashNode;
486486
@Child private DispatchNode equalNode;
487-
@Child private BooleanCastNode booleanCastNode;
488487

489488
public SmallHashLiteralNode(RubyNode[] keyValues) {
490489
super(keyValues);
@@ -493,6 +492,7 @@ public SmallHashLiteralNode(RubyNode[] keyValues) {
493492
@Specialization
494493
@ExplodeLoop
495494
protected Object doHash(VirtualFrame frame,
495+
@Cached BooleanCastNode booleanCastNode,
496496
@Cached InlinedBranchProfile duplicateKeyProfile,
497497
@Cached FreezeHashKeyIfNeededNode freezeHashKeyIfNeededNode) {
498498
final Object[] store = createStore();
@@ -510,7 +510,7 @@ protected Object doHash(VirtualFrame frame,
510510
for (int i = 0; i < n; i++) {
511511
if (i < size &&
512512
hashed == getHashed(store, i) &&
513-
callEqual(key, getKey(store, i))) {
513+
callEqual(key, getKey(store, i), booleanCastNode)) {
514514
duplicateKeyProfile.enter(this);
515515
setKey(store, i, key);
516516
setValue(store, i, value);
@@ -542,18 +542,13 @@ private int hash(Object key) {
542542
return hashNode.executeCached(key);
543543
}
544544

545-
private boolean callEqual(Object receiver, Object key) {
545+
private boolean callEqual(Object receiver, Object key, BooleanCastNode booleanCastNode) {
546546
if (equalNode == null) {
547547
CompilerDirectives.transferToInterpreterAndInvalidate();
548548
equalNode = insert(DispatchNode.create());
549549
}
550550

551-
if (booleanCastNode == null) {
552-
CompilerDirectives.transferToInterpreterAndInvalidate();
553-
booleanCastNode = insert(BooleanCastNode.create());
554-
}
555-
556-
return booleanCastNode.execute(equalNode.call(receiver, "eql?", key));
551+
return booleanCastNode.execute(this, equalNode.call(receiver, "eql?", key));
557552
}
558553

559554
@Override

src/main/java/org/truffleruby/core/inlined/InlinedNotNode.java

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

12+
import com.oracle.truffle.api.dsl.Bind;
13+
import com.oracle.truffle.api.nodes.Node;
1214
import org.truffleruby.RubyLanguage;
1315
import org.truffleruby.core.cast.BooleanCastNode;
1416
import org.truffleruby.language.RubyNode;
@@ -31,10 +33,11 @@ public InlinedNotNode(RubyLanguage language, RubyCallNodeParameters callNodePara
3133
guards = { "lookupNode.lookupProtected(frame, self, METHOD) == coreMethods().NOT", },
3234
assumptions = "assumptions",
3335
limit = "1")
34-
protected boolean not(VirtualFrame frame, Object self,
36+
protected static boolean not(VirtualFrame frame, Object self,
3537
@Cached LookupMethodOnSelfNode lookupNode,
36-
@Cached BooleanCastNode booleanCastNode) {
37-
return !booleanCastNode.execute(self);
38+
@Cached BooleanCastNode booleanCastNode,
39+
@Bind("this") Node node) {
40+
return !booleanCastNode.execute(node, self);
3841
}
3942

4043
@Specialization

0 commit comments

Comments
 (0)