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
return3301233012
end33013+
# Slice assignment with poly_array recv and poly src: the recv33014+
# is statically typed (sp_PolyArray *) but src is sp_RbVal —33015+
# fold into compile_poly_slice_assign by pre-boxing the recv to33016+
# sp_RbVal so the runtime cls_id dispatch can pick the right33017+
# copy loop. This is the shape `@bg_pixels[xfine, 8] =33018+
# @bg_pattern_lut[@bg_pattern]` ends up in once a 3-level array33019+
# 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 = 133024+
compile_poly_slice_assign(nid, recv, "sp_box_poly_array(" + rc + ")", arg_ids)33025+
return33026+
end33027+
end3301333028
idx = "0"3301433029
val = "0"3301533030
if arg_ids.length >= 1@@ -35212,9 +35227,19 @@
3521235227
end3521335228
rt = infer_type(@nd_receiver[nid])3521435229
rc_expr = compile_expr(@nd_receiver[nid])35215-
# Store receiver in a temp to avoid re-evaluation35230+
# Store receiver in a temp to avoid re-evaluation, and root it35231+
# when the type is a GC-allocated pointer. Without the root, an35232+
# array-literal receiver (`[1,2,3].map { ... }`) is held only as35233+
# a C-stack local; a sp_gc_collect inside the block (e.g. when35234+
# the block body itself does .map and grows allocations enough35235+
# to cross the threshold) frees the receiver mid-loop, and the35236+
# next `sp_*Array_length(rc)` reads a recycled IntArray's len.3521635237
rc_tmp = new_temp3521735238
emit(" " + c_type(rt) + " " + rc_tmp + " = " + rc_expr + ";")35239+
if type_needs_transient_root(rt) == 135240+
@needs_gc = 135241+
emit(" SP_GC_ROOT(" + rc_tmp + ");")35242+
end3521835243
rc = rc_tmp3521935244
bp1 = get_block_param(nid, 0)3522035245
if bp1 == ""test/three_level_array_outer_index.rbaddedView file
Loading diff…
test/three_level_array_outer_index.rb.expectedaddedView file
Loading diff…