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 end
1679- if is_array_type(lt) == 1 || is_ptr_array_type(lt) == 1
1679+ if is_array_type(lt) == 1
16801680 return lt
16811681 end
16821682 if lt == "float"
@@ -2380,7 +2380,7 @@
23802380 if bbs.length > 0
23812381 bret = infer_type(bbs.last)
23822382 # If block returns an array type, use it as result type
2383- if is_array_type(bret) == 1 || is_ptr_array_type(bret) == 1
2383+ if is_array_type(bret) == 1
23842384 return bret
23852385 end
23862386 end
@@ -3545,14 +3545,14 @@
35453545 # The canonical "is this an array type?" check. Use this when you need
35463546 # to dispatch a method that's defined for every typed array — `+`,
35473547 # `concat`, `shuffle`, `each_with_object`, `flat_map`, etc. Covers the
3548- # 5 typed arrays (int/str/float/sym/poly). *_ptr_array is intentionally
3549- # excluded for now: sp_PtrArray lacks `_dup`/`_shuffle` and several
3550- # other helpers, and the existing dispatchers don't route ptr_array
3551- # 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 1
35553552 end
3553+ if is_ptr_array_type(t) == 1
3554+ return 1
3555+ end
35563556 0
35573557 end
35583558
@@ -13873,7 +13873,7 @@
1387313873 @needs_string_helpers = 1
1387413874 return "sp_poly_add(" + compile_expr(recv) + ", " + box_expr_to_poly(@nd_arguments[nid] >= 0 ? get_args(@nd_arguments[nid])[0] : -1) + ")"
1387513875 end
13876- if is_array_type(lt) == 1 || is_ptr_array_type(lt) == 1
13876+ if is_array_type(lt) == 1
1387713877 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 end
15158- 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) == 1
1515915159 @needs_rand = 1
1516015160 pfx = array_c_prefix(recv_type)
1516115161 return "sp_" + pfx + "_shuffle(" + rc + ")"
1516215162 end
15163- 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) == 1
1516415164 @needs_rand = 1
1516515165 pfx = array_c_prefix(recv_type)
1516615166 emit(" sp_" + pfx + "_shuffle_bang(" + rc + ");")
@@ -18734,7 +18734,7 @@
1873418734 if mname == "concat"
1873518735 if recv >= 0
1873618736 rt = infer_type(recv)
18737- if is_array_type(rt) == 1 || is_ptr_array_type(rt) == 1
18737+ if is_array_type(rt) == 1
1873818738 rc = compile_expr_gc_rooted(recv)
1873918739 arg = compile_arg0(nid)
1874018740 pfx = array_c_prefix(rt)
@@ -21029,7 +21029,7 @@
2102921029 result = new_temp
2103021030 emit(" " + obj_ct + " " + result + " = " + obj_arg + ";")
2103121031 tmp_i = new_temp
21032- if is_array_type(rt) == 1 || is_ptr_array_type(rt) == 1
21032+ if is_array_type(rt) == 1
2103321033 pfx = array_c_prefix(rt)
2103421034 emit(" {")
2103521035 @indent = @indent + 1
@@ -21790,7 +21790,7 @@
2179021790 end
2179121791 end
2179221792 # Fall back to receiver type if block doesn't return an array
21793- if is_array_type(block_ret) == 0 && is_ptr_array_type(block_ret) == 0
21793+ if is_array_type(block_ret) == 0
2179421794 block_ret = rt
2179521795 end
2179621796 @needs_gc = 1