Commit 2e7cb8b8

2e7cb8b89001Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified

Description

fix(codegen,analyze): Array#values_at for int / sym / str arrays (#742 partial)

[:a, :b, :c].values_at(0, 2) used to fall through to the unresolved-call warning ("cannot resolve call to 'values_at' on sym_array"). Implement values_at for int_array (covers sym_array since they share the IntArray runtime), and str_array.

The codegen emits inline -- build a fresh typed array, push the result of get(arr, idx) for each index arg in order. Variadic arity is handled by walking the args list; no runtime helper needed since the unroll is fixed per call site.

analyze.rb's values_at arm returns the recv's array type so chained ops keep the right shape.

#742 also lists combination and permutation; those are deferred (they need new typed-tuple shapes for the result, not a same-shape return). values_at was the simplest of the three.

Test: test/values_at.rb covers sym, int, str variants plus repeated index lookup.

476 tests pass; optcarrot checksum 59662.

Refs #742

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

Details

Commit
2e7cb8b89001
Parent
a0c43409025a

spinel_analyze.rbmodifiedView file

@@ -3528,6 +3528,16 @@
35283528 end
35293529 end
35303530 end
3531+ if mname == "values_at"
3532+ # `arr.values_at(...)` returns an array of the same element
3533+ # type. Issue #742.
3534+ if recv >= 0
3535+ rt_va = infer_type(recv)
3536+ if is_array_type(rt_va) == 1
3537+ return rt_va
3538+ end
3539+ end
3540+ end
35313541 if mname == "<<"
35323542 if recv >= 0
35333543 if lt == "mutable_str"