Commit edd1240f

edd1240fa8f2Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(analyze): promote tuple element types in method/class returns

return @x, @y, @z materializes as sp_Tuple_int_int_int *, recorded as tuple:int,int,int in @meth_return_types / @cls_meth_returns. The promote pass touched simple int slots but not the inner elems of tuple return entries, so the builder emit (driven by the ivar slot types — now bigint) produced sp_Tuple_bigint_bigint_bigint * while the function's declared return type stayed sp_Tuple_int_int_int *.

Sweep tuple elem types in both promote_meth_returns_table and the @meth_return_types top-level loop.

Promote-mode test count: 546 pass / 47 fail / 25 error -> 547 pass / 47 fail / 24 error. Default raise mode 618 / 0 / 0.

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

Details

Commit
edd1240fa8f2
Parent
6594360f1b95

spinel_analyze.rbmodifiedView file

@@ -20468,6 +20468,21 @@
2046820468 if @meth_return_types[mi] == "int"
2046920469 @meth_return_types[mi] = "bigint"
2047020470 @needs_bigint = 1
20471+ elsif @meth_return_types[mi].start_with?("tuple:")
20472+ tparts_mr = @meth_return_types[mi][6, @meth_return_types[mi].length - 6].split(",")
20473+ changed_tup_mr = 0
20474+ tpm_i = 0
20475+ while tpm_i < tparts_mr.length
20476+ if tparts_mr[tpm_i] == "int"
20477+ tparts_mr[tpm_i] = "bigint"
20478+ @needs_bigint = 1
20479+ changed_tup_mr = 1
20480+ end
20481+ tpm_i = tpm_i + 1
20482+ end
20483+ if changed_tup_mr == 1
20484+ @meth_return_types[mi] = "tuple:" + tparts_mr.join(",")
20485+ end
2047120486 end
2047220487 mi = mi + 1
2047320488 end
@@ -20550,6 +20565,28 @@
2055020565 rets[mj] = "bigint"
2055120566 @needs_bigint = 1
2055220567 changed = 1
20568+ elsif rets[mj].start_with?("tuple:")
20569+ # Tuple element types: a return like `tuple:int,int,int` (built
20570+ # by `return @x, @y, @z` when @x..@z are int) holds raw int
20571+ # slots in the synthesized sp_Tuple_int_int_int struct. With
20572+ # promote mode lifting the ivars to bigint, the tuple build emit
20573+ # produces sp_Tuple_bigint_bigint_bigint at the call site, so
20574+ # the return type slot must move too.
20575+ tparts_ret = rets[mj][6, rets[mj].length - 6].split(",")
20576+ changed_tup_ret = 0
20577+ tpr_i = 0
20578+ while tpr_i < tparts_ret.length
20579+ if tparts_ret[tpr_i] == "int"
20580+ tparts_ret[tpr_i] = "bigint"
20581+ @needs_bigint = 1
20582+ changed_tup_ret = 1
20583+ end
20584+ tpr_i = tpr_i + 1
20585+ end
20586+ if changed_tup_ret == 1
20587+ rets[mj] = "tuple:" + tparts_ret.join(",")
20588+ changed = 1
20589+ end
2055320590 end
2055420591 mj = mj + 1
2055520592 end
@@ -21523,8 +21560,7 @@
2152321560 # Promote-mode safety: annotate may have produced stale "int"
2152421561 # entries for nodes whose inferred type derived from cached
2152521562 # state captured before promote_int_to_bigint_globally landed
21526- # (SuperNode reading cls_method_return's pre-promotion result,
21527- # CallNode chains whose mid-tree return type was cached, etc.).
21563+ # (SuperNode reading cls_method_return's pre-promotion result).
2152821564 # Sweep `@nd_inferred_type` again and rewrite "int" -> "bigint"
2152921565 # for node kinds whose concrete C emit is always bigint when the
2153021566 # underlying slot is promoted.