Commit 1e3bbe44
1e3bbe444f50Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
Support mixed-type Array#product
[1, 2].product(["a", "b"]) was unresolved (a C error): the arm only
handled two int arrays. Build a poly_array of [recv_elem, arg_elem]
pairs for any pair of typed arrays whose element types differ (boxing
each element by its array's type, GC-rooting each pair while it fills).
Two int arrays keep the faster homogeneous int_array_ptr_array path.
The argument list is read with the guarded if @nd_arguments[nid] >= 0
form rather than a get_args(...) : "".split(...) ternary: the latter
unifies an int_array with a str_array to poly_array, so args[0] became
a poly value that poisoned infer_type/compile_expr during self-host.
Refs #1216
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 1e3bbe444f50
- Parent
- 6bfb01fe0149
spinel_analyze.rbmodifiedView file
return "poly_array" end if mname == "product" # Mixed element types (e.g. int_array.product(str_array)) yield a # poly_array of poly_array pairs; two int arrays keep the homogeneous # int_array_ptr_array (kept in sync with codegen's product handling). if recv >= 0 && @nd_block[nid] < 0 && @nd_arguments[nid] >= 0 rt_pr = infer_type(recv) args_pr = get_args(@nd_arguments[nid]) if args_pr.length == 1 at_pr = infer_type(args_pr[0]) if is_array_type(rt_pr) == 1 && is_array_type(at_pr) == 1 && (rt_pr != "int_array" || at_pr != "int_array") @needs_rb_value = 1 return "poly_array" end end end return "int_array_ptr_array" end if mname == "slice_when" || mname == "chunk_while" || mname == "slice_before" || mname == "slice_after"spinel_codegen.rbmodifiedView file
Loading diff…
test/array_product_mixed.rbaddedView file
Loading diff…
test/array_product_mixed.rb.expectedaddedView file
Loading diff…