Commit 1cf6a187
1cf6a187efa1Merged
Yusuke Endoh <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): infer _ptr_array for arr.map { array_block }
When the block of <typed_array>.map { ... } itself returns a
typed array (int_array/float_array/str_array/sym_array),
the outer map's result is an array of arrays — type as
<inner>_ptr_array so each element keeps its concrete shape and
GC sees a real pointer per slot.
Only fires for array-shaped recv (where the elements have a definite shape). For range/int recv, fall through to the int_array placeholder so a follow-up int-typed assignment to the same slot still type-checks (the recv's elements aren't yet known to be array-shaped).
Optcarrot trigger: [1, 6].map { |i| (0..n).map { ... } } —
each outer element is itself an int_array.
Details
- Commit
- 1cf6a187efa1
- Parent
- 60f1b75ea8d0
spinel_codegen.rbmodifiedView file
if is_obj_type(bret) == 1 return bret + "_ptr_array" end # Block returns a non-trivial type (an array literal, # poly value, ...). The map's overall result is still an # Array — fall through to the recv-based default below # only when recv is already array-shaped, otherwise # return int_array as a generic placeholder. # Block returns an array (e.g. # `[1, 6].map { (0..n).map { ... } }` — each outer # element is itself an int_array). The outer map's # result is then an array of arrays, encoded as # `<inner>_ptr_array`. Only fire this for array-shaped # recv (where the elements have a definite shape and # ivar typing reaches the ptr_array placeholder); for # range/int recv we fall through to the int_array # placeholder below so a follow-up int-typed assignment # to the same ivar still type-checks. if bret == "int_array" || bret == "float_array" || bret == "str_array" || bret == "sym_array" rt_recv_p = infer_type(recv) if rt_recv_p != "range" && rt_recv_p != "int" return bret + "_ptr_array" end end # poly_array bret intentionally falls through. Returning # poly_array_ptr_array would be more accurate, but ivars # holding the result (and the corresponding `[nil] * # n` companions) often haven't been widened to the # ptr_array shape by the type-inference pass yet. # Letting it fall through to int_array preserves the # pre-fix typing that those companion ivars match. # Block returns a non-trivial type (poly value, etc.). # The map's overall result is still an Array — fall # through to the recv-based default below only when # recv is already array-shaped, otherwise return # int_array as a generic placeholder. end end end