Commit 9fe34be8

9fe34be8ee2fMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): root each_with_object seed across iteration

Gemini's high-priority review on #74 flagged that the seed object in compile_each_with_object_block was emitted via plain compile_arg0 and was therefore not in the function's GC root set. The seed lives for the entire iteration; any allocation inside the loop body can trigger sp_gc_collect, which would walk sp_gc_roots, find no reference to the seed, and sweep it.

The didn't-trigger-in-tests case is misleading: smaller workloads stay below the GC threshold, so the bug only surfaces under heavier allocation pressure than the test suite exercises.

Switch to compile_expr_gc_rooted, which adds an SP_GC_ROOT for the seed temp before the loop. Same mechanism the receiver already uses on the line above.

117 tests + 56 benches green; bootstrap fixed-point clean.

Refs #74.

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

Details

Commit
9fe34be8ee2f
Parent
73e2aeb2782c

spinel_codegen.rbmodifiedView file

@@ -20151,7 +20151,17 @@
2015120151 obj_ct = c_type(infer_type(aargs[0]))
2015220152 end
2015320153 end
20154- obj_arg = compile_arg0(nid)
20154+ # Root the seed: it lives across every loop iteration, and any
20155+ # allocation inside the block can trigger a GC that would otherwise
20156+ # sweep the freshly constructed seed object before the loop ends.
20157+ obj_arg_nid = -1
20158+ if args_id >= 0
20159+ aargs2 = get_args(args_id)
20160+ if aargs2.length > 0
20161+ obj_arg_nid = aargs2[0]
20162+ end
20163+ end
20164+ obj_arg = compile_expr_gc_rooted(obj_arg_nid)
2015520165 bp1 = get_block_param(nid, 0)
2015620166 bp2 = get_block_param(nid, 1)
2015720167 if bp1 == ""