Skip to content

Commit 06cb0ff

Browse files
committed
DispatchConfig moved to callers
1 parent b6c229a commit 06cb0ff

17 files changed

+260
-226
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.dispatch(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

@@ -314,7 +318,7 @@ protected int getCacheLimit() {
314318
public abstract static class SendWithoutCExtLockBaseNode extends PrimitiveArrayArgumentsNode {
315319
public Object sendWithoutCExtLock(VirtualFrame frame, Object receiver, RubySymbol method, Object block,
316320
ArgumentsDescriptor descriptor, Object[] args,
317-
DispatchNode dispatchNode, InlinedConditionProfile ownedProfile) {
321+
DispatchNode dispatchNode, DispatchConfiguration config, InlinedConditionProfile ownedProfile) {
318322
if (getContext().getOptions().CEXT_LOCK) {
319323
final ReentrantLock lock = getContext().getCExtensionsLock();
320324
boolean owned = ownedProfile.profile(this, lock.isHeldByCurrentThread());
@@ -323,15 +327,16 @@ public Object sendWithoutCExtLock(VirtualFrame frame, Object receiver, RubySymbo
323327
MutexOperations.unlockInternal(lock);
324328
}
325329
try {
326-
return dispatchNode.callWithFrameAndBlock(frame, receiver, method.getString(), block,
330+
return dispatchNode.callWithFrameAndBlock(frame, receiver, method.getString(), config, block,
327331
descriptor, args);
328332
} finally {
329333
if (owned) {
330334
MutexOperations.internalLockEvenWithException(getContext(), lock, this);
331335
}
332336
}
333337
} else {
334-
return dispatchNode.callWithFrameAndBlock(frame, receiver, method.getString(), block, descriptor, args);
338+
return dispatchNode.callWithFrameAndBlock(frame, receiver, method.getString(), config, block,
339+
descriptor, args);
335340
}
336341
}
337342
}
@@ -346,7 +351,7 @@ protected Object sendWithoutCExtLock(
346351
@Cached InlinedConditionProfile ownedProfile) {
347352
final Object[] args = arrayToObjectArrayNode.executeToObjectArray(argsArray);
348353
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,
349-
dispatchNode, ownedProfile);
354+
dispatchNode, PRIVATE, ownedProfile);
350355
}
351356

352357
}
@@ -361,7 +366,7 @@ protected Object sendWithoutCExtLock(
361366
@Cached InlinedConditionProfile ownedProfile) {
362367
final Object[] args = unwrapCArrayNode.execute(argv);
363368
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,
364-
dispatchNode, ownedProfile);
369+
dispatchNode, PRIVATE, ownedProfile);
365370
}
366371
}
367372

@@ -382,11 +387,11 @@ protected Object sendWithoutCExtLock(
382387
if (emptyProfile.profile(this, keywords.empty())) {
383388
args = LiteralCallNode.removeEmptyKeywordArguments(args);
384389
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,
385-
dispatchNode, ownedProfile);
390+
dispatchNode, PRIVATE, ownedProfile);
386391
} else {
387392
return sendWithoutCExtLock(frame, receiver, method, block,
388393
KeywordArgumentsDescriptorManager.EMPTY, args,
389-
dispatchNode, ownedProfile);
394+
dispatchNode, PRIVATE, ownedProfile);
390395
}
391396
}
392397
}
@@ -397,11 +402,11 @@ public abstract static class PublicSendARGVWithoutCExtLockNode extends SendWitho
397402
protected Object publicSendWithoutLock(
398403
VirtualFrame frame, Object receiver, RubySymbol method, Object argv, Object block,
399404
@Cached UnwrapCArrayNode unwrapCArrayNode,
400-
@Cached(parameters = "PUBLIC") DispatchNode dispatchNode,
405+
@Cached DispatchNode dispatchNode,
401406
@Cached InlinedConditionProfile ownedProfile) {
402407
final Object[] args = unwrapCArrayNode.execute(argv);
403408
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,
404-
dispatchNode, ownedProfile);
409+
dispatchNode, PUBLIC, ownedProfile);
405410
}
406411
}
407412

@@ -413,7 +418,7 @@ protected Object sendWithoutCExtLock(
413418
@Cached UnwrapCArrayNode unwrapCArrayNode,
414419
@Cached HashCastNode hashCastNode,
415420
@Cached InlinedConditionProfile emptyProfile,
416-
@Cached(parameters = "PUBLIC") DispatchNode dispatchNode,
421+
@Cached DispatchNode dispatchNode,
417422
@Cached InlinedConditionProfile ownedProfile) {
418423
Object[] args = unwrapCArrayNode.execute(argv);
419424

@@ -422,11 +427,11 @@ protected Object sendWithoutCExtLock(
422427
if (emptyProfile.profile(this, keywords.empty())) {
423428
args = LiteralCallNode.removeEmptyKeywordArguments(args);
424429
return sendWithoutCExtLock(frame, receiver, method, block, EmptyArgumentsDescriptor.INSTANCE, args,
425-
dispatchNode, ownedProfile);
430+
dispatchNode, PUBLIC, ownedProfile);
426431
} else {
427432
return sendWithoutCExtLock(frame, receiver, method, block,
428433
KeywordArgumentsDescriptorManager.EMPTY, args,
429-
dispatchNode, ownedProfile);
434+
dispatchNode, PUBLIC, ownedProfile);
430435
}
431436
}
432437
}

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(object, "to_ary", PRIVATE_RETURN_MISSING);
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(frame, accumulator, symbol, PUBLIC, stores.read(store, n));
14421442
TruffleSafepoint.poll(this);
14431443
}
14441444
} finally {

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

Lines changed: 2 additions & 1 deletion
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 {
@@ -560,7 +561,7 @@ protected Object send(Frame callerFrame, Object self, Object[] rubyArgs, RootCal
560561
@Cached NameToJavaStringNode nameToJavaString) {
561562
Object name = RubyArguments.getArgument(rubyArgs, 0);
562563
return dispatchNode.dispatch(callerFrame, self, nameToJavaString.execute(this, name),
563-
RubyArguments.repack(rubyArgs, self, 1));
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(object, "to_hash", PRIVATE_RETURN_MISSING);
4042

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ protected RubyArray splat(Object object,
119119
private Object callToA(Object nil) {
120120
if (toA == null) {
121121
CompilerDirectives.transferToInterpreterAndInvalidate();
122-
toA = insert(DispatchNode.create(PRIVATE_RETURN_MISSING));
122+
toA = insert(DispatchNode.create());
123123
}
124-
return toA.call(nil, "to_a");
124+
return toA.call(nil, "to_a", PRIVATE_RETURN_MISSING);
125125
}
126126

127127
private RubyArray executeDup(RubyArray array) {

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(object, "to_int", PRIVATE_RETURN_MISSING);
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(string, conversionMethod, PRIVATE_RETURN_MISSING);
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(array, "to_s", PRIVATE_RETURN_MISSING);
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(object, conversionMethod, PRIVATE_RETURN_MISSING);
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.dispatch(callerFrame, self, nameToJavaString.execute(this, name), newArgs, PUBLIC,
1399+
null);
13991400
}
14001401

14011402
}

0 commit comments

Comments
 (0)