Repository navigation
-mm=own: a generator that says @keeps owns the arguments its state holds - #699
Merged
Merged
Conversation
A generator's state captured its parameters as borrows (spec 19), so a lazy helper such as `iter.map(f)` could not be stored or returned past the expression that built it. `@keeps` on a generator now names the parameters its state takes over: callers move them in, the state's release frees them, and the generator is not bounded by its arguments. Spec section 38. 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.
Summary
Under
-mm=owna generator's state captured its parameters as borrows (spec §19). The result of a lazy helper likeiter.map(f)was therefore bounded by its arguments: it could not be stored, returned or handed to another generator.@keepson a generator now names the parameters its state takes over:@keepsgenerator is not bounded by its arguments.@keepsis an error ("names 'iter', but its body keeps 'iter', 'f'").@keepsstill borrows, as before.Implementation:
paramsCapturedIntoState(OwnershipSignatureGenerators) finds the heap-owning parameter cells a generator's state captures.localOwnedParamscounts them as kept when the maker says@keeps.findBorrowingStatesmarks such a stateowns. Its captured box is not a borrowing field, so the release routine frees it, and the result is not marked bounded.decideEscapingno longer reports a kept parameter's cell as "its value is the caller's".isFreshaccepts an extension call to a defined function, andholdsNoBlockaccepts a function reference cast.Spec §38 and
docs/own-memory-model.mdare updated.DefaultLib uses this for
take/filter/map/dropin ASDAlexander77/TypeScriptCompilerDefaultLib (PR to follow).Tests
own_generator_keeps: a class argument, an iterator argument, an iterator plus a callback, a@keepsgenerator nested in another, a generator returned from a function or stored in a global, and one given up after one step. It churns between steps and runs under own, rc, gc and none.@keepsmissing a parameter, an argument used after the move, and a generator without@keepsthat is stored.ctest -C Release: 5872 passed, 0 failed.iterator_map,iterator_filter), with no new failures.🤖 Generated with Claude Code