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: 15c771147ae1
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 57cc8a6886b4
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 6, 2016

  1. Copy the full SHA
    3890a73 View commit details
  2. Copy the full SHA
    55d94bb View commit details
  3. Copy the full SHA
    57cc8a6 View commit details
19 changes: 5 additions & 14 deletions spec/truffle/tags/language/variables_tags.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
fails:Multiple assignment with a single RHS value raises a TypeError of #to_ary does not return an Array
fails:Multiple assignment with a single RHS value raises a TypeError if #to_ary does not return an Array
fails:Multiple assignment with a single RHS value assigns an Array when the RHS is an Array subclass
fails:Multiple assignment with a single splatted RHS value calls #to_a to convert nil to an empty Array
fails:Multiple assignment with a single RHS value raises a TypeError of #to_ary does not return an Array
fails:Multiple assignment with a single RHS value assigns a single LHS splat
fails:Multiple assignment with a single RHS value calls #to_ary to convert an Object RHS
fails:Multiple assignment with a single RHS value raises a TypeError if #to_ary does not return an Array
fails:Multiple assignment with a single RHS value assigns an Array when the RHS is an Array subclass
fails:Multiple assignment with a single RHS value calls #to_ary to convert an Object RHS
fails:Multiple assignment with a single RHS value calls #to_ary to convert an Object RHS with MLHS
fails:Multiple assignment with a single RHS value assigns a MLHS with leading splat
fails:Multiple assignment with a single RHS value does not mutate a RHS Array
fails:Multiple assignment with a single splatted RHS value calls #to_a to convert nil to an empty Array
fails:Multiple assignment with a single RHS value raises a TypeError if #to_ary does not return an Array
fails:Multiple assignment with a single splatted RHS value assigns a MLHS with leading splat
fails:Multiple assignment with a single splatted RHS value calls #to_a to convert an Object RHS with MLHS
fails:Multiple assignment with a single splatted RHS value calls #to_a to convert nil to an empty Array
fails:Multiple assignment with a single splatted RHS value does not mutate a RHS Array
fails:Multiple assignment with a MRHS value raises a TypeError if #to_ary does not return an Array
fails:Multiple assignment with a MRHS value calls #to_ary to convert a splatted Object when the position receiving the value is a multiple assignment
fails:Multiple assignment with a MRHS value does not call #to_ary to convert a splatted Object when the position receiving the value is a simple variable
fails:Multiple assignment with a MRHS value raises a TypeError if #to_ary does not return an Array
fails:Multiple assignment with a MRHS value calls #to_a to convert a splatted Object value in a MRHS
fails:Multiple assignment with a MRHS value calls #to_ary to convert a splatted Object when the position receiving the value is a multiple assignment
fails:Multiple assignment with a MRHS value does not call #to_ary to convert an Object when the position receiving the value is a rest variable
fails:Multiple assignment with a MRHS value does not call #to_ary to convert a splatted Object when the position receiving the value is a simple variable
fails:Multiple assignment with a MRHS value does not call #to_ary to convert an Object when the position receiving the value is a rest variable
fails:Multiple assignment with a MRHS value raises a TypeError if #to_ary does not return an Array
fails:Multiple assignment with a RHS assignment value does not mutate a RHS Array
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.ThreadLocalObjectNode;
import org.jruby.truffle.nodes.arguments.ArrayIsAtLeastAsLargeAsNode;
import org.jruby.truffle.nodes.arguments.IsRubiniusUndefinedNode;
import org.jruby.truffle.nodes.cast.*;
import org.jruby.truffle.nodes.coerce.ToProcNodeGen;
@@ -1979,6 +1980,8 @@ public RubyNode visitMultipleAsgnNode(org.jruby.ast.MultipleAsgnNode node) {

final RubyNode result;

// TODO CS 5-Jan-15 we shouldn't be doing this kind of low level optimisation or pattern matching - EA should do it for us

if (preArray != null
&& node.getPost() == null
&& node.getRest() == null
@@ -2139,6 +2142,12 @@ public RubyNode visitMultipleAsgnNode(org.jruby.ast.MultipleAsgnNode node) {

// This is very similar to the case with pre and rest, so unify with that

final List<RubyNode> sequence = new ArrayList<>();

final String tempRHSName = environment.allocateLocalTemp("rhs");
final RubyNode writeTempRHS = environment.findLocalVarNode(tempRHSName, sourceSection).makeWriteNode(rhsTranslated);
sequence.add(writeTempRHS);

/*
* Create a temp for the array.
*/
@@ -2150,9 +2159,8 @@ public RubyNode visitMultipleAsgnNode(org.jruby.ast.MultipleAsgnNode node) {
* the temp.
*/

final List<RubyNode> sequence = new ArrayList<>();

final RubyNode splatCastNode = SplatCastNodeGen.create(context, sourceSection, translatingNextExpression ? SplatCastNode.NilBehavior.EMPTY_ARRAY : SplatCastNode.NilBehavior.ARRAY_WITH_NIL, false, rhsTranslated);
final RubyNode splatCastNode = SplatCastNodeGen.create(context, sourceSection, translatingNextExpression ? SplatCastNode.NilBehavior.EMPTY_ARRAY : SplatCastNode.NilBehavior.ARRAY_WITH_NIL, false, environment.findLocalVarNode(tempRHSName, sourceSection));

final RubyNode writeTemp = environment.findLocalVarNode(tempName, sourceSection).makeWriteNode(splatCastNode);

@@ -2168,13 +2176,34 @@ public RubyNode visitMultipleAsgnNode(org.jruby.ast.MultipleAsgnNode node) {
sequence.add(translateDummyAssignment(node.getRest(), assignedValue));
}

final List<RubyNode> smallerSequence = new ArrayList<>();

for (int n = 0; n < postArray.size(); n++) {
final RubyNode assignedValue = PrimitiveArrayNodeFactory.read(context, sourceSection, environment.findLocalVarNode(tempName, sourceSection), node.getPreCount() + n);
smallerSequence.add(translateDummyAssignment(postArray.get(n), assignedValue));
}

final RubyNode smaller = SequenceNode.sequence(context, sourceSection, smallerSequence);

final List<RubyNode> atLeastAsLargeSequence = new ArrayList<>();

for (int n = 0; n < postArray.size(); n++) {
final RubyNode assignedValue = PrimitiveArrayNodeFactory.read(context, sourceSection, environment.findLocalVarNode(tempName, sourceSection), -(postArray.size() - n));

sequence.add(translateDummyAssignment(postArray.get(n), assignedValue));
atLeastAsLargeSequence.add(translateDummyAssignment(postArray.get(n), assignedValue));
}

result = SequenceNode.sequence(context, sourceSection, sequence);
final RubyNode atLeastAsLarge = SequenceNode.sequence(context, sourceSection, atLeastAsLargeSequence);

final RubyNode assignPost =
new IfNode(context, sourceSection,
new ArrayIsAtLeastAsLargeAsNode(context, sourceSection, environment.findLocalVarNode(tempName, sourceSection), node.getPreCount() + node.getPostCount()),
atLeastAsLarge,
smaller);

sequence.add(assignPost);

result = new ElidableResultNode(context, sourceSection, SequenceNode.sequence(context, sourceSection, sequence), environment.findLocalVarNode(tempRHSName, sourceSection));
} else {
context.getRuntime().getWarnings().warn(IRubyWarnings.ID.TRUFFLE, source.getName(), node.getPosition().getLine(), node + " unknown form of multiple assignment");
result = nilNode(sourceSection);
Original file line number Diff line number Diff line change
@@ -369,10 +369,6 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnNode node) {

final RubyNode notNilSmaller = SequenceNode.sequence(context, sourceSection, notNilSmallerSequence);

if (notNilSmaller == null) {
throw new UnsupportedOperationException();
}

// The load to use when the array is not nil and at least as large as the number of required arguments

final List<RubyNode> notNilAtLeastAsLargeSequence = new ArrayList<>();