Skip to content

Commit

Permalink
Merge pull request #4406 from jruby/truffle-precise-parser
Browse files Browse the repository at this point in the history
[Truffle] Refactor source section abstractions
  • Loading branch information
eregon committed Dec 22, 2016
2 parents 15f39ab + 1b31760 commit ad3ac33
Show file tree
Hide file tree
Showing 155 changed files with 669 additions and 955 deletions.
Expand Up @@ -29,7 +29,7 @@
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.RubySourceSection;
import org.jruby.truffle.parser.TempSourceSection;
import org.jruby.truffle.language.Visibility;
import org.jruby.truffle.language.arguments.MissingArgumentBehavior;
import org.jruby.truffle.language.arguments.ProfileArgumentNode;
Expand Down Expand Up @@ -187,21 +187,21 @@ private static CallTarget makeGenericMethod(RubyContext context, MethodDetails m
final CoreMethod method = methodDetails.getMethodAnnotation();

final SourceSection sourceSection = sharedMethodInfo.getSourceSection();
final RubySourceSection rubySourceSection = new RubySourceSection(sourceSection);
final TempSourceSection tempSourceSection = new TempSourceSection(sourceSection);

final RubyNode methodNode = createCoreMethodNode(context, sourceSection, methodDetails.getNodeFactory(), method);

if (CHECK_DSL_USAGE) {
AmbiguousOptionalArgumentChecker.verifyNoAmbiguousOptionalArguments(methodDetails);
}

final RubyNode checkArity = Translator.createCheckArityNode(context, sourceSection.getSource(), rubySourceSection, sharedMethodInfo.getArity());
final RubyNode checkArity = Translator.createCheckArityNode(context, sourceSection.getSource(), tempSourceSection, sharedMethodInfo.getArity());

RubyNode node;
if (!isSafe(context, method.unsafe())) {
node = new UnsafeNode(context, sourceSection);
} else {
node = Translator.sequence(context, sourceSection.getSource(), rubySourceSection, Arrays.asList(checkArity, methodNode));
node = Translator.sequence(context, sourceSection.getSource(), tempSourceSection, Arrays.asList(checkArity, methodNode));
node = transformResult(method, node);
}

Expand Down
Expand Up @@ -19,23 +19,23 @@
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.CoreLibrary;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubySourceSection;
import org.jruby.truffle.parser.TempSourceSection;
import org.jruby.truffle.language.objects.AllocateObjectNode;
import org.jruby.truffle.language.objects.AllocateObjectNodeGen;

public abstract class ArrayLiteralNode extends RubyNode {

public static ArrayLiteralNode create(RubyContext context, RubySourceSection sourceSection, RubyNode[] values) {
public static ArrayLiteralNode create(RubyContext context, TempSourceSection sourceSection, RubyNode[] values) {
return new UninitialisedArrayLiteralNode(context, sourceSection, values);
}

@Children protected final RubyNode[] values;
@Child protected AllocateObjectNode allocateObjectNode;

public ArrayLiteralNode(RubyContext context, RubySourceSection sourceSection, RubyNode[] values) {
public ArrayLiteralNode(RubyContext context, TempSourceSection sourceSection, RubyNode[] values) {
super(context, sourceSection);
this.values = values;
this.allocateObjectNode = AllocateObjectNodeGen.create(context, (RubySourceSection) null, false, null, null);
this.allocateObjectNode = AllocateObjectNodeGen.create(context, (TempSourceSection) null, false, null, null);
}

protected DynamicObject makeGeneric(VirtualFrame frame, Object[] alreadyExecuted) {
Expand Down Expand Up @@ -97,7 +97,7 @@ public RubyNode stealNode(int index) {

private static class EmptyArrayLiteralNode extends ArrayLiteralNode {

public EmptyArrayLiteralNode(RubyContext context, RubySourceSection sourceSection, RubyNode[] values) {
public EmptyArrayLiteralNode(RubyContext context, TempSourceSection sourceSection, RubyNode[] values) {
super(context, sourceSection, values);
}

Expand All @@ -110,7 +110,7 @@ public Object execute(VirtualFrame frame) {

private static class FloatArrayLiteralNode extends ArrayLiteralNode {

public FloatArrayLiteralNode(RubyContext context, RubySourceSection sourceSection, RubyNode[] values) {
public FloatArrayLiteralNode(RubyContext context, TempSourceSection sourceSection, RubyNode[] values) {
super(context, sourceSection, values);
}

Expand Down Expand Up @@ -144,7 +144,7 @@ private DynamicObject makeGeneric(VirtualFrame frame, final double[] executedVal

private static class IntegerArrayLiteralNode extends ArrayLiteralNode {

public IntegerArrayLiteralNode(RubyContext context, RubySourceSection sourceSection, RubyNode[] values) {
public IntegerArrayLiteralNode(RubyContext context, TempSourceSection sourceSection, RubyNode[] values) {
super(context, sourceSection, values);
}

Expand Down Expand Up @@ -178,7 +178,7 @@ private DynamicObject makeGeneric(VirtualFrame frame, final int[] executedValues

private static class LongArrayLiteralNode extends ArrayLiteralNode {

public LongArrayLiteralNode(RubyContext context, RubySourceSection sourceSection, RubyNode[] values) {
public LongArrayLiteralNode(RubyContext context, TempSourceSection sourceSection, RubyNode[] values) {
super(context, sourceSection, values);
}

Expand Down Expand Up @@ -212,7 +212,7 @@ private DynamicObject makeGeneric(VirtualFrame frame, final long[] executedValue

private static class ObjectArrayLiteralNode extends ArrayLiteralNode {

public ObjectArrayLiteralNode(RubyContext context, RubySourceSection sourceSection, RubyNode[] values) {
public ObjectArrayLiteralNode(RubyContext context, TempSourceSection sourceSection, RubyNode[] values) {
super(context, sourceSection, values);
}

Expand All @@ -232,7 +232,7 @@ public Object execute(VirtualFrame frame) {

private static class UninitialisedArrayLiteralNode extends ArrayLiteralNode {

public UninitialisedArrayLiteralNode(RubyContext context, RubySourceSection sourceSection, RubyNode[] values) {
public UninitialisedArrayLiteralNode(RubyContext context, TempSourceSection sourceSection, RubyNode[] values) {
super(context, sourceSection, values);
}

Expand Down
Expand Up @@ -60,7 +60,7 @@
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.RubySourceSection;
import org.jruby.truffle.parser.TempSourceSection;
import org.jruby.truffle.language.SnippetNode;
import org.jruby.truffle.language.Visibility;
import org.jruby.truffle.language.arguments.MissingArgumentBehavior;
Expand Down Expand Up @@ -375,13 +375,13 @@ public DynamicObject generateAccessor(VirtualFrame frame, DynamicObject module,
private void createAccesor(DynamicObject module, String name) {
final FrameInstance callerFrame = getContext().getCallStack().getCallerFrameIgnoringSend();
final SourceSection sourceSection = callerFrame.getCallNode().getEncapsulatingSourceSection();
final RubySourceSection rubySourceSection = new RubySourceSection(sourceSection);
final TempSourceSection tempSourceSection = new TempSourceSection(sourceSection);
final Visibility visibility = DeclarationContext.findVisibility(callerFrame.getFrame(FrameAccess.READ_ONLY, true));
final Arity arity = isGetter ? Arity.NO_ARGUMENTS : Arity.ONE_REQUIRED;
final String ivar = "@" + name;
final String accessorName = isGetter ? name : name + "=";

final RubyNode checkArity = Translator.createCheckArityNode(getContext(), sourceSection.getSource(), rubySourceSection, arity);
final RubyNode checkArity = Translator.createCheckArityNode(getContext(), sourceSection.getSource(), tempSourceSection, arity);

final LexicalScope lexicalScope = new LexicalScope(getContext().getRootLexicalScope(), module);
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
Expand All @@ -404,7 +404,7 @@ private void createAccesor(DynamicObject module, String name) {
RubyNode readArgument = new ProfileArgumentNode(new ReadPreArgumentNode(0, MissingArgumentBehavior.RUNTIME_ERROR));
accessInstanceVariable = new WriteInstanceVariableNode(getContext(), sourceSection, ivar, self, readArgument);
}
final RubyNode sequence = Translator.sequence(getContext(), sourceSection.getSource(), rubySourceSection, Arrays.asList(checkArity, accessInstanceVariable));
final RubyNode sequence = Translator.sequence(getContext(), sourceSection.getSource(), tempSourceSection, Arrays.asList(checkArity, accessInstanceVariable));
final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, null, sharedMethodInfo, sequence, false);
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final InternalMethod method = new InternalMethod(getContext(), sharedMethodInfo, lexicalScope, accessorName, module, visibility, callTarget);
Expand Down
Expand Up @@ -26,7 +26,7 @@
import org.jruby.truffle.core.proc.ProcOperations;
import org.jruby.truffle.core.proc.ProcType;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.RubySourceSection;
import org.jruby.truffle.parser.TempSourceSection;
import org.jruby.truffle.language.arguments.RubyArguments;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.methods.Arity;
Expand Down Expand Up @@ -108,7 +108,7 @@ public DynamicObject toProcUncached(VirtualFrame frame, DynamicObject symbol) {
protected DynamicObject createProc(InternalMethod method, DynamicObject symbol) {
final SourceSection sourceSection = getContext().getCallStack().getCallerFrameIgnoringSend()
.getCallNode().getEncapsulatingSourceSection();
final RubySourceSection rubySourceSection = new RubySourceSection(sourceSection);
final TempSourceSection tempSourceSection = new TempSourceSection(sourceSection);

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
sourceSection,
Expand All @@ -122,7 +122,7 @@ protected DynamicObject createProc(InternalMethod method, DynamicObject symbol)
false,
false);

final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, new FrameDescriptor(nil()), sharedMethodInfo, Translator.sequence(getContext(), sourceSection.getSource(), rubySourceSection, Arrays.asList(Translator.createCheckArityNode(getContext(), sourceSection.getSource(), rubySourceSection, Arity.AT_LEAST_ONE), new SymbolProcNode(getContext(), sourceSection, Layouts.SYMBOL.getString(symbol)))), false);
final RubyRootNode rootNode = new RubyRootNode(getContext(), sourceSection, new FrameDescriptor(nil()), sharedMethodInfo, Translator.sequence(getContext(), sourceSection.getSource(), tempSourceSection, Arrays.asList(Translator.createCheckArityNode(getContext(), sourceSection.getSource(), tempSourceSection, Arity.AT_LEAST_ONE), new SymbolProcNode(getContext(), sourceSection, Layouts.SYMBOL.getString(symbol)))), false);

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

Expand Down
19 changes: 10 additions & 9 deletions truffle/src/main/java/org/jruby/truffle/language/RubyBaseNode.java
Expand Up @@ -34,6 +34,7 @@
import org.jruby.truffle.core.string.ByteList;
import org.jruby.truffle.core.string.CoreStrings;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.parser.TempSourceSection;
import org.jruby.truffle.platform.posix.Sockets;
import org.jruby.truffle.platform.posix.TrufflePosix;
import org.jruby.truffle.stdlib.CoverageManager;
Expand Down Expand Up @@ -64,11 +65,11 @@ public RubyBaseNode(RubyContext context) {

public RubyBaseNode(SourceSection sourceSection) {
if (sourceSection != null) {
unsafeSetSourceSection(new RubySourceSection(sourceSection));
unsafeSetSourceSection(new TempSourceSection(sourceSection));
}
}

public RubyBaseNode(RubySourceSection sourceSection) {
public RubyBaseNode(TempSourceSection sourceSection) {
if (sourceSection != null) {
unsafeSetSourceSection(sourceSection);
}
Expand All @@ -78,11 +79,11 @@ public RubyBaseNode(RubyContext context, SourceSection sourceSection) {
this.context = context;

if (sourceSection != null) {
unsafeSetSourceSection(new RubySourceSection(sourceSection));
unsafeSetSourceSection(new TempSourceSection(sourceSection));
}
}

public RubyBaseNode(RubyContext context, RubySourceSection sourceSection) {
public RubyBaseNode(RubyContext context, TempSourceSection sourceSection) {
this.context = context;

if (sourceSection != null) {
Expand Down Expand Up @@ -205,21 +206,21 @@ public RubyContext getContext() {

// Source section

public void unsafeSetSourceSection(RubySourceSection sourceSection) {
public void unsafeSetSourceSection(TempSourceSection sourceSection) {
assert sourceStartLine == 0;
sourceStartLine = sourceSection.getStartLine();
sourceEndLine = sourceSection.getEndLine();
}

public RubySourceSection getRubySourceSection() {
public TempSourceSection getRubySourceSection() {
if (sourceStartLine == 0) {
return null;
} else {
return new RubySourceSection(sourceStartLine, sourceEndLine);
return new TempSourceSection(sourceStartLine, sourceEndLine);
}
}

public RubySourceSection getEncapsulatingRubySourceSection() {
public TempSourceSection getEncapsulatingRubySourceSection() {
Node node = this;

while (node != null) {
Expand All @@ -228,7 +229,7 @@ public RubySourceSection getEncapsulatingRubySourceSection() {
}

if (node instanceof RootNode) {
return new RubySourceSection(node.getSourceSection());
return new TempSourceSection(node.getSourceSection());
}

node = node.getParent();
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.parser.TempSourceSection;

@Instrumentable(factory = RubyNodeWrapper.class)
public abstract class RubyNode extends RubyBaseNode {
Expand All @@ -30,15 +31,15 @@ public RubyNode(SourceSection sourceSection) {
super(sourceSection);
}

public RubyNode(RubySourceSection sourceSection) {
public RubyNode(TempSourceSection sourceSection) {
super(sourceSection);
}

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

public RubyNode(RubyContext context, RubySourceSection sourceSection) {
public RubyNode(RubyContext context, TempSourceSection sourceSection) {
super(context, sourceSection);
}

Expand Down
Expand Up @@ -17,7 +17,7 @@
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.RubySourceSection;
import org.jruby.truffle.parser.TempSourceSection;

public class InstrumentedWriteLocalVariableNode extends WriteLocalVariableNode {

Expand All @@ -28,7 +28,7 @@ public InstrumentedWriteLocalVariableNode(RubyContext context, SourceSection sou
name = frameSlot.getIdentifier().toString();
}

public InstrumentedWriteLocalVariableNode(RubyContext context, RubySourceSection sourceSection, FrameSlot frameSlot, RubyNode valueNode) {
public InstrumentedWriteLocalVariableNode(RubyContext context, TempSourceSection sourceSection, FrameSlot frameSlot, RubyNode valueNode) {
super(context, sourceSection, frameSlot, valueNode);
name = frameSlot.getIdentifier().toString();
}
Expand Down
Expand Up @@ -16,7 +16,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubySourceSection;
import org.jruby.truffle.parser.TempSourceSection;
import org.jruby.truffle.language.arguments.RubyArguments;

public class WriteDeclarationVariableNode extends RubyNode {
Expand All @@ -27,7 +27,7 @@ public class WriteDeclarationVariableNode extends RubyNode {
@Child private RubyNode valueNode;
@Child private WriteFrameSlotNode writeFrameSlotNode;

public WriteDeclarationVariableNode(RubyContext context, RubySourceSection sourceSection,
public WriteDeclarationVariableNode(RubyContext context, TempSourceSection sourceSection,
FrameSlot frameSlot, int frameDepth, RubyNode valueNode) {
super(context, sourceSection);
this.frameDepth = frameDepth;
Expand Down
Expand Up @@ -15,7 +15,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubySourceSection;
import org.jruby.truffle.parser.TempSourceSection;

public class WriteLocalVariableNode extends RubyNode {

Expand All @@ -24,7 +24,7 @@ public class WriteLocalVariableNode extends RubyNode {
@Child private RubyNode valueNode;
@Child private WriteFrameSlotNode writeFrameSlotNode;

public static WriteLocalVariableNode createWriteLocalVariableNode(RubyContext context, RubySourceSection sourceSection,
public static WriteLocalVariableNode createWriteLocalVariableNode(RubyContext context, TempSourceSection sourceSection,
FrameSlot frameSlot, RubyNode valueNode) {
if (context.getCallGraph() == null) {
return new WriteLocalVariableNode(context, sourceSection, frameSlot, valueNode);
Expand All @@ -42,7 +42,7 @@ public static WriteLocalVariableNode createWriteLocalVariableNode(RubyContext co
}
}

protected WriteLocalVariableNode(RubyContext context, RubySourceSection sourceSection,
protected WriteLocalVariableNode(RubyContext context, TempSourceSection sourceSection,
FrameSlot frameSlot, RubyNode valueNode) {
super(context, sourceSection);
this.frameSlot = frameSlot;
Expand Down
Expand Up @@ -29,7 +29,7 @@
import org.jruby.truffle.core.hash.Entry;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubySourceSection;
import org.jruby.truffle.parser.TempSourceSection;
import org.jruby.truffle.language.arguments.RubyArguments;
import org.jruby.truffle.language.control.RaiseException;

Expand All @@ -41,7 +41,7 @@
public abstract class AllocateObjectNode extends RubyNode {

public static AllocateObjectNode create() {
return AllocateObjectNodeGen.create(null, (RubySourceSection) null, null, null);
return AllocateObjectNodeGen.create(null, (TempSourceSection) null, null, null);
}

private final boolean useCallerFrameForTracing;
Expand All @@ -50,7 +50,7 @@ public AllocateObjectNode(RubyContext context, SourceSection sourceSection) {
this(context, sourceSection, true);
}

public AllocateObjectNode(RubyContext context, RubySourceSection sourceSection) {
public AllocateObjectNode(RubyContext context, TempSourceSection sourceSection) {
this(context, sourceSection, true);
}

Expand All @@ -59,7 +59,7 @@ public AllocateObjectNode(RubyContext context, SourceSection sourceSection, bool
this.useCallerFrameForTracing = useCallerFrameForTracing;
}

public AllocateObjectNode(RubyContext context, RubySourceSection sourceSection, boolean useCallerFrameForTracing) {
public AllocateObjectNode(RubyContext context, TempSourceSection sourceSection, boolean useCallerFrameForTracing) {
super(context, sourceSection);
this.useCallerFrameForTracing = useCallerFrameForTracing;
}
Expand Down

0 comments on commit ad3ac33

Please sign in to comment.