Commit 220ad5c6
220ad5c6a894Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): heap-promoted name list reset at method boundary
Ori Pekelman's #564. Fiber.new { ... } bodies that capture
a local from the enclosing method push a _hcell_<name>_<n>
entry onto @heap_promoted_names so fiber_var_ref(<name>)
emits (*_hcell_<name>_<n>) in the capturing function's C
body. The list was never reset at method boundaries: when a
sibling method later in the same compilation unit referenced
a local of the same name (e.g. def do_work(client) called
from inside the fiber body), its emit ALSO picked up the
heap cell ref and the link failed because the cell was
declared only in the spawner's C scope.
Save / restore @heap_promoted_names and @heap_promoted_cells length around the top-level method body emit (the @meth_body_ids walker at line ~9670). The inner compile_fiber_new already has its own save/restore for nested fiber emits; this outer wrapper ensures cells don't leak past a single method's generated C function.
Closes #564
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 220ad5c6a894
- Parent
- 2a78c2da2d2f
spinel_codegen.rbmodifiedView file
yp = yield_params_suffix(mi) end # Reset @heap_promoted_names at method boundary. The list # tracks fiber-capture heap cells that live in the EMITTING # function's local C scope; leaking it across methods makes # sibling methods see `(*_hcell_<name>_<n>)` references to # cells that exist only in the original method. Issue #564. saved_hp_names_len_mb = @heap_promoted_names.length saved_hp_cells_len_mb = @heap_promoted_cells.length if oc_type != "" # Open class method: self is primitive type rt = @meth_return_types[mi] rt = @meth_return_types[mi] pop_scope # Restore @heap_promoted_names to the pre-method baseline so # the next method doesn't see this method's fiber-capture # cells. Issue #564. 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 @current_method_name = "" @current_method_block_param = "" @in_yield_method = 0test/fiber_capture_no_leak_to_sibling.rbaddedView file
Loading diff…
test/fiber_capture_no_leak_to_sibling.rb.expectedaddedView file
Loading diff…