Skip to content

Commit

Permalink
[Truffle] Hash#compare_by_identity
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Mar 7, 2015
1 parent e2cd719 commit bd25c3c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/hash/compare_by_identity_tags.txt

This file was deleted.

Expand Up @@ -43,14 +43,14 @@ public abstract class HashNodes {
public abstract static class EqualNode extends HashCoreMethodNode {

@Child private CallDispatchHeadNode eqlNode;
@Child private CallDispatchHeadNode equalNode;
@Child private BasicObjectNodes.ReferenceEqualNode equalNode;

private final ConditionProfile byIdentityProfile = ConditionProfile.createBinaryProfile();

public EqualNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
eqlNode = DispatchHeadNodeFactory.createMethodCall(context, false, false, null);
equalNode = DispatchHeadNodeFactory.createMethodCall(context, false, false, null);
equalNode = equalNode = BasicObjectNodesFactory.ReferenceEqualNodeFactory.create(context, sourceSection, null, null);
}

public EqualNode(EqualNode prev) {
Expand Down Expand Up @@ -247,7 +247,7 @@ public RubyHash construct(RubyClass hashClass, Object[] args) {
public abstract static class GetIndexNode extends HashCoreMethodNode {

@Child private CallDispatchHeadNode eqlNode;
@Child private CallDispatchHeadNode equalNode;
@Child private BasicObjectNodes.ReferenceEqualNode equalNode;
@Child private YieldDispatchHeadNode yield;
@Child private FindEntryNode findEntryNode;

Expand All @@ -260,7 +260,7 @@ public abstract static class GetIndexNode extends HashCoreMethodNode {
public GetIndexNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
eqlNode = DispatchHeadNodeFactory.createMethodCall(context, false, false, null);
equalNode = DispatchHeadNodeFactory.createMethodCall(context, false, false, null);
equalNode = equalNode = BasicObjectNodesFactory.ReferenceEqualNodeFactory.create(context, sourceSection, null, null);
yield = new YieldDispatchHeadNode(context);
findEntryNode = new FindEntryNode(context, sourceSection);
}
Expand Down Expand Up @@ -302,7 +302,7 @@ public Object getPackedArray(VirtualFrame frame, RubyHash hash, Object key) {
final boolean equal;

if (byIdentityProfile.profile(hash.isCompareByIdentity())) {
equal = equalNode.callBoolean(frame, store[n * 2], "equal?", null, key);
equal = equalNode.executeReferenceEqual(frame, store[n * 2], key);
} else {
equal = eqlNode.callBoolean(frame, store[n * 2], "eql?", null, key);
}
Expand Down Expand Up @@ -392,7 +392,7 @@ public Object getOrUndefined(VirtualFrame frame, RubyHash hash, Object key) {
public abstract static class SetIndexNode extends HashCoreMethodNode {

@Child private CallDispatchHeadNode eqlNode;
@Child private CallDispatchHeadNode equalNode;
@Child private BasicObjectNodes.ReferenceEqualNode equalNode;

private final ConditionProfile byIdentityProfile = ConditionProfile.createBinaryProfile();
private final BranchProfile considerExtendProfile = BranchProfile.create();
Expand All @@ -401,7 +401,7 @@ public abstract static class SetIndexNode extends HashCoreMethodNode {
public SetIndexNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
eqlNode = DispatchHeadNodeFactory.createMethodCall(context, false, false, null);
equalNode = DispatchHeadNodeFactory.createMethodCall(context, false, false, null);
equalNode = BasicObjectNodesFactory.ReferenceEqualNodeFactory.create(context, sourceSection, null, null);
}

public SetIndexNode(SetIndexNode prev) {
Expand Down Expand Up @@ -430,7 +430,7 @@ public Object setPackedArray(VirtualFrame frame, RubyHash hash, Object key, Obje
final boolean equal;

if (byIdentityProfile.profile(hash.isCompareByIdentity())) {
equal = equalNode.callBoolean(frame, store[n * 2], "equal?", null, key);
equal = equalNode.executeReferenceEqual(frame, store[n * 2], key);
} else {
equal = eqlNode.callBoolean(frame, store[n * 2], "eql?", null, key);
}
Expand Down
Expand Up @@ -14,6 +14,8 @@
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.BasicObjectNodes;
import org.jruby.truffle.nodes.core.BasicObjectNodesFactory;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyHash;
Expand All @@ -25,15 +27,15 @@ public class FindEntryNode extends RubyNode {

@Child CallDispatchHeadNode hashNode;
@Child CallDispatchHeadNode eqlNode;
@Child CallDispatchHeadNode equalNode;
@Child BasicObjectNodes.ReferenceEqualNode equalNode;

private final ConditionProfile byIdentityProfile = ConditionProfile.createBinaryProfile();

public FindEntryNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
hashNode = DispatchHeadNodeFactory.createMethodCall(context, true);
eqlNode = DispatchHeadNodeFactory.createMethodCall(context, false, false, null);
equalNode = DispatchHeadNodeFactory.createMethodCall(context, false, false, null);
equalNode = BasicObjectNodesFactory.ReferenceEqualNodeFactory.create(context, sourceSection, null, null);
}

public HashSearchResult search(VirtualFrame frame, RubyHash hash, Object key) {
Expand All @@ -57,7 +59,7 @@ public HashSearchResult search(VirtualFrame frame, RubyHash hash, Object key) {

while (entry != null) {
if (byIdentityProfile.profile(hash.isCompareByIdentity())) {
if (equalNode.callBoolean(frame, key, "equal?", null, entry.getKey())) {
if (equalNode.executeReferenceEqual(frame, key, entry.getKey())) {
return new HashSearchResult(index, previousEntry, entry);
}
} else {
Expand Down
Expand Up @@ -201,7 +201,7 @@ public static void setAtBucket(RubyHash hash, HashSearchResult hashSearchResult,

@CompilerDirectives.TruffleBoundary
public static boolean verySlowSetInBuckets(RubyHash hash, Object key, Object value, boolean byIdentity) {
if (key instanceof RubyString) {
if (!byIdentity && key instanceof RubyString) {
key = DebugOperations.send(hash.getContext(), DebugOperations.send(hash.getContext(), key, "dup", null), "freeze", null);
}

Expand Down

0 comments on commit bd25c3c

Please sign in to comment.