Skip to content

rc: a store through an interface hands the count over, as a store into the field does - #434

Merged
ASDAlexander77 merged 1 commit into
mainfrom
rc-interface-field-store
Oct 2, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
rc-interface-field-store

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Problem

Under -mm=rc, a store through an interface, i.o = x, neither retained x nor released the value the field held, because isOwningSlot didn't recognise the reference an InterfaceSymbolRefOp gives. That caused two failures:

  • Leak: the replaced value was never released. A loop that overwrites an object field through an interface grew to 202 MB over 2M iterations; the same loop with a direct store stays at about 68 MB.
  • Use after free: the stored value kept no reference of its own, so a new stored this way was freed at the end of the storing function while the field still pointed at it. Read back later, it returned whatever had been allocated over it: 999 instead of 31.

Fix

A field reached through an interface belongs to the object behind it. A class instance releases it through its release routine, and a literal's box retained it when the literal was boxed (castTupleToInterface). So isOwningSlot now answers yes for such a field (isOwnedInterfaceFieldSlot), and i.o = x retains and releases exactly as obj.o = x does.

Tests

  • 00owned_interfaces.ts gains both shapes: a store into a class instance and a store into a boxed literal, each read back in another function.
    • Between the store and the read, the test allocates over freed blocks with fillers that stay alive. The existing churn() frees each filler at once, so it kept reusing one block and missed this bug.
    • Both cases fail without the fix, at -O0 and -O3. They pass under rc, none and gc.
  • Release suite: 3349/3349.
  • DefaultLib: 159/159 compiled and 159/159 under JIT (release).
  • Memory, 2M iterations under rc:
    • overwrite through an interface: 202 → 68 MB;
    • the earlier mixed loop (class → interface, string concatenation, interface writes): 251 → 70 MB;
    • literal-backed interfaces: flat, with correct results.
  • Not run: Debug builds, x86, -mm=own.

🤖 Generated with Claude Code

…o the field does

Under -mm=rc, `i.o = x` (an interface's field) neither retained x nor released what
the field held: isOwningSlot did not know an InterfaceSymbolRefOp's reference. The
replaced value leaked (a loop doing it grew ~100 bytes an iteration), and the stored
one kept no reference of its own, so a `new` stored that way was freed at the end of
the storing function while the field still pointed at it - read back later, it gave
whatever was allocated over it.

A field reached through an interface belongs to the object behind it - a class
instance releases it, a literal's box retained it when boxed - so isOwningSlot now
answers yes for it (isOwnedInterfaceFieldSlot).

00owned_interfaces.ts gains both shapes (class instance, boxed literal); they allocate
over freed blocks with fillers kept alive, as churn()'s freed-at-once fillers reused
one block and missed it. Both fail without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 7c54360 into main Oct 2, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the rc-interface-field-store branch October 2, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant