Skip to content

-mm=rc: a read through an interface field filled by a getter no longer leaks - #750

Merged
ASDAlexander77 merged 1 commit into
mainfrom
next-fixes
Oct 30, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
next-fixes

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Under -mm=rc, reading an interface field that a class fills with a getter (#719) leaked the getter's result.

The getter returns its result retained, as every function does under rc. The read was treated as a borrowed one, like a plain field's, so nothing gave that reference back. In a probe, two million reads kept two million objects alive: 274 MB, against 3.4 MB through a plain field. An assignment i.f = v also left an unused read of the place it wrote, and that read called the getter and leaked its result too.

Fix

  • Under rc, a read through an interface field (not optional, not function-typed, owning heap memory) is an owned result (InterfaceFieldAccess).
  • LoadOpLowering retains what a plain slot holds, so both runtime paths give +1. A receiver takes the reference over, or it is released as a temporary (§9.30).
  • An owned interface read that nothing uses is dropped (releaseDiscardedTemporaries).
  • Each such read carries an id of its own (__owned_read). A ts.Load only reads memory, so with --opt CSE folded two reads of the same field into one load that was retained once and released twice. The first full run caught this as heap corruption in own/own_field_chain_let.ts under rc.

Also

  • 00object_literal_contextual_lambda.ts passes under -mm=own now, so it runs there too.

Not fixed: -mm=own
Under own, the same read leaks when the getter returns a fresh object (617 MB in the probe). Own already rejects getters that return a field. The fix there is different, because a plain slot has no reference to hand over, and it is left open.

Tests

  • 00interface_field_getter_owned.ts covers reads into a local, as a temporary, as an argument, as a return value, in a loop, and twice in one call. It also covers stores, and a getter returning a fresh object, read after churn so an early free would show.
  • interface-field-getter-owned.cmake reads the rc IR and checks that every such read is owned and given back exactly once, and that an assignment leaves no read.
  • Full suites: Windows 6435/6435, Linux (WSL) 6408/6408.

🤖 Generated with Claude Code

…r leaks

An interface field a class fills with accessors (#719) is read by calling
the getter, and under rc a getter returns its result retained. The read was
treated as borrowed, like a plain field's, so that reference was never given
back: two million reads kept two million objects alive (274 MB, against
3.4 MB through a plain field). An assignment `i.f = v` also left an unused
read of the place it wrote, which called the getter and leaked its result.

- Under rc a read through an interface field (not optional, not
  function-typed, owning heap memory) is an owned result. The lowering
  retains what a plain slot holds, so both paths give +1; a receiver takes
  it over or it is released as a temporary.
- An owned interface read nothing uses is dropped.
- Each such read has an id of its own (__owned_read): a ts.Load only reads
  memory, and CSE under --opt folded two reads of the same field into one,
  retained once and released twice.
- 00object_literal_contextual_lambda.ts now runs under own as well; the
  error that kept it out no longer happens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 83e5354 into main Oct 30, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the next-fixes branch October 30, 2026 16: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