ruby icon indicating copy to clipboard operation
ruby copied to clipboard

Rewrite Numeric#times in Ruby using Primitive

Open nobu opened this issue 1 year ago • 5 comments

nobu avatar Jan 17 '24 08:01 nobu

Can you clarify the motivation? I don't think Matz asked for it https://bugs.ruby-lang.org/issues/20182#note-5:

If the user intentionally redefines the fundamental method, it should be his/her own responsibility.

Integer#< and Integer#succ are two things that are already optimized well on the interpreter and YJIT, and replacing them with a random cexpr! would only complicate YJIT so much to maintain the current performance. The redefinition concern seems much less meaningful than Array#each's race condition one, unless it's something like Integer#/.

I'm fine with replacing block_yield? with defined?(yield) since it's not Primitive though.

k0kubun avatar Jan 18 '24 19:01 k0kubun

This was just an experiment, but I found that builtin-indexes were not working with while. #9533 worked because it moved i.succ into ary_fetch_next by chance. In that sense, this might be better to focus that bug and be earlier 2 commits only.

nobu avatar Jan 18 '24 21:01 nobu

This was just an experiment, but I found that builtin-indexes were not working with while. In that sense, this might be better to focus that bug and be earlier 2 commits only.

It'd be nice to have those builtin index fixes :+1:

k0kubun avatar Jan 18 '24 21:01 k0kubun

It'd be nice to have those builtin index fixes 👍

Are you OK with the restriction, cexpr! must be up to one per line?

nobu avatar Jan 19 '24 05:01 nobu

Yeah, I'm fine with it as long as it gives an error on conflict. RJIT is an exception, but it'd usually mean that you should merge such primitives.

k0kubun avatar Jan 19 '24 07:01 k0kubun