Commit 1ad97ddd
1ad97ddd695aMerged
Ori Pekelman <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
analyze: don't let a guessed (int-receiver) dispatch collapse a concrete setter param to poly
The forward-ref dispatch widening in scan_new_calls fires when a call's receiver
is still statically int (an as-yet-unresolved ivar/local read) and mname
belongs to user classes: it walks every user class defining mname at the call's
arity and unifies that class's param types with the call-site args, so the
int->class fallback dispatch's C signatures match.
For setters this over-widens. Every x= writer has arity 1, so the arity filter
is no filter: a single recv.body = <poly> call site whose recv hasn't resolved
yet (e.g. res.body = controller.body, res a dispatch param typed later in the
fixpoint) unifies body='s param across every class defining body= --
including unrelated ones that only ever store a String. unify_call_types collapses
String + the poly arg to poly, and the setter body @x = value then carries the
poly into the ivar. The contamination is sticky (poly never narrows back).
Fix: in this branch only -- where the receiver class is a GUESS, not resolved --
lift an int-default param as before, but don't apply a unification that would
collapse an already-concrete param to poly. The real receiver's obj-/poly-
receiver branches (which DO know the class, or narrow via observed_class_ids_for_recv)
still unify precisely once the type resolves.
Repro (roundhouse Rails blog, spinel-dev#8): ArticleRow#body/CommentRow#body
(only ever assigned (row["body"]).to_s) inferred untyped; title/created_at
(same shape, but no same-named poly setter elsewhere) stayed String. After the
fix both recover to String, while genuinely-poly slots are preserved:
Article#body (reads row["body"] raw, a str_poly_hash untyped read) and
Tep::Response#body (a real poly slot) correctly stay untyped.
Self-host bootstrap converges; full suite 831 pass / 0 fail (+ 13 RBS extractor).
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 1ad97ddd695a
- Parent
- 1e7d63da5252
spinel_analyze.rbmodifiedView file
while kk_fwd_c < arg_count_fwd at_fwd_c = infer_type(arg_ids_fwd[kk_fwd_c]) if kk_fwd_c < ptypes_fwd_c.length ptypes_fwd_c[kk_fwd_c] = unify_call_types(ptypes_fwd_c[kk_fwd_c], at_fwd_c, arg_ids_fwd[kk_fwd_c]) prev_fwd_c = ptypes_fwd_c[kk_fwd_c] unified_fwd_c = unify_call_types(prev_fwd_c, at_fwd_c, arg_ids_fwd[kk_fwd_c]) # The receiver type is unresolved ("int"), so this dispatch # target is a GUESS -- every user class defining mname at this # arity is walked, not just the real receiver's class. Lifting an # int-default param to a concrete type is the intended # fallback-signature fix; but letting a guessed target COLLAPSE an # already-concrete param to "poly" contaminates unrelated # same-named setters program-wide (a String-only `Row#body=` # widened to poly because an unrelated `Response#body=` site passes # a poly value through the same as-yet-int-typed local). The real # target's obj-/poly-receiver branches above still unify precisely # once the receiver type resolves. spinel-dev#8. if prev_fwd_c == "int" || unified_fwd_c != "poly" ptypes_fwd_c[kk_fwd_c] = unified_fwd_c end end kk_fwd_c = kk_fwd_c + 1 end