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

Commits on Jan 10, 2016

  1. [Truffle] Fix special block implicit restructure from array shorter t…

    …han required arguments.
    chrisseaton committed Jan 10, 2016
    Copy the full SHA
    cef8acf View commit details
  2. Copy the full SHA
    d2f4f43 View commit details
Showing with 43 additions and 9 deletions.
  1. +0 −3 spec/truffle/tags/language/block_tags.txt
  2. +43 −6 truffle/src/main/java/org/jruby/truffle/translator/LoadArgumentsTranslator.java
3 changes: 0 additions & 3 deletions spec/truffle/tags/language/block_tags.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
fails:A block yielded a single Array assgins elements to post arguments
fails:A block yielded a single Array assigns elements to mixed argument types
fails:A block yielded a single Array assigns elements to optional arguments
fails:A block yielded a single Array assigns elements to required arguments when a keyword rest argument is present
fails:A block yielded a single Array assigns nil to unassigned required arguments
fails:A block yielded a single Array assigns non-symbol keys to non-keyword arguments
fails:A block yielded a single Array assigns symbol keys from a Hash returned by #to_hash to keyword arguments
fails:A block yielded a single Array assigns symbol keys from a Hash to keyword arguments
Original file line number Diff line number Diff line change
@@ -120,17 +120,50 @@ public RubyNode visitArgsNode(org.jruby.ast.ArgsNode node) {
}

int postCount = node.getPostCount();

// The load to use when the array is not nil and the length is smaller than the number of required arguments

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

if (postCount > 0) {
state = State.POST;
org.jruby.ast.Node[] children = node.getPost().children();
index = node.getPreCount();
for (int i = 0; i < children.length; i++) {
notNilSmallerSequence.add(children[i].accept(this));
index++;
}
}

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

// 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<>();

if (postCount > 0) {
state = State.POST;
index = -1;
int postIndex = node.getPostIndex();
for (int i = postCount - 1; i >= 0; i--) {
sequence.add(args[postIndex + i].accept(this));
notNilAtLeastAsLargeSequence.add(args[postIndex + i].accept(this));
required++;
index--;
}
}

final RubyNode notNilAtLeastAsLarge = SequenceNode.sequence(context, sourceSection, notNilAtLeastAsLargeSequence);

if (useArray()) {
sequence.add(new IfNode(context, sourceSection,
new ArrayIsAtLeastAsLargeAsNode(context, sourceSection, loadArray(sourceSection), node.getPreCount() + node.getPostCount()),
notNilAtLeastAsLarge,
notNilSmaller));
} else {
// TODO CS 10-Jan-16 needn't have created notNilSmaller
sequence.add(notNilAtLeastAsLarge);
}

if (hasKeywordArguments) {
kwIndex = 0;
countKwArgs = 0;
@@ -298,7 +331,15 @@ private RubyNode translateLocalAssignment(ISourcePosition sourcePosition, String
minimum += 1;
}

readNode = new ReadOptionalArgumentNode(context, sourceSection, index, minimum, defaultValue);
if (useArray()) {
// TODO CS 10-Jan-16 we should really hoist this check, or see if Graal does it for us
readNode = new IfNode(context, sourceSection,
new ArrayIsAtLeastAsLargeAsNode(context, sourceSection, loadArray(sourceSection), minimum),
PrimitiveArrayNodeFactory.read(context, sourceSection, loadArray(sourceSection), index),
defaultValue);
} else {
readNode = new ReadOptionalArgumentNode(context, sourceSection, index, minimum, defaultValue);
}
}
} else {
readNode = ArraySliceNodeGen.create(context, sourceSection, index, indexFromEnd, loadArray(sourceSection));
@@ -400,10 +441,6 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnNode node) {

final RubyNode notNilAtLeastAsLarge = SequenceNode.sequence(context, sourceSection, notNilAtLeastAsLargeSequence);

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

popArraySlot(arraySlot);

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