Repository navigation
own: TSLANG 49; @final accessors; C function pointer checks (TSLANG 29) - #847
Merged
Merged
Conversation
…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>
…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>
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.
Three
-mm=ownerrors 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 athisresult). 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 ofnullin between. A call in between is still an error.Also in this PR
@finalaccessors (from 48):@finalon 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.constof function type, or a callback parameter) passed to a@cdeclcallback 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, anatexithandler segfaulted at exit. A function named directly isn't checked.(a: Opaque, b: Opaque) => s32. The type match used to take leadingOpaqueparameters for a receiver and refuse it; it now tries the parameters as they are first (MLIRTypeHelper.h).00tslang_issue_29_function_value.ts(skipped on wasm, since it usesatexit),00tslang_issue_29_comparator.ts, andfinal_accessor_override_error.ts;00tslang_issue_48.tsnow covers a@finalgetter.Tests
00tslang_issue_49.ts(every model), plusown_err_moved_when_tested_other.ts,own_err_field_moved_call_between.tsandown_err_override_lends.ts.tests.ps1passes under own, rc, gc and none.🤖 Generated with Claude Code