Commit 4834315f

4834315f8dd4Merged

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

Description

fix(codegen): multi-write value-form on call-returning-array RHS

(a, b = call_returning_array)[i] lowered the multi-write to compile_multi_write(nid); return "0" -- the outer subscript then read sp_IntArray_get(0, 0LL) (NULL recv) and segv'd on the next iteration of any consumer loop. The ArrayNode-literal RHS shape from #554 already handled the value-form correctly; the call-returning-typed-array shape fell through.

Add a sibling arm in compile_expr's MultiWriteNode case: when the RHS isn't an ArrayNode but its static type is an array, emit the RHS into a temp, destructure the targets through the array's _get, and surface the temp as the expression value. Mirrors compile_multi_write's else branch but returns the value temp for the outer consumer.

Fixes #584.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
4834315f8dd4
Parent
34a54d65de77

spinel_codegen.rbmodifiedView file

@@ -10942,6 +10942,34 @@
1094210942 end
1094310943 return arr_tmp
1094410944 end
10945+ # `(a, b = call_returning_typed_array)[i]` -- the RHS is a
10946+ # CallNode (or anything not ArrayNode) whose static type is a
10947+ # typed array. Evaluate the RHS into a single temp, destructure
10948+ # the targets through array `_get`, and surface the temp as the
10949+ # expression value so the outer `[i]` lands on a real array
10950+ # instead of the int 0 fallback that the old "return 0" emit
10951+ # produced (which segv'd in `sp_IntArray_get(0, 0)`). Issue
10952+ # #584; sibling shape to the ArrayNode arm above.
10953+ if val_id_mw >= 0
10954+ val_t_mw_e = infer_type(val_id_mw)
10955+ if is_array_type(val_t_mw_e) == 1
10956+ @needs_gc = 1
10957+ rhs_arr_tmp = new_temp
10958+ emit(" " + c_type(val_t_mw_e) + " " + rhs_arr_tmp + " = " + compile_expr(val_id_mw) + ";")
10959+ if type_needs_transient_root(val_t_mw_e) == 1
10960+ emit(" SP_GC_ROOT(" + rhs_arr_tmp + ");")
10961+ end
10962+ elem_t_mw = elem_type_of_array(val_t_mw_e)
10963+ pfx_mw = array_c_prefix(val_t_mw_e)
10964+ kmw_e = 0
10965+ while kmw_e < targets_mw.length
10966+ slot_expr_mw = "sp_" + pfx_mw + "_get(" + rhs_arr_tmp + ", " + kmw_e.to_s + "LL)"
10967+ emit_multi_write_target(targets_mw[kmw_e], slot_expr_mw, elem_t_mw)
10968+ kmw_e = kmw_e + 1
10969+ end
10970+ return rhs_arr_tmp
10971+ end
10972+ end
1094510973 compile_multi_write(nid)
1094610974 return "0"
1094710975 end