Commit 33694cde
33694cdeee7dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
fix(analyze,codegen): cross-variant sym_str / sym_poly Hash#merge
Closes #515. Sibling to #510. Both cross-variant directions were broken:
-
sym_str_hash.merge(sym_poly_hash)routed to sp_SymStrHash_merge with a sp_SymPolyHash* argument -- C warned -Wincompatible-pointer-types and the helper read the poly hash's memory through SymStrHash field offsets, producing runtime garbage. -
sym_poly_hash.merge(sym_str_hash)had no codegen arm and warned "cannot resolve call to 'merge' on sym_poly_hash" before falling through to emit 0.
Two new helpers emitted alongside the existing sym_str_hash runtime helpers (codegen-emit_raw so they can refer to the codegen-generated sp_SymStrHash typedef):
-
sp_SymStrHash_to_sym_poly: promotes a sym_str_hash to a fresh sym_poly_hash by sp_box_str'ing every value.
-
sp_SymPolyHash_merge_str: copies the poly receiver's entries then folds in the str hash's entries with sp_box_str on the value side.
Dispatch updates:
- sym_str_hash.merge arm: when arg infers as sym_poly_hash, promote recv via sp_SymStrHash_to_sym_poly and merge.
- sym_poly_hash.merge arm: when arg infers as sym_str_hash, call sp_SymPolyHash_merge_str.
Analyze merge-return inference: returns sym_poly_hash when the recv is sym_str_hash and the arg is sym_poly_hash. The mirror direction already returned the (correct) sym_poly_hash via the existing "return infer_type(recv)" branch.
Local: 487 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 33694cdeee7d
- Parent
- b4125a5bffa4
spinel_analyze.rbmodifiedView file
end if mname == "merge" if recv >= 0 return infer_type(recv) rt_merge = infer_type(recv) # Cross-variant promote: sym_str_hash.merge(sym_poly_hash) # returns a fresh sym_poly_hash with the receiver's str # values boxed. Mirror direction (poly recv, str arg) # returns the receiver's type. Issue #515. if rt_merge == "sym_str_hash" args_id_mg = @nd_arguments[nid] if args_id_mg >= 0 arg_ids_mg = get_args(args_id_mg) if arg_ids_mg.length >= 1 && infer_type(arg_ids_mg[0]) == "sym_poly_hash" @needs_rb_value = 1 return "sym_poly_hash" end end end return rt_merge end return "str_int_hash" endspinel_codegen.rbmodifiedView file
Loading diff…
test/sym_hash_cross_variant_merge.rbaddedView file
Loading diff…
test/sym_hash_cross_variant_merge.rb.expectedaddedView file
Loading diff…