Skip to content
Permalink
Browse files
[Truffle] Make the packed array guard for hash, which is complicated …
…by covariance, just the negation of the other two.
  • Loading branch information
chrisseaton committed Dec 16, 2014
1 parent 639ecf6 commit 2bb0e1536e8fa5318e20fd8d1422f18f2e40a7af
Showing with 12 additions and 17 deletions.
  1. +0 −5 core/src/main/java/org/jruby/truffle/nodes/core/HashGuards.java
  2. +12 −12 core/src/main/java/org/jruby/truffle/nodes/core/HashNodes.java
@@ -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[];
}
@@ -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();
@@ -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);

@@ -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);

@@ -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();

@@ -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();

@@ -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();

@@ -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();

@@ -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();
@@ -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);
@@ -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?

@@ -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();

@@ -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();

0 comments on commit 2bb0e15

Please sign in to comment.