Skip to content

Commit eac87c9

Browse files
committed
Combine now-identical Nil and RubyProc specializations
These pairs of specializations used to differ in some way (e.g. converting the `NotProvided block` into a `nil` or `null` for some downstream call) but they’re the same now that `nil` is always used to represent a missing block, so we can combine them and avoid the need to partially evaluate both paths.
1 parent 34ed74d commit eac87c9

File tree

5 files changed

+10
-62
lines changed

5 files changed

+10
-62
lines changed

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -493,17 +493,8 @@ protected Object methodMissingNoName(Object self, NotProvided name, Object[] arg
493493
}
494494

495495
@Specialization(guards = "wasProvided(name)")
496-
protected Object methodMissingNoBlock(Object self, Object name, Object[] args, Nil block) {
497-
return methodMissing(self, name, args, block);
498-
}
499-
500-
@Specialization(guards = "wasProvided(name)")
501-
protected Object methodMissingBlock(Object self, Object name, Object[] args, RubyProc block) {
502-
return methodMissing(self, name, args, block);
503-
}
504-
505-
private Object methodMissing(Object self, Object nameObject, Object[] args, Object block) {
506-
throw new RaiseException(getContext(), buildMethodMissingException(self, nameObject, args, block));
496+
protected Object methodMissing(Object self, Object name, Object[] args, Object block) {
497+
throw new RaiseException(getContext(), buildMethodMissingException(self, name, args, block));
507498
}
508499

509500
private static class FrameAndCallNode {
@@ -618,16 +609,7 @@ public abstract static class SendNode extends CoreMethodArrayArgumentsNode {
618609
@Child private NameToJavaStringNode nameToJavaString = NameToJavaStringNode.create();
619610

620611
@Specialization
621-
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, Nil block) {
622-
return doSend(frame, self, name, args, block);
623-
}
624-
625-
@Specialization
626-
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, RubyProc block) {
627-
return doSend(frame, self, name, args, block);
628-
}
629-
630-
private Object doSend(VirtualFrame frame, Object self, Object name, Object[] args, Object block) {
612+
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, Object block) {
631613
DeclarationContext context = RubyArguments.getDeclarationContext(readCallerFrame.execute(frame));
632614
RubyArguments.setDeclarationContext(frame, context);
633615

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,16 +1599,7 @@ public abstract static class PublicSendNode extends CoreMethodArrayArgumentsNode
15991599
@Child private NameToJavaStringNode nameToJavaString = NameToJavaStringNode.create();
16001600

16011601
@Specialization
1602-
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, Nil block) {
1603-
return doSend(frame, self, name, args, block);
1604-
}
1605-
1606-
@Specialization
1607-
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, RubyProc block) {
1608-
return doSend(frame, self, name, args, block);
1609-
}
1610-
1611-
private Object doSend(VirtualFrame frame, Object self, Object name, Object[] args, Object block) {
1602+
protected Object send(VirtualFrame frame, Object self, Object name, Object[] args, Object block) {
16121603
DeclarationContext context = RubyArguments.getDeclarationContext(readCallerFrame.execute(frame));
16131604
RubyArguments.setDeclarationContext(frame, context);
16141605

src/main/java/org/truffleruby/core/klass/ClassNodes.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.truffleruby.core.inlined.InlinedDispatchNode;
2020
import org.truffleruby.core.inlined.InlinedMethodNode;
2121
import org.truffleruby.core.module.RubyModule;
22-
import org.truffleruby.core.proc.RubyProc;
2322
import org.truffleruby.language.Nil;
2423
import org.truffleruby.language.RubyDynamicObject;
2524
import org.truffleruby.language.Visibility;
@@ -283,13 +282,10 @@ public static NewNode create() {
283282
public abstract Object execute(Object rubyClass, Object[] args, Object block);
284283

285284
@Specialization(guards = "!rubyClass.isSingleton")
286-
protected Object newInstance(RubyClass rubyClass, Object[] args, Nil block) {
287-
return doNewInstance(rubyClass, args, block);
288-
}
289-
290-
@Specialization(guards = "!rubyClass.isSingleton")
291-
protected Object newInstance(RubyClass rubyClass, Object[] args, RubyProc block) {
292-
return doNewInstance(rubyClass, args, block);
285+
protected Object newInstance(RubyClass rubyClass, Object[] args, Object block) {
286+
final Object instance = allocateNode().call(rubyClass, "__allocate__");
287+
initialize().callWithBlock(instance, "initialize", block, args);
288+
return instance;
293289
}
294290

295291
@Specialization(guards = "rubyClass.isSingleton")
@@ -304,12 +300,6 @@ public Object inlineExecute(Frame callerFrame, Object self, Object[] args, Objec
304300
return execute(self, args, block);
305301
}
306302

307-
private Object doNewInstance(RubyClass rubyClass, Object[] args, Object block) {
308-
final Object instance = allocateNode().call(rubyClass, "__allocate__");
309-
initialize().callWithBlock(instance, "initialize", block, args);
310-
return instance;
311-
}
312-
313303
private DispatchingNode allocateNode() {
314304
if (allocateNode == null) {
315305
CompilerDirectives.transferToInterpreterAndInvalidate();

src/main/java/org/truffleruby/core/proc/ProcNodes.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,7 @@ public abstract static class CallNode extends CoreMethodArrayArgumentsNode {
190190
@Child private CallBlockNode callBlockNode = CallBlockNode.create();
191191

192192
@Specialization
193-
protected Object call(RubyProc proc, Object[] args, Nil block) {
194-
return callBlockNode.executeCallBlock(
195-
proc.declarationContext,
196-
proc,
197-
ProcOperations.getSelf(proc),
198-
block,
199-
args);
200-
}
201-
202-
@Specialization
203-
protected Object call(RubyProc proc, Object[] args, RubyProc block) {
193+
protected Object call(RubyProc proc, Object[] args, Object block) {
204194
return callBlockNode.executeCallBlock(
205195
proc.declarationContext,
206196
proc,

src/main/java/org/truffleruby/core/range/RangeNodes.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,7 @@ protected Object eachObject(VirtualFrame frame, RubyLongRange range, Nil block)
152152
}
153153

154154
@Specialization
155-
protected Object each(VirtualFrame frame, RubyObjectRange range, Nil block) {
156-
return eachInternal(frame, range, block);
157-
}
158-
159-
@Specialization
160-
protected Object each(VirtualFrame frame, RubyObjectRange range, RubyProc block) {
155+
protected Object each(VirtualFrame frame, RubyObjectRange range, Object block) {
161156
return eachInternal(frame, range, block);
162157
}
163158
}

0 commit comments

Comments
 (0)