Commit 287a6fb6
287a6fb61aedMerged
Chris Hasiński <[email protected]> · 7 months ago · 2 files · ~2 modified
Description
fix(codegen): route Array#size to length for IntArray/SymArray/StrArray
[1,2,3].size returned 0 because the dispatch for IntArray/SymArray
and StrArray in compile_array_method_expr matched only mname == "length",
letting "size" fall through to a default that returned 0. FloatArray
and PtrArray already accept both names; this brings the remaining
three array types in line.
Implementation:
-
int_array/sym_array: split into separate
lengthandsizearms, each carrying the @hoisted_strlen_var optimisation. Equivalent to the previous behavior forlength; new path forsizereturns the same hoisted-or-direct length. -
str_array: same shape, both arms carry the hoisted check (the
lengtharm already had it; matching it forsizekeeps perf parity inwhile i < arr.sizeloop bounds).
The two arms are duplicated rather than written as
if mname == "length" || mname == "size" because the compound form
in str_array destabilises the self-build (gen1 is fine, but bin1
then mis-compiles unrelated == comparisons in spinel_codegen
itself, producing fragments like if (( && ...))). Kept all three
types consistent for clarity. Worth tracking the underlying inference
quirk separately.
Test: bm_array_lit.rb extended with .size on IntArray, SymArray, and StrArray; on an array post push/pop; and as a loop bound (where the hoisted-length path matters for performance). CRuby and Spinel outputs match.
Details
- Commit
- 287a6fb61aed
- Parent
- effcb5d8ea89
spinel_codegen.rbmodifiedView file
end return "sp_IntArray_length(" + rc + ")" end if mname == "size" if @hoisted_strlen_var != "" && @hoisted_strlen_recv == rc return @hoisted_strlen_var end return "sp_IntArray_length(" + rc + ")" end if mname == "[]" return "sp_IntArray_get(" + rc + ", " + compile_arg0(nid) + ")" end end return "sp_StrArray_length(" + rc + ")" end if mname == "size" if @hoisted_strlen_var != "" && @hoisted_strlen_recv == rc return @hoisted_strlen_var end return "sp_StrArray_length(" + rc + ")" end if mname == "[]" return "sp_StrArray_get(" + rc + ", " + compile_arg0(nid) + ")" endtest/bm_array_lit.rbmodifiedView file
Loading diff…