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

Commits on Dec 13, 2017

  1. Revert "More getName removal"

    This reverts commit a6fac6a.
    enebo committed Dec 13, 2017
    Copy the full SHA
    07224e1 View commit details
  2. Copy the full SHA
    59e8a6a View commit details
Showing with 141 additions and 103 deletions.
  1. +1 −1 core/src/main/java/org/jruby/ast/ConstDeclNode.java
  2. +1 −1 core/src/main/java/org/jruby/ast/Node.java
  3. +5 −5 core/src/main/java/org/jruby/ast/OptArgNode.java
  4. +1 −7 core/src/main/java/org/jruby/ast/RestArgNode.java
  5. +1 −7 core/src/main/java/org/jruby/ast/UnnamedRestArgNode.java
  6. +30 −32 core/src/main/java/org/jruby/ir/IRBuilder.java
  7. +3 −3 core/src/main/java/org/jruby/ir/IRClosure.java
  8. +1 −1 core/src/main/java/org/jruby/ir/IREvalScript.java
  9. +2 −2 core/src/main/java/org/jruby/ir/IRMethod.java
  10. +20 −10 core/src/main/java/org/jruby/ir/IRScope.java
  11. +10 −4 core/src/main/java/org/jruby/ir/instructions/RaiseRequiredKeywordArgumentError.java
  12. +9 −3 core/src/main/java/org/jruby/ir/instructions/ReceiveKeywordArgInstr.java
  13. +10 −4 core/src/main/java/org/jruby/ir/instructions/SetCapturedVarInstr.java
  14. +2 −1 core/src/main/java/org/jruby/ir/operands/ClosureLocalVariable.java
  15. +9 −4 core/src/main/java/org/jruby/ir/operands/LocalVariable.java
  16. +3 −2 core/src/main/java/org/jruby/ir/persistence/IRDumper.java
  17. +3 −3 core/src/main/java/org/jruby/ir/persistence/IRReader.java
  18. +3 −2 core/src/main/java/org/jruby/ir/persistence/IRWriter.java
  19. +16 −0 core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
  20. +1 −1 core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
  21. +4 −4 core/src/main/java/org/jruby/ir/transformations/inlining/InlineCloneInfo.java
  22. +3 −3 core/src/main/java/org/jruby/parser/RubyParser.java
  23. +3 −3 core/src/main/java/org/jruby/parser/RubyParser.y
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ast/ConstDeclNode.java
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ public <T> T accept(NodeVisitor<T> iVisitor) {
* @return name
*/
public String getName() {
return StringSupport.byteListAsString(getByteName());
return name == null ? constNode.getName() : StringSupport.byteListAsString(name);
}

public ByteList getByteName() {
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ast/Node.java
Original file line number Diff line number Diff line change
@@ -147,7 +147,7 @@ public String toString(boolean indent, int indentation) {

if (moreState != null) builder.append("[").append(moreState).append("]");

if (this instanceof INameNode) builder.append(":").append(((INameNode) this).getByteName());
if (this instanceof INameNode) builder.append(":").append(((INameNode) this).getName());

builder.append(" ").append(getPosition().getLine());

10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/ast/OptArgNode.java
Original file line number Diff line number Diff line change
@@ -40,7 +40,6 @@
public class OptArgNode extends Node implements INameNode {
private Node value;

// value must be LocalAsgnNode or DAsgnNode which is an INameNode
public OptArgNode(ISourcePosition position, Node value) {
super(position, value != null && value.containsVariableAssignment());
this.value = value;
@@ -51,7 +50,7 @@ public NodeType getNodeType() {
}

public Node getValue() {
return (Node) value;
return value;
}

@Override
@@ -61,14 +60,15 @@ public Object accept(NodeVisitor visitor) {

@Override
public List<Node> childNodes() {
return Node.createList(getValue());
return Node.createList(value);
}

public String getName() {
return getByteName().toString();
// FIXME: When is this not a INameNode?
return value instanceof INameNode ? ((INameNode) value).getName() : null;
}

public ByteList getByteName() {
return ((INameNode) value).getByteName();
return value instanceof INameNode ? ((INameNode) value).getByteName() : null;
}
}
8 changes: 1 addition & 7 deletions core/src/main/java/org/jruby/ast/RestArgNode.java
Original file line number Diff line number Diff line change
@@ -31,24 +31,18 @@
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;

/*
* The rest argument for a method (def foo(a, *b, c)).
*/
public class RestArgNode extends ArgumentNode implements INameNode {
@Deprecated
public RestArgNode(ISourcePosition position, String name, int index) {
super(position, name, index);
}

public RestArgNode(ISourcePosition position, ByteList name, int index) {
super(position, name, index);
}

// 1.9 only - lvar assign logic returns an Argument node
public RestArgNode(ArgumentNode argNode) {
super(argNode.getPosition(), argNode.getByteName(), argNode.getIndex());
this(argNode.getPosition(), argNode.getName(), argNode.getIndex());
}

@Override
8 changes: 1 addition & 7 deletions core/src/main/java/org/jruby/ast/UnnamedRestArgNode.java
Original file line number Diff line number Diff line change
@@ -29,27 +29,21 @@
package org.jruby.ast;

import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.util.ByteList;

/**
* a bare '*' or nothing. Name is "" if it is '*' and null if it is nothing.
*/
public class UnnamedRestArgNode extends RestArgNode {
@Deprecated
public UnnamedRestArgNode(ISourcePosition position, String name, int index) {
super(position, name, index);
}

public UnnamedRestArgNode(ISourcePosition position, ByteList name, int index) {
super(position, name, index);
}

public boolean isStar() {
return getByteName() != null;
}

@Override
public String getName() {
return isStar() ? super.getByteName().toString() : null;
return isStar() ? super.getName() : null;
}
}
62 changes: 30 additions & 32 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -316,11 +316,11 @@ private boolean needsCodeCoverage() {
return needsCodeCoverage || parent != null && parent.needsCodeCoverage();
}

public void addArgumentDescription(ArgumentType type, String name) {
public void addArgumentDescription(ArgumentType type, ByteList name) {
if (argumentDescriptions == null) argumentDescriptions = new ArrayList<>();

argumentDescriptions.add(type.toString());
argumentDescriptions.add(name);
argumentDescriptions.add(name == null ? null : name.toString());
}

public void addInstr(Instr instr) {
@@ -694,7 +694,7 @@ public void buildAssignment(Node node, Variable rhsVal) {
case DASGNNODE: {
DAsgnNode variable = (DAsgnNode) node;
int depth = variable.getDepth();
addInstr(new CopyInstr(getLocalVariable(variable.getName(), depth), rhsVal));
addInstr(new CopyInstr(getLocalVariable(variable.getByteName(), depth), rhsVal));
break;
}
case GLOBALASGNNODE:
@@ -707,7 +707,7 @@ public void buildAssignment(Node node, Variable rhsVal) {
case LOCALASGNNODE: {
LocalAsgnNode localVariable = (LocalAsgnNode) node;
int depth = localVariable.getDepth();
addInstr(new CopyInstr(getLocalVariable(localVariable.getName(), depth), rhsVal));
addInstr(new CopyInstr(getLocalVariable(localVariable.getByteName(), depth), rhsVal));
break;
}
case ZEROARGNODE:
@@ -723,7 +723,7 @@ public void buildAssignment(Node node, Variable rhsVal) {
}
}

protected LocalVariable getBlockArgVariable(String name, int depth) {
protected LocalVariable getBlockArgVariable(ByteList name, int depth) {
if (!(scope instanceof IRFor)) throw new NotCompilableException("Cannot ask for block-arg variable in 1.9 mode");

return getLocalVariable(name, depth);
@@ -773,7 +773,7 @@ public void buildBlockArgsAssignment(Node node, Operand argsArray, int argIndex,
break;
case DASGNNODE: {
DAsgnNode dynamicAsgn = (DAsgnNode) node;
v = getBlockArgVariable(dynamicAsgn.getName(), dynamicAsgn.getDepth());
v = getBlockArgVariable(dynamicAsgn.getByteName(), dynamicAsgn.getDepth());
receiveBlockArg(v, argsArray, argIndex, isSplat);
break;
}
@@ -800,8 +800,7 @@ public void buildBlockArgsAssignment(Node node, Operand argsArray, int argIndex,
break;
case LOCALASGNNODE: {
LocalAsgnNode localVariable = (LocalAsgnNode) node;
int depth = localVariable.getDepth();
v = getBlockArgVariable(localVariable.getName(), depth);
v = getBlockArgVariable(localVariable.getByteName(), localVariable.getDepth());
receiveBlockArg(v, argsArray, argIndex, isSplat);
break;
}
@@ -1985,7 +1984,7 @@ public Operand buildDAsgn(final DAsgnNode dasgnNode) {
// assignments to block variables within a block. As far as the IR is concerned,
// this is just a simple copy
int depth = dasgnNode.getDepth();
Variable arg = getLocalVariable(dasgnNode.getName(), depth);
Variable arg = getLocalVariable(dasgnNode.getByteName(), depth);
Operand value = build(dasgnNode.getValueNode());

// no use copying a variable to itself
@@ -2096,7 +2095,7 @@ public Operand buildDefs(DefsNode node) { // Class method
return new Symbol(method.getName(), USASCIIEncoding.INSTANCE);
}

protected LocalVariable getArgVariable(String name, int depth) {
protected LocalVariable getArgVariable(ByteList name, int depth) {
// For non-loops, this name will override any name that exists in outer scopes
return scope instanceof IRFor ? getLocalVariable(name, depth) : getNewLocalVariable(name, 0);
}
@@ -2115,8 +2114,8 @@ private void addArgReceiveInstr(Variable v, int argIndex, Signature signature) {
* '_' we create temporary variables in the case the scope has a zsuper in it. If so, then the zsuper
* call will slurp those temps up as it's parameters so it can properly set up the call.
*/
private Variable argumentResult(String name) {
boolean isUnderscore = name.equals("_");
private Variable argumentResult(ByteList name) {
boolean isUnderscore = name.realSize() == 1 && name.charAt(0) == '_';

if (isUnderscore && underscoreVariableSeen) {
return createTemporaryVariable();
@@ -2129,7 +2128,7 @@ private Variable argumentResult(String name) {
public void receiveRequiredArg(Node node, int argIndex, Signature signature) {
switch (node.getNodeType()) {
case ARGUMENTNODE: {
String argName = ((ArgumentNode)node).getName();
ByteList argName = ((ArgumentNode)node).getByteName();

if (scope instanceof IRMethod) addArgumentDescription(ArgumentType.req, argName);

@@ -2190,7 +2189,7 @@ protected void receiveNonBlockArgs(final ArgsNode argsNode) {
// We fall through or jump to variableAssigned once we know we have a valid value in place.
Label variableAssigned = getNewLabel();
OptArgNode optArg = (OptArgNode)args[optIndex + j];
String argName = optArg.getName();
ByteList argName = optArg.getByteName();
Variable argVar = argumentResult(argName);
if (scope instanceof IRMethod) addArgumentDescription(ArgumentType.opt, argName);
// You need at least required+j+1 incoming args for this opt arg to get an arg at all
@@ -2211,13 +2210,13 @@ protected void receiveNonBlockArgs(final ArgsNode argsNode) {
// Consider: def foo(*); .. ; end
// For this code, there is no argument name available from the ruby code.
// So, we generate an implicit arg name
String argName = argsNode.getRestArgNode().getName();
ByteList argName = argsNode.getRestArgNode().getByteName();
if (scope instanceof IRMethod) {
addArgumentDescription(
argName == null || argName.length() == 0 ? ArgumentType.anonrest : ArgumentType.rest,
argName);
}
argName = (argName == null || argName.equals("")) ? "*" : argName;
argName = (argName == null || argName.realSize() == 0) ? new ByteList(new byte[] {'*'}) : argName;

// You need at least required+opt+1 incoming args for the rest arg to get any args at all
// If it is going to get something, then it should ignore required+opt args from the beginning
@@ -2243,7 +2242,7 @@ protected void receiveBlockArg(final ArgsNode argsNode) {
// reify to Proc if we have a block arg
BlockArgNode blockArg = argsNode.getBlock();
if (blockArg != null) {
String argName = blockArg.getName();
ByteList argName = blockArg.getByteName();
Variable blockVar = argumentResult(argName);
if (scope instanceof IRMethod) addArgumentDescription(ArgumentType.block, argName);
Variable tmp = createTemporaryVariable();
@@ -2289,7 +2288,7 @@ public void receiveArgs(final ArgsNode argsNode) {
for (int i = 0; i < keywordsCount; i++) {
KeywordArgNode kwarg = (KeywordArgNode) args[keywordIndex + i];
AssignableNode kasgn = kwarg.getAssignable();
String argName = ((INameNode) kasgn).getName();
ByteList argName = ((INameNode) kasgn).getByteName();
Variable av = getNewLocalVariable(argName, 0);
Label l = getNewLabel();
if (scope instanceof IRMethod) addKeyArgDesc(kasgn, argName);
@@ -2310,7 +2309,7 @@ public void receiveArgs(final ArgsNode argsNode) {
// 2.0 keyword rest arg
KeywordRestArgNode keyRest = argsNode.getKeyRest();
if (keyRest != null) {
String argName = keyRest.getName();
ByteList argName = keyRest.getByteName();
ArgumentType type = ArgumentType.keyrest;

// anonymous keyrest
@@ -2325,7 +2324,7 @@ public void receiveArgs(final ArgsNode argsNode) {
receiveBlockArg(argsNode);
}

private void addKeyArgDesc(AssignableNode kasgn, String argName) {
private void addKeyArgDesc(AssignableNode kasgn, ByteList argName) {
if (isRequiredKeywordArgumentValue(kasgn)) {
addArgumentDescription(ArgumentType.keyreq, argName);
} else {
@@ -2343,14 +2342,14 @@ public void buildArgsMasgn(Node node, Operand argsArray, boolean isMasgnRoot, in
switch (node.getNodeType()) {
case DASGNNODE: {
DAsgnNode dynamicAsgn = (DAsgnNode) node;
v = getArgVariable(dynamicAsgn.getName(), dynamicAsgn.getDepth());
v = getArgVariable(dynamicAsgn.getByteName(), dynamicAsgn.getDepth());
if (isSplat) addInstr(new RestArgMultipleAsgnInstr(v, argsArray, preArgsCount, postArgsCount, index));
else addInstr(new ReqdArgMultipleAsgnInstr(v, argsArray, preArgsCount, postArgsCount, index));
break;
}
case LOCALASGNNODE: {
LocalAsgnNode localVariable = (LocalAsgnNode) node;
v = getArgVariable(localVariable.getName(), localVariable.getDepth());
v = getArgVariable(localVariable.getByteName(), localVariable.getDepth());
if (isSplat) addInstr(new RestArgMultipleAsgnInstr(v, argsArray, preArgsCount, postArgsCount, index));
else addInstr(new ReqdArgMultipleAsgnInstr(v, argsArray, preArgsCount, postArgsCount, index));
break;
@@ -2523,7 +2522,7 @@ public Operand buildDSymbol(Variable result, DSymbolNode node) {
}

public Operand buildDVar(DVarNode node) {
return getLocalVariable(node.getName(), node.getDepth());
return getLocalVariable(node.getByteName(), node.getDepth());
}

public Operand buildDXStr(Variable result, DXStrNode dstrNode) {
@@ -3057,7 +3056,7 @@ public Operand buildLiteral(LiteralNode literalNode) {
}

public Operand buildLocalAsgn(LocalAsgnNode localAsgnNode) {
Variable variable = getLocalVariable(localAsgnNode.getName(), localAsgnNode.getDepth());
Variable variable = getLocalVariable(localAsgnNode.getByteName(), localAsgnNode.getDepth());
Operand value = build(variable, localAsgnNode.getValueNode());

// no use copying a variable to itself
@@ -3091,7 +3090,7 @@ public Operand buildLocalAsgn(LocalAsgnNode localAsgnNode) {
}

public Operand buildLocalVar(LocalVarNode node) {
return getLocalVariable(node.getName(), node.getDepth());
return getLocalVariable(node.getByteName(), node.getDepth());
}

public Operand buildMatch(Variable result, MatchNode matchNode) {
@@ -3120,16 +3119,16 @@ public Operand buildMatch2(Variable result, Match2Node matchNode) {
int offset = slot & 0xffff;

// For now, we'll continue to implicitly reference "$~"
String var = getVarNameFromScopeTree(scope, depth, offset);
ByteList var = getVarNameFromScopeTree(scope, depth, offset);
addInstr(new SetCapturedVarInstr(getLocalVariable(var, depth), result, var));
}
}
return result;
}

private String getVarNameFromScopeTree(IRScope scope, int depth, int offset) {
private ByteList getVarNameFromScopeTree(IRScope scope, int depth, int offset) {
if (depth == 0) {
return scope.getStaticScope().getVariables()[offset];
return scope.getStaticScope().getByteVariables()[offset];
}
return getVarNameFromScopeTree(scope.getLexicalParent(), depth - 1, offset);
}
@@ -4118,11 +4117,11 @@ private TemporaryVariable createTemporaryVariable() {
return scope.createTemporaryVariable();
}

public LocalVariable getLocalVariable(String name, int scopeDepth) {
public LocalVariable getLocalVariable(ByteList name, int scopeDepth) {
return scope.getLocalVariable(name, scopeDepth);
}

public LocalVariable getNewLocalVariable(String name, int scopeDepth) {
public LocalVariable getNewLocalVariable(ByteList name, int scopeDepth) {
return scope.getNewLocalVariable(name, scopeDepth);
}

@@ -4173,8 +4172,7 @@ private static void extractCallOperands(List<Operand> callArgs, List<KeyValuePai
keywordArgs.add(0, new KeyValuePair<Operand, Operand>(Symbol.KW_REST_ARG_DUMMY, ((ReceiveArgBase) instr).getResult()));
} else if (instr instanceof ReceiveKeywordArgInstr) {
ReceiveKeywordArgInstr rkai = (ReceiveKeywordArgInstr) instr;
// FIXME: This lost encoding information when name was converted to string earlier in IRBuilder
keywordArgs.add(new KeyValuePair<Operand, Operand>(new Symbol(rkai.argName, USASCIIEncoding.INSTANCE), rkai.getResult()));
keywordArgs.add(new KeyValuePair<Operand, Operand>(new Symbol(rkai.argName), rkai.getResult()));
} else if (instr instanceof ReceiveRestArgInstr) {
callArgs.add(new Splat(((ReceiveRestArgInstr) instr).getResult()));
} else if (instr instanceof ReceiveArgBase) {
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/IRClosure.java
Original file line number Diff line number Diff line change
@@ -232,7 +232,7 @@ public void setSource(IterNode iter) {
}

@Override
protected LocalVariable findExistingLocalVariable(String name, int scopeDepth) {
protected LocalVariable findExistingLocalVariable(ByteList name, int scopeDepth) {
LocalVariable lvar = lookupExistingLVar(name);
if (lvar != null) return lvar;

@@ -247,7 +247,7 @@ protected LocalVariable findExistingLocalVariable(String name, int scopeDepth) {
return lvar;
}

public LocalVariable getNewLocalVariable(String name, int depth) {
public LocalVariable getNewLocalVariable(ByteList name, int depth) {
if (depth == 0 && !(this instanceof IRFor)) {
LocalVariable lvar = new ClosureLocalVariable(name, 0, getStaticScope().addVariableThisScope(name));
localVars.put(name, lvar);
@@ -274,7 +274,7 @@ public LocalVariable getNewLocalVariable(String name, int depth) {
}

@Override
public LocalVariable getLocalVariable(String name, int depth) {
public LocalVariable getLocalVariable(ByteList name, int depth) {
// AST doesn't seem to be implementing shadowing properly and sometimes
// has the wrong depths which screws up variable access. So, we implement
// shadowing here by searching for an existing local var from depth 0 and upwards.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IREvalScript.java
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ public List<IRClosure> getBeginBlocks() {

@Override
public LocalVariable getNewFlipStateVariable() {
String flipVarName = "%flip_" + allocateNextPrefixedName("%flip");
ByteList flipVarName = new ByteList(("%flip_" + allocateNextPrefixedName("%flip")).getBytes());
LocalVariable v = lookupExistingLVar(flipVarName);

return v == null ? getNewLocalVariable(flipVarName, 0) : v;
Loading