Actions
Bug #17534
closedPattern-matching is broken with find pattern
Bug #17534:
Pattern-matching is broken with find pattern
Description
Actions
Added by zverok (Victor Shepelev) over 5 years ago. Updated over 5 years ago.
Description
zverok (Victor Shepelev) wrote:
The minimal reproduction code:
This outputs long "raw disasm" sequence, and then
That could be related to https://github.com/ruby/ruby/pull/3104.
I'll take a look.
palkan (Vladimir Dementyev) wrote in #note-1:
That could be related to https://github.com/ruby/ruby/pull/3104.
I'll take a look.
Hm, nope. Reproduced in the older revision (d6c9c014e2). Investigating further.
So, what I found: the bug is caused by iseq_peephole_optimize and find patterns iseq incompatibility; remove_unreachable_chunk doesn't remove while_begin, next_loop and other find_pattern specific labels, but removes general pattern matching instructions (including stack allocation for "local" variables). (Disabling remove_unreachable_chunk fixes this).
Possibly, that happens due to the labels cycle (while_begin -> next_loop -> while_begin); though I'm not really familiar with the peephole optimization. /cc @nobu (Nobuyoshi Nakada) @ko1 (Koichi Sasada)
As a quick fix I propose marking patterns as unremoveable: https://github.com/ruby/ruby/pull/4094
@palkan (Vladimir Dementyev):
Thanks to fix!
@naruse (Yui NARUSE):
Could you backport 1b89b99941548fdb65305dd9a412082e7fdba45a to 3.0?
ruby_3_0 2dc39e2fd45aacd5fcd33ed80f602bd6f2ddb504 merged revision(s) 1b89b99941548fdb65305dd9a412082e7fdba45a.