Skip to content

Threads under -mm=own: a Shared<T> in several closures, an object result, named errors (TSLANG 31-33) - #791

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-thread-sharing
Nov 8, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-thread-sharing

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Fixes TSLANG_ISSUES 31-33, the -mm=own limits 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: a const Shared<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 a const Shared<T>. Three existing own_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

  • Windows Release ctest: 6778 run, 3 failed, and those 3 are the expectations updated here, which pass on rerun. The full suite was not repeated after that one-line regex update.
  • New: 00tslang_issues_31_33.ts (gc, rc, none, own; JIT and compiled) and four own_err_* cases.
  • Linux (WSL): the 2340 ctest cases matching issues-31-33|own|shared pass.
  • DefaultLib from a clean clone with the paired PR's tests, Windows: all four models pass, debug and release, JIT and compiled.
  • DefaultLib, Linux: rc, none and own pass. gc has one failure, weakref_basic in release (compile and JIT). That test uses no closures and no Shared, so this change should not reach it; I did not run it on a Linux baseline.

The paired DefaultLib PR lifts // not own from thread_spawn.ts and atomics_wait.ts.

🤖 Generated with Claude Code

…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>
@ASDAlexander77
ASDAlexander77 merged commit 25eeef9 into main Nov 8, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-thread-sharing branch November 8, 2026 23:50
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