fix(ir): release the producer's reference when boxing an owned value as Mixed (#484)#489
Open
mirchaemanuel wants to merge 1 commit into
Open
Conversation
…as Mixed Fixes illegalstudio#484. __rt_mixed_from_value retains refcounted payloads (objects, arrays, hashes, callables, nested cells) and persists strings, so the boxed cell always carries its own reference or copy — but EIR lowering treated Op::MixedBox as consuming its operand and never released the producer's reference. Boxing an owning temporary therefore left the payload one reference high forever: 'function g(): ?P { return new P(); }' leaked one P per call (and fresh arrays boxed on return leaked identically) even though the boxed cell itself was freed on rebind. A new LoweringContext::box_value_as_mixed helper emits the MixedBox and then releases the operand when it is an owning temporary (same ownership pattern as the throw-of-borrowed fix in illegalstudio#477); the 11 value-carrying emission sites now go through it. Borrowed operands (a boxed local) are untouched — the box's retain is their +1 — and concat-scratch strings remain exempt from heap release, so string boxing behavior is unchanged (its separate persisted-copy leak is issue illegalstudio#485). The two remaining direct emission sites box freshly-created nulls (non-refcounted) and need no release. Regression tests in tests/codegen/runtime_gc/regressions.rs for the object and array flavours. Broad suites green (1872 codegen across callables/closures/ runtime_gc/control/types/exceptions/arrays/oop/generators + 993 error tests).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #484.
__rt_mixed_from_valueretains refcounted payloads (objects, arrays, hashes, callables, nested cells) and persists strings, so a boxed Mixed cell always carries its own reference or copy — but EIR lowering treatedOp::MixedBoxas consuming its operand and never released the producer's reference. Boxing an owning temporary therefore left the payload one reference high forever:The boxed cell itself was freed correctly on rebind; only the payload leaked (fresh arrays boxed the same way leaked identically).
Fix
A new
LoweringContext::box_value_as_mixedhelper emits theMixedBoxand then releases the operand when it is an owning temporary — the same ownership rule as the throw-of-borrowed fix in #477. The 11 value-carrying emission sites now route through it; the two remaining direct sites box freshly-created nulls (non-refcounted, commented accordingly).Deliberately unchanged:
Verification
tests/codegen/runtime_gc/regressions.rs; broad suites green (1872 codegen across callables/closures/runtime_gc/control/types/exceptions/arrays/oop/generators + 993 error tests).Found during review (pre-existing, filed separately)
mixedarguments still leak: that boxing happens in codegen call materialization, not EIR, so this fix doesn't reach it (mechanism detailed on the issue).Closure::bindsymptom after isolating the root).matchwith heterogeneousmixedarms dies at runtime coercing the object arm to string.