Skip to content

Commit 044cdfb

Browse files
committed
Convert CallBlockNode to DSL inlinable
1 parent 32ace57 commit 044cdfb

30 files changed

+150
-118
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ Object captureException(RubyProc block,
14731473
@Cached InlinedBranchProfile noExceptionProfile,
14741474
@Cached CallBlockNode yieldNode) {
14751475
try {
1476-
yieldNode.yield(block);
1476+
yieldNode.yield(this, block);
14771477
noExceptionProfile.enter(this);
14781478
return nil;
14791479
} catch (Throwable e) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Object doCatch(Object tag, RubyProc block,
118118
@Cached ReferenceEqualNode referenceEqualNode,
119119
@Cached CallBlockNode yieldNode) {
120120
try {
121-
return yieldNode.yield(block, tag);
121+
return yieldNode.yield(this, block, tag);
122122
} catch (ThrowException e) {
123123
catchProfile.enter(this);
124124
if (matchProfile.profile(this, referenceEqualNode.execute(this, e.getTag(), tag))) {
@@ -154,7 +154,7 @@ Object vmExtendedModules(Object object, RubyProc block,
154154

155155
if (isSingletonProfile.profile(this, metaClass.isSingleton)) {
156156
for (RubyModule included : metaClass.fields.prependedAndIncludedModules()) {
157-
yieldNode.yield(block, included);
157+
yieldNode.yield(this, block, included);
158158
}
159159
}
160160

@@ -420,7 +420,7 @@ Object getSection(Object section, RubyProc block,
420420
.getNativeConfiguration()
421421
.getSection(RubyGuards.getJavaString(section))) {
422422
final RubyString key = createString(fromJavaStringNode, entry.getKey(), Encodings.UTF_8); // CR_7BIT
423-
yieldNode.yield(block, key, entry.getValue());
423+
yieldNode.yield(this, block, key, entry.getValue());
424424
}
425425

426426
return nil;

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ private Object delete(RubyArray array, Object value, Object maybeBlock,
744744
if (maybeBlock == nil) {
745745
return nil;
746746
} else {
747-
return yieldNode.yield((RubyProc) maybeBlock, value);
747+
return yieldNode.yield(this, (RubyProc) maybeBlock, value);
748748
}
749749
}
750750
}
@@ -807,7 +807,7 @@ Object each(RubyArray array, RubyProc block,
807807
public void accept(Node node, CallBlockNode yieldNode, RubyArray array, Object state, Object element, int index,
808808
BooleanCastNode booleanCastNode) {
809809
RubyProc block = (RubyProc) state;
810-
yieldNode.yield(block, element);
810+
yieldNode.yield(node, block, element);
811811
}
812812

813813
}
@@ -827,7 +827,7 @@ Object eachOther(RubyArray array, RubyProc block,
827827
public void accept(Node node, CallBlockNode yieldNode, RubyArray array, Object state, Object element, int index,
828828
BooleanCastNode booleanCastNode) {
829829
RubyProc block = (RubyProc) state;
830-
yieldNode.yield(block, element, index);
830+
yieldNode.yield(node, block, element, index);
831831
}
832832

833833
}
@@ -1100,7 +1100,6 @@ static boolean include(RubyArray array, Object value,
11001100
@ImportStatic({ ArrayGuards.class, ArrayStoreLibrary.class })
11011101
public abstract static class InitializeNode extends CoreMethodArrayArgumentsNode {
11021102

1103-
@Child private ToIntNode toIntNode;
11041103
@Child private DispatchNode toAryNode;
11051104
@Child private KernelNodes.RespondToNode respondToToAryNode;
11061105

@@ -1206,25 +1205,26 @@ RubyArray initializeSizeOther(RubyArray array, Object size, Object fillingValue,
12061205
// With block
12071206

12081207
@Specialization(guards = "size >= 0")
1209-
Object initializeBlock(RubyArray array, int size, Object unusedFillingValue, RubyProc block,
1208+
static Object initializeBlock(RubyArray array, int size, Object unusedFillingValue, RubyProc block,
12101209
@Cached ArrayBuilderNode arrayBuilder,
12111210
@CachedLibrary(limit = "2") @Exclusive ArrayStoreLibrary stores,
12121211
@Cached @Shared IsSharedNode isSharedNode,
12131212
@Cached @Shared ConditionProfile sharedProfile,
12141213
@Cached @Exclusive LoopConditionProfile loopProfile,
1215-
@Cached CallBlockNode yieldNode) {
1214+
@Cached CallBlockNode yieldNode,
1215+
@Bind("this") Node node) {
12161216
BuilderState state = arrayBuilder.start(size);
12171217

12181218
int n = 0;
12191219
try {
12201220
for (; loopProfile.inject(n < size); n++) {
1221-
final Object value = yieldNode.yield(block, n);
1221+
final Object value = yieldNode.yield(node, block, n);
12221222
arrayBuilder.appendValue(state, n, value);
12231223
}
12241224
} finally {
1225-
profileAndReportLoopCount(loopProfile, n);
1225+
profileAndReportLoopCount(node, loopProfile, n);
12261226
Object store = arrayBuilder.finish(state, n);
1227-
if (sharedProfile.profile(isSharedNode.executeIsShared(this, array))) {
1227+
if (sharedProfile.profile(isSharedNode.executeIsShared(node, array))) {
12281228
store = stores.makeShared(store, n);
12291229
}
12301230
setStoreAndSize(array, store, n);
@@ -1355,7 +1355,7 @@ private Object injectBlockHelper(RubyArray array,
13551355
public void accept(Node node, CallBlockNode yieldNode, RubyArray array, Object stateObject, Object element,
13561356
int index, BooleanCastNode booleanCastNode) {
13571357
final State state = (State) stateObject;
1358-
state.accumulator = yieldNode.yield(state.block, state.accumulator, element);
1358+
state.accumulator = yieldNode.yield(node, state.block, state.accumulator, element);
13591359
}
13601360

13611361
// Uses Symbol and no block
@@ -1472,7 +1472,7 @@ public void accept(Node node, CallBlockNode yieldNode, RubyArray array, Object s
14721472
int index, BooleanCastNode booleanCastNode) {
14731473
final State state = (State) stateObject;
14741474

1475-
Object value = yieldNode.yield(state.block, element);
1475+
Object value = yieldNode.yield(node, state.block, element);
14761476
arrayBuilder.appendValue(state.builderState, index, value);
14771477
}
14781478

@@ -1495,7 +1495,7 @@ Object map(RubyArray array, RubyProc block,
14951495
public void accept(Node node, CallBlockNode yieldNode, RubyArray array, Object state, Object element, int index,
14961496
BooleanCastNode booleanCastNode) {
14971497
RubyProc block = (RubyProc) state;
1498-
writeNode.executeWrite(array, index, yieldNode.yield(block, element));
1498+
writeNode.executeWrite(array, index, yieldNode.yield(node, block, element));
14991499
}
15001500

15011501
}
@@ -1768,7 +1768,7 @@ public void accept(Node node, CallBlockNode yieldNode, RubyArray array, Object s
17681768
int index, BooleanCastNode booleanCastNode) {
17691769
final State state = (State) stateObject;
17701770

1771-
if (!booleanCastNode.execute(node, yieldNode.yield(state.block, element))) {
1771+
if (!booleanCastNode.execute(node, yieldNode.yield(node, state.block, element))) {
17721772
arrayBuilder.appendValue(state.builderState, state.newArraySize, element);
17731773
state.newArraySize++;
17741774
}
@@ -1978,7 +1978,7 @@ public void accept(Node node, CallBlockNode yieldNode, RubyArray array, Object s
19781978
int index, BooleanCastNode booleanCastNode) {
19791979
final State state = (State) stateObject;
19801980

1981-
if (booleanCastNode.execute(node, yieldNode.yield(state.block, element))) {
1981+
if (booleanCastNode.execute(node, yieldNode.yield(node, state.block, element))) {
19821982
arrayBuilder.appendValue(state.builderState, state.selectedSize, element);
19831983
state.selectedSize++;
19841984
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ Object instanceExec(VirtualFrame frame, Object receiver, Object[] arguments, Rub
400400
new SingletonClassOfSelfDefaultDefinee(receiver),
401401
block.declarationContext.getRefinements());
402402
var descriptor = RubyArguments.getDescriptor(frame);
403-
return callBlockNode.executeCallBlock(declarationContext, block, receiver, nil, descriptor, arguments);
403+
return callBlockNode.executeCallBlock(this, declarationContext, block, receiver, nil, descriptor,
404+
arguments);
404405
}
405406

406407
@Specialization
@@ -419,14 +420,15 @@ public abstract Object execute(Node node, ArgumentsDescriptor descriptor, Object
419420
RubyProc block);
420421

421422
@Specialization
422-
static Object instanceExec(ArgumentsDescriptor descriptor, Object self, Object[] arguments, RubyProc block,
423+
static Object instanceExec(
424+
Node node, ArgumentsDescriptor descriptor, Object self, Object[] arguments, RubyProc block,
423425
@Cached CallBlockNode callBlockNode) {
424426
final DeclarationContext declarationContext = new DeclarationContext(
425427
Visibility.PUBLIC,
426428
new SingletonClassOfSelfDefaultDefinee(self),
427429
block.declarationContext.getRefinements());
428430

429-
return callBlockNode.executeCallBlock(declarationContext, block, self, nil, descriptor, arguments);
431+
return callBlockNode.executeCallBlock(node, declarationContext, block, self, nil, descriptor, arguments);
430432
}
431433

432434
}

src/main/java/org/truffleruby/core/encoding/EncodingNodes.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,12 @@ Object allocate(RubyClass rubyClass) {
485485
@Primitive(name = "encoding_each_alias")
486486
public abstract static class EachAliasNode extends PrimitiveArrayArgumentsNode {
487487

488-
@Child private CallBlockNode yieldNode = CallBlockNode.create();
489488
@Child private TruffleString.FromByteArrayNode fromByteArrayNode = TruffleString.FromByteArrayNode.create();
490489

491490
@TruffleBoundary
492491
@Specialization
493-
Object eachAlias(RubyProc block) {
492+
Object eachAlias(RubyProc block,
493+
@Cached CallBlockNode yieldNode) {
494494
var iterator = EncodingDB.getAliases().entryIterator();
495495
while (iterator.hasNext()) {
496496
var entry = iterator.next();
@@ -499,6 +499,7 @@ Object eachAlias(RubyProc block) {
499499
ArrayUtils.extractRange(entry.bytes, entry.p, entry.end),
500500
Encodings.US_ASCII); // CR_7BIT
501501
yieldNode.yield(
502+
this,
502503
block,
503504
aliasName,
504505
Encodings.getBuiltInEncoding(entry.value.getEncoding()));

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

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

12+
import com.oracle.truffle.api.dsl.Bind;
1213
import com.oracle.truffle.api.dsl.NeverDefault;
1314
import com.oracle.truffle.api.frame.Frame;
1415
import com.oracle.truffle.api.library.CachedLibrary;
16+
import com.oracle.truffle.api.nodes.Node;
1517
import com.oracle.truffle.api.object.Shape;
1618
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
1719
import org.truffleruby.RubyLanguage;
@@ -322,16 +324,17 @@ Object defaultValue(RubyHash hash) {
322324
public abstract static class DeleteNode extends CoreMethodArrayArgumentsNode {
323325

324326
@Specialization(limit = "hashStrategyLimit()")
325-
Object delete(RubyHash hash, Object key, Object maybeBlock,
327+
static Object delete(RubyHash hash, Object key, Object maybeBlock,
326328
@CachedLibrary("hash.store") HashStoreLibrary hashes,
327329
@Cached CallBlockNode yieldNode,
328330
@Cached @Shared InlinedConditionProfile hasValue,
329-
@Cached @Shared InlinedConditionProfile hasBlock) {
331+
@Cached @Shared InlinedConditionProfile hasBlock,
332+
@Bind("this") Node node) {
330333
final Object value = hashes.delete(hash.store, hash, key);
331-
if (hasValue.profile(this, value != null)) {
334+
if (hasValue.profile(node, value != null)) {
332335
return value;
333-
} else if (hasBlock.profile(this, maybeBlock != nil)) {
334-
return yieldNode.yield((RubyProc) maybeBlock, key);
336+
} else if (hasBlock.profile(node, maybeBlock != nil)) {
337+
return yieldNode.yield(node, (RubyProc) maybeBlock, key);
335338
} else {
336339
return nil;
337340
}
@@ -353,7 +356,7 @@ RubyHash each(RubyHash hash, RubyProc block,
353356

354357
@Override
355358
public void accept(int index, Object key, Object value, Object state) {
356-
callBlockNode.yield((RubyProc) state, createArray(new Object[]{ key, value }));
359+
callBlockNode.yieldCached((RubyProc) state, createArray(new Object[]{ key, value }));
357360
}
358361
}
359362

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ Object yieldPair(RubyProc block, Object key, Object value,
133133
// MRI behavior, see rb_hash_each_pair()
134134
// We use getMethodArityNumber() here since for non-lambda the semantics are the same for both branches
135135
if (arityMoreThanOne.profile(this, block.arity.getMethodArityNumber() > 1)) {
136-
return yieldNode.yield(block, key, value);
136+
return yieldNode.yield(this, block, key, value);
137137
} else {
138-
return yieldNode.yield(block, createArray(new Object[]{ key, value }));
138+
return yieldNode.yield(this, block, createArray(new Object[]{ key, value }));
139139
}
140140
}
141141
}

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ Object classExec(ArgumentsDescriptor descriptor, RubyModule self, Object[] args,
808808
new FixedDefaultDefinee(self),
809809
block.declarationContext.getRefinements());
810810

811-
return callBlockNode.executeCallBlock(declarationContext, block, self, nil, descriptor, args);
811+
return callBlockNode.executeCallBlock(this, declarationContext, block, self, nil, descriptor, args);
812812
}
813813
}
814814

@@ -2262,7 +2262,7 @@ RubyModule refine(RubyModule namespace, RubyModule moduleToRefine, RubyProc bloc
22622262
}
22632263
}
22642264

2265-
CallBlockNode.getUncached().executeCallBlock(
2265+
CallBlockNode.executeUncached(
22662266
declarationContext,
22672267
block,
22682268
refinement,

src/main/java/org/truffleruby/core/monitor/TruffleMonitorNodes.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,17 @@ public abstract class TruffleMonitorNodes {
2929
@Primitive(name = "monitor_synchronize")
3030
public abstract static class SynchronizeNode extends PrimitiveArrayArgumentsNode {
3131

32-
@Child private CallBlockNode yieldNode = CallBlockNode.create();
33-
3432
@Specialization
3533
Object synchronizeOnMutex(RubyMutex mutex, RubyProc block,
36-
@Cached InlinedBranchProfile errorProfile) {
34+
@Cached InlinedBranchProfile errorProfile,
35+
@Cached CallBlockNode yieldNode) {
3736
/* Like Mutex#synchronize we must maintain the owned locks list here as the monitor might be exited inside
3837
* synchronize block and then re-entered again before the end, and we have to make sure the list of owned
3938
* locks remains consistent. */
4039
final RubyThread thread = getLanguage().getCurrentThread();
4140
MutexOperations.lock(getContext(), mutex.lock, thread, this);
4241
try {
43-
return yieldNode.yield(block);
42+
return yieldNode.yield(this, block);
4443
} finally {
4544
MutexOperations.checkOwnedMutex(getContext(), mutex.lock, this, errorProfile);
4645
MutexOperations.unlock(mutex.lock, thread);

src/main/java/org/truffleruby/core/mutex/MutexNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Object synchronize(RubyMutex mutex, RubyProc block,
135135
* locks list to be in consistent state at the end. */
136136
MutexOperations.lock(getContext(), lock, thread, this);
137137
try {
138-
return yieldNode.yield(block);
138+
return yieldNode.yield(this, block);
139139
} finally {
140140
MutexOperations.checkOwnedMutex(getContext(), lock, this, errorProfile);
141141
MutexOperations.unlock(lock, thread);

0 commit comments

Comments
 (0)