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

@@ -25447,6 +25447,15 @@
2544725447 if expr_id >= 0
2544825448 may_gc = expr_may_gc(expr_id)
2544925449 end
25450+ # Detect a wrapped sp_bigint_new_int(...) emit. The wrap itself
25451+ # allocates an sp_Bigint via sp_bigint_alloc, which may trigger
25452+ # GC -- but expr_may_gc walks the AST and sees only the IntegerNode
25453+ # literal at the source level, so we have to look at the C expr.
25454+ # Same shape for any "sp_bigint_*(" prefix that returns a freshly
25455+ # allocated sp_Bigint*.
25456+ 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("))
25457+ may_gc = 1
25458+ end
2545025459 if may_gc == 0 && later_arg_may_gc == 0
2545125460 return expr
2545225461 end