Commit 78b2bcf4

78b2bcf41002Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(analyze): mark_hash_needs on every infer_hash_val_type result (#415)

{ sym_key: <ivar-or-param> } hash literals whose values were not string literals (an ivar read, a param, a method call) emitted a function signature that referenced sp_SymStrHash * but didn't emit the matching typedef + helpers in the same translation unit:

error: unknown type name 'sp_SymStrHash'; did you mean 'sp_StrStrHash'? static inline sp_SymStrHash * sp_Foo_attributes(sp_Foo *self);

The string-literal case ({ title: "hello" }) happened to work because the literal-collecting path flagged the variant via compose_hash_type. The ivar/param/method-call case took a different path through infer_hash_val_type, which returned the variant string but never flagged its template-instantiation need. @needs_sym_str_hash stayed at 0, emit_hash_runtime skipped the typedef, and the cc step failed.

Fix: split infer_hash_val_type into a thin wrapper + infer_hash_val_type_raw impl, route every wrapper return through the existing mark_hash_needs helper. Catches every hash variant the inference produces — sym_str_hash, sym_int_hash, str_str_hash, int_str_hash, sym_poly_hash, str_poly_hash, poly_poly_hash — and matches the flagging the literal path already does.

Closes #415

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
78b2bcf41002
Parent
fe8cf4d54652

spinel_analyze.rbmodifiedView file

@@ -2405,6 +2405,18 @@
24052405 end
24062406
24072407 def infer_hash_val_type(nid)
2408+ rt = infer_hash_val_type_raw(nid)
2409+ # Issue #415: every observed hash variant must flag its template
2410+ # need so emit_hash_runtime instantiates the typedef + helpers.
2411+ # Without this the `{ sym: @ivar }` shape — where the value's
2412+ # concrete type is only resolved on a later inference iteration
2413+ # via the value cache — emits `sp_SymStrHash *` references with
2414+ # no matching typedef in the translation unit.
2415+ mark_hash_needs(rt)
2416+ rt
2417+ end
2418+
2419+ def infer_hash_val_type_raw(nid)
24082420 elems = parse_id_list(@nd_elements[nid])
24092421 if elems.length > 0
24102422 eid = elems[0]