Skip to content

Commit 6bd2c33

Browse files
committed
Merge CheckReceiverArgumentNode in SymbolProcNode
1 parent ebe2b26 commit 6bd2c33

File tree

2 files changed

+16
-38
lines changed

2 files changed

+16
-38
lines changed

src/main/java/org/truffleruby/core/symbol/SymbolNodes.java

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.oracle.truffle.api.frame.MaterializedFrame;
1919
import com.oracle.truffle.api.frame.VirtualFrame;
2020
import com.oracle.truffle.api.object.DynamicObject;
21-
import com.oracle.truffle.api.profiles.BranchProfile;
2221
import com.oracle.truffle.api.source.SourceSection;
2322
import org.truffleruby.Layouts;
2423
import org.truffleruby.builtins.CoreClass;
@@ -28,9 +27,7 @@
2827
import org.truffleruby.core.proc.ProcOperations;
2928
import org.truffleruby.core.proc.ProcType;
3029
import org.truffleruby.core.string.StringNodes;
31-
import org.truffleruby.language.RubyNode;
3230
import org.truffleruby.language.RubyRootNode;
33-
import org.truffleruby.language.SourceIndexLength;
3431
import org.truffleruby.language.Visibility;
3532
import org.truffleruby.language.arguments.ReadCallerFrameNode;
3633
import org.truffleruby.language.arguments.RubyArguments;
@@ -41,9 +38,6 @@
4138
import org.truffleruby.language.methods.SharedMethodInfo;
4239
import org.truffleruby.language.methods.SymbolProcNode;
4340
import org.truffleruby.parser.ArgumentDescriptor;
44-
import org.truffleruby.parser.Translator;
45-
46-
import java.util.Arrays;
4741

4842
@CoreClass("Symbol")
4943
public abstract class SymbolNodes {
@@ -122,7 +116,6 @@ public DynamicObject toProcUncached(VirtualFrame frame, DynamicObject symbol) {
122116
protected DynamicObject createProc(DeclarationContext declarationContext, InternalMethod method, DynamicObject symbol) {
123117
final SourceSection sourceSection = getContext().getCallStack().getCallerFrameIgnoringSend()
124118
.getCallNode().getEncapsulatingSourceSection();
125-
final SourceIndexLength sourceIndexLength = new SourceIndexLength(sourceSection);
126119

127120
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
128121
sourceSection,
@@ -140,15 +133,17 @@ protected DynamicObject createProc(DeclarationContext declarationContext, Intern
140133
// binding as this simplifies the logic elsewhere in the runtime.
141134
final MaterializedFrame declarationFrame = Truffle.getRuntime().createMaterializedFrame(args, coreLibrary().getEmptyDescriptor());
142135
final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, new FrameDescriptor(nil()), sharedMethodInfo,
143-
Translator.sequence(sourceIndexLength, Arrays.asList(new CheckReceiverArgumentNode(), new SymbolProcNode(Layouts.SYMBOL.getString(symbol)))));
136+
new SymbolProcNode(Layouts.SYMBOL.getString(symbol)));
144137

145138
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
146139

147140
return ProcOperations.createRubyProc(
148141
coreLibrary().getProcFactory(),
149142
ProcType.PROC,
150143
sharedMethodInfo,
151-
callTarget, callTarget, declarationFrame,
144+
callTarget,
145+
callTarget,
146+
declarationFrame,
152147
method,
153148
null,
154149
null,
@@ -171,29 +166,6 @@ protected FrameDescriptor getDescriptor(VirtualFrame frame) {
171166
return frame.getFrameDescriptor();
172167
}
173168

174-
/** Not using CheckArityNode as the message is different and arity is reported as -1. */
175-
private static class CheckReceiverArgumentNode extends RubyNode {
176-
177-
private final BranchProfile noReceiverProfile = BranchProfile.create();
178-
179-
@Override
180-
public void doExecuteVoid(VirtualFrame frame) {
181-
final int given = RubyArguments.getArgumentsCount(frame);
182-
183-
if (given == 0) {
184-
noReceiverProfile.enter();
185-
throw new RaiseException(getContext(), coreExceptions().argumentError("no receiver given", this));
186-
}
187-
}
188-
189-
@Override
190-
public Object execute(VirtualFrame frame) {
191-
doExecuteVoid(frame);
192-
return nil();
193-
}
194-
195-
}
196-
197169
}
198170

199171
@CoreMethod(names = "to_s")

src/main/java/org/truffleruby/language/methods/SymbolProcNode.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
import com.oracle.truffle.api.CompilerDirectives;
1313
import com.oracle.truffle.api.frame.VirtualFrame;
1414
import com.oracle.truffle.api.object.DynamicObject;
15+
import com.oracle.truffle.api.profiles.BranchProfile;
16+
1517
import org.truffleruby.core.array.ArrayUtils;
1618
import org.truffleruby.language.RubyNode;
1719
import org.truffleruby.language.arguments.RubyArguments;
20+
import org.truffleruby.language.control.RaiseException;
1821
import org.truffleruby.language.dispatch.CallDispatchHeadNode;
1922

2023
public class SymbolProcNode extends RubyNode {
2124

2225
private final String symbol;
26+
private final BranchProfile noReceiverProfile = BranchProfile.create();
2327

2428
@Child private CallDispatchHeadNode callNode;
2529

@@ -29,15 +33,17 @@ public SymbolProcNode(String symbol) {
2933

3034
@Override
3135
public Object execute(VirtualFrame frame) {
32-
final Object receiver = RubyArguments.getArgument(frame, 0);
36+
// Not using CheckArityNode as the message is different and arity is reported as -1
37+
final int given = RubyArguments.getArgumentsCount(frame);
38+
if (given == 0) {
39+
noReceiverProfile.enter();
40+
throw new RaiseException(getContext(), coreExceptions().argumentError("no receiver given", this));
41+
}
3342

43+
final Object receiver = RubyArguments.getArgument(frame, 0);
44+
final Object[] arguments = ArrayUtils.extractRange(RubyArguments.getArguments(frame), 1, given);
3445
final DynamicObject block = RubyArguments.getBlock(frame);
3546

36-
final Object[] arguments = ArrayUtils.extractRange(
37-
RubyArguments.getArguments(frame),
38-
1,
39-
RubyArguments.getArgumentsCount(frame));
40-
4147
return getCallNode().dispatch(frame, receiver, symbol, block, arguments);
4248
}
4349

0 commit comments

Comments
 (0)