Commit 76e6991b
76e6991b0289Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 11 files · +8 added · ~3 modified
Description
fix: Hash#dup coverage + include-chain const lookup + array equality + regex flag-group parse
Four batched fixes addressing recent Sam Ruby / Adam Doppelt issues.
#592 -- Hash#dup was missing from the str_str_hash and int_str_hash
codegen dispatch arms even though the runtime helpers
(sp_StrStrHash_dup, sp_IntStrHash_dup) were defined. h = {"a" => "1"}; m = h.dup emitted cannot resolve call to 'dup' on str_str_hash (emitting 0) and subsequent .length / []= on the
int-typed 0 segfaulted. Adds the missing if mname == "dup" || mname == "clone" arms to each variant.
#591 -- Bare CONST from an instance method body attached to a class
via include M left the const-resolution chain at the host class
and missed M's namespace. Sibling to #573's method-attachment fix
(b034816 reconcile_class_includes): the methods were copied to
the host class but resolve_const_read_name's scope walk didn't
consult @cls_includes. Adds the include-chain fallback to both
the analyzer's and codegen's resolvers.
#600 puzzle 1 -- [0, 0, 0] != %i[a a a] returned false. sym_array
shares the sp_IntArray layout and sp_IntArray_eq compares raw
bytes; with SPS_a == 0, both arrays encoded to [0,0,0] and the
eq returned true. Fix: when the recv AND first arg are both
ArrayNode literals and the static types differ (int_array vs
sym_array), short-circuit to FALSE. The <<-widened
"int_array carrying syms at runtime" shape from issue #555
keeps both sides typed int_array (the analyzer leaves the
static type alone), so the guard doesn't engage and IntArray_eq
continues to drive the comparison.
#600 puzzle 3 -- /(?x:foo)/.to_s hung at runtime during the
static-regex compilation. re_compile.c's (? parser handled :,
=, !, <...>, <=, <! directives but fell through on
?<flag-char> (x / i / m / s / u / a). With no advance,
compile_seq's outer loop spun on the unconsumed ?. Fix: when
the (? lookahead matches a recognized inline-flag char,
consume to the trailing : (non-capturing body) or )
(whole-group flag application -- spinel doesn't honor scoped
flag SEMANTICS yet, just consumes the directive). Unrecognized
(?<X> raises unrecognized (? construct compile_error
instead of hanging. /x's whitespace-stripping is NOT applied
inside the sub-pattern (top-level strip only); patterns with
literal-character bodies (like the puzzle's (?x:foo)) match
unchanged. The puzzle's .to_s still returns "0" since spinel
doesn't implement Regexp#to_s, but it no longer hangs.
make test: 574/574 pass.
make optcarrot: checksum 59662.
Stage-2 bootstrap fixpoint clean.
Closes #592
Closes #591
Refs #600 (puzzles 1 + 3 fixed; puzzle 2 Hash.new(default_value)
requires runtime-side default tracking and stays open for a
future structural change.)
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 76e6991b0289
- Parent
- a34770e897b1
lib/regexp/re_compile.cmodifiedView file
cap_name_len = (uint16_t)(c->p - cap_name); next_char(c); /* skip > */ } else { /* Inline-flag group `(?xim-xim:...)` or whole-group flag `(?xim)`. Skip the flag chars (and optional `-flags`), then either `:` (non-capturing body) or `)` (apply to outer group). Spinel's compiler doesn't honour the flag SEMANTICS yet -- /x in particular would need to strip whitespace inside this sub-pattern only -- but the parse now consumes the directive so compile_seq advances. Without this, `(?x:foo)` left c->p stuck on `?` and compile_seq's outer loop spun forever. */ int c1 = c->p[1]; int recognized_flag = (c1 == 'x' || c1 == 'i' || c1 == 'm' || c1 == 's' || c1 == 'u' || c1 == 'a'); if (recognized_flag) { next_char(c); /* skip ? */ while (peek(c) != ':' && peek(c) != ')' && peek(c) >= 0) next_char(c); if (peek(c) == ':') { next_char(c); /* skip : */ capturing = FALSE; } else if (peek(c) == ')') { /* `(?xim)` with no body — apply to the enclosing group; spinel doesn't track per-scope flags, so just consume the close paren and emit nothing. The atom loop will see the next token. */ next_char(c); break; } } else { /* Unrecognized `(?<X>...` directive. Compile-error instead of looping: better surface than the prior infinite-loop wedge. */ compile_error(c, "unrecognized (? construct"); break; } } } uint16_t group = 0;spinel_analyze.rbmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…
test/array_eq_int_vs_sym_literal.rbaddedView file
Loading diff…
test/array_eq_int_vs_sym_literal.rb.expectedaddedView file
Loading diff…
test/hash_dup_str_int_str.rbaddedView file
Loading diff…
test/hash_dup_str_int_str.rb.expectedaddedView file
Loading diff…
test/include_chain_const_lookup.rbaddedView file
Loading diff…
test/include_chain_const_lookup.rb.expectedaddedView file
Loading diff…
test/regexp_inline_flag_group_no_hang.rbaddedView file
Loading diff…
test/regexp_inline_flag_group_no_hang.rb.expectedaddedView file
Loading diff…