Skip to content

yield in finally works as in JavaScript; a[i] = v grows under own; dictionary spread of other values and extending dictionary interfaces (TSLANG 152, 153) - #982

Merged
ASDAlexander77 merged 9 commits into
mainfrom
own-array-grow
Nov 21, 2026
Merged

ASDAlexander77 merged 9 commits into
mainfrom
own-array-grow

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

This PR fixes the remaining TSLANG 152 and 153 items that the compiler can fix alone. The next(object) part of item 4 follows in one more commit once it is built.

yield inside a generator's finally works as in JavaScript (TSLANG 153; it was an error since #980)

  • How: a try whose finally yields no longer uses the try's finally region. TryOpLowering copied that region for each way out, and a resume landed in one copy only.
    • The try and its catch go in a labelled block, with a catch-all that keeps the exception.
    • Each way out of them is recorded in a mode variable, and the code leaves the block: a return (and return()'s at a resume point), or a break/continue out of the try.
    • The finally is then generated once after the block, where a yield can resume, and the recorded way out is taken.
  • Return values: a return's value is kept in a variable of the generator. Through nested yielding finallys it is handed on in the same variable.
  • return(v): it gives back what the finally yields, then finishes with v. return() while paused in a yield* finishes through the finally too (not under own).
  • Checked against node for each case: normal end, return, throw, return from catch, break/continue in a loop, nested finallys, a throw after the finally's yield, return()/throw() paused in the body and in the finally, yield*, a class generator method, an untyped generator in for...of, a closure's own return, and strings and objects returned through the finally.
  • Also fixed: a let in a nested block that hides an outer one in a generator shared the outer one's variable.
  • Limits under -mm=own (also recorded in TSLANG 153):
    • A value that owns memory, returned through a yielding finally, is a compile error.
    • An object thrown through one stops at run time with own's existing "cannot copy an any" error.

a[i] = v past the end grows the array under -mm=own too (TSLANG 152)

  • How: it is a SetLengthOf marked as only growing. Its lowering keeps the longer length, and own's passes treat it like a push.
  • Not grown under own: through a let over a parameter's array, where a push is refused too.
  • Not grown in any model: when the right side gave the variable another array (a[1] = (a = [5], 9)).

Dictionaries (TSLANG 152)

  • { ...d } of a dictionary with a different value type now works, through a helper the compiler makes from source. No default library change is needed.
  • interface More extends Counts {}, a dictionary interface with nothing added, is that dictionary.

Tests

  • New: 00generator_yield_in_finally.ts; 00generator_yield_in_finally_values.ts (gc, rc); the own diagnostic generator_return_through_yielding_finally_own.ts.
  • Extended: 00array_write_grows.ts (now also under own), 00object_dictionary.ts.

Verified so far

  • Subsets: ctest of generator, array and dictionary tests (673/0).
  • wasm checked heap: own and rc for these tests.
  • mm_fuzz: 300 programs, 0 failures.
  • Leak probe: memory flat over 200,000 rounds (gc, rc, own).
  • Full ctest, wasm tester and default library suites, and the full sweep are still running; results follow in a comment.

Held

  • The default library changes need a compiler release first: the Generator next(value?)/return?/throw? declarations, and lifting "not own" in object_dictionary.ts.

🤖 Generated with Claude Code

ASDAlexander77 and others added 9 commits November 21, 2026 21:16
The growth is a call of `.array_grow.<type>` given the array's slot, which -mm=own's passes take as any
call given a slot; the guard that kept own out (when the growth was made in place, they read the slot
written as a parameter's kept and a field's array read again as a second reference) is gone. The test
runs under own again (jit own, wasm and Android own skips removed) and covers a parameter's array, a
field's of a parameter and nested arrays. TSLANG 152.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d as a push by the ownership passes

Not through a local over a parameter's array (as a push there, it would make the parameter kept).
TSLANG 152.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The finally of a try whose finally yields is code of its own after the try, once: the try and catch in a
labelled block with a catch-all keeping the exception; each return (and return()'s at a resume point),
break and continue out of them records its way out and leaves the block; after the finally the way out
is taken. return(v) gives what the finally yields and finishes with v. A let of a nested block hiding
one around it in a generator gets a field of its own. Results checked against node. TSLANG 153.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tionary interface is that dictionary; a[i] = v does not grow an array the right side replaced

- { ...d } of a dictionary of other values calls __dictionary_assign_values<T, S>, made from source.
- interface More extends Counts {} of a dictionary interface: type More = Counts.
- a[1] = (a = [5], 9): the store goes into the array the left side read; no growth through the
  variable's slot, which holds another array now (under own the unconditional growth grew it).
TSLANG 152.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…methods, untyped generators; own limits as errors

- return() while paused in a yield* finishes through the finally (resume checks at its yields; not under own).
- -mm=own: a value that owns memory returned through a yielding finally is an error at the return.
- Tests: class generator method, untyped for...of, a closure's return in the try (all models);
  strings and objects returned through it, return() in a yield* (gc, rc); the own error.
TSLANG 152, 153.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…NG 153 notes on own iterator interfaces

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…; strings sent by next() stay allowed

Under -mm=own the generator over the array owns a copy of it (a borrow for the generator's lifetime can't be
said there) and is declared to return the interface. TSLANG 153.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit f1d4569 into main Nov 21, 2026
10 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-array-grow branch November 21, 2026 22:45
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