Skip to content

Commit

Permalink
Merge branch 'master' into ruby-2.3
Browse files Browse the repository at this point in the history
* master: (23 commits)
  Fix build
  Add tags for new failing specs.
  do not raise when precision is passed to BigDecimal#round
  [Truffle] BigDecimal#round do not raise FloatDomainError when precision is used
  [Truffle] Float#to_s slow compatibility implementation
  [Truffle] code style
  [Truffle] Fix rand spec filename.
  [Truffle] Let InternalMethod visit itself.
  [Truffle] Remember the Proc for a define_method, as it may access the block declaration frame.
  [Truffle] Tag new failing specs.
  [Truffle] Add Method#[] as an alias to #call.
  [Truffle] Fix style.
  Squashed 'spec/ruby/' changes from 92311a8..cfdf72f
  Plug in Push/Pop Frame/Binding instructions into the interpreter
  Fix buggy updates from previous commit.
  Add Block variants of push/pop frame/binding instructions
  More tweaks to interpreter signatures
  Rename some IRVisitor methods
  sprintf: test infinite and nan float values
  [Truffle] fix formating of infinite and nan floats
  ...
kares committed Dec 2, 2015
2 parents a4ab413 + 4754c09 commit adbdeab
Showing 165 changed files with 1,307 additions and 579 deletions.
9 changes: 6 additions & 3 deletions core/src/main/java/org/jruby/ir/IRVisitor.java
Original file line number Diff line number Diff line change
@@ -86,14 +86,17 @@ private void error(Object object) {
public void OneOperandArgNoBlockCallInstr(OneOperandArgNoBlockCallInstr oneOperandArgNoBlockCallInstr) { error(oneOperandArgNoBlockCallInstr); }
public void OptArgMultipleAsgnInstr(OptArgMultipleAsgnInstr optargmultipleasgninstr) { error(optargmultipleasgninstr); }
public void PopBindingInstr(PopBindingInstr popbindinginstr) { error(popbindinginstr); }
public void PopFrameInstr(PopMethodFrameInstr popframeinstr) { error(popframeinstr); }
public void PopBlockFrameInstr(PopBlockFrameInstr instr) { error(instr); }
public void PopMethodFrameInstr(PopMethodFrameInstr instr) { error(instr); }
public void ProcessModuleBodyInstr(ProcessModuleBodyInstr processmodulebodyinstr) { error(processmodulebodyinstr); }
public void PutClassVariableInstr(PutClassVariableInstr putclassvariableinstr) { error(putclassvariableinstr); }
public void PutConstInstr(PutConstInstr putconstinstr) { error(putconstinstr); }
public void PutFieldInstr(PutFieldInstr putfieldinstr) { error(putfieldinstr); }
public void PutGlobalVarInstr(PutGlobalVarInstr putglobalvarinstr) { error(putglobalvarinstr); }
public void PushBindingInstr(PushMethodBindingInstr pushbindinginstr) { error(pushbindinginstr); }
public void PushFrameInstr(PushMethodFrameInstr pushframeinstr) { error(pushframeinstr); }
public void PushBlockBindingInstr(PushBlockBindingInstr instr) { error(instr); }
public void PushBlockFrameInstr(PushBlockFrameInstr instr) { error(instr); }
public void PushMethodBindingInstr(PushMethodBindingInstr instr) { error(instr); }
public void PushMethodFrameInstr(PushMethodFrameInstr instr) { error(instr); }
public void RaiseArgumentErrorInstr(RaiseArgumentErrorInstr raiseargumenterrorinstr) { error(raiseargumenterrorinstr); }
public void RaiseRequiredKeywordArgumentErrorInstr(RaiseRequiredKeywordArgumentError instr) { error(instr); }
public void ReifyClosureInstr(ReifyClosureInstr reifyclosureinstr) { error(reifyclosureinstr); }
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/ir/Operation.java
Original file line number Diff line number Diff line change
@@ -207,6 +207,9 @@ public enum Operation {
PUSH_METHOD_FRAME(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
PUSH_METHOD_BINDING(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
POP_METHOD_FRAME(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
PUSH_BLOCK_FRAME(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
PUSH_BLOCK_BINDING(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
POP_BLOCK_FRAME(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
POP_BINDING(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
TOGGLE_BACKTRACE(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect);

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jruby.ir.instructions;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.persistence.IRWriterEncoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;

public class PopBlockFrameInstr extends OneOperandInstr implements FixedArityInstr {
public PopBlockFrameInstr(Operand frame) {
super(Operation.POP_BLOCK_FRAME, frame);
}

public Operand getFrame() {
return getOperand1();
}

@Override
public Instr clone(CloneInfo ii) {
return ii instanceof SimpleCloneInfo ? this : NopInstr.NOP; // FIXME: Is this correct
}

@Override
public void encode(IRWriterEncoder e) {
super.encode(e);
e.encode(getFrame());
}

public static PopBlockFrameInstr decode(IRReaderDecoder d) {
return new PopBlockFrameInstr(d.decodeOperand());
}

@Override
public void visit(IRVisitor visitor) {
visitor.PopBlockFrameInstr(this);
}
}
Original file line number Diff line number Diff line change
@@ -22,6 +22,6 @@ public static PopMethodFrameInstr decode(IRReaderDecoder d) {

@Override
public void visit(IRVisitor visitor) {
visitor.PopFrameInstr(this);
visitor.PopMethodFrameInstr(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.jruby.ir.instructions;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.persistence.IRWriterEncoder;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.transformations.inlining.CloneInfo;

public class PushBlockBindingInstr extends NoOperandInstr implements FixedArityInstr {
public PushBlockBindingInstr() {
super(Operation.PUSH_BLOCK_BINDING);
}

@Override
public Instr clone(CloneInfo ii) {
return this; // FIXME: This has to be wrong if pop_binding is conditionally noop'ing on inline
}

public static PushBlockBindingInstr decode(IRReaderDecoder d) {
return new PushBlockBindingInstr();
}

@Override
public void visit(IRVisitor visitor) {
visitor.PushBlockBindingInstr(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.jruby.ir.instructions;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.persistence.IRWriterEncoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;

public class PushBlockFrameInstr extends NoOperandResultBaseInstr implements FixedArityInstr {
private final String frameName;

public PushBlockFrameInstr(Variable result, String frameName) {
super(Operation.PUSH_BLOCK_FRAME, result);
this.frameName = frameName;
}

public String getFrameName() {
return frameName;
}

@Override
public Instr clone(CloneInfo ii) {
return ii instanceof SimpleCloneInfo ? this : NopInstr.NOP; // FIXME: Is this correct?
}

public static PushBlockFrameInstr decode(IRReaderDecoder d) {
return new PushBlockFrameInstr(d.decodeVariable(), d.decodeString());
}

@Override
public void encode(IRWriterEncoder e) {
super.encode(e);
e.encode(getFrameName());
}

@Override
public void visit(IRVisitor visitor) {
visitor.PushBlockFrameInstr(this);
}
}
Original file line number Diff line number Diff line change
@@ -21,6 +21,6 @@ public static PushMethodBindingInstr decode(IRReaderDecoder d) {

@Override
public void visit(IRVisitor visitor) {
visitor.PushBindingInstr(this);
visitor.PushMethodBindingInstr(this);
}
}
Original file line number Diff line number Diff line change
@@ -29,6 +29,6 @@ public static PushMethodFrameInstr decode(IRReaderDecoder d) {

@Override
public void visit(IRVisitor visitor) {
visitor.PushFrameInstr(this);
visitor.PushMethodFrameInstr(this);
}
}
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
import org.jruby.ir.instructions.JumpInstr;
import org.jruby.ir.instructions.LineNumberInstr;
import org.jruby.ir.instructions.NonlocalReturnInstr;
import org.jruby.ir.instructions.PopBlockFrameInstr;
import org.jruby.ir.instructions.PushBlockFrameInstr;
import org.jruby.ir.instructions.ResultInstr;
import org.jruby.ir.instructions.ReturnBase;
import org.jruby.ir.instructions.RuntimeHelperCall;
@@ -20,6 +22,7 @@
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.Frame;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
@@ -38,10 +41,10 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
int n = instrs.length;
int ipc = 0;
Object exception = null;
Block.Type blockType = block == null ? null : block.type;

StaticScope currScope = interpreterContext.getStaticScope();
DynamicScope currDynScope = context.getCurrentScope();
Block.Type blockType = block == null ? null : block.type;

// Init profiling this scope
boolean debug = IRRuntimeHelpers.isDebug();
@@ -59,6 +62,7 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
ipc++;

try {
Frame f;
switch (operation) {
case RETURN:
return (IRubyObject) retrieveOp(((ReturnBase) instr).getReturnValue(), context, self, currDynScope, currScope, temp);
@@ -78,6 +82,14 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
case THROW:
instr.interpret(context, currScope, currDynScope, self, temp);
break;
case PUSH_BLOCK_FRAME:
f = context.preYieldNoScope(block.getBinding());
setResult(temp, currDynScope, ((PushBlockFrameInstr)instr).getResult(), f);
break;
case POP_BLOCK_FRAME:
f = (Frame)retrieveOp(((PopBlockFrameInstr)instr).getFrame(), context, self, currDynScope, currScope, temp);
context.postYieldNoScope(f);
break;
case PUSH_METHOD_FRAME:
context.preMethodFrameOnly(implClass, name, self, blockArg);
// Only the top-level script scope has PRIVATE visibility.
45 changes: 34 additions & 11 deletions core/src/main/java/org/jruby/ir/interpreter/InterpreterEngine.java
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
import org.jruby.ir.instructions.JumpInstr;
import org.jruby.ir.instructions.LineNumberInstr;
import org.jruby.ir.instructions.NonlocalReturnInstr;
import org.jruby.ir.instructions.PopBlockFrameInstr;
import org.jruby.ir.instructions.PushBlockFrameInstr;
import org.jruby.ir.instructions.ReceiveArgBase;
import org.jruby.ir.instructions.ReceivePostReqdArgInstr;
import org.jruby.ir.instructions.ReceivePreReqdArgInstr;
@@ -53,7 +55,9 @@
import org.jruby.ir.operands.Variable;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.EvalType;
import org.jruby.runtime.Block;
import org.jruby.runtime.Frame;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ThreadContext;
@@ -109,7 +113,6 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
int n = instrs.length;
int ipc = 0;
Object exception = null;
Block.Type blockType = block == null ? null : block.type;

if (interpreterContext.receivesKeywordArguments()) IRRuntimeHelpers.frobnicateKwargsArgument(context, interpreterContext.getRequiredArgsCount(), args);

@@ -153,7 +156,7 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
processCall(context, instr, operation, currDynScope, currScope, temp, self);
break;
case RET_OP:
return processReturnOp(context, instr, operation, currDynScope, temp, self, blockType, currScope);
return processReturnOp(context, block, instr, operation, currDynScope, temp, self, currScope);
case BRANCH_OP:
switch (operation) {
case JUMP: ipc = ((JumpInstr)instr).getJumpTarget().getTargetPC(); break;
@@ -167,12 +170,20 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
// which will now use the updated value of currDynScope.
currDynScope = interpreterContext.newDynamicScope(context);
context.pushScope(currDynScope);
} else if (operation == Operation.PUSH_BLOCK_BINDING) {
DynamicScope newScope = block.getBinding().getDynamicScope();
if (interpreterContext.pushNewDynScope()) {
context.pushScope(block.allocScope(newScope));
} else if (interpreterContext.reuseParentDynScope()) {
// Reuse! We can avoid the push only if surrounding vars aren't referenced!
context.pushScope(newScope);
}
} else {
processBookKeepingOp(context, instr, operation, name, args, self, blockArg, blockType, implClass);
processBookKeepingOp(context, block, instr, operation, name, args, self, blockArg, implClass, currDynScope, temp, currScope);
}
break;
case OTHER_OP:
processOtherOp(context, instr, operation, currDynScope, currScope, temp, self, blockType, floats, fixnums, booleans);
processOtherOp(context, block, instr, operation, currDynScope, currScope, temp, self, floats, fixnums, booleans);
break;
}
} catch (Throwable t) {
@@ -323,12 +334,22 @@ protected static void processCall(ThreadContext context, Instr instr, Operation
}
}

protected static void processBookKeepingOp(ThreadContext context, Instr instr, Operation operation,
String name, IRubyObject[] args, IRubyObject self, Block blockArg,
Block.Type blockType, RubyModule implClass) {
protected static void processBookKeepingOp(ThreadContext context, Block block, Instr instr, Operation operation,
String name, IRubyObject[] args, IRubyObject self, Block blockArg, RubyModule implClass,
DynamicScope currDynScope, Object[] temp, StaticScope currScope) {
Block.Type blockType = block == null ? null : block.type;
Frame f;
switch(operation) {
case LABEL:
break;
case PUSH_BLOCK_FRAME:
f = context.preYieldNoScope(block.getBinding());
setResult(temp, currDynScope, ((PushBlockFrameInstr)instr).getResult(), f);
break;
case POP_BLOCK_FRAME:
f = (Frame)retrieveOp(((PopBlockFrameInstr)instr).getFrame(), context, self, currDynScope, currScope, temp);
context.postYieldNoScope(f);
break;
case PUSH_METHOD_FRAME:
context.preMethodFrameOnly(implClass, name, self, blockArg);
// Only the top-level script scope has PRIVATE visibility.
@@ -369,9 +390,10 @@ protected static void processBookKeepingOp(ThreadContext context, Instr instr, O
}
}

protected static IRubyObject processReturnOp(ThreadContext context, Instr instr, Operation operation,
protected static IRubyObject processReturnOp(ThreadContext context, Block block, Instr instr, Operation operation,
DynamicScope currDynScope, Object[] temp, IRubyObject self,
Block.Type blockType, StaticScope currScope) {
StaticScope currScope) {
Block.Type blockType = block == null ? null : block.type;
switch(operation) {
// --------- Return flavored instructions --------
case RETURN: {
@@ -396,9 +418,10 @@ protected static IRubyObject processReturnOp(ThreadContext context, Instr instr,
return null;
}

protected static void processOtherOp(ThreadContext context, Instr instr, Operation operation, DynamicScope currDynScope,
StaticScope currScope, Object[] temp, IRubyObject self, Block.Type blockType,
protected static void processOtherOp(ThreadContext context, Block block, Instr instr, Operation operation, DynamicScope currDynScope,
StaticScope currScope, Object[] temp, IRubyObject self,
double[] floats, long[] fixnums, boolean[] booleans) {
Block.Type blockType = block == null ? null : block.type;
Object result;
switch(operation) {
case RECV_SELF:
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
int n = instrs.length;
int ipc = 0;
Object exception = null;
Block.Type blockType = block == null ? null : block.type;

if (interpreterContext.receivesKeywordArguments()) IRRuntimeHelpers.frobnicateKwargsArgument(context, interpreterContext.getRequiredArgsCount(), args);

@@ -59,7 +58,7 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel

Operation operation = instr.getOperation();
if (debug) {
Interpreter.LOG.info("I: {" + ipc + "} ", instr + "; <#RPCs=" + rescuePCs.size() + ">");
Interpreter.LOG.info("I: {" + ipc + "} ", instr + "; <#RPCs=" + (rescuePCs == null ? 0 : rescuePCs.size()) + ">");
Interpreter.interpInstrsCount++;
} else if (profile) {
Profiler.instrTick(operation);
@@ -78,7 +77,7 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
processCall(context, instr, operation, currDynScope, currScope, temp, self);
break;
case RET_OP:
return processReturnOp(context, instr, operation, currDynScope, temp, self, blockType, currScope);
return processReturnOp(context, block, instr, operation, currDynScope, temp, self, currScope);
case BRANCH_OP:
switch (operation) {
case JUMP:
@@ -109,11 +108,11 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
rescuePCs.pop();
break;
default:
processBookKeepingOp(context, instr, operation, name, args, self, blockArg, blockType, implClass);
processBookKeepingOp(context, block, instr, operation, name, args, self, blockArg, implClass, currDynScope, temp, currScope);
}
break;
case OTHER_OP:
processOtherOp(context, instr, operation, currDynScope, currScope, temp, self, blockType);
processOtherOp(context, block, instr, operation, currDynScope, currScope, temp, self);
break;
}
} catch (Throwable t) {
@@ -143,8 +142,9 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel
throw context.runtime.newRuntimeError("BUG: interpreter fell through to end unexpectedly");
}

protected static void processOtherOp(ThreadContext context, Instr instr, Operation operation, DynamicScope currDynScope,
StaticScope currScope, Object[] temp, IRubyObject self, Block.Type blockType) {
protected static void processOtherOp(ThreadContext context, Block block, Instr instr, Operation operation, DynamicScope currDynScope,
StaticScope currScope, Object[] temp, IRubyObject self) {
Block.Type blockType = block == null ? null : block.type;
switch(operation) {
case RECV_SELF:
break;
Loading

0 comments on commit adbdeab

Please sign in to comment.