Repository navigation
-mm=rc: a read through an interface field filled by a getter no longer leaks - #750
Merged
Merged
Conversation
…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>
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.
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 = valso left an unused read of the place it wrote, and that read called the getter and leaked its result too.Fix
InterfaceFieldAccess).LoadOpLoweringretains 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).releaseDiscardedTemporaries).__owned_read). Ats.Loadonly reads memory, so with--optCSE 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 inown/own_field_chain_let.tsunder rc.Also
00object_literal_contextual_lambda.tspasses under-mm=ownnow, so it runs there too.Not fixed:
-mm=ownUnder 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.tscovers 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.cmakereads the rc IR and checks that every such read is owned and given back exactly once, and that an assignment leaves no read.🤖 Generated with Claude Code