Commit 89ce0252

89ce0252067dMerged

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

Description

fix(analyze): infer_ivar_init_type returns mutable_str / proc for String.new / Proc.new

scan_ivars used infer_ivar_init_type for its first-pass type, which returned obj_String for String.new. The later writer-scan pass uses infer_type, which returns mutable_str for the same call. Both inferences agreed on what runtime value the call produces, but disagreed on which type tag to attach, and update_ivar_type took the disagreement as a real heterogeneous-write conflict and widened the slot to poly. Same shape for Proc.new (obj_Proc vs proc).

Mirror infer_type's existing String / Proc arms in infer_ivar_init_type so both passes name the same type and no widening fires. Closes the sp_RbVal cascade noted in the roundhouse ActionController traces, which were forced to add .to_s workarounds at every read site.

Fixes #629.

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

Details

Commit
89ce0252067d
Parent
4d162a3df945

spinel_analyze.rbmodifiedView file

@@ -9872,12 +9872,27 @@
98729872 if rname == "Hash"
98739873 return "str_int_hash"
98749874 end
9875+ if rname == "String"
9876+ # `String.new` produces sp_String *, the same type infer_type
9877+ # reports for the same call. Without this match, scan_ivars
9878+ # registers the slot as obj_String first, then the later
9879+ # writer-scan pass observes mutable_str via infer_type and
9880+ # update_ivar_type widens the disagreement to poly even
9881+ # though every write has the same shape. Issue #629.
9882+ return "mutable_str"
9883+ end
98759884 if rname == "StringIO"
98769885 return "stringio"
98779886 end
98789887 if rname == "Fiber"
98799888 return "fiber"
98809889 end
9890+ if rname == "Proc"
9891+ # Same shape as the String arm: infer_type returns "proc" for
9892+ # `Proc.new {...}`; mirroring it here keeps scan_ivars and the
9893+ # later writer-scan in agreement so the slot stays narrow.
9894+ return "proc"
9895+ end
98819896 # Modules can't be instantiated; `module M; def self.new ...`
98829897 # is a user-defined class method. Don't lift to obj_<mod>;
98839898 # the class-method-dispatch inference picks up the declared