Skip to content

Commit

Permalink
Showing 29 changed files with 46 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -168,7 +168,7 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails
final List<RubyNode> argumentsNodes = new ArrayList<>();

if (needsCallerFrame) {
argumentsNodes.add(new ReadCallerFrameNode(context, sourceSection));
argumentsNodes.add(new ReadCallerFrameNode());
}

// Do not use needsSelf=true in module functions, it is either the module/class or the instance.
@@ -190,7 +190,7 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails
}

for (int n = 0; n < arity.getPreRequired() + arity.getOptional(); n++) {
RubyNode readArgumentNode = new ReadPreArgumentNode(context, sourceSection, n, MissingArgumentBehavior.UNDEFINED);
RubyNode readArgumentNode = new ReadPreArgumentNode(n, MissingArgumentBehavior.UNDEFINED);

if (ArrayUtils.contains(method.lowerFixnumParameters(), n)) {
readArgumentNode = FixnumLowerNodeGen.create(context, sourceSection, readArgumentNode);
@@ -203,11 +203,11 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails
argumentsNodes.add(readArgumentNode);
}
if (method.rest()) {
argumentsNodes.add(new ReadRemainingArgumentsNode(context, sourceSection, arity.getPreRequired() + arity.getOptional()));
argumentsNodes.add(new ReadRemainingArgumentsNode(arity.getPreRequired() + arity.getOptional()));
}

if (method.needsBlock()) {
argumentsNodes.add(new ReadBlockNode(context, sourceSection, NotProvided.INSTANCE));
argumentsNodes.add(new ReadBlockNode(NotProvided.INSTANCE));
}

final RubyNode methodNode;
Original file line number Diff line number Diff line change
@@ -2104,7 +2104,7 @@ public MaxBlock(RubyContext context) {

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(context, sourceSection, null, sharedMethodInfo, MaxBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, LocalVariableType.FRAME_LOCAL, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehavior.RUNTIME_ERROR)
new ReadPreArgumentNode(0, MissingArgumentBehavior.RUNTIME_ERROR)
}), false));
}

@@ -2222,7 +2222,7 @@ public MinBlock(RubyContext context) {

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(context, sourceSection, null, sharedMethodInfo, MinBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, LocalVariableType.FRAME_LOCAL, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehavior.RUNTIME_ERROR)
new ReadPreArgumentNode(0, MissingArgumentBehavior.RUNTIME_ERROR)
}), false));
}

Original file line number Diff line number Diff line change
@@ -432,7 +432,7 @@ public DynamicObject generateAccessor(VirtualFrame frame, DynamicObject module,
if (isGetter) {
accessInstanceVariable = new ReadInstanceVariableNode(getContext(), sourceSection, ivar, self);
} else {
ReadPreArgumentNode readArgument = new ReadPreArgumentNode(getContext(), sourceSection, 0, MissingArgumentBehavior.RUNTIME_ERROR);
ReadPreArgumentNode readArgument = new ReadPreArgumentNode(0, MissingArgumentBehavior.RUNTIME_ERROR);
accessInstanceVariable = new WriteInstanceVariableNode(getContext(), sourceSection, ivar, self, readArgument);
}
final RubyNode sequence = Translator.sequence(getContext(), sourceSection, Arrays.asList(checkArity, accessInstanceVariable));
Original file line number Diff line number Diff line change
@@ -42,17 +42,17 @@ public RubyNode createCallPrimitiveNode(RubyContext context, SourceSection sourc
return new CallRubiniusPrimitiveNode(context, sourceSection,
MethodNodesFactory.CallNodeFactory.create(context, sourceSection, new RubyNode[] {
new ObjectLiteralNode(context, sourceSection, method),
new ReadAllArgumentsNode(context, sourceSection),
new ReadBlockNode(context, sourceSection, NotProvided.INSTANCE)
new ReadAllArgumentsNode(),
new ReadBlockNode(NotProvided.INSTANCE)
}), returnID);
}

@Override
public RubyNode createInvokePrimitiveNode(RubyContext context, SourceSection sourceSection, RubyNode[] arguments) {
return MethodNodesFactory.CallNodeFactory.create(context, sourceSection, new RubyNode[] {
new ObjectLiteralNode(context, sourceSection, method),
new ObjectArrayNode(context, sourceSection, arguments),
new ReadBlockNode(context, sourceSection, NotProvided.INSTANCE)
new ObjectArrayNode(arguments),
new ReadBlockNode(NotProvided.INSTANCE)
});
}

Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ public RubyNode createCallPrimitiveNode(RubyContext context, SourceSection sourc
}

for (int n = 0; n < argumentsCount; n++) {
RubyNode readArgumentNode = new ReadPreArgumentNode(context, sourceSection, n, MissingArgumentBehavior.UNDEFINED);
RubyNode readArgumentNode = new ReadPreArgumentNode(n, MissingArgumentBehavior.UNDEFINED);
arguments.add(transformArgument(readArgumentNode, n));
}

@@ -91,7 +91,7 @@ public RubyNode createInvokePrimitiveNode(RubyContext context, SourceSection sou

private RubyNode transformArgument(RubyNode argument, int n) {
if (ArrayUtils.contains(annotation.lowerFixnumParameters(), n)) {
return FixnumLowerNodeGen.create(argument.getContext(), argument.getSourceSection(), argument);
return FixnumLowerNodeGen.create(null, null, argument);
} else {
return argument;
}
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyNode;

@@ -22,9 +20,7 @@ public class ArrayIsAtLeastAsLargeAsNode extends RubyNode {

@Child private RubyNode child;

public ArrayIsAtLeastAsLargeAsNode(RubyContext context, SourceSection sourceSection,
int requiredSize, RubyNode child) {
super(context, sourceSection);
public ArrayIsAtLeastAsLargeAsNode(int requiredSize, RubyNode child) {
this.requiredSize = requiredSize;
this.child = child;
}
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.methods.Arity;
@@ -23,8 +21,7 @@ public class CheckArityNode extends RubyNode {

private final BranchProfile checkFailedProfile = BranchProfile.create();

public CheckArityNode(RubyContext context, SourceSection sourceSection, Arity arity) {
super(context, sourceSection);
public CheckArityNode(Arity arity) {
this.arity = arity;
}

Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ public class CheckKeywordArityNode extends RubyNode {
public CheckKeywordArityNode(RubyContext context, SourceSection sourceSection, Arity arity) {
super(context, sourceSection);
this.arity = arity;
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(context, sourceSection, arity.getRequired());
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(arity.getRequired());
}

@Override
Original file line number Diff line number Diff line change
@@ -10,17 +10,14 @@
package org.jruby.truffle.language.arguments;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.RaiseException;

public class MissingKeywordArgumentNode extends RubyNode {

private final String name;

public MissingKeywordArgumentNode(RubyContext context, SourceSection sourceSection, String name) {
super(context, sourceSection);
public MissingKeywordArgumentNode(String name) {
this.name = name;
}

Original file line number Diff line number Diff line change
@@ -11,16 +11,13 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

public class ObjectArrayNode extends RubyNode {

@Children private final RubyNode[] nodes;

public ObjectArrayNode(RubyContext context, SourceSection sourceSection, RubyNode[] nodes) {
super(context, sourceSection);
public ObjectArrayNode(RubyNode[] nodes) {
this.nodes = nodes;
}

Original file line number Diff line number Diff line change
@@ -16,10 +16,6 @@

public class ReadAllArgumentsNode extends RubyNode {

public ReadAllArgumentsNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Override
public Object[] executeObjectArray(VirtualFrame frame) {
return RubyArguments.getArguments(frame);
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

public class ReadBlockNode extends RubyNode {
@@ -22,8 +20,7 @@ public class ReadBlockNode extends RubyNode {

private final ConditionProfile blockProfile = ConditionProfile.createBinaryProfile();

public ReadBlockNode(RubyContext context, SourceSection sourceSection, Object valueIfAbsent) {
super(context, sourceSection);
public ReadBlockNode(Object valueIfAbsent) {
this.valueIfAbsent = valueIfAbsent;
}

Original file line number Diff line number Diff line change
@@ -11,19 +11,13 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyNode;

public class ReadCallerFrameNode extends RubyNode {

private final ConditionProfile callerFrameProfile = ConditionProfile.createBinaryProfile();

public ReadCallerFrameNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Override
public Object execute(VirtualFrame frame) {
final Object callerFrame = RubyArguments.getCallerFrame(frame);
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ public ReadKeywordArgumentNode(RubyContext context, SourceSection sourceSection,
super(context, sourceSection);
this.name = name;
this.defaultValue = defaultValue;
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(context, sourceSection, minimum);
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(minimum);
}

@Override
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public ReadKeywordRestArgumentNode(RubyContext context, SourceSection sourceSect
int minimum, String[] excludedKeywords) {
super(context, sourceSection);
this.excludedKeywords = excludedKeywords;
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(context, sourceSection, minimum);
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(minimum);
}

@Override
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ public ReadOptionalArgumentNode(RubyContext context, SourceSection sourceSection
this.reduceMinimumWhenNoKWargs = reduceMinimumWhenNoKWargs;

if (reduceMinimumWhenNoKWargs) {
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(context, sourceSection, requiredForKWArgs);
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(requiredForKWArgs);
}
}

Original file line number Diff line number Diff line change
@@ -10,16 +10,13 @@
package org.jruby.truffle.language.arguments;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

public class ReadPostArgumentNode extends RubyNode {

private final int indexFromCount;

public ReadPostArgumentNode(RubyContext context, SourceSection sourceSection, int indexFromCount) {
super(context, sourceSection);
public ReadPostArgumentNode(int indexFromCount) {
this.indexFromCount = indexFromCount;
}

Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.ValueProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyNode;

@@ -26,9 +24,8 @@ public class ReadPreArgumentNode extends RubyNode {

private final ValueProfile argumentValueProfile = ValueProfile.createEqualityProfile();

public ReadPreArgumentNode(RubyContext context, SourceSection sourceSection, int index,
public ReadPreArgumentNode(int index,
MissingArgumentBehavior missingArgumentBehavior) {
super(context, sourceSection);
this.index = index;
this.missingArgumentBehavior = missingArgumentBehavior;
}
Original file line number Diff line number Diff line change
@@ -11,17 +11,14 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

public class ReadRemainingArgumentsNode extends RubyNode {

private final int start;
private final ConditionProfile remainingArguments = ConditionProfile.createBinaryProfile();

public ReadRemainingArgumentsNode(RubyContext context, SourceSection sourceSection, int start) {
super(context, sourceSection);
public ReadRemainingArgumentsNode(int start) {
this.start = start;
}

Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public ReadRestArgumentNode(RubyContext context, SourceSection sourceSection, in
this.keywordArguments = keywordArguments;

if (keywordArguments) {
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(context, sourceSection, minimumForKWargs);
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(minimumForKWargs);
}
}

Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;

@@ -24,8 +22,7 @@ public class ReadUserKeywordsHashNode extends RubyNode {
private final ConditionProfile notEnoughArgumentsProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile lastArgumentIsHashProfile = ConditionProfile.createBinaryProfile();

public ReadUserKeywordsHashNode(RubyContext context, SourceSection sourceSection, int minArgumentCount) {
super(context, sourceSection);
public ReadUserKeywordsHashNode(int minArgumentCount) {
this.minArgumentCount = minArgumentCount;
}

Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.locals.ReadFrameSlotNode;
@@ -28,8 +26,7 @@ public class RunBlockKWArgsHelperNode extends RubyNode {

private final Object kwrestName;

public RunBlockKWArgsHelperNode(RubyContext context, SourceSection sourceSection, FrameSlot arrayFrameSlot, Object kwrestName) {
super(context, sourceSection);
public RunBlockKWArgsHelperNode(FrameSlot arrayFrameSlot, Object kwrestName) {
readArrayNode = ReadFrameSlotNodeGen.create(arrayFrameSlot);
writeArrayNode = WriteFrameSlotNodeGen.create(arrayFrameSlot);
this.kwrestName = kwrestName;
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.dispatch.RespondToNode;
@@ -25,8 +23,7 @@ public class ShouldDestructureNode extends RubyNode {

private final BranchProfile checkIsArrayProfile = BranchProfile.create();

public ShouldDestructureNode(RubyContext context, SourceSection sourceSection, RubyNode readArrayNode) {
super(context, sourceSection);
public ShouldDestructureNode(RubyNode readArrayNode) {
this.readArrayNode = readArrayNode;
}

Loading

1 comment on commit 8bbb289

@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.

@jruby/truffle

If your nodes aren't syntax nodes (as in they don't appear literally in the source code), then they don't need a source section, as they can get that from their parent. It's now also possible to get their context from their parent.

This means we can simplify many node constructors to remove both the context and source section parameters. This is particular beneficial when those were the only parameters, and the whole constructor can go.

A further benefit (not shown here yet) is that this means it may be much easier to create Ruby nodes with an @Cached("new()") now.

Sorry, something went wrong.

Please sign in to comment.