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
end def tuple_c_name(t) # "tuple:int,string" → "sp_Tuple_int_string" "sp_Tuple_" + tuple_elem_types_str(t).split(",", -1).join("_") # "tuple:int,string" → "sp_Tuple_int_string". base_type strips # nullable `?` suffixes: a tuple of int? has the same C storage # as a tuple of int (mrb_int either way; the nil sentinel lives # in-band as SP_INT_NIL). Without this an int_array#pop return # widens the surrounding tuple type to `sp_Tuple_int?_...` whose # `?` is an illegal C identifier char. #832 follow-up. parts = tuple_elem_types_str(t).split(",", -1) out = "".split(",", -1) k = 0 while k < parts.length out.push(base_type(parts[k])) k = k + 1 end "sp_Tuple_" + out.join("_") end # Whether a tuple element type must be traced by the GC scan function.