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

Commits on Feb 20, 2015

  1. [Truffle] FindBugs: remove non-compliant RubyString.equals().

    * Implement missing String#hash.
    eregon committed Feb 20, 2015
    Copy the full SHA
    1b1fcb0 View commit details
  2. Copy the full SHA
    d4f72bd View commit details
  3. [Truffle] FindBugs: remove non-compliant RubySymbol.equals().

    * Implement missing Symbol#hash.
    eregon committed Feb 20, 2015
    Copy the full SHA
    9d3ff1d View commit details
  4. Copy the full SHA
    0a67f09 View commit details
  5. [Truffle] FindBugs: remove non-compliant RubyRegexp.equals().

    * Implement missing Regexp#== and #hash.
    eregon committed Feb 20, 2015
    Copy the full SHA
    29d2e25 View commit details
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/regexp/hash_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/symbol/equal_value_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -29,6 +29,41 @@
@CoreClass(name = "Regexp")
public abstract class RegexpNodes {

@CoreMethod(names = "==", required = 1)
public abstract static class EqualNode extends CoreMethodNode {

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

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

@Specialization
public boolean equal(RubyRegexp a, RubyRegexp b) {
if (a == b) {
return true;
}

if (a.getRegex().getOptions() != b.getRegex().getOptions()) {
return false;
}

if (a.getSource().getEncoding() != b.getSource().getEncoding()) {
return false;
}

return a.getSource().equal(b.getSource());
}

@Specialization(guards = "!isRubyRegexp(arguments[1])")
public boolean equal(RubyRegexp a, Object b) {
return false;
}

}

public abstract static class EscapingNode extends CoreMethodNode {

@Child private EscapeNode escapeNode;
@@ -141,6 +176,25 @@ public RubyString escape(RubyString pattern) {

}

@CoreMethod(names = "hash")
public abstract static class HashNode extends CoreMethodNode {

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

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

@Specialization
public int hash(RubyRegexp regexp) {
int options = regexp.getRegex().getOptions() & ~32 /* option n, NO_ENCODING in common/regexp.rb */;
return options ^ regexp.getSource().hashCode();
}

}

@CoreMethod(names = "inspect")
public abstract static class InspectNode extends CoreMethodNode {

Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ public Object compare(VirtualFrame frame, RubyString a, Object b) {

return compare(a, coerced);
} catch (RaiseException e) {
if (e.getRubyException().getLogicalClass().equals(getContext().getCoreLibrary().getTypeErrorClass())) {
if (e.getRubyException().getLogicalClass() == getContext().getCoreLibrary().getTypeErrorClass()) {
return getContext().getCoreLibrary().getNilObject();
} else {
throw e;
@@ -230,7 +230,7 @@ public RubyString concat(RubyString string, RubyString other) {
try {
EncodingUtils.encCrStrBufCat(getContext().getRuntime(), string, other.getByteList(), other.getByteList().getEncoding(), codeRange, ptr_cr_ret);
} catch (org.jruby.exceptions.RaiseException e) {
if (e.getException().getMetaClass().equals(getContext().getRuntime().getEncodingCompatibilityError())) {
if (e.getException().getMetaClass() == getContext().getRuntime().getEncodingCompatibilityError()) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().encodingCompatibilityError(e.getException().message.asJavaString(), this));
}
@@ -741,7 +741,7 @@ public RubyBasicObject downcase(RubyString string) {

ByteList newByteList = StringNodesHelper.downcase(string);

if (newByteList.equals(string.getBytes())) {
if (newByteList.equal(string.getBytes())) {
return getContext().getCoreLibrary().getNilObject();
} else {
string.set(newByteList);
@@ -938,6 +938,24 @@ public int getByte(RubyString string, int index) {
}
}

@CoreMethod(names = "hash")
public abstract static class HashNode extends CoreMethodNode {

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

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

@Specialization
public int hash(RubyString string) {
return string.getBytes().hashCode();
}

}

@CoreMethod(names = "inspect")
public abstract static class InspectNode extends CoreMethodNode {

47 changes: 21 additions & 26 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/SymbolNodes.java
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.core.StringNodes.HashNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyProc;
@@ -39,36 +41,11 @@ public boolean equal(RubySymbol a, RubySymbol b) {
return a == b;
}

@Specialization
public boolean equal(RubySymbol a, RubyString b) {
notDesignedForCompilation();

return a.toString().equals(b.toString());
}

@Specialization
public boolean equal(RubySymbol a, int b) {
notDesignedForCompilation();

return a.toString().equals(Integer.toString(b));
}

@Specialization
public boolean equal(RubySymbol a, long b) {
notDesignedForCompilation();

return a.toString().equals(Long.toString(b));
}

@Specialization(guards = "notSymbol")
@Specialization(guards = "!isRubySymbol(arguments[1])")
public boolean equal(RubySymbol a, Object b) {
return false;
}

protected boolean notSymbol(RubySymbol a, Object b) {
return !(b instanceof RubySymbol);
}

}

@CoreMethod(names = "<=>", required = 1)
@@ -135,6 +112,24 @@ public boolean empty(RubySymbol symbol) {

}

@CoreMethod(names = "hash")
public abstract static class HashNode extends CoreMethodNode {

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

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

@Specialization
public int hash(RubySymbol symbol) {
return symbol.toString().hashCode();
}

}

@CoreMethod(names = "to_proc")
public abstract static class ToProcNode extends CoreMethodNode {

Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ protected final boolean guardName(Object methodName) {
// TODO(CS, 11-Jan-15) this just repeats the above guard...
return cachedName == methodName;
} else if (cachedName instanceof RubyString) {
return (methodName instanceof RubyString) && ((RubyString) cachedName).getBytes().equals(((RubyString) methodName).getBytes());
return (methodName instanceof RubyString) && ((RubyString) cachedName).getBytes().equal(((RubyString) methodName).getBytes());
} else {
throw new UnsupportedOperationException();
}
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;

import org.jruby.truffle.nodes.ReadNode;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode;
@@ -31,7 +32,7 @@ public class ReadInstanceVariableNode extends RubyNode implements ReadNode {
private final BranchProfile nullProfile = BranchProfile.create();
private final BranchProfile primitiveProfile = BranchProfile.create();

public ReadInstanceVariableNode(RubyContext context, SourceSection sourceSection, Object name, RubyNode receiver, boolean isGlobal) {
public ReadInstanceVariableNode(RubyContext context, SourceSection sourceSection, String name, RubyNode receiver, boolean isGlobal) {
super(context, sourceSection);
this.receiver = receiver;
readNode = new ReadHeadObjectFieldNode(name);
@@ -141,6 +142,6 @@ public Object isDefined(VirtualFrame frame) {

@Override
public RubyNode makeWriteNode(RubyNode rhs) {
return new WriteInstanceVariableNode(getContext(), getSourceSection(), readNode.getName(), receiver, rhs, isGlobal);
return new WriteInstanceVariableNode(getContext(), getSourceSection(), (String) readNode.getName(), receiver, rhs, isGlobal);
}
}
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.WriteNode;
import org.jruby.truffle.nodes.objectstorage.WriteHeadObjectFieldNode;
@@ -27,7 +28,7 @@ public class WriteInstanceVariableNode extends RubyNode implements WriteNode {
@Child private WriteHeadObjectFieldNode writeNode;
private final boolean isGlobal;

public WriteInstanceVariableNode(RubyContext context, SourceSection sourceSection, Object name, RubyNode receiver, RubyNode rhs, boolean isGlobal) {
public WriteInstanceVariableNode(RubyContext context, SourceSection sourceSection, String name, RubyNode receiver, RubyNode rhs, boolean isGlobal) {
super(context, sourceSection);
this.receiver = receiver;
this.rhs = rhs;
@@ -112,7 +113,7 @@ public Object execute(VirtualFrame frame) {

@Override
public RubyNode makeReadNode() {
return new ReadInstanceVariableNode(getContext(), getSourceSection(), writeNode.getName(), receiver, isGlobal);
return new ReadInstanceVariableNode(getContext(), getSourceSection(), (String) writeNode.getName(), receiver, isGlobal);
}

@Override
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ public boolean stringEqual(RubyString string, RubyString other) {
final ByteList a = string.getBytes();
final ByteList b = other.getBytes();

if (incompatibleEncodingProfile.profile((a.getEncoding().equals(b.getEncoding()) == false) &&
if (incompatibleEncodingProfile.profile((a.getEncoding() != b.getEncoding()) &&
(org.jruby.RubyEncoding.areCompatible(string, other) == null))) {
return false;
}
Original file line number Diff line number Diff line change
@@ -396,33 +396,6 @@ public Object scan(RubyString string) {
}
}

@Override
public int hashCode() {
return regex.hashCode();
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof RubyRegexp)) {
return false;
}
RubyRegexp other = (RubyRegexp) obj;
if (source == null) {
if (other.source != null) {
return false;
}
} else if (!source.equals(other.source)) {
return false;
}
return true;
}

public static Regex compile(RubyNode currentNode, RubyContext context, ByteList bytes, int options) {
RubyNode.notDesignedForCompilation();
return compile(currentNode, context, bytes.bytes(), bytes.getEncoding(), options);
Original file line number Diff line number Diff line change
@@ -130,21 +130,6 @@ public RubyString dump() {
return result;
}

@Override
public boolean equals(Object other) {
RubyNode.notDesignedForCompilation();

if (other == this) {
return true;
}

if (other instanceof String || other instanceof RubyString) {
return toString().equals(other.toString());
}

return false;
}

@Override
@TruffleBoundary
public String toString() {
@@ -153,13 +138,6 @@ public String toString() {
return Helpers.decodeByteList(getContext().getRuntime(), bytes);
}

@Override
public int hashCode() {
RubyNode.notDesignedForCompilation();

return bytes.hashCode();
}

public int length() {
return StringSupport.strLengthFromRubyString(this);
}
Original file line number Diff line number Diff line change
@@ -76,24 +76,6 @@ public org.jruby.RubySymbol getJRubySymbol() {
return getContext().getRuntime().newSymbol(bytes);
}

@Override
public int hashCode() {
return symbol.hashCode();
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
} else if (other instanceof RubySymbol) {
return symbol == ((RubySymbol) other).symbol;
} else if (other instanceof RubyString) {
return other.equals(symbol);
} else {
return super.equals(other);
}
}

@Override
public String toString() {
return symbol;
Original file line number Diff line number Diff line change
@@ -118,16 +118,6 @@ public static boolean contains(double[] array, double value) {
return false;
}

public static boolean contains(Object[] array, int length, Object value) {
for (int n = 0; n < length; n++) {
if (array[n].equals(value)) {
return true;
}
}

return false;
}

public static Object[] box(int[] unboxed) {
return box(unboxed, 0);
}