Skip to content

Commit

Permalink
[Truffle] CallDispatchHeadNode and DoesRespondDispatchHeadNode.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Jan 8, 2015
1 parent f2b1582 commit fb4b3b8
Show file tree
Hide file tree
Showing 31 changed files with 261 additions and 264 deletions.
9 changes: 3 additions & 6 deletions core/src/main/java/org/jruby/truffle/nodes/RubyCallNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
import org.jruby.truffle.nodes.cast.BooleanCastNodeFactory;
import org.jruby.truffle.nodes.cast.ProcOrNullNode;
import org.jruby.truffle.nodes.cast.ProcOrNullNodeFactory;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.DispatchNode;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
Expand All @@ -42,7 +39,7 @@ public class RubyCallNode extends RubyNode {
private final boolean isSplatted;
private final boolean isVCall;

@Child private DispatchHeadNode dispatchHead;
@Child private CallDispatchHeadNode dispatchHead;

private final BranchProfile splatNotArrayProfile = BranchProfile.create();

Expand All @@ -51,7 +48,7 @@ public class RubyCallNode extends RubyNode {
@CompilerDirectives.CompilationFinal private boolean seenLongFixnumInUnsplat = false;
@CompilerDirectives.CompilationFinal private boolean seenObjectInUnsplat = false;

@Child private DispatchHeadNode respondToMissing;
@Child private CallDispatchHeadNode respondToMissing;
@Child private BooleanCastNode respondToMissingCast;

private final boolean ignoreVisibility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.DispatchNode;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
Expand All @@ -35,7 +32,7 @@ public abstract class ArrayCastNode extends RubyNode {

private final SplatCastNode.NilBehavior nilBehavior;

@Child private DispatchHeadNode toArrayNode;
@Child private CallDispatchHeadNode toArrayNode;

public ArrayCastNode(RubyContext context, SourceSection sourceSection) {
this(context, sourceSection, SplatCastNode.NilBehavior.NIL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.DispatchNode;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
Expand All @@ -31,7 +28,7 @@
@NodeChild("child")
public abstract class HashCastNode extends RubyNode {

@Child private DispatchHeadNode toHashNode;
@Child private CallDispatchHeadNode toHashNode;

public HashCastNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
Expand All @@ -27,7 +28,7 @@
@NodeChild("child")
public abstract class ProcCastNode extends RubyNode {

@Child private DispatchHeadNode toProc;
@Child private CallDispatchHeadNode toProc;

public ProcCastNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.ArrayDupNode;
import org.jruby.truffle.nodes.core.ArrayDupNodeFactory;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.DispatchNode;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
Expand All @@ -42,9 +39,9 @@ public static enum NilBehavior {
private final boolean useToAry;

@Child private ArrayDupNode dup;
@Child private DispatchHeadNode respondToToA;
@Child private CallDispatchHeadNode respondToToA;
@Child private BooleanCastNode respondToCast;
@Child private DispatchHeadNode toA;
@Child private CallDispatchHeadNode toA;

public SplatCastNode(RubyContext context, SourceSection sourceSection, NilBehavior nilBehavior, boolean useToAry) {
super(context, sourceSection);
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/truffle/nodes/cast/ToSNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jruby.truffle.nodes.RubyTypesGen;
import org.jruby.truffle.nodes.core.KernelNodes;
import org.jruby.truffle.nodes.core.KernelNodesFactory;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
Expand All @@ -27,7 +28,7 @@
@NodeChild(type = RubyNode.class)
public abstract class ToSNode extends RubyNode {

@Child private DispatchHeadNode callToSNode;
@Child private CallDispatchHeadNode callToSNode;
@Child private KernelNodes.ToSNode kernelToSNode;

public ToSNode(RubyContext context, SourceSection sourceSection) {
Expand Down
21 changes: 9 additions & 12 deletions core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import org.jruby.truffle.nodes.CoreSourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.dispatch.PredicateDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.nodes.methods.arguments.MissingArgumentBehaviour;
import org.jruby.truffle.nodes.methods.arguments.ReadPreArgumentNode;
import org.jruby.truffle.nodes.methods.locals.ReadLevelVariableNodeFactory;
Expand Down Expand Up @@ -2057,7 +2054,7 @@ public RubyArray initializeCopyObject(RubyArray self, RubyArray from) {
@ImportGuards(ArrayGuards.class)
public abstract static class InjectNode extends YieldingCoreMethodNode {

@Child private DispatchHeadNode dispatch;
@Child private CallDispatchHeadNode dispatch;

public InjectNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down Expand Up @@ -2183,7 +2180,7 @@ public Object insert(RubyArray array, int index, int value) {
@CoreMethod(names = {"inspect", "to_s"})
public abstract static class InspectNode extends CoreMethodNode {

@Child private DispatchHeadNode inspect;
@Child private CallDispatchHeadNode inspect;

public InspectNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down Expand Up @@ -2490,7 +2487,7 @@ public RubyArray mapInPlaceObject(VirtualFrame frame, RubyArray array, RubyProc
@CoreMethod(names = "max")
public abstract static class MaxNode extends ArrayCoreMethodNode {

@Child private DispatchHeadNode eachNode;
@Child private CallDispatchHeadNode eachNode;
private final MaxBlock maxBlock;

public MaxNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -2531,7 +2528,7 @@ public Object max(VirtualFrame frame, RubyArray array) {

public abstract static class MaxBlockNode extends CoreMethodNode {

@Child private DispatchHeadNode compareNode;
@Child private CallDispatchHeadNode compareNode;

public MaxBlockNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down Expand Up @@ -2609,7 +2606,7 @@ public CallTarget getCallTarget() {
@CoreMethod(names = "min")
public abstract static class MinNode extends ArrayCoreMethodNode {

@Child private DispatchHeadNode eachNode;
@Child private CallDispatchHeadNode eachNode;
private final MinBlock minBlock;

public MinNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -2650,7 +2647,7 @@ public Object min(VirtualFrame frame, RubyArray array) {

public abstract static class MinBlockNode extends CoreMethodNode {

@Child private DispatchHeadNode compareNode;
@Child private CallDispatchHeadNode compareNode;

public MinBlockNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down Expand Up @@ -3473,7 +3470,7 @@ public RubyArray sliceLongFixnum(RubyArray array, int start, int length) {
@CoreMethod(names = "sort", needsBlock = true)
public abstract static class SortNode extends ArrayCoreMethodNode {

@Child private DispatchHeadNode compareDispatchNode;
@Child private CallDispatchHeadNode compareDispatchNode;
@Child private YieldDispatchHeadNode yieldNode;

public SortNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -3655,7 +3652,7 @@ protected static boolean isSmall(RubyArray array) {
@CoreMethod(names = "sort!")
public abstract static class SortBangNode extends ArrayCoreMethodNode {

@Child private DispatchHeadNode compareDispatchNode;
@Child private CallDispatchHeadNode compareDispatchNode;

public SortBangNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import org.jruby.truffle.nodes.RubyCallNode;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.cast.BooleanCastNodeFactory;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.dispatch.PredicateDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
import org.jruby.truffle.runtime.ObjectIDOperations;
import org.jruby.truffle.runtime.RubyContext;
Expand Down Expand Up @@ -310,7 +307,7 @@ private boolean lastCallWasVCall() {
@CoreMethod(names = "__send__", needsBlock = true, required = 1, argumentsAsArray = true)
public abstract static class SendNode extends CoreMethodNode {

@Child private DispatchHeadNode dispatchNode;
@Child private CallDispatchHeadNode dispatchNode;

public SendNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
Expand Down Expand Up @@ -56,7 +57,7 @@ public RubyBasicObject allocate(RubyClass rubyClass) {
public abstract static class NewNode extends CoreMethodNode {

@Child private AllocateNode allocateNode;
@Child private DispatchHeadNode initialize;
@Child private CallDispatchHeadNode initialize;
@CompilerDirectives.CompilationFinal private boolean isCached = true;
@CompilerDirectives.CompilationFinal private RubyClass cachedClass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
Expand All @@ -22,7 +23,7 @@ public abstract class ComparableNodes {

public abstract static class ComparableCoreMethodNode extends CoreMethodNode {

@Child private DispatchHeadNode compareNode;
@Child private CallDispatchHeadNode compareNode;

public ComparableCoreMethodNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.methods.UnsupportedOperationBehavior;
Expand Down Expand Up @@ -69,7 +70,7 @@ public RubyBignum negWithOverflow(long value) {
@CoreMethod(names = "+", required = 1)
public abstract static class AddNode extends BignumNodes.BignumCoreMethodNode {

@Child private DispatchHeadNode rationalAdd;
@Child private CallDispatchHeadNode rationalAdd;

public AddNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down Expand Up @@ -784,7 +785,7 @@ public boolean lessEqual(long a, RubyBignum b) {
@CoreMethod(names = {"==", "==="}, required = 1)
public abstract static class EqualNode extends CoreMethodNode {

@Child private DispatchHeadNode reverseCallNode;
@Child private CallDispatchHeadNode reverseCallNode;

public EqualNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down Expand Up @@ -1250,7 +1251,7 @@ static boolean isStrictlyNegative(int value) {
@CoreMethod(names = ">>", required = 1, lowerFixnumParameters = 0)
public abstract static class RightShiftNode extends CoreMethodNode {

@Child private DispatchHeadNode toInt;
@Child private CallDispatchHeadNode toInt;

public RightShiftNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.PredicateDispatchHeadNode;
Expand Down Expand Up @@ -692,7 +693,7 @@ public RubyHash dupBuckets(RubyHash self, RubyHash from) {
@CoreMethod(names = {"inspect", "to_s"})
public abstract static class InspectNode extends HashCoreMethodNode {

@Child private DispatchHeadNode inspect;
@Child private CallDispatchHeadNode inspect;

public InspectNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
Expand All @@ -25,7 +26,7 @@ public class InteroplatedRegexpNode extends RubyNode {

@Children private final RubyNode[] children;
private final RegexpOptions options;
@Child private DispatchHeadNode toS;
@Child private CallDispatchHeadNode toS;

public InteroplatedRegexpNode(RubyContext context, SourceSection sourceSection, RubyNode[] children, RegexpOptions options) {
super(context, sourceSection);
Expand Down

3 comments on commit fb4b3b8

@chrisseaton
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eregon @nirvdrum there's now a couple of subclasses of DispatchHeadNode, CallDispatchHeadNode and DoesRespondDispatchHeadNode - create these using DispatchHeadNodeFactory. CallDispatchHeadNode has methods on it that return a particular type and will raise TypeError if it doesn't get it. I wrote those for Math which passes all the specs so they hopefully do the right thing in most cases. This will help us to get rid of all the random casts we often have after calls to dispatch.

@eregon
Copy link
Member

@eregon eregon commented on fb4b3b8 Jan 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, is it on purpose that not all nodes use the factory yet?

@chrisseaton
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - I'll make the constructor of DispatchHeadNode package protected and then we will be able to update them.

Please sign in to comment.