Skip to content

JIT: Override of Array#find is incorrect and was disabled #1011

Description

@eregon

In ruby#17715 we found that the current override of Array#find:

ruby/array.rb

Lines 291 to 304 in f66235e

def find(if_none_proc = nil) # :nodoc:
Primitive.attr! :inline_block, :c_trace, :without_interrupts
unless defined?(yield)
return Primitive.cexpr! 'SIZED_ENUMERATOR(self, 0, 0, ary_enum_length)'
end
i = 0
until Primitive.rb_jit_ary_at_end(i)
value = Primitive.rb_jit_ary_at(i)
return value if yield(value)
i = Primitive.rb_jit_fixnum_inc(i)
end
if_none_proc&.call
end

is incorrect and fails 3 specs, see ruby#17715 (comment)

To avoid blocking the specs update I have disabled that override, which also fixes compatibility but might reduce performance.

I took a quick look but it seems non-trivial to fix because we'd need to pass the if_none_proc argument to SIZED_ENUMERATOR as a 1-element C array or so.
See

ruby/array.c

Line 2098 in f66235e

RETURN_ENUMERATOR(ary, argc, argv);
for what the original/C definition of Array#find does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions