Commit 6d6d5954

6d6d5954730fMerged

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

Description

codegen: tuple_c_name strips nullable ? from element types

After #832 (int_array#pop returns int?), code like return [a.pop, b.pop, c.pop] produced tuple type tuple:int?,int?,int? whose default C-name was sp_Tuple_int?_int?_int? -- illegal C identifier (stray ? chars). The typedef emitted fine when the caller hit a different (earlier) registration, leading to a name mismatch between the typedef and the use sites.

Fix: base_type each element when building the C identifier. The nullable info lives in the runtime sentinel (SP_INT_NIL), so the C storage is the same as the non-nullable form -- a tuple of int? and a tuple of int share the same struct layout.

Restores optcarrot to fps ~655 / checksum 59662.

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

Details

Commit
6d6d5954730f
Parent
c5f8b5252746

spinel_codegen.rbmodifiedView file

@@ -3982,8 +3982,20 @@
39823982 end
39833983
39843984 def tuple_c_name(t)
3985- # "tuple:int,string" → "sp_Tuple_int_string"
3986- "sp_Tuple_" + tuple_elem_types_str(t).split(",", -1).join("_")
3985+ # "tuple:int,string" → "sp_Tuple_int_string". base_type strips
3986+ # nullable `?` suffixes: a tuple of int? has the same C storage
3987+ # as a tuple of int (mrb_int either way; the nil sentinel lives
3988+ # in-band as SP_INT_NIL). Without this an int_array#pop return
3989+ # widens the surrounding tuple type to `sp_Tuple_int?_...` whose
3990+ # `?` is an illegal C identifier char. #832 follow-up.
3991+ parts = tuple_elem_types_str(t).split(",", -1)
3992+ out = "".split(",", -1)
3993+ k = 0
3994+ while k < parts.length
3995+ out.push(base_type(parts[k]))
3996+ k = k + 1
3997+ end
3998+ "sp_Tuple_" + out.join("_")
39873999 end
39884000
39894001 # Whether a tuple element type must be traced by the GC scan function.