Commit 5797ccf4
5797ccf4af2eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #264 from mame/pr/widen-int-obj-to-poly
feat(codegen): widen heterogeneous int/nil + obj scalar slots to poly
Details
- Commit
- 5797ccf4af2e
- Parent
- d1954cab98d6
- Merge parent
- cca27aa74597
spinel_codegen.rbmodifiedView file
@@ -6433,7 +6433,26 @@
64336433
if names[k] == iname64346434
if k < types.length64356435
old = types[k]6436-
if old == "int" || old == "nil"6436+
# Heterogeneous int/nil + obj → poly when the prior write6437+
# was a *definite* int/nil literal. The previous "int wins"6438+
# / "nil wins" overwrite silently cast the int payload to a6439+
# struct pointer, miscompiling `@x = 10; @x = Box.new` and6440+
# any subsequent obj method dispatch. Widen to poly so the6441+
# slot can carry either case at runtime; the dispatch path6442+
# then decides per cls_id at the call site.6443+
#6444+
# The definiteness gate avoids false widening when "int"6445+
# was just `infer_ivar_init_type`'s placeholder fallback for6446+
# a CallNode rhs that's later refined to an obj type by6447+
# the writer-scan / inference passes (e.g.6448+
# `@m = method(:foo)` initially scans as int and a6449+
# refinement promotes it to `obj_Method` — no heterogeneity6450+
# to widen for).6451+
if (old == "int" || old == "nil") && is_obj_type(new_type) == 1 && cls_ivar_definite_flag(ci, iname) == 16452+
types[k] = "poly"6453+
@needs_rb_value = 16454+
@cls_ivar_types[ci] = types.join(";")6455+
elsif old == "int" || old == "nil"64376456
types[k] = new_type64386457
@cls_ivar_types[ci] = types.join(";")64396458
elsif old != new_type && old != "poly"test/widen_int_obj_to_poly.rbaddedView file
Loading diff…