Commit 83e4c0d0
83e4c0d075d1Merged
Sam Ruby <[email protected]> · 6 months ago · 3 files · +1 added · ~2 modified
Description
fix(analyze,codegen): emit Hash arms in poly-recv .fetch
#470. Polymorphic .fetch dispatch on an sp_RbVal receiver
enumerated only user-class arms (def fetch) and missed every
built-in Hash variant (StrIntHash / StrStrHash / StrPolyHash).
At runtime a Hash receiver matched no arm and the result temp
stayed at its nil default — silent miscompile, not a C compile
failure.
Surfaced after #463 boxed lv_raw_sub to sp_RbVal in real-blog:
the downstream sub.fetch "title", "" site's emitted dispatch
contained only ActionDispatch::Flash#fetch /
ActionDispatch::Session#fetch arms (both sym-keyed), so the
cls_id never matched the actual StrStrHash receiver and the
mismatched parameter types cascaded to 16 C compile errors.
Sibling to 4859894 (#456), which added Hash arms to poly-recv
[] / []= when the key is statically a String. Two parts:
-
analyze:
fetchon a poly recv now widens topoly, matching the[]poly-recv widening. Without this the result temp's static C type comes from the first user-classfetchreturn (e.g.const char *) and the int-valued Hash arm'ssp_box_int(...)rhs is a C type mismatch. -
codegen:
emit_poly_builtin_dispatchgains afetchblock parallel to the[]Str-Hash arms. Each arm tests_has_keyfirst, returns the boxed value on hit, or the boxed default on miss. Sym-keyed variants are deferred for the same@needs-gating reason as[].
Closes #470.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 83e4c0d075d1
- Parent
- 1c3e51e42296
spinel_analyze.rbmodifiedView file
if rt == "str_str_hash" || rt == "sym_str_hash" || rt == "int_str_hash" return "string" end # Poly recv: runtime can be any user class (with `def fetch`) # OR any built-in Hash variant. The codegen-side dispatch # (`compile_poly_method_call` + `emit_poly_builtin_dispatch`) # boxes each per-cls_id arm to sp_RbVal because the value # types diverge across arms. Surface that here so the caller's # slot widens accordingly — without this, `lookup` keeps a # `const char *` return slot and the boxed dispatch result is # a C type mismatch. Sibling to the `[]` poly-recv widening # at line 4520 above. if rt == "poly" @needs_rb_value = 1 return "poly" end end # Don't claim "int" for fetch on receivers we don't recognize # as a built-in collection — let later dispatch resolve aspinel_codegen.rbmodifiedView file
Loading diff…
test/poly_recv_fetch_hash_arms.rbaddedView file
Loading diff…