Skip to content

Commit

Permalink
[Truffle] Make the packed array guard for hash, which is complicated …
Browse files Browse the repository at this point in the history
…by covariance, just the negation of the other two.
  • Loading branch information
chrisseaton committed Dec 16, 2014
1 parent 639ecf6 commit 2bb0e15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public static boolean isNull(RubyHash hash) {
return hash.getStore() == null;
}

public static boolean isPackedArray(RubyHash hash) {
// Arrays are covariant in Java!
return hash.getStore() instanceof Object[] && !(hash.getStore() instanceof Entry[]);
}

public static boolean isBuckets(RubyHash hash) {
return hash.getStore() instanceof Entry[];
}
Expand Down
24 changes: 12 additions & 12 deletions core/src/main/java/org/jruby/truffle/nodes/core/HashNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public Object getNull(VirtualFrame frame, RubyHash hash, Object key) {
}

@ExplodeLoop
@Specialization(guards = "isPackedArray")
@Specialization(guards = {"!isNull", "!isBuckets"})
public Object getPackedArray(VirtualFrame frame, RubyHash hash, Object key) {
final Object[] store = (Object[]) hash.getStore();
final int size = hash.getSize();
Expand Down Expand Up @@ -312,7 +312,7 @@ public Object setNull(RubyHash hash, Object key, Object value) {
}

@ExplodeLoop
@Specialization(guards = "isPackedArray")
@Specialization(guards = {"!isNull", "!isBuckets"})
public Object setPackedArray(VirtualFrame frame, RubyHash hash, Object key, Object value) {
hash.checkFrozen(this);

Expand Down Expand Up @@ -416,7 +416,7 @@ public RubyNilClass deleteNull(RubyHash hash, Object key) {
return getContext().getCoreLibrary().getNilObject();
}

@Specialization(guards = "isPackedArray")
@Specialization(guards = {"!isNull", "!isBuckets"})
public Object deletePackedArray(VirtualFrame frame, RubyHash hash, Object key) {
hash.checkFrozen(this);

Expand Down Expand Up @@ -500,7 +500,7 @@ public RubyHash eachNull(RubyHash hash, RubyProc block) {
}

@ExplodeLoop
@Specialization(guards = "isPackedArray")
@Specialization(guards = {"!isNull", "!isBuckets"})
public RubyHash eachPackedArray(VirtualFrame frame, RubyHash hash, RubyProc block) {
notDesignedForCompilation();

Expand Down Expand Up @@ -626,7 +626,7 @@ public RubyHash dupNull(RubyHash self, RubyHash from) {
return self;
}

@Specialization(guards = "isPackedArray(arguments[1])")
@Specialization(guards = {"!isNull(arguments[1])", "!isBuckets(arguments[1])"})
public RubyHash dupPackedArray(RubyHash self, RubyHash from) {
notDesignedForCompilation();

Expand Down Expand Up @@ -726,7 +726,7 @@ public boolean keyNull(RubyHash hash, Object key) {
return false;
}

@Specialization(guards = "isPackedArray")
@Specialization(guards = {"!isNull", "!isBuckets"})
public boolean keyPackedArray(VirtualFrame frame, RubyHash hash, Object key) {
notDesignedForCompilation();

Expand Down Expand Up @@ -773,7 +773,7 @@ public RubyArray keysNull(RubyHash hash) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), null, 0);
}

@Specialization(guards = "isPackedArray")
@Specialization(guards = {"!isNull", "!isBuckets"})
public RubyArray keysPackedArray(RubyHash hash) {
notDesignedForCompilation();

Expand Down Expand Up @@ -821,7 +821,7 @@ public MapNode(MapNode prev) {
}

@ExplodeLoop
@Specialization(guards = "isPackedArray")
@Specialization(guards = {"!isNull", "!isBuckets"})
public RubyArray mapPackedArray(VirtualFrame frame, RubyHash hash, RubyProc block) {
final Object[] store = (Object[]) hash.getStore();
final int size = hash.getSize();
Expand Down Expand Up @@ -890,7 +890,7 @@ public MergeNode(MergeNode prev) {
eqlNode = prev.eqlNode;
}

@Specialization(guards = {"isPackedArray", "isNull(arguments[1])"})
@Specialization(guards = {"!isNull", "!isBuckets", "isNull(arguments[1])"})
public RubyHash mergePackedArrayNull(RubyHash hash, RubyHash other) {
final Object[] store = (Object[]) hash.getStore();
final Object[] copy = Arrays.copyOf(store, HashOperations.SMALL_HASH_SIZE * 2);
Expand All @@ -899,7 +899,7 @@ public RubyHash mergePackedArrayNull(RubyHash hash, RubyHash other) {
}

@ExplodeLoop
@Specialization(guards = {"isPackedArray", "isPackedArray(arguments[1])"})
@Specialization(guards = {"!isNull", "!isBuckets", "!isNull(arguments[1])", "!isBuckets(arguments[1])"})
public RubyHash mergePackedArrayPackedArray(VirtualFrame frame, RubyHash hash, RubyHash other) {
// TODO(CS): what happens with the default block here? Which side does it get merged from?

Expand Down Expand Up @@ -1077,7 +1077,7 @@ public RubyArray valuesNull(RubyHash hash) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), null, 0);
}

@Specialization(guards = "isPackedArray")
@Specialization(guards = {"!isNull", "!isBuckets"})
public RubyArray valuesPackedArray(RubyHash hash) {
final Object[] store = (Object[]) hash.getStore();

Expand Down Expand Up @@ -1128,7 +1128,7 @@ public RubyArray toArrayNull(RubyHash hash) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), null, 0);
}

@Specialization(guards = "isPackedArray")
@Specialization(guards = {"!isNull", "!isBuckets"})
public RubyArray toArrayPackedArray(RubyHash hash) {
notDesignedForCompilation();

Expand Down

0 comments on commit 2bb0e15

Please sign in to comment.