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

Commits on Feb 6, 2015

  1. Copy the full SHA
    ee1084c View commit details
  2. [Truffle] Avoid using frame-style visibility in core.

    * For easier debugging.
    eregon committed Feb 6, 2015
    Copy the full SHA
    933a2c3 View commit details
  3. [Truffle] Do not error if there is no visibility in the caller frame.

    * Just set it to make IRB happy. Actual behavior is mysterious.
    eregon committed Feb 6, 2015
    Copy the full SHA
    4221159 View commit details
  4. [Truffle] Use the declaration frame chain to find visibility.

    * Dynamic call stack is wrong for cases such as eval with binding.
    * instance_eval(String) should set visibility to PUBLIC.
    eregon committed Feb 6, 2015
    Copy the full SHA
    e037724 View commit details
  5. Copy the full SHA
    cf80174 View commit details
  6. Copy the full SHA
    37bc09e View commit details
  7. Copy the full SHA
    a005832 View commit details
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -138,7 +138,6 @@ public class Options {
public static final Option<Integer> TRUFFLE_HASHES_SMALL = integer(TRUFFLE, "truffle.hashes.small", 3, "Maximum size of a Hash to consider small for optimisations.");

public static final Option<Boolean> TRUFFLE_LOAD_CORE = bool(TRUFFLE, "truffle.load_core", true, "Load the Truffle core library.");
public static final Option<Boolean> TRUFFLE_PROC_BINDING = bool(TRUFFLE, "truffle.proc.binding", true, "Enable Proc#binding.");

public static final Option<Integer> TRUFFLE_PASSALOT = integer(TRUFFLE, "truffle.passalot", 0, "Probabilty between 0 and 100 to randomly insert Thread.pass at a given line.");
public static final Option<Integer> TRUFFLE_STACK_SERVER_PORT = integer(TRUFFLE, "truffle.stack_server_port", 0, "Port number to run an HTTP server on that returns stack traces");
1 change: 0 additions & 1 deletion test/pom.rb
Original file line number Diff line number Diff line change
@@ -345,7 +345,6 @@
'<arg value="-J-server" />' +
'<arg value="-J-G:+TruffleCompilationExceptionsAreThrown" />' +
'<arg value="-X+T" />' +
'<arg value="-Xtruffle.proc.binding=false" />' +
'<arg value="-Xtruffle.debug.enable_assert_constant=true" />' +
'<arg value="test/truffle/pe/pe.rb" />' +
'</exec>' +
1 change: 0 additions & 1 deletion test/pom.xml
Original file line number Diff line number Diff line change
@@ -810,7 +810,6 @@
<arg value="-J-server" />
<arg value="-J-G:+TruffleCompilationExceptionsAreThrown" />
<arg value="-X+T" />
<arg value="-Xtruffle.proc.binding=false" />
<arg value="-Xtruffle.debug.enable_assert_constant=true" />
<arg value="test/truffle/pe/pe.rb" />
</exec>
2 changes: 1 addition & 1 deletion test/truffle/pe/core/hash_pe.rb
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
truffle_assert_constant hash[:b]
end

example "mapped to an Array and indexed by a constant" do
broken_example "mapped to an Array and indexed by a constant" do
hash = {a: 0, b: 1, c: 2}
array = hash.map { |k, v| v }
truffle_assert_constant array[0]
2 changes: 1 addition & 1 deletion test/truffle/pe/macro/pushing_pixels_pe.rb
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ def method_missing(method, *args)

PETests.tests do

example "A set of constants used in a literal hash, mapped to an array, indexed, used in an array literal, sorted, indexed, and added, all via method_missing, respond_to? and send" do
broken_example "A set of constants used in a literal hash, mapped to an array, indexed, used in an array literal, sorted, indexed, and added, all via method_missing, respond_to? and send" do
bar = PushingPixelsFixtures::Bar.new
truffle_assert_constant bar.foo(14, 8, 6)
end
1 change: 0 additions & 1 deletion tool/jt.rb
Original file line number Diff line number Diff line change
@@ -154,7 +154,6 @@ def test_pe
run(*%w[
--graal
-J-G:+TruffleCompilationExceptionsAreThrown
-Xtruffle.proc.binding=false
-Xtruffle.debug.enable_assert_constant=true
test/truffle/pe/pe.rb])
end
Original file line number Diff line number Diff line change
@@ -281,7 +281,7 @@ public InstanceEvalNode(InstanceEvalNode prev) {
public Object instanceEval(VirtualFrame frame, Object receiver, RubyString string, UndefinedPlaceholder block) {
notDesignedForCompilation();

return getContext().eval(string.getBytes(), receiver, this);
return getContext().instanceEval(string.getBytes(), receiver, this);
}

@Specialization
Original file line number Diff line number Diff line change
@@ -436,7 +436,7 @@ private Object classEvalSource(VirtualFrame frame, RubyModule module, Source sou
return getContext().execute(getContext(), source, encoding, TranslatorDriver.ParserContext.MODULE, module, binding.getFrame(), this, new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return new SetMethodDeclarationContext(node.getContext(), node.getSourceSection(), "class_eval", node);
return new SetMethodDeclarationContext(node.getContext(), node.getSourceSection(), Visibility.PUBLIC, "class_eval", node);
}
});
}
Original file line number Diff line number Diff line change
@@ -61,11 +61,6 @@ public BindingNode(BindingNode prev) {

@Specialization
public Object binding(RubyProc proc) {
if (!RubyProc.PROC_BINDING) {
getContext().getWarnings().warn("Proc#binding disabled, returning nil. Use -Xtruffle.proc.binding=true to enable it.");
return getContext().getCoreLibrary().getNilObject();
}

final MaterializedFrame frame = proc.getDeclarationFrame();

return new RubyBinding(getContext().getCoreLibrary().getBindingClass(),
Original file line number Diff line number Diff line change
@@ -20,7 +20,9 @@

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.TruffleFatalException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.core.RubySymbol;
@@ -66,28 +68,28 @@ public RubySymbol execute(VirtualFrame frame) {
return getContext().newSymbol(method.getName());
}

private Visibility getVisibility(VirtualFrame frame, String name) {
private static Visibility getVisibility(Frame 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>() {
return getVisibility(frame);
}
}

@Override
public Visibility visitFrame(FrameInstance frameInstance) {
Frame frame = frameInstance.getFrame(FrameAccess.READ_ONLY, true);
return findVisibility(frame);
}
private static Visibility getVisibility(Frame frame) {
notDesignedForCompilation();

});
while (frame != null) {
Visibility visibility = findVisibility(frame);
if (visibility != null) {
return visibility;
}
frame = RubyArguments.getDeclarationFrame(frame.getArguments());
}

throw new UnsupportedOperationException("No declaration frame with visibility found");
}

private static Visibility findVisibility(Frame frame) {
Original file line number Diff line number Diff line change
@@ -23,11 +23,13 @@ public class SetMethodDeclarationContext extends RubyNode {

@Child private RubyNode child;

final Visibility visibility;
final String what;

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

@@ -39,7 +41,7 @@ public Object execute(VirtualFrame frame) {
Object oldVisibility = frame.getValue(slot);

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

return child.execute(frame);
} finally {
Original file line number Diff line number Diff line change
@@ -38,16 +38,17 @@ public Object dispatchWithModifiedBlock(VirtualFrame frame, RubyProc block, Ruby
return dispatch.dispatchWithModifiedBlock(frame, block, modifiedBlock, argumentsObjects);
}

public Object dispatchWithModifiedSelf(VirtualFrame frame, RubyProc block, Object self, Object... argumentsObjects) {
public Object dispatchWithModifiedSelf(VirtualFrame currentFrame, RubyProc block, Object self, Object... argumentsObjects) {
// TODO: assumes this also changes the default definee.

Frame frame = block.getDeclarationFrame();
FrameSlot slot = frame.getFrameDescriptor().findOrAddFrameSlot(RubyModule.VISIBILITY_FRAME_SLOT_ID, "dynamic visibility for def", FrameSlotKind.Object);
Object oldVisibility = frame.getValue(slot);

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

return dispatch.dispatchWithModifiedSelf(frame, block, self, argumentsObjects);
return dispatch.dispatchWithModifiedSelf(currentFrame, block, self, argumentsObjects);
} finally {
frame.setObject(slot, oldVisibility);
}
12 changes: 9 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby;
import org.jruby.RubyNil;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.TruffleHooks;
import org.jruby.truffle.nodes.RubyNode;
@@ -169,7 +170,7 @@ public void load(Source source, RubyNode currentNode, final NodeWrapper nodeWrap
final NodeWrapper loadWrapper = new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return new SetMethodDeclarationContext(node.getContext(), node.getSourceSection(), "load", node);
return new SetMethodDeclarationContext(node.getContext(), node.getSourceSection(), Visibility.PRIVATE, "load", node);
}
};

@@ -202,9 +203,14 @@ public Object eval(ByteList code, RubyNode 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) {
public Object instanceEval(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, NodeWrapper.IDENTITY);
return execute(this, source, code.getEncoding(), TranslatorDriver.ParserContext.TOP_LEVEL, self, null, currentNode, new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return new SetMethodDeclarationContext(node.getContext(), node.getSourceSection(), Visibility.PUBLIC, "instance_eval", node);
}
});
}

public Object eval(ByteList code, RubyBinding binding, boolean ownScopeForAssignments, RubyNode currentNode) {
Original file line number Diff line number Diff line change
@@ -16,11 +16,13 @@
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.FrameSlotKind;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.utilities.CyclicAssumption;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.methods.AddMethodNode;
import org.jruby.truffle.nodes.objects.Allocator;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -365,8 +367,8 @@ public static void setCurrentVisibility(Visibility visibility) {
assert callerFrame != null;
assert callerFrame.getFrameDescriptor() != null;

final FrameSlot visibilitySlot = callerFrame.getFrameDescriptor().findFrameSlot(VISIBILITY_FRAME_SLOT_ID);
assert visibilitySlot != null : "no visibility slot";
final FrameSlot visibilitySlot = callerFrame.getFrameDescriptor().findOrAddFrameSlot(
RubyModule.VISIBILITY_FRAME_SLOT_ID, "visibility for frame", FrameSlotKind.Object);

callerFrame.setObject(visibilitySlot, visibility);
}
Original file line number Diff line number Diff line change
@@ -26,8 +26,6 @@
*/
public class RubyProc extends RubyBasicObject implements MethodLike {

public static final boolean PROC_BINDING = Options.TRUFFLE_PROC_BINDING.load();

public static enum Type {
BLOCK, PROC, LAMBDA
}
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import org.jruby.ast.*;
import org.jruby.common.IRubyWarnings;
import org.jruby.lexer.yacc.InvalidSourcePosition;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.*;
import org.jruby.truffle.nodes.DefinedNode;
import org.jruby.truffle.nodes.ForNode;
@@ -1051,8 +1052,8 @@ public RubyNode visitDefsNode(org.jruby.ast.DefsNode node) {

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

return new SetMethodDeclarationContext(context, sourceSection, "defs",
translateMethodDefinition(sourceSection, singletonClassNode, node.getName(), node, node.getArgsNode(), node.getBodyNode()));
return new SetMethodDeclarationContext(context, sourceSection, Visibility.PUBLIC,
"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) {
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.control.SequenceNode;
@@ -61,7 +62,7 @@ public MethodDefinitionNode compileClassNode(SourceSection sourceSection, String

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

body = new SetMethodDeclarationContext(context, sourceSection, name, body);
body = new SetMethodDeclarationContext(context, sourceSection, Visibility.PUBLIC, name, body);

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

Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ public class TranslatorEnvironment {
private final boolean neverAssignInParentScope;

protected final TranslatorEnvironment parent;
private boolean needsDeclarationFrame = RubyProc.PROC_BINDING;
private boolean needsDeclarationFrame = true; // We keep the logic as we might do it differently one day.
private final SharedMethodInfo sharedMethodInfo;

private final String namedMethodName;
5 changes: 3 additions & 2 deletions truffle/src/main/ruby/jruby/truffle/core/kernel.rb
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@

module Kernel

module_function

def p(*args)
args.each do |arg|
print arg.inspect
@@ -18,6 +16,7 @@ def p(*args)

args.size <= 1 ? args.first : args
end
module_function :p

def puts(*args)
print "\n" if args.empty?
@@ -32,10 +31,12 @@ def puts(*args)
end
end
end
module_function :puts

def printf(*args)
print sprintf(*args)
end
module_function :printf

alias_method :trust, :untaint
alias_method :untrust, :taint