Repository navigation
Threads under -mm=own: a Shared<T> in several closures, an object result, named errors (TSLANG 31-33) - #791
Merged
Merged
Conversation
…ult, named errors (TSLANG 31-33) 31: a closure that escapes owns what it captures, so a plain object in two closures stays an error. A const Shared<T> is now captured by copy, so any number of closures hold a counted handle each. Under own a handle's count is always atomic, since handles are what threads share. A box that borrows what it holds gives nothing back, so its handle retain goes too. 32: an error about a captured variable names it, with or without --di, points at its first use in the closure and says to use a const Shared<T>. 33: the result of a call through a callback is the caller's when every function that can reach the call is defined here and none returns a borrow of its argument, so this.result = this.fn() is accepted. 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.
Fixes TSLANG_ISSUES 31-33, the
-mm=ownlimits found by the default library's thread tests.31, sharing between closures. A closure that escapes owns what it captures, so a plain object in two closures stays an error.
Shared<T>is the way to share one, and it now works: aconstShared<T>is captured by copy, so any number of closures hold a counted handle each, in a loop too. This applies under every model; before, the capture went through the variable's cell. Under own a handle's count is always atomic, since handles are what threads share. A box that borrows what it holds gives nothing back, so its handle retain is erased as well (that also fixes a leak for a parameter's handle in a closure that does not escape).32, the error names the capture. An error about a captured variable names it with or without
--di, points at its first use inside the closure, and suggests aconst Shared<T>. Three existingown_err_closure_escape_*expectations change for this.33, an object result in a field.
this.result = this.fn()is accepted when every function that can reach the call is defined in the module and none returns a borrow of its argument. A callback that gives back its argument or what it captured is still refused.Not done: an error inside a generic still reports only the library's line, with no note for the instantiating call. The issue asked for that only if the move stayed rejected.
Tests
00tslang_issues_31_33.ts(gc, rc, none, own; JIT and compiled) and fourown_err_*cases.issues-31-33|own|sharedpass.weakref_basicin release (compile and JIT). That test uses no closures and noShared, so this change should not reach it; I did not run it on a Linux baseline.The paired DefaultLib PR lifts
// not ownfromthread_spawn.tsandatomics_wait.ts.🤖 Generated with Claude Code