Commit f6b89b02

f6b89b028b0cMerged

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

Description

Merge pull request #354 from mame/pr/map-block-receiver-gc-root

feat(codegen): map block returning nested array preserves cls_id chain

Details

Commit
f6b89b028b0c
Parent
8d3731c74d4a
Merge parent
5faaa776133b

spinel_codegen.rbmodifiedView file

@@ -33010,6 +33010,21 @@
3301033010 compile_poly_slice_assign(nid, recv, rc, arg_ids)
3301133011 return
3301233012 end
33013+ # Slice assignment with poly_array recv and poly src: the recv
33014+ # is statically typed (sp_PolyArray *) but src is sp_RbVal —
33015+ # fold into compile_poly_slice_assign by pre-boxing the recv to
33016+ # sp_RbVal so the runtime cls_id dispatch can pick the right
33017+ # copy loop. This is the shape `@bg_pixels[xfine, 8] =
33018+ # @bg_pattern_lut[@bg_pattern]` ends up in once a 3-level array
33019+ # constant (TILE_LUT) types its inner-of-inner reads as poly.
33020+ if arg_ids.length == 3 && rt == "poly_array"
33021+ src_t_check2 = infer_type(arg_ids[2])
33022+ if src_t_check2 == "poly"
33023+ @needs_rb_value = 1
33024+ compile_poly_slice_assign(nid, recv, "sp_box_poly_array(" + rc + ")", arg_ids)
33025+ return
33026+ end
33027+ end
3301333028 idx = "0"
3301433029 val = "0"
3301533030 if arg_ids.length >= 1
@@ -35212,9 +35227,19 @@
3521235227 end
3521335228 rt = infer_type(@nd_receiver[nid])
3521435229 rc_expr = compile_expr(@nd_receiver[nid])
35215- # Store receiver in a temp to avoid re-evaluation
35230+ # Store receiver in a temp to avoid re-evaluation, and root it
35231+ # when the type is a GC-allocated pointer. Without the root, an
35232+ # array-literal receiver (`[1,2,3].map { ... }`) is held only as
35233+ # a C-stack local; a sp_gc_collect inside the block (e.g. when
35234+ # the block body itself does .map and grows allocations enough
35235+ # to cross the threshold) frees the receiver mid-loop, and the
35236+ # next `sp_*Array_length(rc)` reads a recycled IntArray's len.
3521635237 rc_tmp = new_temp
3521735238 emit(" " + c_type(rt) + " " + rc_tmp + " = " + rc_expr + ";")
35239+ if type_needs_transient_root(rt) == 1
35240+ @needs_gc = 1
35241+ emit(" SP_GC_ROOT(" + rc_tmp + ");")
35242+ end
3521835243 rc = rc_tmp
3521935244 bp1 = get_block_param(nid, 0)
3522035245 if bp1 == ""