Skip to content

Commit 27ffb2c

Browse files
committed
[GR-19220] Represent missing block argument as nil instead of NotProvided (#2241)
PullRequest: truffleruby/2387
2 parents 22161c4 + 3def288 commit 27ffb2c

22 files changed

+228
-324
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ public RubyNode createCoreMethodNode(NodeFactory<? extends RubyNode> nodeFactory
306306
/* The way we write specializations for getting a block or not is that we use NotProvided like a missing
307307
* argument. The block coming into the method is actually always Nil or RubyProc, so here we check which and
308308
* convert Nil to NotProvided. */
309-
argumentsNodes[i++] = new ReadBlockFromCurrentFrameArgumentsNode.ConvertNilBlockToNotProvidedNode(
310-
new ReadBlockFromCurrentFrameArgumentsNode());
309+
argumentsNodes[i++] = new ReadBlockFromCurrentFrameArgumentsNode();
311310
}
312311

313312
if (!method.keywordAsOptional().isEmpty()) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
import org.truffleruby.interop.TranslateInteropExceptionNode;
6969
import org.truffleruby.core.string.ImmutableRubyString;
7070
import org.truffleruby.language.LexicalScope;
71-
import org.truffleruby.language.NotProvided;
7271
import org.truffleruby.language.RubyContextNode;
7372
import org.truffleruby.language.RubyDynamicObject;
7473
import org.truffleruby.language.RubyGuards;
@@ -1119,7 +1118,7 @@ protected RubyClass classNew(RubyClass superclass) {
11191118

11201119
RubyClass klass = (RubyClass) allocateNode
11211120
.call(getContext().getCoreLibrary().classClass, "__allocate__");
1122-
return initializeClassNode.executeInitialize(klass, superclass, NotProvided.INSTANCE);
1121+
return initializeClassNode.executeInitialize(klass, superclass, nil);
11231122
}
11241123

11251124
}

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

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ private Object delete(VirtualFrame frame, RubyArray array, Object value, Object
697697
array.size = i;
698698
return found;
699699
} else {
700-
if (maybeBlock == NotProvided.INSTANCE) {
700+
if (maybeBlock == nil) {
701701
return nil;
702702
} else {
703703
return yield((RubyProc) maybeBlock, value);
@@ -961,7 +961,7 @@ public abstract static class FillNode extends ArrayCoreMethodNode {
961961
@Specialization(
962962
guards = { "args.length == 1", "stores.acceptsValue(array.store, value(args))" },
963963
limit = "storageStrategyLimit()")
964-
protected RubyArray fill(RubyArray array, Object[] args, NotProvided block,
964+
protected RubyArray fill(RubyArray array, Object[] args, Nil block,
965965
@CachedLibrary("array.store") ArrayStoreLibrary stores,
966966
@Cached PropagateSharingNode propagateSharingNode,
967967
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
@@ -983,7 +983,7 @@ protected Object value(Object[] args) {
983983
}
984984

985985
@Specialization
986-
protected Object fillFallback(VirtualFrame frame, RubyArray array, Object[] args, NotProvided block,
986+
protected Object fillFallback(VirtualFrame frame, RubyArray array, Object[] args, Nil block,
987987
@Cached DispatchNode callFillInternal) {
988988
return callFillInternal.call(array, "fill_internal", args);
989989
}
@@ -1066,14 +1066,10 @@ public abstract static class InitializeNode extends YieldingCoreMethodNode {
10661066
@Child private KernelNodes.RespondToNode respondToToAryNode;
10671067

10681068
protected abstract RubyArray executeInitialize(RubyArray array, Object size, Object fillingValue,
1069-
NotProvided block);
1069+
Nil block);
10701070

10711071
@Specialization
1072-
protected RubyArray initializeNoArgs(
1073-
RubyArray array,
1074-
NotProvided size,
1075-
NotProvided fillingValue,
1076-
NotProvided block) {
1072+
protected RubyArray initializeNoArgs(RubyArray array, NotProvided size, NotProvided fillingValue, Nil block) {
10771073
setStoreAndSize(array, ArrayStoreLibrary.INITIAL_STORE, 0);
10781074
return array;
10791075
}
@@ -1112,20 +1108,12 @@ protected RubyArray initializeNegativeLongSize(
11121108

11131109
@TruffleBoundary
11141110
@Specialization(guards = "size >= MAX_INT")
1115-
protected RubyArray initializeSizeTooBig(
1116-
RubyArray array,
1117-
long size,
1118-
NotProvided fillingValue,
1119-
NotProvided block) {
1111+
protected RubyArray initializeSizeTooBig(RubyArray array, long size, NotProvided fillingValue, Nil block) {
11201112
throw new RaiseException(getContext(), coreExceptions().argumentError("array size too big", this));
11211113
}
11221114

11231115
@Specialization(guards = "size >= 0")
1124-
protected RubyArray initializeWithSizeNoValue(
1125-
RubyArray array,
1126-
int size,
1127-
NotProvided fillingValue,
1128-
NotProvided block) {
1116+
protected RubyArray initializeWithSizeNoValue(RubyArray array, int size, NotProvided fillingValue, Nil block) {
11291117
final Object[] store = new Object[size];
11301118
Arrays.fill(store, nil);
11311119
setStoreAndSize(array, store, size);
@@ -1135,11 +1123,7 @@ protected RubyArray initializeWithSizeNoValue(
11351123
@Specialization(
11361124
guards = { "size >= 0", "wasProvided(fillingValue)" },
11371125
limit = "storageStrategyLimit()")
1138-
protected RubyArray initializeWithSizeAndValue(
1139-
RubyArray array,
1140-
int size,
1141-
Object fillingValue,
1142-
NotProvided block,
1126+
protected RubyArray initializeWithSizeAndValue(RubyArray array, int size, Object fillingValue, Nil block,
11431127
@CachedLibrary("array.store") ArrayStoreLibrary stores,
11441128
@CachedLibrary(limit = "1") ArrayStoreLibrary allocatedStores,
11451129
@Cached ConditionProfile needsFill,
@@ -1159,7 +1143,7 @@ protected RubyArray initializeWithSizeAndValue(
11591143

11601144
@Specialization(
11611145
guards = { "wasProvided(size)", "!isInteger(size)", "!isLong(size)", "wasProvided(fillingValue)" })
1162-
protected RubyArray initializeSizeOther(RubyArray array, Object size, Object fillingValue, NotProvided block) {
1146+
protected RubyArray initializeSizeOther(RubyArray array, Object size, Object fillingValue, Nil block) {
11631147
int intSize = toInt(size);
11641148
return executeInitialize(array, intSize, fillingValue, block);
11651149
}
@@ -1202,7 +1186,7 @@ protected RubyArray initializeFromArray(
12021186

12031187
@Specialization(
12041188
guards = { "!isInteger(object)", "!isLong(object)", "wasProvided(object)", "!isRubyArray(object)" })
1205-
protected RubyArray initialize(RubyArray array, Object object, NotProvided unusedValue, NotProvided block) {
1189+
protected RubyArray initialize(RubyArray array, Object object, NotProvided unusedValue, Nil block) {
12061190
RubyArray copy = null;
12071191
if (respondToToAry(getLanguage(), object)) {
12081192
Object toAryResult = callToAry(object);
@@ -1212,10 +1196,10 @@ protected RubyArray initialize(RubyArray array, Object object, NotProvided unuse
12121196
}
12131197

12141198
if (copy != null) {
1215-
return executeInitialize(array, copy, NotProvided.INSTANCE, NotProvided.INSTANCE);
1199+
return executeInitialize(array, copy, NotProvided.INSTANCE, nil);
12161200
} else {
12171201
int size = toInt(object);
1218-
return executeInitialize(array, size, NotProvided.INSTANCE, NotProvided.INSTANCE);
1202+
return executeInitialize(array, size, NotProvided.INSTANCE, nil);
12191203
}
12201204
}
12211205

@@ -2116,7 +2100,7 @@ protected RubyArray sortEmpty(RubyArray array, Object unusedBlock) {
21162100
@Specialization(
21172101
guards = { "!isEmptyArray(array)", "isSmall(array)" },
21182102
limit = "storageStrategyLimit()")
2119-
protected RubyArray sortVeryShort(VirtualFrame frame, RubyArray array, NotProvided block,
2103+
protected RubyArray sortVeryShort(VirtualFrame frame, RubyArray array, Nil block,
21202104
@CachedLibrary("array.store") ArrayStoreLibrary originalStores,
21212105
@CachedLibrary(limit = "1") ArrayStoreLibrary stores,
21222106
@Cached DispatchNode compareDispatchNode,
@@ -2165,7 +2149,7 @@ protected RubyArray sortVeryShort(VirtualFrame frame, RubyArray array, NotProvid
21652149
"getLanguage().coreMethodAssumptions.integerCmpAssumption",
21662150
"getLanguage().coreMethodAssumptions.floatCmpAssumption" },
21672151
limit = "storageStrategyLimit()")
2168-
protected Object sortPrimitiveArrayNoBlock(RubyArray array, NotProvided block,
2152+
protected Object sortPrimitiveArrayNoBlock(RubyArray array, Nil block,
21692153
@CachedLibrary("array.store") ArrayStoreLibrary stores,
21702154
@CachedLibrary(limit = "1") ArrayStoreLibrary mutableStores) {
21712155
final int size = array.size;
@@ -2179,7 +2163,7 @@ protected Object sortPrimitiveArrayNoBlock(RubyArray array, NotProvided block,
21792163
@Specialization(
21802164
guards = { "!isEmptyArray(array)", "!isSmall(array)" },
21812165
limit = "storageStrategyLimit()")
2182-
protected Object sortArrayWithoutBlock(RubyArray array, NotProvided block,
2166+
protected Object sortArrayWithoutBlock(RubyArray array, Nil block,
21832167
@CachedLibrary("array.store") ArrayStoreLibrary stores,
21842168
@Cached DispatchNode fallbackNode) {
21852169
return fallbackNode.call(array, "sort_fallback");

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

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ protected Object instanceEval(
355355
Object string,
356356
Object fileName,
357357
int line,
358-
NotProvided block,
358+
Nil block,
359359
@CachedLibrary(limit = "2") RubyStringLibrary strings,
360360
@CachedLibrary(limit = "2") RubyStringLibrary stringsFileName,
361361
@Cached ReadCallerFrameNode callerFrameNode,
@@ -378,7 +378,7 @@ protected Object instanceEval(
378378
Object string,
379379
Object fileName,
380380
NotProvided line,
381-
NotProvided block,
381+
Nil block,
382382
@CachedLibrary(limit = "2") RubyStringLibrary strings,
383383
@CachedLibrary(limit = "2") RubyStringLibrary stringsFileName,
384384
@Cached ReadCallerFrameNode callerFrameNode,
@@ -401,7 +401,7 @@ protected Object instanceEval(
401401
Object string,
402402
NotProvided fileName,
403403
NotProvided line,
404-
NotProvided block,
404+
Nil block,
405405
@CachedLibrary(limit = "2") RubyStringLibrary strings,
406406
@Cached ReadCallerFrameNode callerFrameNode,
407407
@Cached IndirectCallNode callNode) {
@@ -481,7 +481,7 @@ protected Object instanceExec(Object receiver, Object[] arguments, RubyProc bloc
481481
}
482482

483483
@Specialization
484-
protected Object instanceExec(Object receiver, Object[] arguments, NotProvided block) {
484+
protected Object instanceExec(Object receiver, Object[] arguments, Nil block) {
485485
throw new RaiseException(getContext(), coreExceptions().localJumpError("no block given", this));
486486
}
487487

@@ -491,22 +491,13 @@ protected Object instanceExec(Object receiver, Object[] arguments, NotProvided b
491491
public abstract static class MethodMissingNode extends CoreMethodArrayArgumentsNode {
492492

493493
@Specialization
494-
protected Object methodMissingNoName(Object self, NotProvided name, Object[] args, NotProvided block) {
494+
protected Object methodMissingNoName(Object self, NotProvided name, Object[] args, Nil block) {
495495
throw new RaiseException(getContext(), coreExceptions().argumentError("no id given", this));
496496
}
497497

498498
@Specialization(guards = "wasProvided(name)")
499-
protected Object methodMissingNoBlock(Object self, Object name, Object[] args, NotProvided block) {
500-
return methodMissing(self, name, args, null);
501-
}
502-
503-
@Specialization(guards = "wasProvided(name)")
504-
protected Object methodMissingBlock(Object self, Object name, Object[] args, RubyProc block) {
505-
return methodMissing(self, name, args, block);
506-
}
507-
508-
private Object methodMissing(Object self, Object nameObject, Object[] args, RubyProc block) {
509-
throw new RaiseException(getContext(), buildMethodMissingException(self, nameObject, args, block));
499+
protected Object methodMissing(Object self, Object name, Object[] args, Object block) {
500+
throw new RaiseException(getContext(), buildMethodMissingException(self, name, args, block));
510501
}
511502

512503
private static class FrameAndCallNode {
@@ -521,7 +512,7 @@ private FrameAndCallNode(Frame frame, Node callNode) {
521512

522513
@TruffleBoundary
523514
private RubyException buildMethodMissingException(Object self, Object nameObject, Object[] args,
524-
RubyProc block) {
515+
Object block) {
525516
final String name;
526517
if (nameObject instanceof RubySymbol) {
527518
name = ((RubySymbol) nameObject).getString();
@@ -621,16 +612,7 @@ public abstract static class SendNode extends CoreMethodArrayArgumentsNode {
621612
@Child private NameToJavaStringNode nameToJavaString = NameToJavaStringNode.create();
622613

623614
@Specialization
624-
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, NotProvided block) {
625-
return doSend(frame, self, name, args, nil);
626-
}
627-
628-
@Specialization
629-
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, RubyProc block) {
630-
return doSend(frame, self, name, args, block);
631-
}
632-
633-
private Object doSend(VirtualFrame frame, Object self, Object name, Object[] args, Object block) {
615+
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, Object block) {
634616
DeclarationContext context = RubyArguments.getDeclarationContext(readCallerFrame.execute(frame));
635617
RubyArguments.setDeclarationContext(frame, context);
636618

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public abstract static class DeleteNode extends CoreMethodArrayArgumentsNode {
342342
@Child private YieldNode yieldNode = YieldNode.create();
343343

344344
@Specialization(guards = "isNullHash(hash)")
345-
protected Object deleteNull(RubyHash hash, Object key, NotProvided block) {
345+
protected Object deleteNull(RubyHash hash, Object key, Nil block) {
346346
assert HashOperations.verifyStore(getContext(), hash);
347347

348348
return nil;
@@ -382,7 +382,7 @@ protected Object deletePackedArray(RubyHash hash, Object key, Object maybeBlock,
382382

383383
assert HashOperations.verifyStore(getContext(), hash);
384384

385-
if (maybeBlock == NotProvided.INSTANCE) {
385+
if (maybeBlock == nil) {
386386
return nil;
387387
} else {
388388
return yieldNode.executeDispatch((RubyProc) maybeBlock, key);
@@ -397,7 +397,7 @@ protected Object delete(RubyHash hash, Object key, Object maybeBlock) {
397397
final Entry entry = lookupResult.getEntry();
398398

399399
if (entry == null) {
400-
if (maybeBlock == NotProvided.INSTANCE) {
400+
if (maybeBlock == nil) {
401401
return nil;
402402
} else {
403403
return yieldNode.executeDispatch((RubyProc) maybeBlock, key);
@@ -512,7 +512,7 @@ protected boolean emptyPackedArray(RubyHash hash) {
512512
public abstract static class InitializeNode extends CoreMethodArrayArgumentsNode {
513513

514514
@Specialization
515-
protected RubyHash initialize(RubyHash hash, NotProvided defaultValue, NotProvided block) {
515+
protected RubyHash initialize(RubyHash hash, NotProvided defaultValue, Nil block) {
516516
assert HashOperations.verifyStore(getContext(), hash);
517517
hash.defaultValue = nil;
518518
hash.defaultBlock = nil;
@@ -530,7 +530,7 @@ protected RubyHash initialize(RubyHash hash, NotProvided defaultValue, RubyProc
530530
}
531531

532532
@Specialization(guards = "wasProvided(defaultValue)")
533-
protected RubyHash initialize(RubyHash hash, Object defaultValue, NotProvided block,
533+
protected RubyHash initialize(RubyHash hash, Object defaultValue, Nil block,
534534
@Cached PropagateSharingNode propagateSharingNode) {
535535
assert HashOperations.verifyStore(getContext(), hash);
536536
propagateSharingNode.executePropagate(hash, defaultValue);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import com.oracle.truffle.api.nodes.ExplodeLoop;
1717

1818
import org.truffleruby.RubyLanguage;
19-
import org.truffleruby.language.NotProvided;
2019
import org.truffleruby.language.RubyNode;
2120
import org.truffleruby.language.dispatch.RubyCallNodeParameters;
2221
import org.truffleruby.language.methods.InternalMethod;
@@ -72,8 +71,7 @@ public Object execute(VirtualFrame frame) {
7271

7372
public Object executeWithArgumentsEvaluated(VirtualFrame frame, Object receiverObject, Object blockObject,
7473
Object[] argumentsObjects) {
75-
final Object blockArgument = blockObject == nil ? NotProvided.INSTANCE : blockObject;
76-
return inlinedMethod.inlineExecute(frame, receiverObject, argumentsObjects, blockArgument);
74+
return inlinedMethod.inlineExecute(frame, receiverObject, argumentsObjects, blockObject);
7775
}
7876

7977
private Object executeBlock(VirtualFrame frame) {

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ protected boolean isATypeError(Object self, Object module) {
12551255
public abstract static class LambdaNode extends CoreMethodArrayArgumentsNode {
12561256

12571257
@Specialization
1258-
protected RubyProc lambda(NotProvided block) {
1258+
protected RubyProc lambda(Nil block) {
12591259
throw new RaiseException(getContext(), coreExceptions().argumentErrorProcWithoutBlock(this));
12601260
}
12611261

@@ -1490,16 +1490,7 @@ public abstract static class PublicSendNode extends CoreMethodArrayArgumentsNode
14901490
@Child private NameToJavaStringNode nameToJavaString = NameToJavaStringNode.create();
14911491

14921492
@Specialization
1493-
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, NotProvided block) {
1494-
return doSend(frame, self, name, args, nil);
1495-
}
1496-
1497-
@Specialization
1498-
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, RubyProc block) {
1499-
return doSend(frame, self, name, args, block);
1500-
}
1501-
1502-
private Object doSend(VirtualFrame frame, Object self, Object name, Object[] args, Object block) {
1493+
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, Object block) {
15031494
DeclarationContext context = RubyArguments.getDeclarationContext(readCallerFrame.execute(frame));
15041495
RubyArguments.setDeclarationContext(frame, context);
15051496

0 commit comments

Comments
 (0)