Repository navigation
-mm=own: yielded values are the caller's, try locals, rest arrays borrow - #705
Merged
Merged
Conversation
- What a generator yields is taken out of the record next() returns (spec
48). A for...of or spread that keeps the value now moves it out of the
record's `value` field, and the field is then cleared. This applies when
the value is moved once and nothing reads it, or the field, before the
record local ends.
- A local declared in a `try` is now treated as declared by the store
right before its ts.RetainSlot, so try { const r = mk(); } compiles.
- A global given its value once in the program's `main` is now a
candidate immortal, as one given its value by a static constructor is.
A class's ..new also counts as making a fresh value.
- A built array stored into a global moves in.
- The array a rest parameter is given borrows its elements (spec 49).
rc's references for the elements go. A shallow ts.Release (the new
OWN_SHALLOW_RELEASE_ATTR_NAME lowering) frees the array after the call
without its elements. a.concat(b) no longer moves b.
DefaultLib: string_matchAll and string_match_lastIndex now compile and run
under own.
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.
The second batch of
-mm=ownDefaultLib fixes. With it, every DefaultLib test that isn't markednot ownpasses under own. Spec sections 48–49, and the user doc's limits section is updated.Changes
What a generator yields is the caller's (§48).
for (const v of g()) a.push(v)and[...s.matchAll(re)]used to fail withborrows a field and cannot be stored. The value is now moved out of thevaluefield of the record thatnext()returns. Two conditions must hold:checkPlaceReadredoes the walk with the move's retain and its taker counted as uses (takenOps). rc's retain goes, and ats.Defaultis stored into the field after the taker, so the record's release frees nothing twice. A value that isn't moved, for example one pushed on some paths only, stays in the field and is freed with the record.Related fixes that unblocked the
matchAlltests:try. MLIRGen declares a local inside atrywith no value and fills it with a store right before rc'sts.RetainSlot. That store now counts as the declaration (slotDeclarationStore,declarationRetainOf).try { const r = mk(); }used to fail withtakes a second reference.main, when nothing callsmain(a script's top level), is now a candidate immortal global. A class's..new(a regex literal, for example) also counts as making a fresh value.Rest-parameter arrays borrow their elements (§49).
a.concat(b)movedbinto the array that...otheris given. Under own that array was never released, sobcouldn't be used after the call, and the elements leaked with the array.classifyArgumentArraysnow treats such an array as borrowing its elements when all of these hold:rc's references to the elements are dropped. A
ts.ReleasemarkedOWN_SHALLOW_RELEASE_ATTR_NAMEfollows the call; it frees the array's data block and header but not the elements (emitReleaseArrayShallow).Tests
own_generator_takeandown_rest_array_borrows, under own, rc, gc and none. Each step churns memory, so a value freed too early reads garbage. Own emits no reference counting.own_err_generator_take_used_after.not own) out of 172, in release and debug, compile and JIT. That was 159 passed with 3 failures before. rc, gc and none are unchanged.Not in this PR
Array<string>andArray<Shared<T>>still don't compile under own:fillstores a string parameter inside a loop.The dependent DefaultLib PR marks
array_reduceRightasnot own.🤖 Generated with Claude Code