Skip to content

Commit b1226d5

Browse files
committed
Rename Primitive.object_can_contain_object to Primitive.array_can_contain_object?
1 parent 319368f commit b1226d5

File tree

4 files changed

+41
-44
lines changed

4 files changed

+41
-44
lines changed

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,14 +2380,14 @@ private Entry(RubyArray array, int index) {
23802380
@Specialization(guards = "!canContainObject.execute(array)", limit = "1")
23812381
protected boolean flattenHelperPrimitive(RubyArray array, RubyArray out, int maxLevels,
23822382
@Cached @Exclusive ArrayAppendManyNode concat,
2383-
@Cached @Exclusive TypeNodes.CanContainObjectNode canContainObject) {
2383+
@Cached @Exclusive ArrayCanContainObjectNode canContainObject) {
23842384
concat.executeAppendMany(out, array);
23852385
return false;
23862386
}
23872387

23882388
@Specialization(replaces = "flattenHelperPrimitive")
23892389
protected boolean flattenHelper(RubyArray array, RubyArray out, int maxLevels,
2390-
@Cached @Exclusive TypeNodes.CanContainObjectNode canContainObject,
2390+
@Cached @Exclusive ArrayCanContainObjectNode canContainObject,
23912391
@Cached @Exclusive ArrayAppendManyNode concat,
23922392
@Cached AtNode at,
23932393
@Cached DispatchNode convert,
@@ -2457,4 +2457,40 @@ private static void add(EconomicSet<RubyArray> set, RubyArray array) {
24572457
set.add(array);
24582458
}
24592459
}
2460+
2461+
@Primitive(name = "array_can_contain_object?")
2462+
@ImportStatic(ArrayGuards.class)
2463+
public abstract static class ArrayCanContainObjectNode extends PrimitiveArrayArgumentsNode {
2464+
2465+
@NeverDefault
2466+
public static ArrayCanContainObjectNode create() {
2467+
return ArrayNodesFactory.ArrayCanContainObjectNodeFactory.create(null);
2468+
}
2469+
2470+
public abstract boolean execute(RubyArray array);
2471+
2472+
@Specialization(
2473+
guards = {
2474+
"stores.accepts(array.getStore())",
2475+
"stores.isPrimitive(array.getStore())" })
2476+
protected boolean primitiveArray(RubyArray array,
2477+
@CachedLibrary(limit = "storageStrategyLimit()") ArrayStoreLibrary stores) {
2478+
return false;
2479+
}
2480+
2481+
@Specialization(
2482+
guards = {
2483+
"stores.accepts(array.getStore())",
2484+
"!stores.isPrimitive(array.getStore())" })
2485+
protected boolean objectArray(RubyArray array,
2486+
@CachedLibrary(limit = "storageStrategyLimit()") ArrayStoreLibrary stores) {
2487+
return true;
2488+
}
2489+
2490+
@Specialization(guards = "!isRubyArray(array)")
2491+
protected boolean other(Object array) {
2492+
return true;
2493+
}
2494+
2495+
}
24602496
}

src/main/java/org/truffleruby/core/support/TypeNodes.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
import org.truffleruby.annotations.CoreModule;
2121
import org.truffleruby.annotations.Primitive;
2222
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
23-
import org.truffleruby.core.array.ArrayGuards;
2423
import org.truffleruby.core.array.RubyArray;
25-
import org.truffleruby.core.array.library.ArrayStoreLibrary;
2624
import org.truffleruby.core.basicobject.BasicObjectNodes.ReferenceEqualNode;
2725
import org.truffleruby.core.cast.BooleanCastNode;
2826
import org.truffleruby.core.cast.ToIntNode;
@@ -54,7 +52,6 @@
5452
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5553
import com.oracle.truffle.api.dsl.Cached;
5654
import com.oracle.truffle.api.dsl.Fallback;
57-
import com.oracle.truffle.api.dsl.ImportStatic;
5855
import com.oracle.truffle.api.dsl.NodeChild;
5956
import com.oracle.truffle.api.dsl.Specialization;
6057
import com.oracle.truffle.api.library.CachedLibrary;
@@ -359,42 +356,6 @@ protected Object objectHiddenVarSet(RubyDynamicObject object, Object identifier,
359356
}
360357
}
361358

362-
@Primitive(name = "object_can_contain_object")
363-
@ImportStatic(ArrayGuards.class)
364-
public abstract static class CanContainObjectNode extends PrimitiveArrayArgumentsNode {
365-
366-
@NeverDefault
367-
public static CanContainObjectNode create() {
368-
return TypeNodesFactory.CanContainObjectNodeFactory.create(null);
369-
}
370-
371-
public abstract boolean execute(RubyArray array);
372-
373-
@Specialization(
374-
guards = {
375-
"stores.accepts(array.getStore())",
376-
"stores.isPrimitive(array.getStore())" })
377-
protected boolean primitiveArray(RubyArray array,
378-
@CachedLibrary(limit = "storageStrategyLimit()") ArrayStoreLibrary stores) {
379-
return false;
380-
}
381-
382-
@Specialization(
383-
guards = {
384-
"stores.accepts(array.getStore())",
385-
"!stores.isPrimitive(array.getStore())" })
386-
protected boolean objectArray(RubyArray array,
387-
@CachedLibrary(limit = "storageStrategyLimit()") ArrayStoreLibrary stores) {
388-
return true;
389-
}
390-
391-
@Specialization(guards = "!isRubyArray(array)")
392-
protected boolean other(Object array) {
393-
return true;
394-
}
395-
396-
}
397-
398359
@Primitive(name = "rb_any_to_s")
399360
public abstract static class ObjectToSNode extends PrimitiveArrayArgumentsNode {
400361
@Specialization

src/main/ruby/truffleruby/core/array.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def flatten!(level = -1)
518518
end
519519

520520
def hash
521-
unless Primitive.object_can_contain_object(self)
521+
unless Primitive.array_can_contain_object?(self)
522522
# Primitive arrays do not need the recursion check
523523
return hash_internal
524524
end

src/main/ruby/truffleruby/core/truffle/thread_operations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module Truffle::ThreadOperations
6767
# If there is one, it returns true.
6868
# Otherwise, it will yield once and return false.
6969
def self.detect_recursion(obj, &block)
70-
unless Primitive.object_can_contain_object obj
70+
unless Primitive.array_can_contain_object? obj
7171
yield
7272
return false
7373
end
@@ -81,7 +81,7 @@ def self.detect_recursion(obj, &block)
8181
# If there is one, it returns true.
8282
# Otherwise, it will yield once and return false.
8383
def self.detect_pair_recursion(obj, paired_obj)
84-
unless Primitive.object_can_contain_object obj
84+
unless Primitive.array_can_contain_object? obj
8585
yield
8686
return false
8787
end

0 commit comments

Comments
 (0)