Repository navigation
-mm=own: @nodrops C declarations and @final classes, toward an own default library - #611
Merged
Merged
Conversation
…brary hit Toward building the default library under -mm=own (62 errors in lib.ts, now 14): - `@nodrops declare function f(...)`: a C function that destroys nothing a TypeScript caller can reach. The signature pass resolves a call to it as it resolves one to an imported own library's no-drops function, so a borrow of a field can be lent to it. A declaration had no facts, so every body that reached strncmp, boundedCopy and the like might destroy anything. - An owning local returned on more than one way out (`if (c) return r; return r;`) moves once on each: receivers no path joins are decided alone, as the receivers separated by assignments already were. - A string concatenation reads its operands into a block of its own: its result is no longer walked as the borrow (`v[i] = v[i] + s`). - `ts.Assert` only reads its message. - `return [...a]`: the spread's builder is moved out by the return, as it is moved into the `let` it is read into. Tests: own_declared_no_drops, own_return_paths, own_string_concat_element (run under own, AOT and JIT), own_err_declared_drops. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A method or accessor of a value whose static type is a @Final class is called through ThisSymbolRef, not the vtable; the receiver's finality is carried through the walk to the base classes. A method read as a value (const fn = f.m) is bound by a new ThisSymbolRef lowering. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With --di, the variable that if (r == null) narrows is recorded as a cast of the class value to null, which holds no block; it was read as a second reference to a fresh call result. Found building the default library's String.match with debug info. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The generator wrapper declaration dropped the DllExport/DllImport/IsPublic flags the class gave the method, so a public generator method was private. Through the vtable nobody noticed; a direct call on a @Final class (the default library's String[Symbol.iterator] under the JIT) found no symbol. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ses as one From the final review: a static importer of a @Final class whose base its library does not export failed to link (the inherited member has no symbol in the import library), so a member is called directly only when its class is defined in this module. And a class that fits a @Final class member by member is no longer assignable to it: the direct call would run the @Final class's body on the other class's fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It checks the IR for dllexport, which ELF does not have; the Linux CI job failed on it. 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.
Toward building the default library under
-mm=own: it had 62 ownership errors inlib.ts. With this PR and ASDAlexander77/TypeScriptCompilerDefaultLib branchown-default-lib, 5 remain (release; 7 with--di). All 5 are inmatchAll,String[Symbol.iterator]andResponse.constructor. Those are exported functions that keep or borrow a parameter, which needs a separate decision.@nodropsC declarations (f25aaf8)@nodrops declare function f(...)marks a C function that destroys nothing a TypeScript caller can reach. The ownership signature pass resolves a call to it the way it resolves an imported own library's no-drops function. Before this, every body that reachedstrncmp,boundedCopyand the like counted as "may destroy anything".if (c) return r; return r;) failed for every type. It now moves once on each path.v[i] = v[i] + s).ts.Assertonly reads its message.return [...a]now compiles.@finalclassesSpec:
tslang/docs/superpowers/specs/2026-10-19-final-classes-design.md. Plan:tslang/docs/superpowers/plans/2026-10-19-final-classes.md.@finalclass. That includes from another module, because__declskeeps@final.@final abstractand@final @cppare errors.@finalclass is called directly (ThisSymbolRef), not through the vtable. This applies only when the member's class is defined in this module. Members of imported or declared classes keep vtable calls: a static importer can't link a member of a base the library doesn't export. The vtable, interfaces andinstanceofare unchanged.@finalclass member by member is no longer assignable to it.const fn = f.m) had no lowering forThisSymbolRef.DllExport/IsPublic.--di, a cast tonull(how--direcords a variable narrowed by== null) counted as taking a reference.Tests
final/error cases.final_dispatchunder gc, rc, none and own, AOT and JIT.-sharedexport/import pair, including a@static importof a@finalclass with a non-exported base.own_final_*,own_declared_no_drops,own_return_paths,own_string_concat_element,own_null_narrowing_di.test-export-generator-methodandtest-compile-class-cast-to-final-error.own-default-lib): release gc and rc builds passtests.ps1, compiled and JIT.🤖 Generated with Claude Code