Commit c915ee1a
c915ee1ac501Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · ~3 modified
Description
fix(analyze): int_str_hash → str_str_hash merge in refine passes (#437)
Follow-up to b3a6838. When pass 0 of refine_locals_multi_pass_full
(and refine_method_body_locals) saw h[parts[0]] = "v" with parts
undeclared, kt fell back to int and promote_empty_hash_for returned
"int_str_hash" — legitimate when the user really intends int keys
with string values, but for the unresolved-key case it pins the
local incorrectly. Pass 1 with parts declared correctly produced
str_str_hash, but the merge rule only handled
str_int_hash → str_str_hash and dropped the upgrade.
Add merge rules: int_str_hash widens to str_str_hash / sym_str_hash
/ str_int_hash / sym_int_hash when the later pass observes a
matching shape. The literal-int-keyed case (h[200] = "OK") stays
on int_str_hash because both passes agree on the int key.
Closes the remaining def self.build(s) / def build(s) shape
from #437 that b3a6838 left open.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- c915ee1ac501
- Parent
- 1814b4f17933
spinel_analyze.rbmodifiedView file
ltypes[k] = lt[j] set_var_type(lnames[k], lt[j]) end # When pass 0 saw an unresolved key expression (e.g. `parts[0]` # where parts wasn't declared yet) and produced `int_str_hash` # from `kt=int + vt=string`, but pass 1 with parts declared # correctly resolves the key as string (str_str_hash) or # symbol (sym_str_hash), promote the local to the better # variant. Symmetric to the str_int_hash → str_str_hash rule # above; without it the hash stays pinned at int_str_hash and # the call site emits `sp_IntStrHash_set(h, const char *, ...)` # with a -Wint-conversion error. if ltypes[k] == "int_str_hash" && (lt[j] == "str_str_hash" || lt[j] == "sym_str_hash" || lt[j] == "str_int_hash" || lt[j] == "sym_int_hash") ltypes[k] = lt[j] set_var_type(lnames[k], lt[j]) end if is_tuple_type(lt[j]) == 1 && is_tuple_type(ltypes[k]) == 0 ltypes[k] = lt[j] set_var_type(lnames[k], lt[j]) ltypes2[j] == "poly_array") ltypes[k] = ltypes2[j] set_var_type(lnames[k], ltypes2[j]) # Pass 1 picked int_str_hash from an unresolved key # expression (`kt=int + vt=string` via the analyzer # fallback for an undeclared local). Pass 2 with the key # resolved as string (or symbol) corrects to str_str_hash / # sym_str_hash. Mirrors the str_int_hash → str_str_hash # widening rule in refine_locals_multi_pass_full. elsif ltypes[k] == "int_str_hash" && (ltypes2[j] == "str_str_hash" || ltypes2[j] == "sym_str_hash" || ltypes2[j] == "str_int_hash" || ltypes2[j] == "sym_int_hash") ltypes[k] = ltypes2[j] set_var_type(lnames[k], ltypes2[j]) end end k = k + 1test/empty_hash_int_int_no_widen.rbmodifiedView file
Loading diff…
test/empty_hash_int_int_no_widen.rb.expectedmodifiedView file
Loading diff…