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: b64c383399e2
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2d95d471d61c
Choose a head ref
  • 5 commits
  • 14 files changed
  • 1 contributor

Commits on Jan 8, 2015

  1. [Truffle] Check visibility only in AddMethodNode, not in MethodDefini…

    …tionNode.
    
    * Blocks don't need visibility.
    * Remove now unused ignoreLocalVisibility superseeded by per-frame visibility.
    eregon committed Jan 8, 2015
    Copy the full SHA
    09af835 View commit details
  2. [Truffle] Prefer SetMethodDeclarationContext to SetFrameVisibilityNode.

    * Remove TranslatorEnvironment.addMethodDeclarationSlots.
    eregon committed Jan 8, 2015
    Copy the full SHA
    4182c8c View commit details
  3. [Truffle] Remove eval-like methods variants without NodeWrapper.

    * The vast majority of cases should have a wrapper for method definition
      and it is easy enough to give NodeWrapper.IDENTITY.
    eregon committed Jan 8, 2015
    Copy the full SHA
    6c42cc3 View commit details
  4. Copy the full SHA
    f0bc034 View commit details
  5. Copy the full SHA
    2d95d47 View commit details
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/truffle/TruffleBridgeImpl.java
Original file line number Diff line number Diff line change
@@ -14,13 +14,14 @@
import com.oracle.truffle.api.source.BytesDecoder;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.TruffleBridge;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.TopLevelRaiseHandler;
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.core.*;
import org.jruby.truffle.nodes.methods.SetFrameVisibilityNode;
import org.jruby.truffle.nodes.methods.SetMethodDeclarationContext;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyClass;
@@ -174,8 +175,7 @@ public RubyNode wrap(RubyNode node) {
SourceSection sourceSection = node.getSourceSection();
return SequenceNode.sequence(context, sourceSection,
new SetTopLevelBindingNode(context, sourceSection),
new TopLevelRaiseHandler(context, sourceSection,
SetFrameVisibilityNode.PRIVATE_VISIBILITY_WRAPPER.wrap(node)));
new TopLevelRaiseHandler(context, sourceSection, node));
}
});
return truffleContext.getCoreLibrary().getNilObject();
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
import org.jruby.truffle.nodes.dispatch.DispatchAction;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.methods.SetMethodDeclarationContext;
import org.jruby.truffle.nodes.methods.arguments.CheckArityNode;
import org.jruby.truffle.nodes.methods.arguments.MissingArgumentBehaviour;
import org.jruby.truffle.nodes.methods.arguments.ReadPreArgumentNode;
@@ -41,6 +42,7 @@
import org.jruby.truffle.runtime.methods.MethodLike;
import org.jruby.truffle.runtime.methods.RubyMethod;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
import org.jruby.truffle.translator.NodeWrapper;
import org.jruby.truffle.translator.TranslatorDriver;
import org.jruby.util.IdUtil;

@@ -420,7 +422,12 @@ public Object classEval(VirtualFrame frame, RubyModule module, RubyString code,
}

private Object classEvalSource(VirtualFrame frame, RubyModule module, Source source, Encoding encoding) {
return getContext().execute(getContext(), source, encoding, TranslatorDriver.ParserContext.MODULE, module, frame.materialize(), this);
return getContext().execute(getContext(), source, encoding, TranslatorDriver.ParserContext.MODULE, module, frame.materialize(), this, new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return new SetMethodDeclarationContext(node.getContext(), node.getSourceSection(), "class_eval", node);
}
});
}

@Specialization
Original file line number Diff line number Diff line change
@@ -9,8 +9,15 @@
*/
package org.jruby.truffle.nodes.methods;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
@@ -24,7 +31,7 @@ public class AddMethodNode extends RubyNode {
@Child protected RubyNode receiver;
@Child protected MethodDefinitionNode methodNode;

public AddMethodNode(RubyContext context, SourceSection section, RubyNode receiver, MethodDefinitionNode method, boolean topLevel) {
public AddMethodNode(RubyContext context, SourceSection section, RubyNode receiver, MethodDefinitionNode method) {
super(context, section);
this.receiver = receiver;
this.methodNode = method;
@@ -46,7 +53,8 @@ public RubySymbol execute(VirtualFrame frame) {
module = ((RubyBasicObject) receiverObject).getSingletonClass(this);
}

final RubyMethod method = methodObject.withDeclaringModule(module);
final Visibility visibility = getVisibility(frame, methodObject.getName());
final RubyMethod method = methodObject.withDeclaringModule(module).withVisibility(visibility);

if (method.getVisibility() == Visibility.MODULE_FUNCTION) {
module.addMethod(this, method.withVisibility(Visibility.PRIVATE));
@@ -57,4 +65,40 @@ public RubySymbol execute(VirtualFrame frame) {

return getContext().newSymbol(method.getName());
}

private Visibility getVisibility(VirtualFrame frame, String name) {
notDesignedForCompilation();

if (name.equals("initialize") || name.equals("initialize_copy") || name.equals("initialize_clone") || name.equals("initialize_dup") || name.equals("respond_to_missing?")) {
return Visibility.PRIVATE;
} else {
// Ignore scopes who do not have a visibility slot.
Visibility currentFrameVisibility = findVisibility(frame);
if (currentFrameVisibility != null) {
return currentFrameVisibility;
}

return Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Visibility>() {
@Override
public Visibility visitFrame(FrameInstance frameInstance) {
Frame frame = frameInstance.getFrame(FrameAccess.READ_ONLY, true);
return findVisibility(frame);
}
});
}
}

private static Visibility findVisibility(Frame frame) {
FrameSlot slot = frame.getFrameDescriptor().findFrameSlot(RubyModule.VISIBILITY_FRAME_SLOT_ID);
if (slot == null) {
return null;
} else {
Object visibilityObject = frame.getValue(slot);
if (visibilityObject instanceof Visibility) {
return (Visibility) visibilityObject;
} else {
return Visibility.PUBLIC;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -44,16 +44,13 @@ public class MethodDefinitionNode extends RubyNode {

private final boolean requiresDeclarationFrame;

private final boolean ignoreLocalVisibility;

public MethodDefinitionNode(RubyContext context, SourceSection sourceSection, String name, SharedMethodInfo sharedMethodInfo,
boolean requiresDeclarationFrame, CallTarget callTarget, boolean ignoreLocalVisibility) {
boolean requiresDeclarationFrame, CallTarget callTarget) {
super(context, sourceSection);
this.name = name;
this.sharedMethodInfo = sharedMethodInfo;
this.requiresDeclarationFrame = requiresDeclarationFrame;
this.callTarget = callTarget;
this.ignoreLocalVisibility = ignoreLocalVisibility;
}

public RubyMethod executeMethod(VirtualFrame frame) {
@@ -72,46 +69,8 @@ public RubyMethod executeMethod(VirtualFrame frame) {

public RubyMethod executeMethod(VirtualFrame frame, MaterializedFrame declarationFrame) {
notDesignedForCompilation();
Visibility visibility = getVisibility(frame);
return new RubyMethod(sharedMethodInfo, name, null, visibility, false, callTarget, declarationFrame);
}

private Visibility getVisibility(VirtualFrame frame) {
notDesignedForCompilation();

if (ignoreLocalVisibility) {
return Visibility.PUBLIC;
} else if (name.equals("initialize") || name.equals("initialize_copy") || name.equals("initialize_clone") || name.equals("initialize_dup") || name.equals("respond_to_missing?")) {
return Visibility.PRIVATE;
} else {
// Ignore scopes who do not have a visibility slot.
Visibility currentFrameVisibility = findVisibility(frame);
if (currentFrameVisibility != null) {
return currentFrameVisibility;
}

return Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Visibility>() {
@Override
public Visibility visitFrame(FrameInstance frameInstance) {
Frame frame = frameInstance.getFrame(FrameAccess.READ_ONLY, true);
return findVisibility(frame);
}
});
}
}

private static Visibility findVisibility(Frame frame) {
FrameSlot slot = frame.getFrameDescriptor().findFrameSlot(RubyModule.VISIBILITY_FRAME_SLOT_ID);
if (slot == null) {
return null;
} else {
Object visibilityObject = frame.getValue(slot);
if (visibilityObject instanceof Visibility) {
return (Visibility) visibilityObject;
} else {
return Visibility.PUBLIC;
}
}
return new RubyMethod(sharedMethodInfo, name, null, null, false, callTarget, declarationFrame);
}

@Override

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.methods;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyModule;

import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.FrameSlotKind;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

public class SetMethodDeclarationContext extends RubyNode {

@Child protected RubyNode child;

final String what;

public SetMethodDeclarationContext(RubyContext context, SourceSection sourceSection, String what, RubyNode child) {
super(context, sourceSection);
this.child = child;
this.what = what;
}

@Override
public Object execute(VirtualFrame frame) {
notDesignedForCompilation();

FrameSlot slot = frame.getFrameDescriptor().findOrAddFrameSlot(RubyModule.VISIBILITY_FRAME_SLOT_ID, "visibility for " + what, FrameSlotKind.Object);
Object oldVisibility = frame.getValue(slot);

try {
frame.setObject(slot, Visibility.PUBLIC);

return child.execute(frame);
} finally {
frame.setObject(slot, oldVisibility);
}
}

}
35 changes: 21 additions & 14 deletions core/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.BytesDecoder;
import com.oracle.truffle.api.source.Source;

import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby;
@@ -22,7 +23,7 @@
import org.jruby.truffle.TruffleHooks;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.methods.SetFrameVisibilityNode;
import org.jruby.truffle.nodes.methods.SetMethodDeclarationContext;
import org.jruby.truffle.nodes.rubinius.RubiniusPrimitiveManager;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.*;
@@ -161,15 +162,25 @@ private void loadFileAbsolute(String fileName, RubyNode currentNode) {
// Assume UTF-8 for the moment
final Source source = Source.fromBytes(bytes, fileName, new BytesDecoder.UTF8BytesDecoder());

load(source, currentNode, SetFrameVisibilityNode.PRIVATE_VISIBILITY_WRAPPER);
}

public void load(Source source, RubyNode currentNode) {
load(source, currentNode, NodeWrapper.IDENTITY);
}

public void load(Source source, RubyNode currentNode, NodeWrapper nodeWrapper) {
execute(this, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode, nodeWrapper);
public void load(Source source, RubyNode currentNode, final NodeWrapper nodeWrapper) {
final NodeWrapper loadWrapper = new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return new SetMethodDeclarationContext(node.getContext(), node.getSourceSection(), "load", node);
}
};

final NodeWrapper composed = new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return nodeWrapper.wrap(loadWrapper.wrap(node));
}
};

execute(this, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode, composed);
}

public RubySymbol.SymbolTable getSymbolTable() {
@@ -188,21 +199,17 @@ public RubySymbol newSymbol(ByteList name) {

public Object eval(ByteList code, RubyNode currentNode) {
final Source source = Source.fromText(code, "(eval)");
return execute(this, source, code.getEncoding(), TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode);
return execute(this, source, code.getEncoding(), TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode, NodeWrapper.IDENTITY);
}

public Object eval(ByteList code, Object self, RubyNode currentNode) {
final Source source = Source.fromText(code, "(eval)");
return execute(this, source, code.getEncoding(), TranslatorDriver.ParserContext.TOP_LEVEL, self, null, currentNode);
return execute(this, source, code.getEncoding(), TranslatorDriver.ParserContext.TOP_LEVEL, self, null, currentNode, NodeWrapper.IDENTITY);
}

public Object eval(ByteList code, RubyBinding binding, RubyNode currentNode) {
final Source source = Source.fromText(code, "(eval)");
return execute(this, source, code.getEncoding(), TranslatorDriver.ParserContext.TOP_LEVEL, binding.getSelf(), binding.getFrame(), currentNode);
}

public Object execute(RubyContext context, Source source, Encoding defaultEncoding, TranslatorDriver.ParserContext parserContext, Object self, MaterializedFrame parentFrame, RubyNode currentNode) {
return execute(context, source, defaultEncoding, parserContext, self, parentFrame, currentNode, NodeWrapper.IDENTITY);
return execute(this, source, code.getEncoding(), TranslatorDriver.ParserContext.TOP_LEVEL, binding.getSelf(), binding.getFrame(), currentNode, NodeWrapper.IDENTITY);
}

public Object execute(RubyContext context, Source source, Encoding defaultEncoding, TranslatorDriver.ParserContext parserContext, Object self, MaterializedFrame parentFrame, RubyNode currentNode, NodeWrapper wrapper) {
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.source.Source;

import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
import org.jcodings.specific.UTF8Encoding;
@@ -21,13 +22,15 @@
import org.jruby.runtime.load.LoadServiceResource;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.ArrayNodes;
import org.jruby.truffle.nodes.methods.SetMethodDeclarationContext;
import org.jruby.truffle.runtime.RubyCallStack;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.control.TruffleFatalException;
import org.jruby.truffle.runtime.hash.HashOperations;
import org.jruby.truffle.runtime.hash.KeyValue;
import org.jruby.truffle.translator.NodeWrapper;
import org.jruby.truffle.translator.TranslatorDriver;
import org.jruby.util.cli.Options;
import org.jruby.util.cli.OutputStrings;
@@ -389,7 +392,7 @@ public void loadRubyCore(String fileName) {
throw new RuntimeException(e);
}

context.execute(context, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, mainObject, null, null);
context.load(source, null, NodeWrapper.IDENTITY);
}

public void initializeEncodingConstants() {
Original file line number Diff line number Diff line change
@@ -366,7 +366,7 @@ public static void setCurrentVisibility(Visibility visibility) {
assert callerFrame.getFrameDescriptor() != null;

final FrameSlot visibilitySlot = callerFrame.getFrameDescriptor().findFrameSlot(VISIBILITY_FRAME_SLOT_ID);
assert visibilitySlot != null;
assert visibilitySlot != null : "no visibility slot";

callerFrame.setObject(visibilitySlot, visibility);
}
32 changes: 17 additions & 15 deletions core/src/main/java/org/jruby/truffle/translator/BodyTranslator.java
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import com.oracle.truffle.api.nodes.NodeUtil;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import org.joni.NameEntry;
import org.joni.Regex;
import org.joni.Syntax;
@@ -972,13 +973,21 @@ public RubyNode visitDefnNode(org.jruby.ast.DefnNode node) {
final RubyNode classNode;

if (topLevel) {
/*
* In the top-level, methods are defined in the class of the main object. This is
* counter-intuitive - I would have expected them to be defined in the singleton class.
* Apparently this is a design decision to make top-level methods sort of global.
*
* http://stackoverflow.com/questions/1761148/where-are-methods-defined-at-the-ruby-top-level
*/

// TODO: different for Kernel#load(..., true)
classNode = new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getObjectClass());
} else {
classNode = new SelfNode(context, sourceSection);
}

return translateMethodDefinition(sourceSection, classNode, node.getName(), node, node.getArgsNode(), node.getBodyNode(), false);
return translateMethodDefinition(sourceSection, classNode, node.getName(), node, node.getArgsNode(), node.getBodyNode());
}

@Override
@@ -989,10 +998,11 @@ public RubyNode visitDefsNode(org.jruby.ast.DefsNode node) {

final SingletonClassNode singletonClassNode = SingletonClassNodeFactory.create(context, sourceSection, objectNode);

return translateMethodDefinition(sourceSection, singletonClassNode, node.getName(), node, node.getArgsNode(), node.getBodyNode(), true);
return new SetMethodDeclarationContext(context, sourceSection, "defs",
translateMethodDefinition(sourceSection, singletonClassNode, node.getName(), node, node.getArgsNode(), node.getBodyNode()));
}

protected RubyNode translateMethodDefinition(SourceSection sourceSection, RubyNode classNode, String methodName, org.jruby.ast.Node parseTree, org.jruby.ast.ArgsNode argsNode, org.jruby.ast.Node bodyNode, boolean ignoreLocalVisiblity) {
protected RubyNode translateMethodDefinition(SourceSection sourceSection, RubyNode classNode, String methodName, org.jruby.ast.Node parseTree, org.jruby.ast.ArgsNode argsNode, org.jruby.ast.Node bodyNode) {
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, environment.getLexicalScope(), methodName, false, parseTree, false);

final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(
@@ -1002,17 +1012,9 @@ protected RubyNode translateMethodDefinition(SourceSection sourceSection, RubyNo

final MethodTranslator methodCompiler = new MethodTranslator(currentNode, context, this, newEnvironment, false, parent == null, source);

final MethodDefinitionNode functionExprNode = (MethodDefinitionNode) methodCompiler.compileFunctionNode(sourceSection, methodName, argsNode, bodyNode, ignoreLocalVisiblity, sharedMethodInfo);

/*
* In the top-level, methods are defined in the class of the main object. This is
* counter-intuitive - I would have expected them to be defined in the singleton class.
* Apparently this is a design decision to make top-level methods sort of global.
*
* http://stackoverflow.com/questions/1761148/where-are-methods-defined-at-the-ruby-top-level
*/
final MethodDefinitionNode functionExprNode = (MethodDefinitionNode) methodCompiler.compileFunctionNode(sourceSection, methodName, argsNode, bodyNode, sharedMethodInfo);

return new AddMethodNode(context, sourceSection, classNode, functionExprNode, topLevel);
return new AddMethodNode(context, sourceSection, classNode, functionExprNode);
}

@Override
@@ -1486,7 +1488,7 @@ public RubyNode visitIterNode(org.jruby.ast.IterNode node) {
methodCompiler.useClassVariablesAsIfInClass = true;
}

return methodCompiler.compileFunctionNode(translate(node.getPosition()), sharedMethodInfo.getName(), argsNode, node.getBodyNode(), false, sharedMethodInfo);
return methodCompiler.compileFunctionNode(translate(node.getPosition()), sharedMethodInfo.getName(), argsNode, node.getBodyNode(), sharedMethodInfo);
}

@Override
@@ -2562,7 +2564,7 @@ public RubyNode visitLambdaNode(org.jruby.ast.LambdaNode node) {
throw new UnsupportedOperationException();
}

final RubyNode definitionNode = methodCompiler.compileFunctionNode(translate(node.getPosition()), sharedMethodInfo.getName(), argsNode, node.getBodyNode(), false, sharedMethodInfo);
final RubyNode definitionNode = methodCompiler.compileFunctionNode(translate(node.getPosition()), sharedMethodInfo.getName(), argsNode, node.getBodyNode(), sharedMethodInfo);

return new LambdaNode(context, translate(node.getPosition()), definitionNode);
}
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ public MethodTranslator(RubyNode currentNode, RubyContext context, BodyTranslato
this.isTopLevel = isTopLevel;
}

public RubyNode compileFunctionNode(SourceSection sourceSection, String methodName, ArgsNode argsNode, org.jruby.ast.Node bodyNode, boolean ignoreLocalVisiblity, SharedMethodInfo sharedMethodInfo) {
public RubyNode compileFunctionNode(SourceSection sourceSection, String methodName, ArgsNode argsNode, org.jruby.ast.Node bodyNode, SharedMethodInfo sharedMethodInfo) {
if (PRINT_PARSE_TREE_METHOD_NAMES.contains(methodName)) {
System.err.println(methodName);
System.err.println(sharedMethodInfo.getParseTree().toString(true, 0));
@@ -186,7 +186,7 @@ public RubyNode compileFunctionNode(SourceSection sourceSection, String methodNa
final CallTarget callTargetForMethods = Truffle.getRuntime().createCallTarget(withoutBlockDestructureSemantics(rootNode));
return new BlockDefinitionNode(context, sourceSection, environment.getSharedMethodInfo(), environment.needsDeclarationFrame(), callTarget, callTargetForMethods);
} else {
return new MethodDefinitionNode(context, sourceSection, methodName, environment.getSharedMethodInfo(), environment.needsDeclarationFrame(), Truffle.getRuntime().createCallTarget(rootNode), ignoreLocalVisiblity);
return new MethodDefinitionNode(context, sourceSection, methodName, environment.getSharedMethodInfo(), environment.needsDeclarationFrame(), Truffle.getRuntime().createCallTarget(rootNode));
}
}

Original file line number Diff line number Diff line change
@@ -12,13 +12,15 @@
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.literal.ObjectLiteralNode;
import org.jruby.truffle.nodes.methods.AliasNodeFactory;
import org.jruby.truffle.nodes.methods.CatchReturnPlaceholderNode;
import org.jruby.truffle.nodes.methods.MethodDefinitionNode;
import org.jruby.truffle.nodes.methods.SetMethodDeclarationContext;
import org.jruby.truffle.nodes.objects.SelfNode;
import org.jruby.truffle.runtime.RubyContext;

@@ -39,8 +41,6 @@ public ModuleTranslator(RubyNode currentNode, RubyContext context, BodyTranslato
}

public MethodDefinitionNode compileClassNode(SourceSection sourceSection, String name, org.jruby.ast.Node bodyNode) {
environment.addMethodDeclarationSlots();

RubyNode body;

if (bodyNode != null) {
@@ -61,6 +61,8 @@ public MethodDefinitionNode compileClassNode(SourceSection sourceSection, String

body = new CatchReturnPlaceholderNode(context, sourceSection, body, environment.getReturnID());

body = new SetMethodDeclarationContext(context, sourceSection, name, body);

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

return new MethodDefinitionNode(
@@ -69,15 +71,14 @@ public MethodDefinitionNode compileClassNode(SourceSection sourceSection, String
environment.getSharedMethodInfo().getName(),
environment.getSharedMethodInfo(),
environment.needsDeclarationFrame(),
Truffle.getRuntime().createCallTarget(rootNode),
false);
Truffle.getRuntime().createCallTarget(rootNode));
}

@Override
public RubyNode visitDefnNode(org.jruby.ast.DefnNode node) {
final SourceSection sourceSection = translate(node.getPosition());
final SelfNode classNode = new SelfNode(context, sourceSection);
return translateMethodDefinition(sourceSection, classNode, node.getName(), node, node.getArgsNode(), node.getBodyNode(), false);
return translateMethodDefinition(sourceSection, classNode, node.getName(), node, node.getArgsNode(), node.getBodyNode());
}

@Override
Original file line number Diff line number Diff line change
@@ -56,10 +56,6 @@ public RubyNode parse(RubyContext context, org.jruby.ast.Node parseTree, org.jru
final TranslatorEnvironment environment = new TranslatorEnvironment(
context, environmentForFrame(context, null), this, allocateReturnID(), true, true, sharedMethod, sharedMethod.getName(), false);

// All parsing contexts have a visibility slot at their top level

environment.addMethodDeclarationSlots();

// Translate to Ruby Truffle nodes

final MethodTranslator translator;
@@ -70,7 +66,7 @@ public RubyNode parse(RubyContext context, org.jruby.ast.Node parseTree, org.jru
throw new RuntimeException(e);
}

return translator.compileFunctionNode(sourceSection, "(unknown)", argsNode, bodyNode, false, sharedMethod);
return translator.compileFunctionNode(sourceSection, "(unknown)", argsNode, bodyNode, sharedMethod);
}

public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEncoding, ParserContext parserContext, MaterializedFrame parentFrame, RubyNode currentNode, NodeWrapper wrapper) {
@@ -137,10 +133,6 @@ public RubyRootNode parse(RubyNode currentNode, RubyContext context, Source sour
context.getCoreLibrary().getObjectClass().setConstant(currentNode, "DATA", data);
}

// All parsing contexts have a visibility slot at their top level

environment.addMethodDeclarationSlots();

// Translate to Ruby Truffle nodes

final BodyTranslator translator;
Original file line number Diff line number Diff line change
@@ -201,10 +201,6 @@ public boolean getNeverAssignInParentScope() {
return neverAssignInParentScope;
}

public void addMethodDeclarationSlots() {
frameDescriptor.addFrameSlot(RubyModule.VISIBILITY_FRAME_SLOT_ID, "lexical visibility for def", FrameSlotKind.Object);
}

public SharedMethodInfo getSharedMethodInfo() {
return sharedMethodInfo;
}