Commit 7d38b433
7d38b433b776Merged
Yusuke Endoh <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
chore(codegen): fold ptr_array into is_array_type and drop the per-site disjunctions
After the per-method ptr_array fixes (Array#shuffle, Array#+,
Array#concat, Array#each_with_object, Array#flat_map), eight call
sites now spelled out the same is_array_type(t) == 1 || is_ptr_array_type(t) == 1 predicate (or its inverse). Now that
sp_PtrArray has the helpers the dispatchers rely on, fold ptr_array
into is_array_type and collapse those disjunctions back to a single
is_array_type call. No behavior change.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 7d38b433b776
- Parent
- 63fb62ec4328
spinel_codegen.rbmodifiedView file
@@ -1676,7 +1676,7 @@
16761676
if lt == "poly"16771677
return "poly"16781678
end1679-
if is_array_type(lt) == 1 || is_ptr_array_type(lt) == 11679+
if is_array_type(lt) == 116801680
return lt16811681
end16821682
if lt == "float"@@ -2380,7 +2380,7 @@
23802380
if bbs.length > 023812381
bret = infer_type(bbs.last)23822382
# If block returns an array type, use it as result type2383-
if is_array_type(bret) == 1 || is_ptr_array_type(bret) == 12383+
if is_array_type(bret) == 123842384
return bret23852385
end23862386
end@@ -3545,14 +3545,14 @@
35453545
# The canonical "is this an array type?" check. Use this when you need35463546
# to dispatch a method that's defined for every typed array — `+`,35473547
# `concat`, `shuffle`, `each_with_object`, `flat_map`, etc. Covers the3548-
# 5 typed arrays (int/str/float/sym/poly). *_ptr_array is intentionally3549-
# excluded for now: sp_PtrArray lacks `_dup`/`_shuffle` and several3550-
# other helpers, and the existing dispatchers don't route ptr_array3551-
# through this path correctly even on master.3548+
# 5 typed arrays (int/str/float/sym/poly) and any *_ptr_array.35523549
def is_array_type(t)35533550
if t == "int_array" || t == "str_array" || t == "float_array" || t == "sym_array" || t == "poly_array"35543551
return 135553552
end3553+
if is_ptr_array_type(t) == 13554+
return 13555+
end35563556
035573557
end35583558
@@ -13873,7 +13873,7 @@
1387313873
@needs_string_helpers = 11387413874
return "sp_poly_add(" + compile_expr(recv) + ", " + box_expr_to_poly(@nd_arguments[nid] >= 0 ? get_args(@nd_arguments[nid])[0] : -1) + ")"1387513875
end13876-
if is_array_type(lt) == 1 || is_ptr_array_type(lt) == 113876+
if is_array_type(lt) == 11387713877
rc = compile_expr_gc_rooted(recv)1387813878
arg = compile_arg0(nid)1387913879
pfx = array_c_prefix(lt)@@ -15155,12 +15155,12 @@
1515515155
pfx = array_c_prefix(recv_type)1515615156
return "sp_" + pfx + "_get(" + rc + ", rand() % sp_" + pfx + "_length(" + rc + "))"1515715157
end15158-
if mname == "shuffle" && (is_array_type(recv_type) == 1 || is_ptr_array_type(recv_type) == 1)15158+
if mname == "shuffle" && is_array_type(recv_type) == 11515915159
@needs_rand = 11516015160
pfx = array_c_prefix(recv_type)1516115161
return "sp_" + pfx + "_shuffle(" + rc + ")"1516215162
end15163-
if mname == "shuffle!" && (is_array_type(recv_type) == 1 || is_ptr_array_type(recv_type) == 1)15163+
if mname == "shuffle!" && is_array_type(recv_type) == 11516415164
@needs_rand = 11516515165
pfx = array_c_prefix(recv_type)1516615166
emit(" sp_" + pfx + "_shuffle_bang(" + rc + ");")@@ -18734,7 +18734,7 @@
1873418734
if mname == "concat"1873518735
if recv >= 01873618736
rt = infer_type(recv)18737-
if is_array_type(rt) == 1 || is_ptr_array_type(rt) == 118737+
if is_array_type(rt) == 11873818738
rc = compile_expr_gc_rooted(recv)1873918739
arg = compile_arg0(nid)1874018740
pfx = array_c_prefix(rt)@@ -21029,7 +21029,7 @@
2102921029
result = new_temp2103021030
emit(" " + obj_ct + " " + result + " = " + obj_arg + ";")2103121031
tmp_i = new_temp21032-
if is_array_type(rt) == 1 || is_ptr_array_type(rt) == 121032+
if is_array_type(rt) == 12103321033
pfx = array_c_prefix(rt)2103421034
emit(" {")2103521035
@indent = @indent + 1@@ -21790,7 +21790,7 @@
2179021790
end2179121791
end2179221792
# Fall back to receiver type if block doesn't return an array21793-
if is_array_type(block_ret) == 0 && is_ptr_array_type(block_ret) == 021793+
if is_array_type(block_ret) == 02179421794
block_ret = rt2179521795
end2179621796
@needs_gc = 1