Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d6939af9d96c
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 574f975d14d3
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 7, 2015

  1. [Truffle] Do not create a RubyRootNode with invalid AST for blocks.

    * Resolve the BehaveAs*Nodes before creating it.
    eregon committed Aug 7, 2015
    Copy the full SHA
    5abd1e4 View commit details
  2. Copy the full SHA
    9fc3c9b View commit details
  3. 3
    Copy the full SHA
    574f975 View commit details
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrument.Probe;
import com.oracle.truffle.api.nodes.NodeUtil;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.runtime.RubyContext;
@@ -29,7 +28,6 @@ public class RubyRootNode extends RootNode {
private final RubyContext context;
private final SharedMethodInfo sharedMethodInfo;
@Child private RubyNode body;
private final RubyNode uninitializedBody;
private final boolean needsDeclarationFrame;

private boolean instrumentationApplied = false;
@@ -45,11 +43,6 @@ public RubyRootNode(RubyContext context, SourceSection sourceSection, FrameDescr
this.body = body;
this.sharedMethodInfo = sharedMethodInfo;
this.needsDeclarationFrame = needsDeclarationFrame;
uninitializedBody = NodeUtil.cloneNode(body);
}

public RubyRootNode cloneRubyRootNode() {
return new RubyRootNode(context, getSourceSection(), getFrameDescriptor(), sharedMethodInfo, NodeUtil.cloneNode(uninitializedBody), needsDeclarationFrame);
}

@Override
Original file line number Diff line number Diff line change
@@ -29,10 +29,11 @@
public class OpenModuleNode extends RubyNode {

@Child private RubyNode definingModule;
@Child private MethodDefinitionNode definitionMethod;
final protected LexicalScope lexicalScope;
@Child private IndirectCallNode callModuleDefinitionNode;

final private MethodDefinitionNode definitionMethod;

public OpenModuleNode(RubyContext context, SourceSection sourceSection, RubyNode definingModule, MethodDefinitionNode definitionMethod, LexicalScope lexicalScope) {
super(context, sourceSection);
this.definingModule = definingModule;
Original file line number Diff line number Diff line change
@@ -189,75 +189,78 @@ public RubyNode compileFunctionNode(SourceSection sourceSection, String methodNa
if (!isBlock) {
// TODO(CS, 10-Jan-15) why do we only translate exceptions in methods and not blocks?
body = new ExceptionTranslatingNode(context, sourceSection, body);
}

final RubyRootNode rootNode = new RubyRootNode(
context, sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body, environment.needsDeclarationFrame());
final RubyRootNode rootNode = new RubyRootNode(
context, sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body, environment.needsDeclarationFrame());

if (PRINT_AST_METHOD_NAMES.contains(methodName)) {
System.err.println(sourceSection + " " + methodName);
NodeUtil.printCompactTree(System.err, rootNode);
}
if (PRINT_AST_METHOD_NAMES.contains(methodName)) {
System.err.println(sourceSection + " " + methodName);
NodeUtil.printCompactTree(System.err, rootNode);
}

if (PRINT_FULL_AST_METHOD_NAMES.contains(methodName)) {
System.err.println(sourceSection + " " + methodName);
NodeUtil.printTree(System.err, rootNode);
if (PRINT_FULL_AST_METHOD_NAMES.contains(methodName)) {
System.err.println(sourceSection + " " + methodName);
NodeUtil.printTree(System.err, rootNode);
}

final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
return new MethodDefinitionNode(context, sourceSection, methodName, environment.getSharedMethodInfo(), callTarget);
}

if (isBlock) {
// Blocks
final RubyRootNode newRootNodeForBlocks = rootNode.cloneRubyRootNode();
// Blocks
final RubyNode newNodeForBlocks = NodeUtil.cloneNode(body);

for (BehaveAsBlockNode behaveAsBlockNode : NodeUtil.findAllNodeInstances(newRootNodeForBlocks, BehaveAsBlockNode.class)) {
behaveAsBlockNode.replace(behaveAsBlockNode.getAsBlock());
}
for (BehaveAsBlockNode behaveAsBlockNode : NodeUtil.findAllNodeInstances(newNodeForBlocks, BehaveAsBlockNode.class)) {
behaveAsBlockNode.replace(behaveAsBlockNode.getAsBlock());
}

for (BehaveAsProcNode behaveAsProcNode : NodeUtil.findAllNodeInstances(newRootNodeForBlocks, BehaveAsProcNode.class)) {
behaveAsProcNode.replace(behaveAsProcNode.getNotAsProc());
}
for (BehaveAsProcNode behaveAsProcNode : NodeUtil.findAllNodeInstances(newNodeForBlocks, BehaveAsProcNode.class)) {
behaveAsProcNode.replace(behaveAsProcNode.getNotAsProc());
}

final CallTarget callTargetAsBlock = Truffle.getRuntime().createCallTarget(newRootNodeForBlocks);
final RubyRootNode newRootNodeForBlocks = new RubyRootNode(context, sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(),
newNodeForBlocks, environment.needsDeclarationFrame());

// Procs
final RubyRootNode newRootNodeForProcs = rootNode.cloneRubyRootNode();
// Procs
final RubyNode newNodeForProcs = NodeUtil.cloneNode(body);

for (BehaveAsBlockNode behaveAsBlockNode : NodeUtil.findAllNodeInstances(newRootNodeForProcs, BehaveAsBlockNode.class)) {
behaveAsBlockNode.replace(behaveAsBlockNode.getAsBlock());
}
for (BehaveAsBlockNode behaveAsBlockNode : NodeUtil.findAllNodeInstances(newNodeForProcs, BehaveAsBlockNode.class)) {
behaveAsBlockNode.replace(behaveAsBlockNode.getAsBlock());
}

for (BehaveAsProcNode behaveAsProcNode : NodeUtil.findAllNodeInstances(newRootNodeForProcs, BehaveAsProcNode.class)) {
behaveAsProcNode.replace(behaveAsProcNode.getAsProc());
}
for (BehaveAsProcNode behaveAsProcNode : NodeUtil.findAllNodeInstances(newNodeForProcs, BehaveAsProcNode.class)) {
behaveAsProcNode.replace(behaveAsProcNode.getAsProc());
}

final CallTarget callTargetAsProc = Truffle.getRuntime().createCallTarget(newRootNodeForProcs);
final RubyRootNode newRootNodeForProcs = new RubyRootNode(context, sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(),
newNodeForProcs, environment.needsDeclarationFrame());

// Lambdas
final RubyRootNode newRootNodeForLambdas = rootNode.cloneRubyRootNode();
// Lambdas
final RubyNode newNodeForLambdas = NodeUtil.cloneNode(body);

for (BehaveAsBlockNode behaveAsBlockNode : NodeUtil.findAllNodeInstances(newRootNodeForLambdas, BehaveAsBlockNode.class)) {
behaveAsBlockNode.replace(behaveAsBlockNode.getNotAsBlock());
}
for (BehaveAsBlockNode behaveAsBlockNode : NodeUtil.findAllNodeInstances(newNodeForLambdas, BehaveAsBlockNode.class)) {
behaveAsBlockNode.replace(behaveAsBlockNode.getNotAsBlock());
}

for (BehaveAsProcNode behaveAsProcNode : NodeUtil.findAllNodeInstances(newRootNodeForLambdas, BehaveAsProcNode.class)) {
behaveAsProcNode.replace(behaveAsProcNode.getNotAsProc());
}
for (BehaveAsProcNode behaveAsProcNode : NodeUtil.findAllNodeInstances(newNodeForLambdas, BehaveAsProcNode.class)) {
behaveAsProcNode.replace(behaveAsProcNode.getNotAsProc());
}

final RubyRootNode newRootNodeWithCatchReturn = new RubyRootNode(
context,
newRootNodeForLambdas.getSourceSection(),
newRootNodeForLambdas.getFrameDescriptor(), newRootNodeForLambdas.getSharedMethodInfo(),
new CatchBreakAsReturnNode(context, sourceSection,
new CatchReturnNode(context, newRootNodeForLambdas.getSourceSection(),
newRootNodeForLambdas.getBody(), getEnvironment().getReturnID())), environment.needsDeclarationFrame());
final RubyRootNode newRootNodeForLambdas = new RubyRootNode(
context, sourceSection,
environment.getFrameDescriptor(), environment.getSharedMethodInfo(),
new CatchBreakAsReturnNode(context, sourceSection,
new CatchReturnNode(context, sourceSection,
newNodeForLambdas, environment.getReturnID())),
environment.needsDeclarationFrame());

final CallTarget callTargetAsLambda = Truffle.getRuntime().createCallTarget(newRootNodeWithCatchReturn);

return new BlockDefinitionNode(context, sourceSection, environment.getSharedMethodInfo(),
callTargetAsBlock, callTargetAsProc, callTargetAsLambda, environment.getBreakID());
} else {
return new MethodDefinitionNode(context, sourceSection, methodName, environment.getSharedMethodInfo(),
Truffle.getRuntime().createCallTarget(rootNode));
}
final CallTarget callTargetAsBlock = Truffle.getRuntime().createCallTarget(newRootNodeForBlocks);
final CallTarget callTargetAsProc = Truffle.getRuntime().createCallTarget(newRootNodeForProcs);
final CallTarget callTargetAsLambda = Truffle.getRuntime().createCallTarget(newRootNodeForLambdas);

return new BlockDefinitionNode(context, sourceSection, environment.getSharedMethodInfo(),
callTargetAsBlock, callTargetAsProc, callTargetAsLambda, environment.getBreakID());
}

public static Arity getArity(org.jruby.ast.ArgsNode argsNode) {