Skip to content

Commit c1d3c7c

Browse files
committed
Lazily create the DispatchNode for ArrayCastNode and HashCastNode
1 parent 26e3d37 commit c1d3c7c

File tree

4 files changed

+8
-20
lines changed

4 files changed

+8
-20
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.oracle.truffle.api.frame.VirtualFrame;
2626
import com.oracle.truffle.api.profiles.BranchProfile;
2727

28-
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE_RETURN_MISSING;
2928

3029
/*
3130
* TODO(CS): could probably unify this with SplatCastNode with some final configuration getContext().getOptions().
@@ -37,8 +36,6 @@ public abstract class ArrayCastNode extends RubyContextSourceNode {
3736

3837
private final SplatCastNode.NilBehavior nilBehavior;
3938

40-
@Child private DispatchNode toArrayNode = DispatchNode.create(PRIVATE_RETURN_MISSING);
41-
4239
public static ArrayCastNode create() {
4340
return ArrayCastNodeGen.create(null);
4441
}
@@ -104,9 +101,10 @@ protected Object cast(Nil nil) {
104101

105102
@Specialization(guards = { "!isRubyBignum(object)", "!isRubyArray(object)" })
106103
protected Object cast(RubyDynamicObject object,
107-
@Cached BranchProfile errorProfile) {
108-
final Object result = toArrayNode.call(object, "to_ary");
104+
@Cached BranchProfile errorProfile,
105+
@Cached(parameters = "PRIVATE_RETURN_MISSING") DispatchNode toArrayNode) {
109106

107+
final Object result = toArrayNode.call(object, "to_ary");
110108
if (result == nil) {
111109
return nil;
112110
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@
2424
import com.oracle.truffle.api.frame.VirtualFrame;
2525
import com.oracle.truffle.api.profiles.BranchProfile;
2626

27-
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE_RETURN_MISSING;
2827

2928
// TODO(CS): copy and paste of ArrayCastNode
3029

3130
@NodeChild(value = "child", type = RubyNode.class)
3231
public abstract class HashCastNode extends RubyContextSourceNode {
3332

34-
@Child private DispatchNode toHashNode = DispatchNode.create(PRIVATE_RETURN_MISSING);
35-
3633
protected abstract RubyNode getChild();
3734

3835
@Specialization
@@ -72,9 +69,10 @@ protected Object castHash(RubyHash hash) {
7269

7370
@Specialization(guards = { "!isRubyBignum(object)", "!isRubyHash(object)" })
7471
protected Object cast(RubyDynamicObject object,
75-
@Cached BranchProfile errorProfile) {
76-
final Object result = toHashNode.call(object, "to_hash");
72+
@Cached BranchProfile errorProfile,
73+
@Cached(parameters = "PRIVATE_RETURN_MISSING") DispatchNode toHashNode) {
7774

75+
final Object result = toHashNode.call(object, "to_hash");
7876
if (result == DispatchNode.MISSING) {
7977
return nil;
8078
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.truffleruby.language.control.RaiseException;
1616
import org.truffleruby.language.dispatch.DispatchNode;
1717

18-
import com.oracle.truffle.api.CompilerDirectives;
1918
import com.oracle.truffle.api.dsl.Cached;
2019
import com.oracle.truffle.api.dsl.NodeChild;
2120
import com.oracle.truffle.api.dsl.Specialization;
@@ -25,8 +24,6 @@
2524
@NodeChild(value = "child", type = RubyNode.class)
2625
public abstract class ToAryNode extends RubyContextSourceNode {
2726

28-
@Child private DispatchNode toAryNode;
29-
3027
public static ToAryNode createInternal() {
3128
return ToAryNodeGen.create(null);
3229
}
@@ -40,12 +37,8 @@ protected RubyArray coerceRubyArray(RubyArray array) {
4037

4138
@Specialization(guards = "!isRubyArray(object)")
4239
protected RubyArray coerceObject(Object object,
43-
@Cached BranchProfile errorProfile) {
44-
if (toAryNode == null) {
45-
CompilerDirectives.transferToInterpreterAndInvalidate();
46-
toAryNode = insert(DispatchNode.create());
47-
}
48-
40+
@Cached BranchProfile errorProfile,
41+
@Cached DispatchNode toAryNode) {
4942
final Object coerced;
5043
try {
5144
coerced = toAryNode.call(object, "to_ary");

src/main/java/org/truffleruby/parser/BodyTranslator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,6 @@ public RubyNode visitHashNode(HashParseNode node) {
16151615
final SourceIndexLength sourceSection = node.getPosition();
16161616

16171617
final List<RubyNode> hashConcats = new ArrayList<>();
1618-
16191618
final List<RubyNode> keyValues = new ArrayList<>();
16201619

16211620
for (ParseNodeTuple pair : node.getPairs()) {

0 commit comments

Comments
 (0)