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

Commits on Jan 8, 2015

  1. Copy the full SHA
    d90784a View commit details
  2. Copy the full SHA
    91c9730 View commit details
  3. Copy the full SHA
    40b4ba0 View commit details
  4. [Truffle] Implement Array#[index,length] on int to see how much specs…

    … we pass.
    
    * Also fix for an Object array.
    eregon committed Jan 8, 2015
    Copy the full SHA
    ed9267a View commit details
  5. Copy the full SHA
    e1dbdcd View commit details
32 changes: 27 additions & 5 deletions core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.CoreSourceSection;
import org.jruby.truffle.nodes.RubyNode;
@@ -571,6 +572,23 @@ public Object getIntegerFixnum(RubyArray array, int index, UndefinedPlaceholder
}
}

@Specialization(guards = "isIntegerFixnum")
public Object getIntegerFixnum(RubyArray array, int index, int length) {
notDesignedForCompilation();

final int normalisedIndex = array.normaliseIndex(index);

if (normalisedIndex < 0 || normalisedIndex > array.getSize() || length < 0) {
return getContext().getCoreLibrary().getNilObject();
} else if (normalisedIndex == array.getSize()) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), null, 0);
} else {
final int end = Math.min(array.getSize(), normalisedIndex + length);

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOfRange((int[]) array.getStore(), normalisedIndex, end), end - normalisedIndex);
}
}

@Specialization(guards = "isLongFixnum", rewriteOn=UnexpectedResultException.class)
public long getLongFixnumInBounds(RubyArray array, int index, UndefinedPlaceholder undefined) throws UnexpectedResultException {
int normalisedIndex = array.normaliseIndex(index);
@@ -631,12 +649,16 @@ public Object getObject(RubyArray array, int index, UndefinedPlaceholder undefin
public Object getObject(RubyArray array, int index, int length) {
notDesignedForCompilation();

int normalisedIndex = array.normaliseIndex(index);
final int normalisedIndex = array.normaliseIndex(index);

if (normalisedIndex < 0 || normalisedIndex >= array.getSize()) {
if (normalisedIndex < 0 || normalisedIndex > array.getSize() || length < 0) {
return getContext().getCoreLibrary().getNilObject();
} else if (normalisedIndex == array.getSize()) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), null, 0);
} else {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOfRange((Object[]) array.getStore(), normalisedIndex, normalisedIndex + length), length);
final int end = Math.min(array.getSize(), normalisedIndex + length);

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((Object[]) array.getStore(), normalisedIndex, end), end - normalisedIndex);
}
}

@@ -652,7 +674,7 @@ public Object getObject(RubyArray array, RubyRange.IntegerFixnumRange range, Und
final int end = array.normaliseIndex(range.getEnd());
final int excludingEnd = array.clampExclusiveIndex(range.doesExcludeEnd() ? end : end+1);

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOfRange((Object[]) array.getStore(), normalisedIndex, excludingEnd), excludingEnd - normalisedIndex);
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), ArrayUtils.extractRange((Object[]) array.getStore(), normalisedIndex, excludingEnd), excludingEnd - normalisedIndex);
}
}

@@ -3191,7 +3213,7 @@ public Object selectFixnumInteger(VirtualFrame frame, RubyArray array, RubyProc

}

@CoreMethod(names = "reject!", needsBlock = true)
@CoreMethod(names = { "reject!", "delete_if" }, needsBlock = true)
@ImportGuards(ArrayGuards.class)
public abstract static class RejectInPlaceNode extends YieldingCoreMethodNode {

4 changes: 0 additions & 4 deletions spec/truffle/tags/core/array/delete_if_tags.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
fails:Array#delete_if removes each element for which block returns true
fails:Array#delete_if returns self
fails:Array#delete_if returns an Enumerator if no block given
fails:Array#delete_if returns self when called on an Array emptied with #shift
fails:Array#delete_if returns an Enumerator if no block given, and the enumerator can modify the original array
fails:Array#delete_if returns an Enumerator if no block given, and the array is frozen
fails:Array#delete_if raises a RuntimeError on a frozen array
fails:Array#delete_if raises a RuntimeError on an empty frozen array
fails:Array#delete_if keeps tainted status
fails:Array#delete_if keeps untrusted status
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/array/element_reference_tags.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
fails:Array#[] returns count elements starting from index with [index, count]
fails:Array#[] returns count elements starting at index from the end of array with [-index, count]
fails:Array#[] returns the subarray which is independent to self with [index,count]
fails:Array#[] tries to convert the passed argument to an Integer using #to_int
fails:Array#[] returns the elements specified by Range indexes with [m..n]
fails:Array#[] returns elements specified by Range indexes except the element at index n with [m...n]
fails:Array#[] accepts Range instances having a negative m and both signs for n with [m..n] and [m...n]
fails:Array#[] returns the subarray which is independent to self with [m..n]
fails:Array#[] tries to convert Range elements to Integers using #to_int with [m..n] and [m...n]
fails:Array#[] returns the same elements as [m..n] and [m...n] with Range subclasses
fails:Array#[] returns [] if index == array.size with [index, length]
fails:Array#[] returns nil if length is negative with [index, length]
fails:Array#[] returns an empty array when m == n with [m...n]
fails:Array#[] returns an empty array with [0...0]
fails:Array#[] returns an array containing the first element with [0..0]
2 changes: 1 addition & 1 deletion tool/jt.rb
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ def tag(path)

def untag(path)
puts
puts "WARNING: untag is currently not very reliable - run test #{path} after and manually annotate any new failures"
puts "WARNING: untag is currently not very reliable - run `jt test #{path}` after and manually annotate any new failures"
puts
mspec 'tag', '--del', 'fails', '--pass', path
end