Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
	truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
  • Loading branch information
chrisseaton committed Mar 13, 2015
2 parents 871889f + 9a87aff commit 86858cc
Show file tree
Hide file tree
Showing 27 changed files with 593 additions and 97 deletions.
9 changes: 6 additions & 3 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,7 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
result.associateEncoding(resultEnc);

boolean isUnicode = StringSupport.isUnicode(enc);
boolean asciiCompat = enc.isAsciiCompatible();

EncodingDB.Entry e = null;
CaseInsensitiveBytesHash<EncodingDB.Entry> encodings = runtime.getEncodingService().getEncodings();
Expand All @@ -2100,6 +2101,7 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
} else if (c0 == 0xFF && c1 == 0xFE) {
e = encodings.get("UTF-16LE".getBytes());
} else {
e = encodings.get("ASCII-8BIT".getBytes());
isUnicode = false;
}
} else if (enc == encodings.get("UTF-32".getBytes()).getEncoding() && end - p > 3) {
Expand All @@ -2113,6 +2115,7 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
} else if (c3 == 0 && c2 == 0 && c1 == 0xFE && c0 == 0xFF) {
e = encodings.get("UTF-32LE".getBytes());
} else {
e = encodings.get("ASCII-8BIT".getBytes());
isUnicode = false;
}
}
Expand All @@ -2137,13 +2140,13 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
}
int c = enc.mbcToCode(bytes, p, end);
p += n;
if ((enc.isAsciiCompatible() || isUnicode) &&
if ((asciiCompat || isUnicode) &&
(c == '"' || c == '\\' ||
(c == '#' && p < end && (StringSupport.preciseLength(enc, bytes, p, end) > 0) &&
(cc = codePoint(runtime, enc, bytes, p, end)) == '$' || cc == '@' || cc == '{'))) {
if (p - n > prev) result.cat(bytes, prev, p - n - prev);
result.cat('\\');
if (enc.isAsciiCompatible() || enc == resultEnc) {
if (asciiCompat || enc == resultEnc) {
prev = p - n;
continue;
}
Expand All @@ -2169,7 +2172,7 @@ public static IRubyObject inspect19(Ruby runtime, ByteList byteList) {
continue;
}

if ((enc == resultEnc && enc.isPrint(c)) || (enc.isAsciiCompatible() && Encoding.isAscii(c) && enc.isPrint(c))) {
if ((enc == resultEnc && enc.isPrint(c)) || (asciiCompat && Encoding.isAscii(c) && enc.isPrint(c))) {
continue;
} else {
if (p - n > prev) result.cat(bytes, prev, p - n - prev);
Expand Down
1 change: 1 addition & 0 deletions maven/jruby-dist/src/main/assembly/jruby.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<include>LICENSE*</include>
<include>COPYING*</include>
<include>lib/jruby.jar</include>
<include>lib/jruby-truffle.jar</include>
<include>lib/jni/**/*</include>
<include>samples/**/*</include>
<include>docs/**/*</include>
Expand Down
15 changes: 5 additions & 10 deletions spec/regression/GH-1675_casecmp_on_UTF16LE_encoded_string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
describe 'String#casecmp' do
it 'returns correct value' do
Encoding.name_list.each do |enc_name|
if (enc_name != "UTF-7") && (enc_name != "CP65000")
# this condition statement escape the following error:
# Encoding::ConverterNotFoundError:
# code converter not found for UTF-7

# using "UTF-16LE", "UTF-8", "Shift_JIS", and other available encodings
a = 'ABC'.encode(enc_name)
b = 'ABC'.encode(enc_name)
b.casecmp(a).should be_true
end
enc = Encoding.find(enc_name)
next if !enc || enc.dummy?
a = 'ABC'.encode(enc)
b = 'ABC'.encode(enc)
b.casecmp(a).should == 0
end
end
end
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/concat_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fails:Array#concat tries to convert the passed argument to an Array using #to_ary
fails:Array#concat is not infected by the other
fails:Array#concat is not infected untrustedness by the other
fails:Array#concat returns the array itself
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/flatten_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/initialize_copy_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/replace_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/random/equal_value_tags.txt

This file was deleted.

8 changes: 0 additions & 8 deletions spec/truffle/tags/core/random/new_tags.txt

This file was deleted.

16 changes: 1 addition & 15 deletions spec/truffle/tags/core/random/rand_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,15 @@ fails:Random.rand returns an Integer >= 0 if an Integer argument is passed
fails:Random.rand returns an Integer < the max argument if an Integer argument is passed
fails:Random.rand returns the same sequence for a given seed if an Integer argument is passed
fails:Random.rand coerces arguments to Integers with #to_int
fails:Random#rand with Fixnum returns an Integer
fails:Random#rand with Fixnum returns a Fixnum greater than or equal to 0
fails:Random#rand with Fixnum returns a Fixnum less than the argument
fails:Random#rand with Fixnum returns the same sequence for a given seed
fails:Random#rand with Fixnum eventually returns all possible values
fails:Random#rand with Fixnum raises an ArgumentError when the argument is 0
fails:Random#rand with Fixnum raises an ArgumentError when the argument is negative
fails:Random#rand with Bignum typically returns a Bignum
fails:Random#rand with Bignum returns a Bignum greater than or equal to 0
fails:Random#rand with Bignum returns a Bignum less than the argument
fails:Random#rand with Bignum returns the same sequence for a given seed
fails:Random#rand with Bignum raises an ArgumentError when the argument is negative
fails:Random#rand with Float returns a Float
fails:Random#rand with Float returns a Float greater than or equal to 0.0
fails:Random#rand with Float returns a Float less than the argument
fails:Random#rand with Float returns the same sequence for a given seed
fails:Random#rand with Float raises an ArgumentError when the argument is negative
fails:Random#rand with Range returns an element from the Range
fails:Random#rand with Fixnum returns the same sequence for a given seed
fails:Random#rand with Range returns an object that is a member of the Range
fails:Random#rand with Range works with inclusive ranges
fails:Random#rand with Range works with exclusive ranges
fails:Random#rand with Range returns the same sequence for a given seed
fails:Random#rand with Range eventually returns all possible values
fails:Random#rand with Range considers Integers as Floats if one end point is a float
fails:Random#rand with Range raises an ArgumentError when the startpoint lacks #+ and #- methods
fails:Random#rand with Range raises an ArgumentError when the endpoint lacks #+ and #- methods
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/random/seed_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/truffle/tags/core/thread/join_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/thread/main_tags.txt

This file was deleted.

16 changes: 16 additions & 0 deletions tool/truffle-findbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,20 @@
<Class name="org.jruby.truffle.runtime.subsystems.SimpleShell" />
<Bug pattern="DM_EXIT" />
</Match>
<Match>
<Class name="org.jruby.truffle.nodes.debug.AssertConstantNode" />
<Bug pattern="VO_VOLATILE_REFERENCE_TO_ARRAY" />
</Match>
<Match>
<Class name="org.jruby.truffle.nodes.debug.AssertNotCompiledNode" />
<Bug pattern="VO_VOLATILE_REFERENCE_TO_ARRAY" />
</Match>
<Match>
<Class name="org.jruby.truffle.nodes.debug.AssertConstantNode" />
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
</Match>
<Match>
<Class name="org.jruby.truffle.nodes.debug.AssertNotCompiledNode" />
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.jruby.truffle.nodes.coerce;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;


@NodeChild(value = "child", type = RubyNode.class)
public abstract class ToAryNode extends RubyNode {

@Child private CallDispatchHeadNode toAryNode;

public ToAryNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public ToAryNode(ToAryNode prev) {
super(prev);
}

@Specialization
public RubyArray coerceRubyArray(RubyArray rubyArray) {
return rubyArray;
}

@Specialization(guards = "!isRubyArray(object)")
public RubyArray coerceObject(VirtualFrame frame, Object object) {
notDesignedForCompilation();

if (toAryNode == null) {
CompilerDirectives.transferToInterpreter();
toAryNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

final Object coerced;

try {
coerced = toAryNode.call(frame, object, "to_ary", null);
} catch (RaiseException e) {
if (e.getRubyException().getLogicalClass() == getContext().getCoreLibrary().getNoMethodErrorClass()) {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(
getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "Array", this));
} else {
throw e;
}
}
if (coerced instanceof RubyArray) {
return (RubyArray) coerced;
} else {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(
getContext().getCoreLibrary().typeErrorBadCoercion(object, "Array", "to_ary", coerced, this));
}
}
}
34 changes: 31 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.array.*;
import org.jruby.truffle.nodes.coerce.ToIntNode;
import org.jruby.truffle.nodes.coerce.ToAryNodeFactory;
import org.jruby.truffle.nodes.coerce.ToIntNodeFactory;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.nodes.methods.arguments.MissingArgumentBehaviour;
Expand Down Expand Up @@ -598,7 +599,12 @@ public Object compactObjects(RubyArray array) {
}

@CoreMethod(names = "concat", required = 1, raiseIfFrozenSelf = true)
public abstract static class ConcatNode extends ArrayCoreMethodNode {
@NodeChildren({
@NodeChild(value = "array"),
@NodeChild(value = "other")
})
@ImportStatic(ArrayGuards.class)
public abstract static class ConcatNode extends RubyNode {

public ConcatNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand All @@ -608,6 +614,10 @@ public ConcatNode(ConcatNode prev) {
super(prev);
}

@CreateCast("other") public RubyNode coerceOtherToAry(RubyNode other) {
return ToAryNodeFactory.create(getContext(), getSourceSection(), other);
}

@Specialization(guards = "areBothNull(array, other)")
public RubyArray concatNull(RubyArray array, RubyArray other) {
return array;
Expand Down Expand Up @@ -1236,7 +1246,12 @@ public RubyArray initialize(RubyArray array, RubyArray copy, UndefinedPlaceholde
}

@CoreMethod(names = "initialize_copy", visibility = Visibility.PRIVATE, required = 1, raiseIfFrozenSelf = true)
public abstract static class InitializeCopyNode extends ArrayCoreMethodNode {
@NodeChildren({
@NodeChild(value = "self"),
@NodeChild(value = "from")
})
@ImportStatic(ArrayGuards.class)
public abstract static class InitializeCopyNode extends RubyNode {
// TODO(cs): what about allocationSite ?

public InitializeCopyNode(RubyContext context, SourceSection sourceSection) {
Expand All @@ -1247,6 +1262,10 @@ public InitializeCopyNode(InitializeCopyNode prev) {
super(prev);
}

@CreateCast("from") public RubyNode coerceOtherToAry(RubyNode other) {
return ToAryNodeFactory.create(getContext(), getSourceSection(), other);
}

@Specialization(guards = "isOtherNull(self, from)")
public RubyArray initializeCopyNull(RubyArray self, RubyArray from) {
if (self == from) {
Expand Down Expand Up @@ -2657,7 +2676,12 @@ public Object rejectInPlaceObject(VirtualFrame frame, RubyArray array, RubyProc
}

@CoreMethod(names = "replace", required = 1, raiseIfFrozenSelf = true)
public abstract static class ReplaceNode extends ArrayCoreMethodNode {
@NodeChildren({
@NodeChild(value = "array"),
@NodeChild(value = "other")
})
@ImportStatic(ArrayGuards.class)
public abstract static class ReplaceNode extends RubyNode {

public ReplaceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand All @@ -2667,6 +2691,10 @@ public ReplaceNode(ReplaceNode prev) {
super(prev);
}

@CreateCast("other") public RubyNode coerceOtherToAry(RubyNode index) {
return ToAryNodeFactory.create(getContext(), getSourceSection(), index);
}

@Specialization(guards = "isOtherNull(array, other)")
public RubyArray replace(RubyArray array, RubyArray other) {
notDesignedForCompilation();
Expand Down

0 comments on commit 86858cc

Please sign in to comment.