Skip to content

Commit 78234f7

Browse files
author
Nicolas Laurent
committed
add fallback support for Array#[] with endless range and delete endless int range specialization
1 parent 03800da commit 78234f7

File tree

4 files changed

+8
-31
lines changed

4 files changed

+8
-31
lines changed

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,6 @@ protected DynamicObject slice(DynamicObject array, DynamicObject range, NotProvi
7777
}
7878
}
7979

80-
@Specialization(guards = "isIntEndlessRange(getContext(), range)")
81-
protected DynamicObject endlessSlice(DynamicObject array, DynamicObject range, NotProvided len,
82-
@Cached("createBinaryProfile()") ConditionProfile negativeBeginProfile,
83-
@Cached("create()") ArrayReadSliceNormalizedNode readNormalizedSliceNode) {
84-
final int size = getSize(array);
85-
final int normalizedBegin = ArrayOperations
86-
.normalizeIndex(size, (int) Layouts.OBJECT_RANGE.getBegin(range), negativeBeginProfile);
87-
88-
if (normalizedBegin < 0 || normalizedBegin > size) {
89-
return nil();
90-
} else {
91-
if (size == normalizedBegin) {
92-
return allocateObjectNode
93-
.allocate(Layouts.BASIC_OBJECT.getLogicalClass(array), ArrayStrategy.NULL_ARRAY_STORE, 0);
94-
}
95-
96-
return readNormalizedSliceNode.executeReadSlice(array, normalizedBegin, size - normalizedBegin);
97-
}
98-
}
99-
10080
@Specialization(guards = "isFallback(index, maybeLength)")
10181
protected Object fallbackIndex(DynamicObject array, Object index, Object maybeLength) {
10282
return fallback(array, index, maybeLength);

src/main/java/org/truffleruby/language/RubyGuards.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,6 @@ public static boolean isEndlessRange(RubyContext context, DynamicObject object)
132132
return isNil(context, Layouts.OBJECT_RANGE.getEnd(object));
133133
}
134134

135-
public static boolean isIntEndlessRange(RubyContext context, DynamicObject object) {
136-
return isObjectRange(object) && isInteger(Layouts.OBJECT_RANGE.getBegin(object)) && isEndlessRange(
137-
context,
138-
object);
139-
}
140-
141135
public static boolean isRubyRange(Object value) {
142136
return isIntRange(value) || isLongRange(value) || isObjectRange(value);
143137
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,19 @@ def ==(other)
153153
unless arg.begin.respond_to?(:to_int)
154154
raise TypeError, "no implicit conversion of #{arg.begin.class} into Integer"
155155
end
156-
unless arg.end.respond_to?(:to_int)
156+
unless arg.end == nil || arg.end.respond_to?(:to_int)
157157
raise TypeError, "no implicit conversion of #{arg.end.class} into Integer"
158158
end
159159
start_index = arg.begin.to_int
160-
end_index = arg.end.to_int
161160
Truffle::Type.check_long(start_index)
162-
Truffle::Type.check_long(end_index)
163161
start_index = Truffle::Type.clamp_to_int(start_index)
164-
end_index = Truffle::Type.clamp_to_int(end_index)
162+
if arg.end == nil
163+
end_index = arg.exclude_end? ? size : size - 1
164+
else
165+
end_index = arg.end.to_int
166+
Truffle::Type.check_long(end_index)
167+
end_index = Truffle::Type.clamp_to_int(end_index)
168+
end
165169
range = Range.new(start_index, end_index, arg.exclude_end?)
166170
TrufflePrimitive.array_aref(self, range, undefined)
167171
else

test/mri/excludes/TestArray.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
exclude :test_union, "needs investigation"
2525
exclude :test_uniq_bang_with_freeze, "needs investigation"
2626
exclude :test_zip, "needs investigation"
27-
exclude :test_0_literal, "needs investigation"
2827
exclude :test_AREF, "needs investigation"
2928
exclude :test_combination_with_callcc, "needs investigation"
3029
exclude :test_fill_0, "needs investigation"

0 commit comments

Comments
 (0)