Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 23, 2014
2 parents 8f74f30 + 4b3b272 commit 03a8a55
Show file tree
Hide file tree
Showing 271 changed files with 4,522 additions and 1,543 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Expand Up @@ -98,6 +98,3 @@ core/.classpath
core/.gitignore
core/.project
core/.settings

# Truffle benchmark stuff
reference.txt
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -37,6 +37,7 @@ env:
- PHASE='-Prake -Dtask=spec:profiler'
- PHASE='-Ptruffle-specs-language'
- PHASE='-Ptruffle-specs-core'
- PHASE='-Ptruffle-specs-rubysl'

matrix:
include:
Expand Down Expand Up @@ -66,6 +67,7 @@ matrix:
- env: PHASE='-Pcomplete'
- env: PHASE='-Prake -Dtask=spec:jrubyc'
- env: PHASE='-Prake -Dtask=spec:profiler'
- env: PHASE='-Ptruffle-specs-rubysl'

branches:
only:
Expand Down
Expand Up @@ -583,4 +583,9 @@ public T visitZSuperNode(ZSuperNode node) {
return defaultVisit(node);
}

@Override
public T visitOther(Node node) {
return defaultVisit(node);
}

}
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ast/visitor/NodeVisitor.java
Expand Up @@ -146,4 +146,5 @@ public interface NodeVisitor<T> {
public T visitYieldNode(YieldNode iVisited);
public T visitZArrayNode(ZArrayNode iVisited);
public T visitZSuperNode(ZSuperNode iVisited);
public T visitOther(Node iVisited);
}
13 changes: 8 additions & 5 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -987,7 +987,7 @@ public Operand buildCall(CallNode callNode, IRScope s) {
List<Operand> args = setupCallArgs(callArgsNode, s);
Operand block = setupCallClosure(callNode.getIterNode(), s);
Variable callResult = s.createTemporaryVariable();
CallInstr callInstr = CallInstr.create(callResult, callNode.getName(), receiver, args.toArray(new Operand[args.size()]), block);
CallInstr callInstr = (CallInstr)CallInstr.create(callResult, callNode.getName(), receiver, args.toArray(new Operand[args.size()]), block).specializeForInterpretation();

// This is to support the ugly Proc.new with no block, which must see caller's frame
if (
Expand Down Expand Up @@ -2204,7 +2204,7 @@ public Operand buildFCall(FCallNode fcallNode, IRScope s) {
List<Operand> args = setupCallArgs(callArgsNode, s);
Operand block = setupCallClosure(fcallNode.getIterNode(), s);
Variable callResult = s.createTemporaryVariable();
CallInstr callInstr = CallInstr.create(CallType.FUNCTIONAL, callResult, fcallNode.getName(), s.getSelf(), args.toArray(new Operand[args.size()]), block);
CallInstr callInstr = (CallInstr)CallInstr.create(CallType.FUNCTIONAL, callResult, fcallNode.getName(), s.getSelf(), args.toArray(new Operand[args.size()]), block).specializeForInterpretation();
receiveBreakException(s, block, callInstr);
return callResult;
}
Expand Down Expand Up @@ -2917,8 +2917,8 @@ public Operand buildPostExe(PostExeNode postExeNode, IRScope s) {
closureBuilder.addInstr(endClosure, new CopyInstr(endClosure.getCurrentModuleVariable(), new ScopeModule(0)));
closureBuilder.build(postExeNode.getBodyNode(), endClosure);

// Record to IRScope so JIT can pre-compile all potentially activated END blocks.
topLevel.recordEndBlock(endClosure);
// END does not have either explicit or implicit return, so we add one
closureBuilder.addInstr(endClosure, new ReturnInstr(new Nil()));

// Add an instruction in 's' to record the end block in the 'topLevel' scope.
// SSS FIXME: IR support for end-blocks that access vars in non-toplevel-scopes
Expand All @@ -2939,6 +2939,9 @@ public Operand buildPreExe(PreExeNode preExeNode, IRScope s) {
closureBuilder.addInstr(beginClosure, new CopyInstr(beginClosure.getCurrentModuleVariable(), new ScopeModule(0)));
closureBuilder.build(preExeNode.getBodyNode(), beginClosure);

// BEGIN does not have either explicit or implicit return, so we add one
closureBuilder.addInstr(beginClosure, new ReturnInstr(new Nil()));

// Record the begin block at IR build time
s.getTopLevelScope().recordBeginBlock(beginClosure);
return manager.getNil();
Expand Down Expand Up @@ -3378,7 +3381,7 @@ public Operand buildVAlias(VAliasNode valiasNode, IRScope s) {

public Operand buildVCall(VCallNode node, IRScope s) {
Variable callResult = s.createTemporaryVariable();
Instr callInstr = CallInstr.create(CallType.VARIABLE, callResult, node.getName(), s.getSelf(), NO_ARGS, null);
Instr callInstr = CallInstr.create(CallType.VARIABLE, callResult, node.getName(), s.getSelf(), NO_ARGS, null).specializeForInterpretation();
addInstr(s, callInstr);
return callResult;
}
Expand Down
15 changes: 1 addition & 14 deletions core/src/main/java/org/jruby/ir/IREvalScript.java
Expand Up @@ -13,7 +13,6 @@

public class IREvalScript extends IRClosure {
private List<IRClosure> beginBlocks;
private List<IRClosure> endBlocks;
private EvalType evalType;

public IREvalScript(IRManager manager, IRScope lexicalParent, String fileName,
Expand Down Expand Up @@ -68,22 +67,10 @@ public void recordBeginBlock(IRClosure beginBlockClosure) {
beginBlocks.add(beginBlockClosure);
}

/* Record an end block -- not all scope implementations can handle them */
@Override
public void recordEndBlock(IRClosure endBlockClosure) {
if (endBlocks == null) endBlocks = new ArrayList<>();
endBlockClosure.setBeginEndBlock();
endBlocks.add(endBlockClosure);
}

public List<IRClosure> getBeginBlocks() {
return beginBlocks;
}

public List<IRClosure> getEndBlocks() {
return endBlocks;
}

@Override
public LocalVariable getNewFlipStateVariable() {
String flipVarName = "%flip_" + allocateNextPrefixedName("%flip");
Expand All @@ -101,4 +88,4 @@ public boolean isScriptScope() {
public boolean isFlipScope() {
return true;
}
}
}
5 changes: 0 additions & 5 deletions core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -1108,11 +1108,6 @@ public void recordBeginBlock(IRClosure beginBlockClosure) {
throw new RuntimeException("BEGIN blocks cannot be added to: " + this.getClass().getName());
}

/* Record an end block. Only eval and script body scopes support this */
public void recordEndBlock(IRClosure endBlockClosure) {
throw new RuntimeException("END blocks cannot be added to: " + this.getClass().getName());
}

public List<IRClosure> getBeginBlocks() {
return null;
}
Expand Down
14 changes: 0 additions & 14 deletions core/src/main/java/org/jruby/ir/IRScriptBody.java
Expand Up @@ -11,7 +11,6 @@

public class IRScriptBody extends IRScope {
private List<IRClosure> beginBlocks;
private List<IRClosure> endBlocks;
private DynamicScope toplevelScope;

public IRScriptBody(IRManager manager, String sourceName, StaticScope staticScope) {
Expand Down Expand Up @@ -59,24 +58,11 @@ public void recordBeginBlock(IRClosure beginBlockClosure) {
beginBlocks.add(beginBlockClosure);
}

/* Record an end block -- not all scope implementations can handle them */
@Override
public void recordEndBlock(IRClosure endBlockClosure) {
if (endBlocks == null) endBlocks = new ArrayList<IRClosure>();
endBlockClosure.setBeginEndBlock();
endBlocks.add(endBlockClosure);
}

@Override
public List<IRClosure> getBeginBlocks() {
return beginBlocks;
}

@Override
public List<IRClosure> getEndBlocks() {
return endBlocks;
}

@Override
public boolean isScriptScope() {
return true;
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/ir/IRVisitor.java
Expand Up @@ -5,6 +5,10 @@
import org.jruby.ir.instructions.boxing.*;
import org.jruby.ir.instructions.defined.GetErrorInfoInstr;
import org.jruby.ir.instructions.defined.RestoreErrorInfoInstr;
import org.jruby.ir.instructions.specialized.OneFixnumArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneFloatArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.ZeroOperandArgNoBlockCallInstr;
import org.jruby.ir.operands.*;
import org.jruby.ir.operands.Boolean;

Expand Down Expand Up @@ -75,6 +79,9 @@ private void error(Object object) {
public void NonlocalReturnInstr(NonlocalReturnInstr nonlocalreturninstr) { error(nonlocalreturninstr); }
public void NopInstr(NopInstr nopinstr) { error(nopinstr); }
public void NoResultCallInstr(NoResultCallInstr noresultcallinstr) { error(noresultcallinstr); }
public void OneFixnumArgNoBlockCallInstr(OneFixnumArgNoBlockCallInstr oneFixnumArgNoBlockCallInstr) { error(oneFixnumArgNoBlockCallInstr); }
public void OneFloatArgNoBlockCallInstr(OneFloatArgNoBlockCallInstr oneFloatArgNoBlockCallInstr) { error(oneFloatArgNoBlockCallInstr); }
public void OneOperandArgNoBlockCallInstr(OneOperandArgNoBlockCallInstr oneOperandArgNoBlockCallInstr) { error(oneOperandArgNoBlockCallInstr); }
public void OptArgMultipleAsgnInstr(OptArgMultipleAsgnInstr optargmultipleasgninstr) { error(optargmultipleasgninstr); }
public void PopBindingInstr(PopBindingInstr popbindinginstr) { error(popbindinginstr); }
public void PopFrameInstr(PopFrameInstr popframeinstr) { error(popframeinstr); }
Expand Down Expand Up @@ -111,6 +118,7 @@ private void error(Object object) {
public void UndefMethodInstr(UndefMethodInstr undefmethodinstr) { error(undefmethodinstr); }
public void UnresolvedSuperInstr(UnresolvedSuperInstr unresolvedsuperinstr) { error(unresolvedsuperinstr); }
public void YieldInstr(YieldInstr yieldinstr) { error(yieldinstr); }
public void ZeroOperandArgNoBlockCallInstr(ZeroOperandArgNoBlockCallInstr zeroOperandArgNoBlockCallInstr) { error(zeroOperandArgNoBlockCallInstr); }
public void ZSuperInstr(ZSuperInstr zsuperinstr) { error(zsuperinstr); }

// "defined" instructions
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/Operation.java
Expand Up @@ -68,6 +68,7 @@ public enum Operation {

/* specialized calls */
CALL_1F(OpFlags.f_has_side_effect | OpFlags.f_is_call | OpFlags.f_can_raise_exception),
CALL_1D(OpFlags.f_has_side_effect | OpFlags.f_is_call | OpFlags.f_can_raise_exception),
CALL_1O(OpFlags.f_has_side_effect | OpFlags.f_is_call | OpFlags.f_can_raise_exception),
CALL_1OB(OpFlags.f_has_side_effect | OpFlags.f_is_call | OpFlags.f_can_raise_exception),
CALL_0O(OpFlags.f_has_side_effect | OpFlags.f_is_call | OpFlags.f_can_raise_exception),
Expand Down Expand Up @@ -153,7 +154,7 @@ public enum Operation {
MASGN_REST(0),
RAISE_ARGUMENT_ERROR(OpFlags.f_can_raise_exception),
RAISE_REQUIRED_KEYWORD_ARGUMENT_ERROR(OpFlags.f_can_raise_exception),
RECORD_END_BLOCK(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
RECORD_END_BLOCK(OpFlags.f_has_side_effect),
RESCUE_EQQ(OpFlags.f_can_raise_exception), // a === call used in rescue
RUNTIME_HELPER(OpFlags.f_has_side_effect | OpFlags.f_can_raise_exception),
SET_CAPTURED_VAR(OpFlags.f_can_raise_exception),
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/org/jruby/ir/instructions/CallBase.java
Expand Up @@ -4,6 +4,7 @@
import org.jruby.ir.IRScope;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.*;
import org.jruby.ir.operands.Float;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
Expand Down Expand Up @@ -149,6 +150,14 @@ public boolean isAllFixnums() {
return true;
}

public boolean isAllFloats() {
for (Operand argument : arguments) {
if (!(argument instanceof Float)) return false;
}

return true;
}

@Override
public boolean computeScopeFlags(IRScope scope) {
boolean modifiedScope = false;
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/ir/instructions/CallInstr.java
Expand Up @@ -3,6 +3,7 @@
import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.specialized.OneFixnumArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneFloatArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.ZeroOperandArgNoBlockCallInstr;
Expand Down Expand Up @@ -62,6 +63,7 @@ public CallBase specializeForInterpretation() {
return hasClosure() ? this : new ZeroOperandArgNoBlockCallInstr(this);
case 1:
if (isAllFixnums() && !hasClosure()) return new OneFixnumArgNoBlockCallInstr(this);
if (isAllFloats() && !hasClosure()) return new OneFloatArgNoBlockCallInstr(this);

return hasClosure() ? new OneOperandArgBlockCallInstr(this) : new OneOperandArgNoBlockCallInstr(this);
}
Expand Down
@@ -1,10 +1,15 @@
package org.jruby.ir.instructions;

import org.jruby.ir.*;
import org.jruby.ir.interpreter.BeginEndInterpreterContext;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.WrappedIRClosure;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class RecordEndBlockInstr extends Instr implements FixedArityInstr {
private final IRScope declaringScope;
Expand Down Expand Up @@ -47,8 +52,11 @@ public Instr clone(CloneInfo ii) {
return new RecordEndBlockInstr(declaringScope, (WrappedIRClosure) endBlockClosure.cloneForInlining(ii));
}

public void interpret() {
((BeginEndInterpreterContext) declaringScope.getTopLevelScope().getInterpreterContext()).recordEndBlock(endBlockClosure);
@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
Block blk = (Block) endBlockClosure.retrieve(context, self, currScope, context.getCurrentScope(), temp);
IRRuntimeHelpers.pushExitBlock(context, blk);
return null;
}

@Override
Expand Down
@@ -1,5 +1,6 @@
package org.jruby.ir.instructions.specialized;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.CallInstr;
import org.jruby.ir.operands.Fixnum;
Expand Down Expand Up @@ -34,4 +35,9 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
IRubyObject object = (IRubyObject) receiver.retrieve(context, self, currScope, dynamicScope, temp);
return getCallSite().call(context, self, object, fixNum);
}

@Override
public void visit(IRVisitor visitor) {
visitor.OneFixnumArgNoBlockCallInstr(this);
}
}
@@ -0,0 +1,42 @@
package org.jruby.ir.instructions.specialized;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.CallInstr;
import org.jruby.ir.operands.Float;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class OneFloatArgNoBlockCallInstr extends CallInstr {
private final double flote;

public OneFloatArgNoBlockCallInstr(CallInstr call) {
super(Operation.CALL_1D, call);

assert getCallArgs().length == 1;

this.flote = ((Float) getCallArgs()[0]).value;
}

@Override
public String toString() {
return super.toString() + "{1F}";
}

public double getFloatArg() {
return flote;
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope dynamicScope, IRubyObject self, Object[] temp) {
IRubyObject object = (IRubyObject) receiver.retrieve(context, self, currScope, dynamicScope, temp);
return getCallSite().call(context, self, object, flote);
}

@Override
public void visit(IRVisitor visitor) {
visitor.OneFloatArgNoBlockCallInstr(this);
}
}
@@ -1,5 +1,6 @@
package org.jruby.ir.instructions.specialized;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.CallInstr;
import org.jruby.ir.operands.Operand;
Expand Down Expand Up @@ -28,4 +29,9 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
IRubyObject arg1 = (IRubyObject) getCallArgs()[0].retrieve(context, self, currScope, dynamicScope, temp);
return getCallSite().call(context, self, object, arg1);
}

@Override
public void visit(IRVisitor visitor) {
visitor.OneOperandArgNoBlockCallInstr(this);
}
}
@@ -1,8 +1,8 @@
package org.jruby.ir.instructions.specialized;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.CallInstr;
import org.jruby.ir.operands.Operand;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand All @@ -24,4 +24,9 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco

return getCallSite().call(context, self, object);
}

@Override
public void visit(IRVisitor visitor) {
visitor.ZeroOperandArgNoBlockCallInstr(this);
}
}

0 comments on commit 03a8a55

Please sign in to comment.