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 form1073710737
# rather than collapsing to poly. `@x = "hi"` (string) +1073810738
# `@x = some_string_or_nil` (string?) is one storage shape10739-
# — `const char *` with NULL as the nil sentinel.10740-
elsif base_type(old) == base_type(new_type) && is_nullable_pointer_type(old) == 110739+
# — `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) == 01074210743
types[k] = new_type1074310744
@cls_ivar_types[ci] = types.join(";")@@ -13656,6 +13657,11 @@
1365613657
end1365713658
end1365813659
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) == 113663+
return old_pt13664+
end1365913665
# Numeric compat: int + float is safe in both directions.1366013666
if old_pt == "float"1366113667
return "float"@@ -16690,6 +16696,22 @@
1669016696
end1669116697
end1669216698
16699+
def synthetic_struct_class?(ci)16700+
if ci < 0 || ci >= @cls_meth_names.length16701+
return 016702+
end16703+
names = @cls_meth_names[ci].split(";", -1)16704+
bodies = @cls_meth_bodies[ci].split(";", -1)16705+
k = 016706+
while k < names.length && k < bodies.length16707+
if names[k] == "initialize" && bodies[k] == "-2"16708+
return 116709+
end16710+
k = k + 116711+
end16712+
016713+
end16714+
1669316715
# Post-pass for #634 shape A. An optional param with an explicit1669416716
# `= nil` default whose call sites then widen its type to a1669516717
# 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 = 116774+
if pt == "int" && synthetic_struct_class?(ci) == 116775+
types[k] = "int?"16776+
else16777+
types[k] = "poly"16778+
@needs_rb_value = 116779+
end1675416780
changed_c = 11675516781
end1675616782
endspinel_codegen.rbmodifiedView file
Loading diff…
test/struct_int_member_unboxed.rbaddedView file
Loading diff…
test/struct_int_member_unboxed.rb.expectedaddedView file
Loading diff…