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
if rname == "Hash" return "str_int_hash" end if rname == "String" # `String.new` produces sp_String *, the same type infer_type # reports for the same call. Without this match, scan_ivars # registers the slot as obj_String first, then the later # writer-scan pass observes mutable_str via infer_type and # update_ivar_type widens the disagreement to poly even # though every write has the same shape. Issue #629. return "mutable_str" end if rname == "StringIO" return "stringio" end if rname == "Fiber" return "fiber" end if rname == "Proc" # Same shape as the String arm: infer_type returns "proc" for # `Proc.new {...}`; mirroring it here keeps scan_ivars and the # later writer-scan in agreement so the slot stays narrow. return "proc" end # Modules can't be instantiated; `module M; def self.new ...` # is a user-defined class method. Don't lift to obj_<mod>; # the class-method-dispatch inference picks up the declaredtest/ivar_same_shape_string_new_no_widen.expectedaddedView file
Loading diff…
test/ivar_same_shape_string_new_no_widen.rbaddedView file
Loading diff…