Skip to content

own: TSLANG 49; @final accessors; C function pointer checks (TSLANG 29) - #847

Merged
ASDAlexander77 merged 6 commits into
mainfrom
fix-own-item-49
Nov 14, 2026
Merged

ASDAlexander77 merged 6 commits into
mainfrom
fix-own-item-49

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Three -mm=own errors that powder_sandbox reduced from its build (TSLANG_ISSUES 49):

  • if (l) { this.level = l; }: "moved here on some paths only". A value moved on some paths only is now accepted when every other path to its release passed a branch that tested it empty (if (l), if (!l) return;, l !== null). On those paths it holds nothing, so the release is dropped (emptyWhereNotMoved). if (l && n == "y") is still an error.
  • const l = this.read(n); this.level = l;: "takes a second reference". The result of a call through the vtable to a method another module may override now belongs to the caller when no method of the family says it borrows (@lends, @borrows, @record, or a this result). Each method of the family defined in this module must also return its own result (familyResultsFresh). To keep that sound, under own an override may not declare a borrow that the method it overrides doesn't (checkOverrideResultFacts).
  • this.other = this.level; this.level = null;: "borrows a field and cannot be stored". This is now a move, by extending spec 77: the source field is refilled right after the store into the new owner, with only reads, constants and rc's counts of null in between. A call in between is still an error.

Also in this PR

  • @final accessors (from 48): @final on a get/set accessor now works as it does on a method. Calls to it are direct, overriding it is an error, and the declaration printer writes it. The own note about an overridable call also covers accessors.
  • TSLANG 29 leftover: a function value (a const of function type, or a callback parameter) passed to a @cdecl callback parameter is now checked at run time. A closure throws "a closure or a bound method can't be used as a plain function pointer" instead of crashing when the C side runs it later; before, an atexit handler segfaulted at exit. A function named directly isn't checked.
  • Opaque-first function types: a capturing arrow can now be assigned to (a: Opaque, b: Opaque) => s32. The type match used to take leading Opaque parameters for a receiver and refuse it; it now tries the parameters as they are first (MLIRTypeHelper.h).
  • New tests: 00tslang_issue_29_function_value.ts (skipped on wasm, since it uses atexit), 00tslang_issue_29_comparator.ts, and final_accessor_override_error.ts; 00tslang_issue_48.ts now covers a @final getter.
  • Suites on the second commit: ctest passes all 7172 tests except 3 disabled, plus the new accessor and item 29 tests. DefaultLib passes under own, rc, gc and none.

Tests

  • New: 00tslang_issue_49.ts (every model), plus own_err_moved_when_tested_other.ts, own_err_field_moved_call_between.ts and own_err_override_lends.ts.
  • ctest (Release, Windows): 7156 tests, all pass except 3 disabled.
  • DefaultLib (clean clone of main, rebuilt with this compiler): tests.ps1 passes under own, rc, gc and none.
  • Not run: Linux/WSL.

🤖 Generated with Claude Code

ASDAlexander77 and others added 4 commits November 14, 2026 00:59
…oolean assignment errors

- -mm=own: an object a `const` names, captured by copy by a closure that escapes, is the closure's
  from the capture on; a later use is "captured by a closure that escapes, and is still used here".
  A closure stored once into a field of the object it captures is a back-reference and borrows it.
- `(() => T) | null` fields and locals: the closure is the function value itself.
- Assigning a boolean to a number or a string, or a number to a boolean, is an error, as in tsc.

The CMake registrations and the shared ownership-facts helpers these use are in the next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…TSLANG 47, 48)

TSLANG 47 (-mm=own): `let r = this.cached; if (!r) { r = new Q(); this.cached = r; } return r;`
- Before the facts, a read of a local where it provably holds what a field holds is read as the
  field (OwnershipSignatureFieldLocals.cpp): a local declared from the field, or given a value just
  moved into it. The local's first value, read by nothing then, is dropped.
- A store into a field tested empty on the way (`!f`, `f == null`, `f === undefined`, the else of
  `if (f)`) frees nothing (fillsEmptyField). The signature pass decides each fill once, judging a
  call in between by facts that count every fill as a drop, and pins it on the release.
- Diagnostics name a folded const under --di; "another variable" is gone.

TSLANG 48: a method can be @Final. It can't be overridden or be abstract, a call of it runs it
(directly, or through the vtable with the one callee known when imported), and the -shared
declaration printer writes it. Under own, a borrow ended by a call of an overridable method gets a
note naming the method and pointing at @Final.

Also: dropsInBody's `!releasesNothing(r) && a || b` counted a store into a number field as a drop.

Item 49 (three reduced own errors from powder_sandbox) is filed open in TSLANG_ISSUES.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Release, off by default)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t, a field moved into another (TSLANG 49)

- A value moved on some ways only is fine when, on every other way to its release, a branch tested it
  empty (`if (l) { this.f = l; }`): its release there frees nothing (emptyWhereNotMoved).
- The result of a virtual call another module may override is the caller's when no method of the
  family says it borrows and each one defined here returns its own (familyResultsFresh). Under own,
  an override may not say it borrows when the method it overrides does not (checkOverrideResultFacts).
- `this.other = this.level; this.level = null;` is a move: the source field refilled right after the
  taker, with only reads, constants and rc's counts of `null` between (spec 77 extended).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from fix-fn-or-null-and-boolean-assign to main November 14, 2026 01:33
ASDAlexander77 and others added 2 commits November 14, 2026 01:34
…nto fix-own-item-49

# Conflicts:
#	TSLANG_ISSUES.md
#	tslang/lib/TypeScript/OwnershipFacts.h
#	tslang/lib/TypeScript/OwnershipSignaturePass.cpp
#	tslang/lib/TypeScript/OwnershipSignaturePass.h
#	tslang/test/tester/CMakeLists.txt
…paque-first closures (TSLANG 48, 29)

- @Final on a get/set accessor works as on a method: a direct call, the override error ("accessor 'x'
  overrides the @Final accessor of 'Base'"), the declaration printer writes it, and the own note for
  an overridable call names an accessor's slot too.
- TSLANG 29: a function value (a const of function type, a callback parameter) passed to a @cdecl
  callback parameter is checked at run time: a closure throws "a closure or a bound method can't be
  used as a plain function pointer" instead of being run later without its captures. A function named
  directly is not checked.
- A capturing arrow can be assigned to `(a: Opaque, b: Opaque) => s32`: the function type match tries
  the parameters as they are before taking leading Opaque/object parameters for a receiver.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77 ASDAlexander77 changed the title own: nullable local moved when not null, virtual call results, field-to-field moves (TSLANG 49) own: TSLANG 49; @final accessors; C function pointer checks (TSLANG 29) Nov 14, 2026
@ASDAlexander77
ASDAlexander77 merged commit 3570053 into main Nov 14, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-own-item-49 branch November 14, 2026 10:37
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