Skip to content

Commit 069a9ef

Browse files
committed
[GR-17457] DispatchNode is converted to DSL node
PullRequest: truffleruby/3908
2 parents 9459868 + 659c98a commit 069a9ef

31 files changed

+509
-488
lines changed

src/main/java/org/truffleruby/builtins/ReturnEnumeratorIfNoBlockNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
2020
import com.oracle.truffle.api.frame.VirtualFrame;
2121
import com.oracle.truffle.api.profiles.ConditionProfile;
22+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE;
2223

2324
public final class ReturnEnumeratorIfNoBlockNode extends RubyContextSourceNode {
2425

@@ -52,7 +53,7 @@ public Object execute(VirtualFrame frame) {
5253
final Object[] rubyArgs = RubyArguments.repack(frame.getArguments(), receiver, 0, 1);
5354
RubyArguments.setArgument(rubyArgs, 0, methodSymbol);
5455

55-
return toEnumNode.dispatch(null, receiver, "to_enum", rubyArgs);
56+
return toEnumNode.execute(null, receiver, "to_enum", rubyArgs, PRIVATE, null);
5657
} else {
5758
return method.execute(frame);
5859
}

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
import org.truffleruby.language.control.RetryException;
106106
import org.truffleruby.language.control.RaiseException;
107107
import org.truffleruby.language.control.ThrowException;
108+
import org.truffleruby.language.dispatch.DispatchConfiguration;
108109
import org.truffleruby.language.dispatch.DispatchNode;
109110
import org.truffleruby.language.dispatch.LiteralCallNode;
110111
import org.truffleruby.language.globals.ReadGlobalVariableNode;
@@ -139,6 +140,9 @@
139140
import com.oracle.truffle.api.source.SourceSection;
140141
import org.truffleruby.parser.RubySource;
141142

143+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE;
144+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PUBLIC;
145+
142146
@CoreModule("Truffle::CExt")
143147
public abstract class CExtNodes {
144148

@@ -319,7 +323,7 @@ protected int getCacheLimit() {
319323
public abstract static class SendWithoutCExtLockBaseNode extends PrimitiveArrayArgumentsNode {
320324
public Object sendWithoutCExtLock(VirtualFrame frame, Object receiver, RubySymbol method, Object block,
321325
ArgumentsDescriptor descriptor, Object[] args,
322-
DispatchNode dispatchNode, InlinedConditionProfile ownedProfile) {
326+
DispatchNode dispatchNode, DispatchConfiguration config, InlinedConditionProfile ownedProfile) {
323327
if (getContext().getOptions().CEXT_LOCK) {
324328
final ReentrantLock lock = getContext().getCExtensionsLock();
325329
boolean owned = ownedProfile.profile(this, lock.isHeldByCurrentThread());
@@ -328,15 +332,16 @@ public Object sendWithoutCExtLock(VirtualFrame frame, Object receiver, RubySymbo
328332
MutexOperations.unlockInternal(lock);
329333
}
330334
try {
331-
return dispatchNode.callWithFrameAndBlock(frame, receiver, method.getString(), block,
335+
return dispatchNode.callWithFrameAndBlock(config, frame, receiver, method.getString(), block,
332336
descriptor, args);
333337
} finally {
334338
if (owned) {
335339
MutexOperations.internalLockEvenWithException(getContext(), lock, this);
336340
}
337341
}
338342
} else {
339-
return dispatchNode.callWithFrameAndBlock(frame, receiver, method.getString(), block, descriptor, args);
343+
return dispatchNode.callWithFrameAndBlock(config, frame, receiver, method.getString(), block,
344+
descriptor, args);
340345
}
341346
}
342347
}
@@ -351,7 +356,7 @@ protected Object sendWithoutCExtLock(
351356
@Cached InlinedConditionProfile ownedProfile) {
352357
final Object[] args = arrayToObjectArrayNode.executeToObjectArray(argsArray);
353358
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,
354-
dispatchNode, ownedProfile);
359+
dispatchNode, PRIVATE, ownedProfile);
355360
}
356361

357362
}
@@ -366,7 +371,7 @@ protected Object sendWithoutCExtLock(
366371
@Cached InlinedConditionProfile ownedProfile) {
367372
final Object[] args = unwrapCArrayNode.execute(argv);
368373
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,
369-
dispatchNode, ownedProfile);
374+
dispatchNode, PRIVATE, ownedProfile);
370375
}
371376
}
372377

@@ -387,11 +392,11 @@ protected Object sendWithoutCExtLock(
387392
if (emptyProfile.profile(this, keywords.empty())) {
388393
args = LiteralCallNode.removeEmptyKeywordArguments(args);
389394
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,
390-
dispatchNode, ownedProfile);
395+
dispatchNode, PRIVATE, ownedProfile);
391396
} else {
392397
return sendWithoutCExtLock(frame, receiver, method, block,
393398
KeywordArgumentsDescriptorManager.EMPTY, args,
394-
dispatchNode, ownedProfile);
399+
dispatchNode, PRIVATE, ownedProfile);
395400
}
396401
}
397402
}
@@ -402,11 +407,11 @@ public abstract static class PublicSendARGVWithoutCExtLockNode extends SendWitho
402407
protected Object publicSendWithoutLock(
403408
VirtualFrame frame, Object receiver, RubySymbol method, Object argv, Object block,
404409
@Cached UnwrapCArrayNode unwrapCArrayNode,
405-
@Cached(parameters = "PUBLIC") DispatchNode dispatchNode,
410+
@Cached DispatchNode dispatchNode,
406411
@Cached InlinedConditionProfile ownedProfile) {
407412
final Object[] args = unwrapCArrayNode.execute(argv);
408413
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,
409-
dispatchNode, ownedProfile);
414+
dispatchNode, PUBLIC, ownedProfile);
410415
}
411416
}
412417

@@ -418,7 +423,7 @@ protected Object sendWithoutCExtLock(
418423
@Cached UnwrapCArrayNode unwrapCArrayNode,
419424
@Cached HashCastNode hashCastNode,
420425
@Cached InlinedConditionProfile emptyProfile,
421-
@Cached(parameters = "PUBLIC") DispatchNode dispatchNode,
426+
@Cached DispatchNode dispatchNode,
422427
@Cached InlinedConditionProfile ownedProfile) {
423428
Object[] args = unwrapCArrayNode.execute(argv);
424429

@@ -427,11 +432,11 @@ protected Object sendWithoutCExtLock(
427432
if (emptyProfile.profile(this, keywords.empty())) {
428433
args = LiteralCallNode.removeEmptyKeywordArguments(args);
429434
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,
430-
dispatchNode, ownedProfile);
435+
dispatchNode, PUBLIC, ownedProfile);
431436
} else {
432437
return sendWithoutCExtLock(frame, receiver, method, block,
433438
KeywordArgumentsDescriptorManager.EMPTY, args,
434-
dispatchNode, ownedProfile);
439+
dispatchNode, PUBLIC, ownedProfile);
435440
}
436441
}
437442
}

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

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

18+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE_RETURN_MISSING;
19+
1820
/** Attempts converting its argument to an array by calling #to_ary, or if that doesn't work, by wrapping it inside a
1921
* one-element array. */
2022
public abstract class ArrayConvertNode extends RubyBaseNode {
@@ -30,8 +32,8 @@ protected RubyArray castArray(RubyArray array) {
3032
protected RubyArray cast(Object object,
3133
@Cached ConditionProfile canCast,
3234
@Cached ArrayBuilderNode arrayBuilder,
33-
@Cached(parameters = "PRIVATE_RETURN_MISSING") DispatchNode toArrayNode) {
34-
final Object result = toArrayNode.call(object, "to_ary");
35+
@Cached DispatchNode toArrayNode) {
36+
final Object result = toArrayNode.call(PRIVATE_RETURN_MISSING, object, "to_ary");
3537
if (canCast.profile(result instanceof RubyArray)) {
3638
return (RubyArray) result;
3739
} else {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import static org.truffleruby.core.array.ArrayHelpers.setSize;
1313
import static org.truffleruby.core.array.ArrayHelpers.setStoreAndSize;
14-
import static org.truffleruby.language.dispatch.DispatchNode.PUBLIC;
14+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PUBLIC;
1515

1616
import java.util.Arrays;
1717

@@ -1320,7 +1320,7 @@ private static final class State {
13201320
}
13211321
}
13221322

1323-
@Child private DispatchNode dispatch = DispatchNode.create(PUBLIC);
1323+
@Child private DispatchNode dispatch = DispatchNode.create();
13241324

13251325
// Uses block and no Symbol
13261326

@@ -1438,7 +1438,7 @@ private Object injectSymbolHelper(VirtualFrame frame, RubyArray array, String sy
14381438
int n = start;
14391439
try {
14401440
for (; loopProfile.inject(n < arraySizeProfile.profile(array.size)); n++) {
1441-
accumulator = dispatch.callWithFrame(frame, accumulator, symbol, stores.read(store, n));
1441+
accumulator = dispatch.callWithFrame(PUBLIC, frame, accumulator, symbol, stores.read(store, n));
14421442
TruffleSafepoint.poll(this);
14431443
}
14441444
} finally {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import com.oracle.truffle.api.nodes.Node;
9090
import com.oracle.truffle.api.nodes.NodeUtil;
9191
import com.oracle.truffle.api.object.DynamicObjectLibrary;
92+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE;
9293

9394
@CoreModule(value = "BasicObject", isClass = true)
9495
public abstract class BasicObjectNodes {
@@ -559,8 +560,8 @@ protected Object send(Frame callerFrame, Object self, Object[] rubyArgs, RootCal
559560
@Cached DispatchNode dispatchNode,
560561
@Cached NameToJavaStringNode nameToJavaString) {
561562
Object name = RubyArguments.getArgument(rubyArgs, 0);
562-
return dispatchNode.dispatch(callerFrame, self, nameToJavaString.execute(this, name),
563-
RubyArguments.repack(rubyArgs, self, 1));
563+
return dispatchNode.execute(callerFrame, self, nameToJavaString.execute(this, name),
564+
RubyArguments.repack(rubyArgs, self, 1), PRIVATE, null);
564565
}
565566
}
566567

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.oracle.truffle.api.dsl.Specialization;
2424
import com.oracle.truffle.api.frame.VirtualFrame;
2525

26+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE_RETURN_MISSING;
27+
2628
public abstract class HashCastNode extends RubyBaseNode {
2729

2830
public abstract RubyHash execute(Object value);
@@ -35,8 +37,8 @@ protected RubyHash castHash(RubyHash hash) {
3537
@Specialization(guards = "!isRubyHash(object)")
3638
protected RubyHash cast(Object object,
3739
@Cached InlinedBranchProfile errorProfile,
38-
@Cached(parameters = "PRIVATE_RETURN_MISSING") DispatchNode toHashNode) {
39-
final Object result = toHashNode.call(object, "to_hash");
40+
@Cached DispatchNode toHashNode) {
41+
final Object result = toHashNode.call(PRIVATE_RETURN_MISSING, object, "to_hash");
4042

4143
if (result == DispatchNode.MISSING) {
4244
errorProfile.enter(this);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.oracle.truffle.api.dsl.NodeChild;
2626
import com.oracle.truffle.api.dsl.Specialization;
2727

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

3029
/** Splat as used to cast a value to an array if it isn't already, as in {@code *value}. Must be a RubyNode because it's
3130
* used in the translator. */
@@ -119,7 +118,7 @@ protected RubyArray splat(Object object,
119118
private Object callToA(Object nil) {
120119
if (toA == null) {
121120
CompilerDirectives.transferToInterpreterAndInvalidate();
122-
toA = insert(DispatchNode.create(PRIVATE_RETURN_MISSING));
121+
toA = insert(DispatchNode.create());
123122
}
124123
return toA.call(nil, "to_a");
125124
}

src/main/java/org/truffleruby/core/format/convert/ToLongNode.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import com.oracle.truffle.api.dsl.Specialization;
2626
import com.oracle.truffle.api.frame.VirtualFrame;
2727

28+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE_RETURN_MISSING;
29+
2830
@NodeChild("value")
2931
public abstract class ToLongNode extends FormatNode {
3032

@@ -75,12 +77,12 @@ protected long toLong(VirtualFrame frame, Object object) {
7577
@Specialization(
7678
guards = { "!errorIfNeedsConversion", "!isBoolean(object)", "!isRubyInteger(object)", "!isNil(object)" })
7779
protected static long toLong(VirtualFrame frame, Object object,
78-
@Cached(parameters = "PRIVATE_RETURN_MISSING") DispatchNode toIntNode,
80+
@Cached DispatchNode toIntNode,
7981
@Cached("create(true)") ToLongNode redoNode,
8082
@Cached InlinedBranchProfile noConversionAvailable,
8183
@Bind("this") Node node) {
8284

83-
Object result = toIntNode.call(object, "to_int");
85+
Object result = toIntNode.call(PRIVATE_RETURN_MISSING, object, "to_int");
8486
if (result == DispatchNode.MISSING) {
8587
noConversionAvailable.enter(node);
8688
throw new CantConvertException("can't convert Object to Integer");

src/main/java/org/truffleruby/core/format/convert/ToStringNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected Object toStringString(Object string,
110110
@Cached @Shared RubyStringLibrary libString,
111111
@Cached @Exclusive RubyStringLibrary argLibString) {
112112
if ("inspect".equals(conversionMethod)) {
113-
final Object value = getToStrNode().call(string, conversionMethod);
113+
final Object value = getToStrNode().call(PRIVATE_RETURN_MISSING, string, conversionMethod);
114114

115115
if (libString.isRubyString(value)) {
116116
return value;
@@ -126,10 +126,10 @@ protected Object toString(RubyArray array,
126126
@Cached @Shared RubyStringLibrary libString) {
127127
if (toSNode == null) {
128128
CompilerDirectives.transferToInterpreterAndInvalidate();
129-
toSNode = insert(DispatchNode.create(PRIVATE_RETURN_MISSING));
129+
toSNode = insert(DispatchNode.create());
130130
}
131131

132-
final Object value = toSNode.call(array, "to_s");
132+
final Object value = toSNode.call(PRIVATE_RETURN_MISSING, array, "to_s");
133133

134134
if (libString.isRubyString(value)) {
135135
return value;
@@ -142,7 +142,7 @@ protected Object toString(RubyArray array,
142142
guards = { "isNotRubyString(object)", "!isRubyArray(object)", "!isForeignObject(object)" })
143143
protected Object toString(Object object,
144144
@Cached @Shared RubyStringLibrary libString) {
145-
final Object value = getToStrNode().call(object, conversionMethod);
145+
final Object value = getToStrNode().call(PRIVATE_RETURN_MISSING, object, conversionMethod);
146146

147147
if (libString.isRubyString(value)) {
148148
return value;
@@ -172,7 +172,7 @@ protected RubyString toStringForeign(Object object,
172172
private DispatchNode getToStrNode() {
173173
if (toStrNode == null) {
174174
CompilerDirectives.transferToInterpreterAndInvalidate();
175-
toStrNode = insert(DispatchNode.create(PRIVATE_RETURN_MISSING));
175+
toStrNode = insert(DispatchNode.create());
176176
}
177177
return toStrNode;
178178
}

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@
167167
import com.oracle.truffle.api.object.Shape;
168168
import com.oracle.truffle.api.source.SourceSection;
169169

170+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE;
171+
import static org.truffleruby.language.dispatch.DispatchConfiguration.PUBLIC;
172+
170173
@CoreModule("Kernel")
171174
public abstract class KernelNodes {
172175

@@ -1228,8 +1231,7 @@ protected RubyMethod method(Frame callerFrame, Object self, Object[] rubyArgs, R
12281231
@Cached ToStringOrSymbolNode toStringOrSymbolNode,
12291232
@Cached GetMethodObjectNode getMethodObjectNode) {
12301233
Object name = toStringOrSymbolNode.execute(RubyArguments.getArgument(rubyArgs, 0));
1231-
return getMethodObjectNode.execute(callerFrame, self, name,
1232-
DispatchConfiguration.PRIVATE);
1234+
return getMethodObjectNode.execute(callerFrame, self, name, PRIVATE);
12331235
}
12341236

12351237
}
@@ -1287,10 +1289,9 @@ protected boolean isNil() {
12871289
@CoreMethod(names = "p", isModuleFunction = true, required = 1)
12881290
public abstract static class DebugPrintNode extends CoreMethodArrayArgumentsNode {
12891291

1290-
@Child private DispatchNode callInspectNode = DispatchNode.create();
1291-
12921292
@Specialization
1293-
protected Object p(VirtualFrame frame, Object value) {
1293+
protected Object p(VirtualFrame frame, Object value,
1294+
@Cached DispatchNode callInspectNode) {
12941295
Object inspected = callInspectNode.call(value, "inspect");
12951296
print(inspected);
12961297
return value;
@@ -1360,8 +1361,7 @@ protected RubyMethod method(Frame callerFrame, Object self, Object[] rubyArgs, R
13601361
@Cached ToStringOrSymbolNode toStringOrSymbolNode,
13611362
@Cached GetMethodObjectNode getMethodObjectNode) {
13621363
Object name = toStringOrSymbolNode.execute(RubyArguments.getArgument(rubyArgs, 0));
1363-
return getMethodObjectNode.execute(callerFrame, self, name,
1364-
DispatchConfiguration.PUBLIC);
1364+
return getMethodObjectNode.execute(callerFrame, self, name, PUBLIC);
13651365
}
13661366

13671367
}
@@ -1391,11 +1391,12 @@ public abstract static class PublicSendNode extends AlwaysInlinedMethodNode {
13911391

13921392
@Specialization
13931393
protected Object send(Frame callerFrame, Object self, Object[] rubyArgs, RootCallTarget target,
1394-
@Cached(parameters = "PUBLIC") DispatchNode dispatchNode,
1394+
@Cached DispatchNode dispatchNode,
13951395
@Cached NameToJavaStringNode nameToJavaString) {
13961396
Object name = RubyArguments.getArgument(rubyArgs, 0);
13971397
Object[] newArgs = RubyArguments.repack(rubyArgs, self, 1);
1398-
return dispatchNode.dispatch(callerFrame, self, nameToJavaString.execute(this, name), newArgs);
1398+
return dispatchNode.execute(callerFrame, self, nameToJavaString.execute(this, name), newArgs, PUBLIC,
1399+
null);
13991400
}
14001401

14011402
}

0 commit comments

Comments
 (0)