Commit 75a05343
75a053431aa3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
Merge pull request #1254 from fc-anjos/feature/spinel-struct-member-typing
Keep nullable int struct members unboxed
Details
- Commit
- 75a053431aa3
- Parent
- 19317e2af8e8
- Merge parent
- ab07bd11e85d
spinel_analyze.rbmodifiedView file
@@ -10888,8 +10888,9 @@
1088810888
# Same base, one nullable: keep / adopt the nullable form1088910889
# rather than collapsing to poly. `@x = "hi"` (string) +1089010890
# `@x = some_string_or_nil` (string?) is one storage shape10891-
# — `const char *` with NULL as the nil sentinel.10892-
elsif base_type(old) == base_type(new_type) && is_nullable_pointer_type(old) == 110891+
# — `const char *` with NULL as the nil sentinel. Scalar int?10892+
# follows the same merge rule with SP_INT_NIL as its sentinel.10893+
elsif base_type(old) == base_type(new_type) && (is_nullable_pointer_type(old) == 1 || is_scalar_nullable_type(old) == 1)1089310894
if is_nullable_type(new_type) == 1 && is_nullable_type(old) == 01089410895
types[k] = new_type1089510896
@cls_ivar_types[ci] = types.join(";")@@ -13813,6 +13814,11 @@
1381313814
end1381413815
end1381513816
if at == "int"13817+
# A literal int call-site is compatible with an existing int?13818+
# slot; keep the sentinel-capable storage instead of widening.13819+
if is_scalar_nullable_type(old_pt) == 113820+
return old_pt13821+
end1381613822
# Numeric compat: int + float is safe in both directions.1381713823
if old_pt == "float"1381813824
return "float"@@ -16847,6 +16853,22 @@
1684716853
end1684816854
end1684916855
16856+
def synthetic_struct_class?(ci)16857+
if ci < 0 || ci >= @cls_meth_names.length16858+
return 016859+
end16860+
names = @cls_meth_names[ci].split(";", -1)16861+
bodies = @cls_meth_bodies[ci].split(";", -1)16862+
k = 016863+
while k < names.length && k < bodies.length16864+
if names[k] == "initialize" && bodies[k] == "-2"16865+
return 116866+
end16867+
k = k + 116868+
end16869+
016870+
end16871+
1685016872
# Post-pass for #634 shape A. An optional param with an explicit1685116873
# `= nil` default whose call sites then widen its type to a1685216874
# Post-pass for #634 shape B. An ivar exposed by attr_reader /@@ -16906,8 +16928,12 @@
1690616928
assigned = ivar_assigned_in_init_chain?(ci, iname)1690716929
obs = cls_ivar_observed_types_for(ci, iname)1690816930
if assigned == 0 && obs == ""16909-
types[k] = "poly"16910-
@needs_rb_value = 116931+
if pt == "int" && synthetic_struct_class?(ci) == 116932+
types[k] = "int?"16933+
else16934+
types[k] = "poly"16935+
@needs_rb_value = 116936+
end1691116937
changed_c = 11691216938
end1691316939
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…