Repository navigation
-mm=own: a @keeps generator given a bounded generator is bounded in turn - #700
Merged
Merged
Conversation
`new Set(a).values().take(2)` was "borrows its generator's arguments and cannot be stored": moving a bounded result (a generator that borrows its argument, spec 19) into a `@keeps` generator's kept argument (spec 38) counted as keeping it. The keeper's state owns the bounded state, so it is bounded by the same arguments: `boundedUses` now follows the keeper's result as the bounded one's, so it can be walked in place but not returned, stored or used after its source ends. Spec section 39. 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.
Summary
Under
-mm=own,new Set([1, 2, 3]).values().take(2)failed with "borrows its generator's arguments and cannot be stored, returned or captured". The cause:values()is a generator whose state borrows the set (spec §19), so its result is bounded by the set.takesays@keeps(spec §38), so passing that result totakecounted as keeping it.The temporary Set was never freed early; this rule alone refused the code.
The helper's state owns the bounded state, so it is bounded by the same arguments. When
boundedUsesmeets the bounded result as a kept argument of a call that returns a@keepsgenerator's state (ownsKeptState), it now follows that call's result as it follows a local holding the bounded one. That result's uses are then checked against the ends of the original arguments:for...of,.next()in the same statement, a local holding it, or another helper given it (.drop(1).take(2)).Nothing changes at release: the helper's state frees the bounded state, and that release gives back nothing it borrows.
Spec §39 is new.
docs/own-memory-model.mdno longer sayss.values().take(2)is an error.Tests
New
own_generator_keeps_bounded, run under own, rc, gc and none with churn between steps:AOT under own: 200000 iterations peak at 4.4 MB, the same as 1000.
own_err_generator_keeps_boundedfrom -mm=own: a generator that says @keeps owns the arguments its state holds #699 walked the chain in place, which is now allowed. It now returns the chain instead. Newown_err_generator_keeps_bounded_outlivesuses the chain after its source is overwritten.Full
ctest -C Release: 5882 passed, 0 failed.DefaultLib suites, with ASDAlexander77/TypeScriptCompilerDefaultLib's
take/droplimit made a number (separate PR):iterator_take,iterator_drop), with no new failures.🤖 Generated with Claude Code