Commit 074145e1
074145e1dc2aMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): hoist sp_bigint_new_int constructor args to GC-rooted temps
root_constructor_arg_if_needed now treats a sp_bigint_*-prefixed emit as may_gc=1 even when the source-level AST is a static literal. expr_may_gc walks the AST and sees only the IntegerNode at the source (no allocation), but the codegen-side bigint wrap allocates an sp_Bigint via sp_bigint_alloc -- and a constructor that does substantial allocation downstream (e.g. Tile.new building a 256-elt FloatArray inside its initializer) can trigger GC before SP_GC_ROOT(lv_tag) inside the callee runs. The bigint arg would be unreachable mid-call.
Pattern that broke: [Tile.new(10), Tile.new(20), ...] literal under
promote mode, where each inline sp_bigint_new_int(10) is followed by
sp_Tile_new(...) whose FloatArray.new + 256 pushes cross the GC
threshold mid-construction.
Picks up gc_root_ptr_array_literal under promote mode.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 074145e1dc2a
- Parent
- f92cfe82e654
spinel_codegen.rbmodifiedView file
if expr_id >= 0 may_gc = expr_may_gc(expr_id) end # Detect a wrapped sp_bigint_new_int(...) emit. The wrap itself # allocates an sp_Bigint via sp_bigint_alloc, which may trigger # GC -- but expr_may_gc walks the AST and sees only the IntegerNode # literal at the source level, so we have to look at the C expr. # Same shape for any "sp_bigint_*(" prefix that returns a freshly # allocated sp_Bigint*. if may_gc == 0 && (expr.start_with?("sp_bigint_new_int(") || expr.start_with?("sp_bigint_add(") || expr.start_with?("sp_bigint_sub(") || expr.start_with?("sp_bigint_mul(")) may_gc = 1 end if may_gc == 0 && later_arg_may_gc == 0 return expr end