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
obj_ct = c_type(infer_type(aargs[0])) end end obj_arg = compile_arg0(nid) # Root the seed: it lives across every loop iteration, and any # allocation inside the block can trigger a GC that would otherwise # sweep the freshly constructed seed object before the loop ends. obj_arg_nid = -1 if args_id >= 0 aargs2 = get_args(args_id) if aargs2.length > 0 obj_arg_nid = aargs2[0] end end obj_arg = compile_expr_gc_rooted(obj_arg_nid) bp1 = get_block_param(nid, 0) bp2 = get_block_param(nid, 1) if bp1 == ""