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

@@ -20143,6 +20143,19 @@
2014320143 ltypes[k] = lt[j]
2014420144 set_var_type(lnames[k], lt[j])
2014520145 end
20146+ # When pass 0 saw an unresolved key expression (e.g. `parts[0]`
20147+ # where parts wasn't declared yet) and produced `int_str_hash`
20148+ # from `kt=int + vt=string`, but pass 1 with parts declared
20149+ # correctly resolves the key as string (str_str_hash) or
20150+ # symbol (sym_str_hash), promote the local to the better
20151+ # variant. Symmetric to the str_int_hash → str_str_hash rule
20152+ # above; without it the hash stays pinned at int_str_hash and
20153+ # the call site emits `sp_IntStrHash_set(h, const char *, ...)`
20154+ # with a -Wint-conversion error.
20155+ 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")
20156+ ltypes[k] = lt[j]
20157+ set_var_type(lnames[k], lt[j])
20158+ end
2014620159 if is_tuple_type(lt[j]) == 1 && is_tuple_type(ltypes[k]) == 0
2014720160 ltypes[k] = lt[j]
2014820161 set_var_type(lnames[k], lt[j])
@@ -20422,6 +20435,15 @@
2042220435 ltypes2[j] == "poly_array")
2042320436 ltypes[k] = ltypes2[j]
2042420437 set_var_type(lnames[k], ltypes2[j])
20438+ # Pass 1 picked int_str_hash from an unresolved key
20439+ # expression (`kt=int + vt=string` via the analyzer
20440+ # fallback for an undeclared local). Pass 2 with the key
20441+ # resolved as string (or symbol) corrects to str_str_hash /
20442+ # sym_str_hash. Mirrors the str_int_hash → str_str_hash
20443+ # widening rule in refine_locals_multi_pass_full.
20444+ 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")
20445+ ltypes[k] = ltypes2[j]
20446+ set_var_type(lnames[k], ltypes2[j])
2042520447 end
2042620448 end
2042720449 k = k + 1