Repository navigation
-mm=own: Map and Set of strings and numbers; generator methods over this - #693
Merged
Merged
Conversation
A generator method whose state borrows `this` (@borrows("this")) no longer keeps it: the signature pass finds the borrowing states before the facts, and the box's store of `this` keeps nothing. Its callers keep their object and may use it after the loop. A method of a class that is not @Final is called through its vtable: the forwarder check (`entries() { return this.iter(); }`) and the bound check see the object through ts.GetThis. A state field read only into a tuple yielded (`yield [k, v]`, also cast to a named tuple) moves into the yield as a field read straight into it does, and a tuple made of borrowed strings starts from copies of them (spec 22) instead of rc's retain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-on-some-paths, method callbacks What the default library's Map and Set need to compile under own (spec 2026-10-26-own-generic-containers-design.md): - A string read out of a place and given to a callback that may free it, or to a call that keeps it, gets a copy (released after the call when the callee does not keep it). A direct call that may free it is still an error, so @nodrops keeps its meaning. - A parameter kept on some paths only is released on the others: takenParams is now the parameters a move reaches every return from. - findBetween does not search past the read's own block: around a loop (`continue`) it is read again. - A call's drops for `length =`, pop, shift, splice are the elements of arrays of that element type. - Callback families for methods no other method overrides, called through their vtable; a closed family with no members calls nothing. Tests: own_generator_method_this, own_string_copy_call, own_param_kept_some_paths, own_method_callbacks, own_loop_read_again, own_length_drops_elements, own_tuple_param_kept, own_err_generator_method_reassigned, own_err_callback_method_overridden. Retired: own_err_param_kept_some_paths and own_err_string_call_keeps_twice, which now compile (and are covered by the positive tests). 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.
Makes the default library's
MapandSet(lib.generics.ts, compiled into each program) compile under-mm=ownfor number, boolean and string keys and values. Design notes:tslang/docs/superpowers/specs/2026-10-26-own-generic-containers-design.md. The library side is ASDAlexander77/TypeScriptCompilerDefaultLib PRown-generic-iterators, which needs this one.Generator methods over
thisthis(@borrows("this")) no longer keeps it. Before,w.iter()movedwinto the generator, sowcould not be used after the loop.@final, and through forwarders (entries() { return this.iter(); }); the bound check sees the object throughts.GetThis, so reassigning the object while its iterator is read is an error (it compiled and read freed memory).yield [k, v], also cast to a named tuple) moves into the yield.Strings as values (spec 22), more places
@nodropskeeps its meaning.Other analysis changes
takenParams= parameters a move reaches every return from). Behavior change:own_err_param_kept_some_pathsandown_err_string_call_keeps_twicenow compile and are retired; the new positive tests cover them.findBetweendoes not search past the read's own block: acontinuepath reads again.length =,pop,shift,spliceare the elements of arrays of that element type, not anything.Not covered (in the spec):
anyor object elements (constructor from an array, object moved into an entry tuple; waits on a ruling about containers of owned values); untypednew Set([1, 2])also instantiatesSet<any>(MLIRGen, every model); JIT under own loses library facts for some calls (looks pre-existing, e.g.date_getTime).Tests
own_generator_method_this,own_string_copy_call,own_param_kept_some_paths,own_method_callbacks,own_loop_read_again,own_length_drops_elements,own_tuple_param_kept(each also checked under gc, rc and none),own_err_generator_method_reassigned,own_err_callback_method_overridden.weakref_basic, gc-only).🤖 Generated with Claude Code