Repository navigation
-mm=own: a read through an interface field filled by a getter is freed - #751
Merged
Merged
Conversation
Under own a read through an interface field is a borrow (spec 28). When a class fills the field with a getter, the read is instead the getter's result, a fresh value nothing else holds, and it was never freed: two million reads kept two million objects (617 MB). Own already rejects a getter that returns a field, so every getter read there was a leak. - MLIRGen marks such a read (__own_cell_read) plus an id of its own, so CSE cannot fold two reads into one freed twice. - After own's inference (releaseCellReads), a read whose value, and what is borrowed from it, stays in its block gets a ts.Release after its last use. An unused read, which an assignment `i.f = v` leaves, is erased. - ReleaseOpLowering frees it only when the slot names a cell of accessors; through a plain field the read stays a borrow and nothing is freed. A read that escapes (returned, stored, put in a `let`) gets no release and still leaks on the getter's path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ale test entries Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Oct 30, 2026
…a call that writes a global A second fuzz round (600 programs, seeds 71000-71599, on main with #751 and this branch) found no own failures in 1101 checked programs, and one rc crash: `g(p.n)` where `p` was a global's object (`f(HG)`) and `g` did `HG.n = mk(5)`. The argument was borrowed with no count, so the store freed it while `g` still read it, or after `g` gave it back. An argument read out of a global itself was already held across such a call (#647). An argument read out of a field or an element of an object a parameter names is now held too, when the callee may give any global a new value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Oct 30, 2026
…local's value, rc arguments read through a parameter's object (#752) * -mm=own: two fuzzer finds - keeper literal elements, parameters given a local's value A round of mm_fuzz.py (400 programs, seeds 70000-70399) found 10 own failures and no rc ones. Two causes: - A keeper (an append-only array global) makes what is pushed onto it immortal, and reads of its elements own nothing. `const GA: N[] = [mk(5)]` was taken for one, but the elements its literal is made with were never made immortal, so a local given `GA[0]` freed it when its block ended (9 of the 10). An array literal of anything but constants makes no keeper now. - `p = n` with `p` a parameter stored `n`'s value in a slot that owns nothing, with no retain for own to judge, so `n = mk()` then freed what `p` read. Own reported an assigned parameter only while explaining a retain; a store of a value that owns a block into a parameter's slot is reported now, unless the value is another parameter's, which the caller holds for the whole call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * -mm=rc: an argument read through a parameter's object is held across a call that writes a global A second fuzz round (600 programs, seeds 71000-71599, on main with #751 and this branch) found no own failures in 1101 checked programs, and one rc crash: `g(p.n)` where `p` was a global's object (`f(HG)`) and `g` did `HG.n = mk(5)`. The argument was borrowed with no count, so the store freed it while `g` still read it, or after `g` gave it back. An argument read out of a global itself was already held across such a call (#647). An argument read out of a field or an element of an object a parameter names is now held too, when the callee may give any global a new value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Oct 31, 2026
…c conditional record literal (#758) * -mm=rc: a conditional between record literals keeps the objects its branch made `c ? { start: this.pos, dir: new V(1) } : { ... }`: each branch yields the literal it built, whose field holds an object the branch made, and the branch gave that object back before it ended. The receiver's retain after the `ts.If` - which retains the literal's fields - came too late, and the field was freed under it (heap corruption, 0xC0000374; hand-written fuzz seed review7__pM1). consumeConditionalResults now treats such a branch as it treats one yielding a field of a temporary it made: the branch retains what it yields. Not under own, which settles a literal's fields itself (and rejects this shape). Test: tests/00conditional_record_literal_temporary.ts (gc, and rc/none through the corpus). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * -mm=own: three borrowing literals that compiled and crashed (fuzz seeds 73095, 73544, 74808) A 2000-program mm_fuzz round (seeds 73000-74999) found three own crashes among 1735 accepted programs; each is now a compile error. - An array literal argument that borrows its elements (`f([HG.v])`, classifyArgumentArrays) given to a callee that may overwrite an element (`p[0] = v`) or destroy anything: the overwrite freed the global's value and the new element was lost with the shallow release. Such an array no longer borrows, so the element read is the error it is anywhere else. - A borrowing record literal (`{ v: n.items[0] }`) given to a callee whose known overwrites include a field (`p.v = ...`): walkRecord treats it as a write of the field here, which keeps the record. - walkRecord treated a `ts.Invoke` (a call inside `try`) as a plain branch and skipped it, so a borrowing record given to a call in a `try` had no use there: `f({ v: n.items[0] }, (n = mk(), n))` freed the element before the call read it. Tests: own_err_literal_element_overwritten, own_err_record_field_overwritten, own_err_record_borrow_in_try (each compiled without error before). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * -mm=own: a getter-filled interface field read put in a `let` is freed at the returns `let x = i.item; for (...) use(x); return x.n` - a read through an interface field a getter may fill, held in a `let` read across blocks - was never freed: #751 releases such a read only when it and what is borrowed from it stay in its block. Two million calls kept two million Boxes (280.5 MB peak; 4.3 MB now). releaseCellReads now also frees a read that is the initializer of a `let` nobody assigns or captures, whose reads stay in the function (staysInBlock over any block), when the read reaches every return and the object it reads through is a parameter's, which outlives them: the same conditional release, at each return. A read returned or stored still leaks on the getter's path. Tests: own_interface_getter_let (own, no counting, rc, gc, none) and test-own-interface-getter-let-released, which reads the IR (fails before the fix). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * -mm=own: a getter-filled interface field read that would leave its block is an error User ruling (2026-10-31): `return i.item`, where a class of the module fills `item` with a getter, is a compile error rather than a leak. On the getter's path the read is a new value only its own release frees; returned (a borrow of `i` to the caller), stored, or kept where neither the in-block release nor the `let` release reaches, it was lost. releaseCellReads now reports such a read when a class in the module fills a field of that name with accessors (its `<class>.<interface>..vtbl.<field>.accessor` cell); a field no class fills that way is a borrow on every path and may still be returned. A method called on the read (`i.item.get()`) is followed by staysInBlock now (the bound method, its object and function, the call), so it is freed rather than rejected. DefaultLib src/lib.ts compiles under own and rc with no errors. Test: own_err_getter_read_returned. Release ctest 6506/6506; mm_fuzz seeds 76000-76399 clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * -mm=own: a callback may give a captured object a new value `bag.forEach(b => { last = new Box(b.n) })` was rejected: the assignment through a captured variable's cell in the closure body was a drop of anything (fieldDropsInBody), so a method that walks the array a field holds and calls the callback had its element borrow "used after it may be released". Spec 52 made this precise for numbers and strings; this does it for objects and arrays. - The assignment is a place drop of its own, OWN_CAPTURED_CELL_POSITION: it frees what only the cell owns, so it drops a chain read through a captured variable's cell (dropsChain), nothing else. - A call given anything read through a variable a closure assigns, when the call may run such a closure, is an error where it is made (checkArgumentsAssigned): no parameter of the callee can be under the value the closure frees. `bag.forEach(b => { bag = new Bag() })` is that error. Tests: own_callback_assigns_capture (own, no counting, rc, gc, none; rejected before), own_err_callback_assigns_receiver, own_err_callback_assigns_borrowed. DefaultLib src/lib.ts compiles under own and rc with no errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- 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.
This is the
-mm=ownhalf of #750. Under own, reading an interface field that a class fills with a getter leaked the getter's result.Under own a read through an interface field is a borrow (spec 28). When the slot names a cell of accessors, though, the read is the getter's result: a fresh value that nothing else holds. Nothing ever freed it, so two million reads kept two million objects alive (617 MB). Own already rejects a getter that returns a field, so every read through a getter leaked.
Fix
__own_cell_read, plus its own id so that CSE cannot fold two reads into one that is then freed twice.releaseCellReadschecks each marked read. If the value, and anything borrowed from it, stays in its block, it gets a taggedts.Releaseafter its last use. Allowed uses are field reads, call arguments whose results are checked the same way, and scalars.ts.Releaseoperand as an ownership candidate.i.f = vleaves behind, is erased.ReleaseOpLoweringfrees the value only when the slot names a cell. Through a plain field the read stays a borrow and nothing is freed. To make this possible,ReleaseOpLoweringmoves belowInterfaceAccessorCellin LowerToLLVM.cpp.The probe drops from 617 MB to 4.3 MB, the same at
-O3. A plain field's read is unaffected.Not covered
A read that escapes its block (returned, stored, or put in a
let) gets no release, so it still leaks on the getter's path.Tests
own/own_interface_getter_read.ts, under own in JIT and AOT. It covers a temporary, a foldedconst, an argument, a loop, the same field read twice in one call, and an assignment that must not call the getter. Values are checked after churn, so an early free would show.test-own-interface-getter-read-releasedchecks that the tagged release is placed.🤖 Generated with Claude Code