Skip to content

-mm=own: a @keeps generator given a bounded generator is bounded in turn - #700

Merged
ASDAlexander77 merged 2 commits into
mainfrom
own-keeps-bounded-arg
Oct 27, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
own-keeps-bounded-arg

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

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.
  • take says @keeps (spec §38), so passing that result to take counted 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 boundedUses meets the bounded result as a kept argument of a call that returns a @keeps generator'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:

  • Allowed: walking the chain in place: a for...of, .next() in the same statement, a local holding it, or another helper given it (.drop(1).take(2)).
  • Still refused: returning it, storing it, or using it after its source ends.

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.md no longer says s.values().take(2) is an error.

Tests

  • New own_generator_keeps_bounded, run under own, rc, gc and none with churn between steps:

    • helpers over a generator that borrows a temporary
    • two helpers deep
    • one step in the statement that made it
    • a chain over a named source held in a local

    AOT under own: 200000 iterations peak at 4.4 MB, the same as 1000.

  • own_err_generator_keeps_bounded from -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. New own_err_generator_keeps_bounded_outlives uses the chain after its source is overwritten.

  • Full ctest -C Release: 5882 passed, 0 failed.

  • DefaultLib suites, with ASDAlexander77/TypeScriptCompilerDefaultLib's take/drop limit made a number (separate PR):

    • rc, gc and none pass every test.
    • own goes from 140 to 142/170 (iterator_take, iterator_drop), with no new failures.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits October 27, 2026 15:27
`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>
@ASDAlexander77
ASDAlexander77 merged commit 3277852 into main Oct 27, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-keeps-bounded-arg branch October 27, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant