Commit 8b774e72

8b774e72730aMerged

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

Description

fix(codegen,analyze): cross-key-shape hash merge promotes to str_poly_hash

{:a => 1}.merge({"b" => 2}) — sym keys merged with str keys — previously dispatched through sp_SymIntHash_merge(SymInt, StrInt) or sp_SymStrHash_merge(SymStr, StrInt). The callee expected its own variant for both args; clang errored on the cross-type pass.

  • analyze: infer_call_type's merge arm returns str_poly_hash when the recv is sym-keyed and the arg is str-keyed (or vice versa). The arg's key shape decides the result variant; str_poly_hash is the canonical wide form since sym keys round-trip through sp_sym_to_s.
  • codegen: sym_int_hash / sym_str_hash merge dispatch arms route cross-key-shape sites through sp_StrPolyHash_merge, calling hash_variant_convert on both sides. Gated on the arg actually being str-keyed so same-variant merges stay on the direct sp__merge path.
  • codegen (compile_typed_call_args + compile_call_args_coerced_ for_cmeth): hash variant mismatch at call boundary also routes through compile_expr_for_expected_type's new hash-variant arm.

Clears 2 of the 6 remaining warnings in #685's roundhouse emit (11 -> 6 after this and the prior Phase 1c). One residual cross- variant call-site warning at button_to/render_attrs comes from an outer cast-away-volatile-arg wrapping the converter result; its emit path needs to skip the cast when the inner expression is already coerced. Left for follow-up.

Tests: default 460/0/0, promote 460/0/0, optcarrot checksum 59662.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
8b774e72730a
Parent
ee61faad91f1

spinel_analyze.rbmodifiedView file

@@ -4942,6 +4942,13 @@
49424942 @needs_rb_value = 1
49434943 return "sym_poly_hash"
49444944 end
4945+ # Cross-key-shape: sym recv + str arg -> result has mixed
4946+ # keys. Promote to str_poly_hash; codegen-side merge dispatch
4947+ # routes both sides through StrPolyHash converters.
4948+ if arg_t_mg == "str_int_hash" || arg_t_mg == "str_str_hash" || arg_t_mg == "str_poly_hash"
4949+ @needs_rb_value = 1
4950+ return "str_poly_hash"
4951+ end
49454952 end
49464953 end
49474954 end