Commit e6c85b7f

e6c85b7fbbeeMerged

ydah <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(analyze): preserve nil state for scalar ivars

Details

Commit
e6c85b7fbbee
Parent
1c819212d772

spinel_analyze.rbmodifiedView file

@@ -7612,7 +7612,18 @@
76127612 # `@m = method(:foo)` initially scans as int and a
76137613 # refinement promotes it to `obj_Method` — no heterogeneity
76147614 # to widen for).
7615- if (old == "int" || old == "nil") && is_obj_type(new_type) == 1 && cls_ivar_definite_flag(ci, iname) == 1
7615+ nil_scalar_mix = 0
7616+ if old == "nil" && (new_type == "int" || new_type == "float" || new_type == "bool" || new_type == "symbol")
7617+ nil_scalar_mix = 1
7618+ elsif new_type == "nil" && (old == "int" || old == "float" || old == "bool" || old == "symbol")
7619+ nil_scalar_mix = 1
7620+ end
7621+ if nil_scalar_mix == 1
7622+ types[k] = "poly"
7623+ @needs_rb_value = 1
7624+ @cls_ivar_types[ci] = types.join(";")
7625+ @cls_ivar_types_version = @cls_ivar_types_version + 1
7626+ elsif (old == "int" || old == "nil") && is_obj_type(new_type) == 1 && cls_ivar_definite_flag(ci, iname) == 1
76167627 types[k] = "poly"
76177628 @needs_rb_value = 1
76187629 @cls_ivar_types[ci] = types.join(";")
@@ -7904,7 +7915,7 @@
79047915 if new_def == 1 && cur_def == 1 && cur != vtype && cur != "poly"
79057916 replace_ivar_type(ci, iname, "poly")
79067917 @needs_rb_value = 1
7907- elsif vtype != "int"
7918+ elsif vtype != "int" || cur == "nil"
79087919 update_ivar_type(ci, iname, vtype)
79097920 end
79107921 end
@@ -10829,7 +10840,12 @@
1082910840 if ij < ivar_types.length
1083010841 if ivar_names[ij] == iname
1083110842 if ptypes[pi] != ""
10832- ivar_types[ij] = unify_call_types(ivar_types[ij], ptypes[pi], -1)
10843+ if ivar_types[ij] == "nil" && (ptypes[pi] == "int" || ptypes[pi] == "float" || ptypes[pi] == "bool" || ptypes[pi] == "symbol")
10844+ ivar_types[ij] = "poly"
10845+ @needs_rb_value = 1
10846+ else
10847+ ivar_types[ij] = unify_call_types(ivar_types[ij], ptypes[pi], -1)
10848+ end
1083310849 end
1083410850 end
1083510851 end
@@ -13435,7 +13451,7 @@
1343513451 update_ivar_type(@current_class_idx, chain_inames[ci_idx], at)
1343613452 ci_idx = ci_idx + 1
1343713453 end
13438- elsif at != "int" && at != "nil"
13454+ elsif at != "nil" && (at != "int" || cls_ivar_type(@current_class_idx, iname) == "nil")
1343913455 update_ivar_type(@current_class_idx, iname, at)
1344013456 end
1344113457 end