Skip to content

Commit

Permalink
Merge branch 'master' into truffle-kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Mar 17, 2015
2 parents ae474b3 + edafd13 commit 44060f3
Show file tree
Hide file tree
Showing 2,657 changed files with 58,803 additions and 4,744 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Expand Up @@ -56,10 +56,11 @@ matrix:
jdk: openjdk7
- env: PHASE='-Pj2ee'
jdk: oraclejdk7
# These next two started crashing on JDK7 in March 2015, possibly due to JVM issues on Travis's Docker-based env
- env: PHASE='-Pjruby-jars,test -Dinvoker.test=extended'
jdk: oraclejdk7
jdk: oraclejdk8
- env: PHASE='-Pmain,test -Dinvoker.test=extended'
jdk: openjdk7
jdk: oraclejdk8
- env: PHASE='-Pjruby_complete_jar_extended -Dinvoker.skip=true'
jdk: oraclejdk8
- env: COMMAND=test/check_versions.sh
Expand All @@ -68,6 +69,7 @@ matrix:
jdk: oraclejdk8
fast_finish: true


branches:
only:
- master
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -3491,6 +3491,11 @@ public RubySymbol newSymbol(String name) {
return symbolTable.getSymbol(name);
}

public RubySymbol newSymbol(String name, Encoding encoding) {
ByteList byteList = RubyString.encodeBytelist(name, encoding);
return symbolTable.getSymbol(byteList);
}

public RubySymbol newSymbol(ByteList name) {
return symbolTable.getSymbol(name);
}
Expand Down
38 changes: 6 additions & 32 deletions core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -271,23 +271,6 @@ final boolean singleByteOptimizable(Encoding enc) {
return StringSupport.isSingleByteOptimizable(this, enc);
}

// rb_enc_compatible
private Encoding isCompatibleWith(RubyString other) {
Encoding enc1 = value.getEncoding();
Encoding enc2 = other.value.getEncoding();

if (enc1 == enc2) return enc1;

if (other.value.getRealSize() == 0) return enc1;
if (value.getRealSize() == 0) {
return (enc1.isAsciiCompatible() && other.isAsciiOnly()) ? enc1 : enc2;
}

if (!enc1.isAsciiCompatible() || !enc2.isAsciiCompatible()) return null;

return RubyEncoding.areCompatible(enc1, scanForCodeRange(), enc2, other.scanForCodeRange());
}

final Encoding isCompatibleWith(EncodingCapable other) {
if (other instanceof RubyString) return checkEncoding((RubyString)other);
Encoding enc1 = value.getEncoding();
Expand All @@ -303,7 +286,7 @@ final Encoding isCompatibleWith(EncodingCapable other) {

// rb_enc_check
public final Encoding checkEncoding(RubyString other) {
return checkEncoding((ByteListHolder) other);
return checkEncoding((CodeRangeable) other);
}

final Encoding checkEncoding(EncodingCapable other) {
Expand All @@ -314,9 +297,8 @@ final Encoding checkEncoding(EncodingCapable other) {
}

@Override
public final Encoding checkEncoding(ByteListHolder other) {
// TODO (nirvdrum 13-Jan-15): This cast is untenable. It's a temporary measure until isCompatibleWith and its call graph are generalized.
Encoding enc = isCompatibleWith((RubyString) other);
public final Encoding checkEncoding(CodeRangeable other) {
Encoding enc = StringSupport.areCompatible(this, other);
if (enc == null) throw getRuntime().newEncodingCompatibilityError("incompatible character encodings: " +
value.getEncoding() + " and " + other.getByteList().getEncoding());
return enc;
Expand Down Expand Up @@ -1141,20 +1123,12 @@ public IRubyObject op_plus(ThreadContext context, IRubyObject _str) {
public IRubyObject op_plus19(ThreadContext context, IRubyObject _str) {
RubyString str = _str.convertToString();
Encoding enc = checkEncoding(str);
RubyString resultStr = newStringNoCopy(context.runtime, addByteLists(value, str.value),
RubyString resultStr = newStringNoCopy(context.runtime, StringSupport.addByteLists(value, str.value),
enc, CodeRangeSupport.codeRangeAnd(getCodeRange(), str.getCodeRange()));
resultStr.infectBy(flags | str.flags);
return resultStr;
}

private ByteList addByteLists(ByteList value1, ByteList value2) {
ByteList result = new ByteList(value1.getRealSize() + value2.getRealSize());
result.setRealSize(value1.getRealSize() + value2.getRealSize());
System.arraycopy(value1.getUnsafeBytes(), value1.getBegin(), result.getUnsafeBytes(), 0, value1.getRealSize());
System.arraycopy(value2.getUnsafeBytes(), value2.getBegin(), result.getUnsafeBytes(), value1.getRealSize(), value2.getRealSize());
return result;
}

public IRubyObject op_mul(ThreadContext context, IRubyObject other) {
return op_mul19(context, other);
}
Expand Down Expand Up @@ -1568,7 +1542,7 @@ public IRubyObject casecmp(ThreadContext context, IRubyObject other) {
public IRubyObject casecmp19(ThreadContext context, IRubyObject other) {
Ruby runtime = context.runtime;
RubyString otherStr = other.convertToString();
Encoding enc = isCompatibleWith(otherStr);
Encoding enc = StringSupport.areCompatible(this, otherStr);
if (enc == null) return runtime.getNil();

if (singleByteOptimizable() && otherStr.singleByteOptimizable()) {
Expand Down Expand Up @@ -2469,7 +2443,7 @@ private IRubyObject subBangCommon19(ThreadContext context, Regex pattern, Matche
final int end = matcher.getEnd();
int cr = getCodeRange();

Encoding enc = isCompatibleWith(repl);
Encoding enc = StringSupport.areCompatible(this, repl);
if (enc == null) enc = subBangVerifyEncoding(context, repl, beg, end);

final int plen = end - beg;
Expand Down
22 changes: 11 additions & 11 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -1265,7 +1265,7 @@ public Operand buildConstDeclAssignment(ConstDeclNode constDeclNode, Operand val

private void genInheritanceSearchInstrs(Operand startingModule, Variable constVal, Label foundLabel, boolean noPrivateConstants, String name) {
addInstr(new InheritanceSearchConstInstr(constVal, startingModule, name, noPrivateConstants));
addInstr(BNEInstr.create(constVal, UndefinedValue.UNDEFINED, foundLabel));
addInstr(BNEInstr.create(foundLabel, constVal, UndefinedValue.UNDEFINED));
addInstr(new ConstMissingInstr(constVal, startingModule, name));
addInstr(new LabelInstr(foundLabel));
}
Expand Down Expand Up @@ -1417,7 +1417,7 @@ public Operand run() {
Operand v = protectCodeWithRescue(protectedCode, rescueBlock);
Label doneLabel = getNewLabel();
Variable tmpVar = getValueInTemporaryVariable(v);
addInstr(BNEInstr.create(tmpVar, manager.getNil(), doneLabel));
addInstr(BNEInstr.create(doneLabel, tmpVar, manager.getNil()));
addInstr(new CopyInstr(tmpVar, new FrozenString("expression")));
addInstr(new LabelInstr(doneLabel));

Expand Down Expand Up @@ -1480,9 +1480,9 @@ public Operand run() {
Variable tmpVar = createTemporaryVariable();
String constName = ((ConstNode) node).getName();
addInstr(new LexicalSearchConstInstr(tmpVar, startingSearchScope(), constName));
addInstr(BNEInstr.create(tmpVar, UndefinedValue.UNDEFINED, defLabel));
addInstr(BNEInstr.create(defLabel, tmpVar, UndefinedValue.UNDEFINED));
addInstr(new InheritanceSearchConstInstr(tmpVar, findContainerModule(), constName, false)); // SSS FIXME: should this be the current-module var or something else?
addInstr(BNEInstr.create(tmpVar, UndefinedValue.UNDEFINED, defLabel));
addInstr(BNEInstr.create(defLabel, tmpVar, UndefinedValue.UNDEFINED));
addInstr(new CopyInstr(tmpVar, manager.getNil()));
addInstr(new JumpInstr(doneLabel));
addInstr(new LabelInstr(defLabel));
Expand Down Expand Up @@ -1855,7 +1855,7 @@ protected void receiveNonBlockArgs(final ArgsNode argsNode) {
if (scope instanceof IRMethod) addArgumentDescription(IRMethodArgs.ArgType.opt, argName);
// You need at least required+j+1 incoming args for this opt arg to get an arg at all
addInstr(new ReceiveOptArgInstr(av, required, numPreReqd, j));
addInstr(BNEInstr.create(av, UndefinedValue.UNDEFINED, l)); // if 'av' is not undefined, go to default
addInstr(BNEInstr.create(l, av, UndefinedValue.UNDEFINED)); // if 'av' is not undefined, go to default
build(n.getValue());
addInstr(new LabelInstr(l));
}
Expand Down Expand Up @@ -1942,7 +1942,7 @@ public void receiveArgs(final ArgsNode argsNode) {
Label l = getNewLabel();
if (scope instanceof IRMethod) addKeyArgDesc(kasgn, argName);
addInstr(new ReceiveKeywordArgInstr(av, argName, required));
addInstr(BNEInstr.create(av, UndefinedValue.UNDEFINED, l)); // if 'av' is not undefined, we are done
addInstr(BNEInstr.create(l, av, UndefinedValue.UNDEFINED)); // if 'av' is not undefined, we are done

// Required kwargs have no value and check_arity will throw if they are not provided.
if (!isRequiredKeywordArgumentValue(kasgn)) {
Expand Down Expand Up @@ -2385,11 +2385,11 @@ public Operand buildFlip(FlipNode flipNode) {
addInstr(new CopyInstr(returnVal, manager.getFalse()));

// Are we in state 1?
addInstr(BNEInstr.create(flipState, s1, s2Label));
addInstr(BNEInstr.create(s2Label, flipState, s1));

// ----- Code for when we are in state 1 -----
Operand s1Val = build(flipNode.getBeginNode());
addInstr(BNEInstr.create(s1Val, manager.getTrue(), s2Label));
addInstr(BNEInstr.create(s2Label, s1Val, manager.getTrue()));

// s1 condition is true => set returnVal to true & move to state 2
addInstr(new CopyInstr(returnVal, manager.getTrue()));
Expand All @@ -2402,12 +2402,12 @@ public Operand buildFlip(FlipNode flipNode) {
if (flipNode.isExclusive()) addInstr(BEQInstr.create(returnVal, manager.getTrue(), doneLabel));

// Are we in state 2?
addInstr(BNEInstr.create(flipState, s2, doneLabel));
addInstr(BNEInstr.create(doneLabel, flipState, s2));

// ----- Code for when we are in state 2 -----
Operand s2Val = build(flipNode.getEndNode());
addInstr(new CopyInstr(returnVal, manager.getTrue()));
addInstr(BNEInstr.create(s2Val, manager.getTrue(), doneLabel));
addInstr(BNEInstr.create(doneLabel, s2Val, manager.getTrue()));

// s2 condition is true => move to state 1
addInstr(new CopyInstr(flipState, s1));
Expand Down Expand Up @@ -3452,7 +3452,7 @@ public Operand run() {
// Generate the next set of instructions
if (next != null) addInstr(new LabelInstr(next));
next = getNewLabel();
addInstr(BNEInstr.create(new Fixnum(depthFromSuper), scopeDepth, next));
addInstr(BNEInstr.create(next, new Fixnum(depthFromSuper), scopeDepth));
Operand[] args = adjustVariableDepth(getCallArgs(superScope, superBuilder), depthFromSuper);
addInstr(new ZSuperInstr(zsuperResult, buildSelf(), args, block));
addInstr(new JumpInstr(allDoneLabel));
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/org/jruby/ir/Operation.java
Expand Up @@ -172,9 +172,7 @@ public enum Operation {

/* Instructions to support defined? */
BLOCK_GIVEN(0),
DEFINED_CONSTANT_OR_METHOD(OpFlags.f_can_raise_exception),
GET_ERROR_INFO(0),
METHOD_DEFINED(OpFlags.f_can_raise_exception),
RESTORE_ERROR_INFO(OpFlags.f_has_side_effect),

/* Boxing/Unboxing between Ruby <--> Java types */
Expand Down
Expand Up @@ -189,7 +189,7 @@ public boolean addStores(Map<Operand, Operand> varRenameMap, Set<LocalVariable>
// we'll be in trouble in that scenario!
if (spillAllVars || cl.usesLocalVariable(v) || cl.definesLocalVariable(v)) {
addedStores = true;
instrs.add(new StoreLocalVarInstr(problem.getLocalVarReplacement(v, varRenameMap), scope, v));
instrs.add(new StoreLocalVarInstr(scope, problem.getLocalVarReplacement(v, varRenameMap), v));
newDirtyVars.remove(v);
}
}
Expand All @@ -200,7 +200,7 @@ public boolean addStores(Map<Operand, Operand> varRenameMap, Set<LocalVariable>
instrs.previous();
for (LocalVariable v : dirtyVars) {
addedStores = true;
instrs.add(new StoreLocalVarInstr(problem.getLocalVarReplacement(v, varRenameMap), scope, v));
instrs.add(new StoreLocalVarInstr(scope, problem.getLocalVarReplacement(v, varRenameMap), v));
}
instrs.next();
dirtyVars.clear();
Expand All @@ -221,7 +221,7 @@ public boolean addStores(Map<Operand, Operand> varRenameMap, Set<LocalVariable>
|| (!(v instanceof ClosureLocalVariable) && scope.getScopeType().isClosureType()))
{
addedStores = true;
instrs.add(new StoreLocalVarInstr(problem.getLocalVarReplacement(v, varRenameMap), scope, v));
instrs.add(new StoreLocalVarInstr(scope, problem.getLocalVarReplacement(v, varRenameMap), v));
newDirtyVars.remove(v);
}
}
Expand Down Expand Up @@ -270,7 +270,7 @@ public boolean addStores(Map<Operand, Operand> varRenameMap, Set<LocalVariable>
instrs.previous();
for (LocalVariable v : dirtyVars) {
addedStores = true;
instrs.add(new StoreLocalVarInstr(problem.getLocalVarReplacement(v, varRenameMap), scope, v));
instrs.add(new StoreLocalVarInstr(scope, problem.getLocalVarReplacement(v, varRenameMap), v));
}
instrs.next();
dirtyVars.clear();
Expand All @@ -283,7 +283,7 @@ public boolean addStores(Map<Operand, Operand> varRenameMap, Set<LocalVariable>
instrs.previous();
for (LocalVariable v : dirtyVars) {
addedStores = true;
instrs.add(new StoreLocalVarInstr(problem.getLocalVarReplacement(v, varRenameMap), scope, v));
instrs.add(new StoreLocalVarInstr(scope, problem.getLocalVarReplacement(v, varRenameMap), v));
}
instrs.next();
dirtyVars.clear();
Expand Down
Expand Up @@ -69,7 +69,7 @@ boolean addClosureExitStoreLocalVars(ListIterator<Instr> instrs, Set<LocalVariab
for (LocalVariable v : dirtyVars) {
if (isEvalScript || !(v instanceof ClosureLocalVariable) || !((ClosureLocalVariable)v).isDefinedLocally()) {
addedStores = true;
instrs.add(new StoreLocalVarInstr(getLocalVarReplacement(v, varRenameMap), scope, v));
instrs.add(new StoreLocalVarInstr(scope, getLocalVarReplacement(v, varRenameMap), v));
}
}
return addedStores;
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/AliasInstr.java
Expand Up @@ -5,6 +5,7 @@
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.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.CloneInfo;
Expand All @@ -13,8 +14,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

import java.util.Map;

public class AliasInstr extends Instr implements FixedArityInstr {
// SSS FIXME: Implicit self arg -- make explicit to not get screwed by inlining!
public AliasInstr(Operand newName, Operand oldName) {
Expand All @@ -35,6 +34,10 @@ public void encode(IRWriterEncoder e) {
e.encode(getOldName());
}

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

@Override
public Instr clone(CloneInfo ii) {
return new AliasInstr(getNewName().cloneForInlining(ii), getOldName().cloneForInlining(ii));
Expand Down
Expand Up @@ -4,6 +4,7 @@
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.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
Expand Down Expand Up @@ -34,4 +35,8 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
}
return context.runtime.newFixnum(i);
}

public static ArgScopeDepthInstr decode(IRReaderDecoder d) {
return new ArgScopeDepthInstr(d.decodeVariable());
}
}
15 changes: 15 additions & 0 deletions core/src/main/java/org/jruby/ir/instructions/AttrAssignInstr.java
@@ -1,10 +1,12 @@
package org.jruby.ir.instructions;

import org.jruby.RubyInstanceConfig;
import org.jruby.ir.IRScope;
import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.specialized.OneArgOperandAttrAssignInstr;
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.parser.StaticScope;
Expand Down Expand Up @@ -44,6 +46,19 @@ public Instr clone(CloneInfo ii) {
return new AttrAssignInstr(getReceiver().cloneForInlining(ii), getName(), cloneCallArgs(ii));
}

@Override
public void encode(IRWriterEncoder e) {
if (RubyInstanceConfig.IR_WRITING_DEBUG) System.out.println("Instr(" + getOperation() + "): " + this);
e.encode(getOperation());
e.encode(getReceiver());
e.encode(getName());
e.encode(getCallArgs());
}

public static AttrAssignInstr decode(IRReaderDecoder d) {
return create(d.decodeOperand(), d.decodeString(), d.decodeOperandArray());
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope dynamicScope, IRubyObject self, Object[] temp) {
IRubyObject object = (IRubyObject) getReceiver().retrieve(context, self, currScope, dynamicScope, temp);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/BEQInstr.java
Expand Up @@ -22,8 +22,8 @@ public static BranchInstr create(Operand v1, Operand v2, Label jmpTarget) {
return new BEQInstr(jmpTarget, v1, v2);
}

protected BEQInstr(Label jmpTarget, Operand v1, Operand v2) {
super(Operation.BEQ, v1, v2, jmpTarget);
protected BEQInstr(Label jumpTarget, Operand v1, Operand v2) {
super(Operation.BEQ, jumpTarget, v1, v2);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/instructions/BNEInstr.java
Expand Up @@ -14,15 +14,15 @@
import org.jruby.runtime.builtin.IRubyObject;

public class BNEInstr extends TwoOperandBranchInstr implements FixedArityInstr {
public static BranchInstr create(Operand v1, Operand v2, Label jmpTarget) {
public static BranchInstr create(Label jmpTarget, Operand v1, Operand v2) {
if (v2 instanceof Boolean) {
return ((Boolean) v2).isFalse() ? new BTrueInstr(jmpTarget, v1) : new BFalseInstr(jmpTarget, v1);
}
return new BNEInstr(jmpTarget, v1, v2);
}

public BNEInstr(Label jmpTarget, Operand v1, Operand v2) {
super(Operation.BNE, v1, v2, jmpTarget);
public BNEInstr(Label jumpTarget, Operand v1, Operand v2) {
super(Operation.BNE, jumpTarget, v1, v2);
}

@Override
Expand Down
Expand Up @@ -6,6 +6,7 @@
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.parser.StaticScope;
Expand Down Expand Up @@ -38,6 +39,10 @@ public void encode(IRWriterEncoder e) {
e.encode(getPieces());
}

public static BacktickInstr decode(IRReaderDecoder d) {
return new BacktickInstr(d.decodeVariable(), d.decodeOperandArray());
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
RubyString newString = context.runtime.newString();
Expand Down

0 comments on commit 44060f3

Please sign in to comment.