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

@@ -4985,6 +4985,20 @@
49854985 return "poly_array"
49864986 end
49874987 if mname == "product"
4988+ # Mixed element types (e.g. int_array.product(str_array)) yield a
4989+ # poly_array of poly_array pairs; two int arrays keep the homogeneous
4990+ # int_array_ptr_array (kept in sync with codegen's product handling).
4991+ if recv >= 0 && @nd_block[nid] < 0 && @nd_arguments[nid] >= 0
4992+ rt_pr = infer_type(recv)
4993+ args_pr = get_args(@nd_arguments[nid])
4994+ if args_pr.length == 1
4995+ at_pr = infer_type(args_pr[0])
4996+ if is_array_type(rt_pr) == 1 && is_array_type(at_pr) == 1 && (rt_pr != "int_array" || at_pr != "int_array")
4997+ @needs_rb_value = 1
4998+ return "poly_array"
4999+ end
5000+ end
5001+ end
49885002 return "int_array_ptr_array"
49895003 end
49905004 if mname == "slice_when" || mname == "chunk_while" || mname == "slice_before" || mname == "slice_after"