mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Mark pattern labels as unremoveable
Peephole optimization doesn't play well with find pattern at least. The only case when a pattern matching could have unreachable patterns is when we have lasgn/dasgn node, which shouldn't happen in real-life. Fixes https://bugs.ruby-lang.org/issues/17534
This commit is contained in:
parent
9d1475c621
commit
1b89b99941
2 changed files with 11 additions and 1 deletions
|
@ -6408,11 +6408,11 @@ compile_case3(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const orig_no
|
||||||
int pat_line = nd_line(pattern);
|
int pat_line = nd_line(pattern);
|
||||||
LABEL *next_pat = NEW_LABEL(pat_line);
|
LABEL *next_pat = NEW_LABEL(pat_line);
|
||||||
ADD_INSN (cond_seq, pat_line, dup);
|
ADD_INSN (cond_seq, pat_line, dup);
|
||||||
|
|
||||||
// NOTE: set deconstructed_pos to the current cached value location
|
// NOTE: set deconstructed_pos to the current cached value location
|
||||||
// (it's "under" the matchee value, so it's position is 2)
|
// (it's "under" the matchee value, so it's position is 2)
|
||||||
CHECK(iseq_compile_pattern_each(iseq, cond_seq, pattern, l1, next_pat, FALSE, 2));
|
CHECK(iseq_compile_pattern_each(iseq, cond_seq, pattern, l1, next_pat, FALSE, 2));
|
||||||
ADD_LABEL(cond_seq, next_pat);
|
ADD_LABEL(cond_seq, next_pat);
|
||||||
|
LABEL_UNREMOVABLE(next_pat);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
COMPILE_ERROR(ERROR_ARGS "unexpected node");
|
COMPILE_ERROR(ERROR_ARGS "unexpected node");
|
||||||
|
|
|
@ -791,6 +791,16 @@ END
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# https://bugs.ruby-lang.org/issues/17534
|
||||||
|
assert_block do
|
||||||
|
case [0, 1, 2]
|
||||||
|
in x
|
||||||
|
true
|
||||||
|
in [*, 2, *]
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_hash_pattern
|
def test_hash_pattern
|
||||||
|
|
Loading…
Reference in a new issue