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

Commits on Oct 31, 2014

  1. Copy the full SHA
    26fb642 View commit details
  2. Copy the full SHA
    46092f4 View commit details
  3. [Truffle] Get rid of superfluous #=== and #eql? definitions.

    * So we match MRI and avoid code duplication.
    * MRI still defines #=== uselessly on a couple classes like Fixnum, Symbol and String.
    * No more reference to the confusing "three equal".
    eregon committed Oct 31, 2014
    Copy the full SHA
    5a8ee14 View commit details
Original file line number Diff line number Diff line change
@@ -21,13 +21,13 @@ public class WhenSplatNode extends RubyNode {

@Child protected RubyNode readCaseExpression;
@Child protected RubyNode splat;
@Child protected DispatchHeadNode dispatchThreeEqual;
@Child protected DispatchHeadNode dispatchCaseEqual;

public WhenSplatNode(RubyContext context, SourceSection sourceSection, RubyNode readCaseExpression, RubyNode splat) {
super(context, sourceSection);
this.readCaseExpression = readCaseExpression;
this.splat = splat;
dispatchThreeEqual = new DispatchHeadNode(context);
dispatchCaseEqual = new DispatchHeadNode(context);
}

@Override
@@ -47,7 +47,7 @@ public boolean executeBoolean(VirtualFrame frame) {
for (Object value : array.slowToArray()) {
// TODO(CS): how to cast this to a boolean?

if ((boolean) dispatchThreeEqual.call(frame, caseExpression, "===", null, value)) {
if ((boolean) dispatchCaseEqual.call(frame, caseExpression, "===", null, value)) {
return true;
}
}
24 changes: 10 additions & 14 deletions core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -1166,16 +1166,16 @@ public RubyArray concat(RubyArray array, RubyArray other) {
@CoreMethod(names = "delete", required = 1)
public abstract static class DeleteNode extends ArrayCoreMethodNode {

@Child protected DispatchHeadNode threeEqual;
@Child protected KernelNodes.SameOrEqualNode equalNode;

public DeleteNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
threeEqual = new DispatchHeadNode(context);
equalNode = KernelNodesFactory.SameOrEqualNodeFactory.create(context, sourceSection, new RubyNode[]{null,null});
}

public DeleteNode(DeleteNode prev) {
super(prev);
threeEqual = prev.threeEqual;
equalNode = prev.equalNode;
}

@Specialization(guards = "isIntegerFixnum")
@@ -1189,9 +1189,7 @@ public Object deleteIntegerFixnum(VirtualFrame frame, RubyArray array, Object va
for (int n = 0; n < array.getSize(); n++) {
final Object stored = store[n];

// TODO(CS): need a cast node around the dispatch

if (stored == value || (boolean) threeEqual.call(frame, store[n], "===", null, value)) {
if (equalNode.executeSameOrEqual(frame, stored, value)) {
found = store[n];
continue;
}
@@ -1218,9 +1216,7 @@ public Object deleteObject(VirtualFrame frame, RubyArray array, Object value) {
for (int n = 0; n < array.getSize(); n++) {
final Object stored = store[n];

// TODO(CS): need a cast node around the dispatch

if (stored == value || (boolean) threeEqual.call(frame, store[n], "===", null, value)) {
if (equalNode.executeSameOrEqual(frame, stored, value)) {
found = store[n];
continue;
}
@@ -1741,16 +1737,16 @@ public RubyArray flatten(RubyArray array) {
@CoreMethod(names = "include?", required = 1)
public abstract static class IncludeNode extends ArrayCoreMethodNode {

@Child protected DispatchHeadNode threeEqual;
@Child protected KernelNodes.SameOrEqualNode equalNode;

public IncludeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
threeEqual = new DispatchHeadNode(context);
equalNode = KernelNodesFactory.SameOrEqualNodeFactory.create(context, sourceSection, new RubyNode[]{null,null});
}

public IncludeNode(IncludeNode prev) {
super(prev);
threeEqual = prev.threeEqual;
equalNode = prev.equalNode;
}

@Specialization(guards = "isNull")
@@ -1768,7 +1764,7 @@ public boolean includeFixnum(VirtualFrame frame, RubyArray array, Object value)
// TODO(CS): cast node around the dispatch
notDesignedForCompilation();

if (stored == value || (boolean) threeEqual.call(frame, store[n], "===", null, value)) {
if (equalNode.executeSameOrEqual(frame, stored, value)) {
return true;
}
}
@@ -1786,7 +1782,7 @@ public boolean includeObject(VirtualFrame frame, RubyArray array, Object value)
// TODO(CS): cast node around the dispatch
notDesignedForCompilation();

if (stored == value || (boolean) threeEqual.call(frame, store[n], "===", null, value)) {
if (equalNode.executeSameOrEqual(frame, stored, value)) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@
@CoreClass(name = "Encoding")
public abstract class EncodingNodes {

@CoreMethod(names = {"==", "==="}, required = 1)
// TODO(cs): this should not exist, Encoding instances should be unique.
@CoreMethod(names = "==", required = 1)
public abstract static class EqualNode extends CoreMethodNode {

public EqualNode(RubyContext context, SourceSection sourceSection) {
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ public boolean not() {

}

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

public EqualNode(RubyContext context, SourceSection sourceSection) {
Original file line number Diff line number Diff line change
@@ -753,7 +753,7 @@ public boolean lessEqual(long a, BigInteger b) {
}
}

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

public EqualNode(RubyContext context, SourceSection sourceSection) {
14 changes: 10 additions & 4 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -38,26 +38,32 @@
@CoreClass(name = "Kernel")
public abstract class KernelNodes {

/**
* Check if operands are the same object or call #==.
* Known as rb_equal() in MRI. The fact Kernel#=== uses this is pure coincidence.
*/
@CoreMethod(names = "===", required = 1)
public abstract static class CaseEqualNode extends CoreMethodNode {
public abstract static class SameOrEqualNode extends CoreMethodNode {

@Child protected BasicObjectNodes.ReferenceEqualNode referenceEqualNode;
@Child protected DispatchHeadNode equalNode;

public CaseEqualNode(RubyContext context, SourceSection sourceSection) {
public SameOrEqualNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
referenceEqualNode = BasicObjectNodesFactory.ReferenceEqualNodeFactory.create(context, sourceSection, new RubyNode[]{null, null});
equalNode = new DispatchHeadNode(context);
}

public CaseEqualNode(CaseEqualNode prev) {
public SameOrEqualNode(SameOrEqualNode prev) {
super(prev);
referenceEqualNode = prev.referenceEqualNode;
equalNode = prev.equalNode;
}

public abstract boolean executeSameOrEqual(VirtualFrame frame, Object a, Object b);

@Specialization
public boolean caseEqual(VirtualFrame frame, Object a, Object b) {
public boolean sameOrEqual(VirtualFrame frame, Object a, Object b) {
if (referenceEqualNode.executeEqual(frame, a, b))
return true;
// TODO(CS): cast
20 changes: 0 additions & 20 deletions core/src/main/java/org/jruby/truffle/nodes/core/NilClassNodes.java
Original file line number Diff line number Diff line change
@@ -34,26 +34,6 @@ public boolean not() {
}
}

@CoreMethod(names = {"==", "eql?"}, needsSelf = false, 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(Object b) {
notDesignedForCompilation();

return b instanceof RubyNilClass || b instanceof RubyNilClass;
}

}

@CoreMethod(names = "!=", needsSelf = false, required = 1)
public abstract static class NotEqualNode extends CoreMethodNode {

Original file line number Diff line number Diff line change
@@ -41,13 +41,13 @@ public boolean equal(RubyRegexp a, RubyRegexp b) {
}

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

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

public ThreeEqualNode(ThreeEqualNode prev) {
public CaseEqualNode(CaseEqualNode prev) {
super(prev);
}

Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
@CoreClass(name = "Symbol")
public abstract class SymbolNodes {

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

public EqualNode(RubyContext context, SourceSection sourceSection) {
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ public boolean not() {

}

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

public EqualNode(RubyContext context, SourceSection sourceSection) {
1 change: 1 addition & 0 deletions spec/truffle/tags/core/module/prepend_tags.txt
Original file line number Diff line number Diff line change
@@ -16,3 +16,4 @@ fails:Module#prepend calls prepended after prepend_features
fails:Module#prepend detects cyclic prepends
fails:Module#prepend returns the class it's included into
fails:Module#prepend clears any caches
fails:Module#prepend includes prepended modules in ancestors