Commit ab07bd11

ab07bd11e85dMerged

fc-anjos <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified

Description

Keep nullable int struct members unboxed

Co-Authored-By: OpenAI Codex 5.5

Details

Commit
ab07bd11e85d
Parent
b9e10e60c0f8

spinel_analyze.rbmodifiedView file

@@ -10736,8 +10736,9 @@
1073610736 # Same base, one nullable: keep / adopt the nullable form
1073710737 # rather than collapsing to poly. `@x = "hi"` (string) +
1073810738 # `@x = some_string_or_nil` (string?) is one storage shape
10739- # — `const char *` with NULL as the nil sentinel.
10740- elsif base_type(old) == base_type(new_type) && is_nullable_pointer_type(old) == 1
10739+ # — `const char *` with NULL as the nil sentinel. Scalar int?
10740+ # follows the same merge rule with SP_INT_NIL as its sentinel.
10741+ elsif base_type(old) == base_type(new_type) && (is_nullable_pointer_type(old) == 1 || is_scalar_nullable_type(old) == 1)
1074110742 if is_nullable_type(new_type) == 1 && is_nullable_type(old) == 0
1074210743 types[k] = new_type
1074310744 @cls_ivar_types[ci] = types.join(";")
@@ -13656,6 +13657,11 @@
1365613657 end
1365713658 end
1365813659 if at == "int"
13660+ # A literal int call-site is compatible with an existing int?
13661+ # slot; keep the sentinel-capable storage instead of widening.
13662+ if is_scalar_nullable_type(old_pt) == 1
13663+ return old_pt
13664+ end
1365913665 # Numeric compat: int + float is safe in both directions.
1366013666 if old_pt == "float"
1366113667 return "float"
@@ -16690,6 +16696,22 @@
1669016696 end
1669116697 end
1669216698
16699+ def synthetic_struct_class?(ci)
16700+ if ci < 0 || ci >= @cls_meth_names.length
16701+ return 0
16702+ end
16703+ names = @cls_meth_names[ci].split(";", -1)
16704+ bodies = @cls_meth_bodies[ci].split(";", -1)
16705+ k = 0
16706+ while k < names.length && k < bodies.length
16707+ if names[k] == "initialize" && bodies[k] == "-2"
16708+ return 1
16709+ end
16710+ k = k + 1
16711+ end
16712+ 0
16713+ end
16714+
1669316715 # Post-pass for #634 shape A. An optional param with an explicit
1669416716 # `= nil` default whose call sites then widen its type to a
1669516717 # Post-pass for #634 shape B. An ivar exposed by attr_reader /
@@ -16749,8 +16771,12 @@
1674916771 assigned = ivar_assigned_in_init_chain?(ci, iname)
1675016772 obs = cls_ivar_observed_types_for(ci, iname)
1675116773 if assigned == 0 && obs == ""
16752- types[k] = "poly"
16753- @needs_rb_value = 1
16774+ if pt == "int" && synthetic_struct_class?(ci) == 1
16775+ types[k] = "int?"
16776+ else
16777+ types[k] = "poly"
16778+ @needs_rb_value = 1
16779+ end
1675416780 changed_c = 1
1675516781 end
1675616782 end