Commit c07eac2c
c07eac2cfdd5Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
codegen: reset heap-promoted cells at class/instance method boundary
A Fiber.new closure capturing a method-local heap-promotes it and
records _hcell_<name>_<fid> in @heap_promoted_names. That list is
consulted by fiber_var_ref for every local read, so a sibling method
whose parameter shares the captured name has its plain read rewritten
to (*_hcell_<name>_<fid>), a cell declared only in the first
method's C function. The top-level method emitter already reset the
list at its boundary (#564); the class instance method and class
method emitters did not, so the leak surfaced as
"'hcell_' undeclared" in any program with two same-class
methods sharing a captured parameter name. Save and restore the list
length around both emitters, matching the top-level path.
Fixes #1007
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- c07eac2cfdd5
- Parent
- b86e0e16f140
spinel_codegen.rbmodifiedView file
@indent = 1 @in_gc_scope = 0 # Reset @heap_promoted_names at the method boundary; otherwise a # sibling method whose param shares a name with a fiber-captured # local here reads `(*_hcell_<name>_<n>)`, a cell declared only in # this function's C scope. The top-level method path already does # this; class instance / class methods did not. saved_hp_names_len_mb = @heap_promoted_names.length saved_hp_cells_len_mb = @heap_promoted_cells.length midx = cls_find_method_direct(ci, mname) if midx >= 0 if cls_method_has_yield(ci, midx) == 1 @in_yield_method = 0 @current_method_yield_arity = 1 @indent = 0 while @heap_promoted_names.length > saved_hp_names_len_mb @heap_promoted_names.pop end while @heap_promoted_cells.length > saved_hp_cells_len_mb @heap_promoted_cells.pop end emit_raw(" return " + c_return_default(rt) + ";") emit_raw("}") emit_raw("") @indent = 1 @in_gc_scope = 0 # Reset @heap_promoted_names at the method boundary; see the note # in emit_instance_method. saved_hp_names_len_mb = @heap_promoted_names.length saved_hp_cells_len_mb = @heap_promoted_cells.length emit_raw("static " + c_type(rt) + " sp_" + cname + "_cls_" + sanitize_name(mname) + "(" + build_params_decl(pnames, ptypes) + ") {") push_scope @current_method_name = "" @current_method_block_param = "" @indent = 0 while @heap_promoted_names.length > saved_hp_names_len_mb @heap_promoted_names.pop end while @heap_promoted_cells.length > saved_hp_cells_len_mb @heap_promoted_cells.pop end emit_raw(" return " + c_return_default(rt) + ";") emit_raw("}") emit_raw("")test/i1007.rbaddedView file
Loading diff…
test/i1007.rb.expectedaddedView file
Loading diff…