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

Commits on Aug 9, 2017

  1. Make literal hashes keep track of whether their keys are all symbols.

    IR and later can use this information to potentially optimize kwarg calls.
    enebo committed Aug 9, 2017
    Copy the full SHA
    5973a6a View commit details
  2. Copy the full SHA
    5afbd30 View commit details
  3. allocating labels for lonely operator support even when the call was …

    …not part
    
    of a lonely operator (this fix reduces memory of an empty Rails app by 0.1%).
    enebo committed Aug 9, 2017
    Copy the full SHA
    d9566c6 View commit details
  4. Copy the full SHA
    1edbd92 View commit details
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/ast/CallNode.java
Original file line number Diff line number Diff line change
@@ -140,6 +140,11 @@ public Node getReceiverNode() {
return receiverNode;
}

/**
* Is this call lazily execute because it was on right hand side of the lonely (&.) operator?
*
* @return true if so.
*/
public boolean isLazy() {
return isLazy;
}
15 changes: 13 additions & 2 deletions core/src/main/java/org/jruby/ast/HashNode.java
Original file line number Diff line number Diff line change
@@ -41,10 +41,11 @@

/**
* A Literal Hash that can represent either a {a=&b, c=&d} type expression or the list
* of default values in a method call.
* of default values or kwarg in a method call.
*/
public class HashNode extends Node implements ILiteralNode {
private final List<KeyValuePair<Node,Node>> pairs;
private boolean hasOnlySymbolKeys = true;

public HashNode(ISourcePosition position) {
super(position, false);
@@ -55,7 +56,14 @@ public HashNode(ISourcePosition position) {
public HashNode(ISourcePosition position, KeyValuePair<Node,Node> pair) {
this(position);

pairs.add(pair);
add(pair);
}

/**
* @return true if all elements of this hash uses symbol keys (might end up representing a kwarg).
*/
public boolean hasOnlySymbolKeys() {
return hasOnlySymbolKeys;
}

public NodeType getNodeType() {
@@ -67,6 +75,9 @@ public HashNode add(KeyValuePair<Node,Node> pair) {
pair.getValue() != null && pair.getValue().containsVariableAssignment()) {
containsVariableAssignment = true;
}

if (!(pair.getKey() instanceof SymbolNode)) hasOnlySymbolKeys = false;

pairs.add(pair);

return this;
19 changes: 13 additions & 6 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -865,10 +865,12 @@ private Operand buildAttrAssign(Variable result, AttrAssignNode attrAssignNode)
boolean containsAssignment = attrAssignNode.containsVariableAssignment();
Operand obj = buildWithOrder(attrAssignNode.getReceiverNode(), containsAssignment);

Label lazyLabel = getNewLabel();
Label endLabel = getNewLabel();
Label lazyLabel = null;
Label endLabel = null;
if (result == null) result = createTemporaryVariable();
if (attrAssignNode.isLazy()) {
lazyLabel = getNewLabel();
endLabel = getNewLabel();
addInstr(new BNilInstr(lazyLabel, obj));
}

@@ -1052,9 +1054,12 @@ public Operand buildCall(Variable result, CallNode callNode) {
return result;
}

Label lazyLabel = getNewLabel();
Label endLabel = getNewLabel();
Label lazyLabel = null;
Label endLabel = null;

if (callNode.isLazy()) {
lazyLabel = getNewLabel();
endLabel = getNewLabel();
addInstr(new BNilInstr(lazyLabel, receiver));
}

@@ -3190,10 +3195,12 @@ public Operand buildOpAsgn(OpAsgnNode opAsgnNode) {
// get attr
Operand v1 = build(opAsgnNode.getReceiverNode());

Label lazyLabel = getNewLabel();
Label endLabel = getNewLabel();
Label lazyLabel = null;
Label endLabel = null;
Variable result = createTemporaryVariable();
if (opAsgnNode.isLazy()) {
lazyLabel = getNewLabel();
endLabel = getNewLabel();
addInstr(new BNilInstr(lazyLabel, v1));
}

2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -118,6 +118,8 @@ public Node arg_concat(ISourcePosition position, Node node1, Node node2) {
return node2 == null ? node1 : new ArgsCatNode(position, node1, node2);
}

// firstNode is ArgsCatNode, SplatNode, ArrayNode, HashNode
// secondNode is null or not
public Node arg_blk_pass(Node firstNode, BlockPassNode secondNode) {
if (secondNode != null) {
secondNode.setArgsNode(firstNode);
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/parser/RubyParser.y
Original file line number Diff line number Diff line change
@@ -1333,7 +1333,7 @@ opt_call_args : none
}


// [!null]
// [!null] - ArgsCatNode, SplatNode, ArrayNode, HashNode, BlockPassNode
call_args : command {
value_expr(lexer, $1);
$$ = support.newArrayNode(support.getPosition($1), $1);
@@ -1352,6 +1352,7 @@ call_args : command {
| block_arg {
}

// [!null] - ArgsCatNode, SplatNode, ArrayNode, HashNode, BlockPassNode
command_args : /* none */ {
$$ = Long.valueOf(lexer.getCmdArgumentState().getStack());
lexer.getCmdArgumentState().begin();