Skip to content

Toward an own default library: @nodrops C declarations, @final classes, five rewrites - #36

Merged
ASDAlexander77 merged 2 commits into
mainfrom
own-default-lib
Oct 19, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
own-default-lib

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Toward a default library built under -mm=own. It needs the compiler's @nodrops and @final support from ASDAlexander77/TypeScriptCompiler#611. A tslang without it ignores unknown decorators, but builds this library under gc and rc the way it did before.

lib.ts under -mm=own goes from 62 errors to 5 (release; 7 with --di). The 5 left are in matchAll, String[Symbol.iterator] and Response.constructor. Those are exported functions that keep or borrow a parameter, which needs a separate compiler decision. Own stays out of build.bat / build.sh until lib.ts compiles under own with no errors.

  • @nodrops on every C function declaration (lib.native.d.ts, lib.win32.ts, lib.linux.ts), except the GC_* ones, which can run finalizers.
  • @final on Boolean, Number, BigInt, Date, MatchIndicesResults, MatchResults, RegExp, String, Headers and Response, in lib.ts and lib.d.ts. ArrayBuffer is marked in lib.ts only, because it has no declaration.
  • ArrayBuffer: slice copies the bytes, as JavaScript's does, instead of a view that shares them. transfer copies too. [Symbol.dispose] no longer deletes: the assignment releases the bytes under rc and own, and the collector frees them under gc.
  • MatchResults.indices makes a new MatchIndicesResults each time instead of caching one in a field.
  • Headers' constructor gives set copies of the caller's strings, because set may overwrite an element of this.values.
  • HashHelpers.hashCodeAny takes the address of its parameter rather than of a local copy.

Release gc and rc builds pass tests.ps1, compiled and JIT: gc 167/167, rc 166/167 with 1 gc-only test skipped.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits October 19, 2026 01:09
… and five rewrites

lib.ts compiled under -mm=own had 62 errors; with the compiler's @nodrops support and
fixes (TypeScriptCompiler branch own-nodrops-declarations) and these changes, 14 remain,
all waiting on two compiler decisions (an exported class's methods may be overridden in
another module; an exported function cannot keep a parameter).

- Every C function declaration (lib.native.d.ts, lib.win32.ts, lib.linux.ts) is
  `@nodrops`: it destroys nothing the program owns, so a borrow of a field may be lent
  to a function that calls it. Not the GC_* ones, which can run finalizers.
- ArrayBuffer.slice copies the bytes, as JavaScript's does, instead of a view sharing
  them; transfer copies too, and [Symbol.dispose] no longer deletes (the assignment
  releases under rc and own, the collector frees under gc).
- MatchResults.indices makes a new MatchIndicesResults each time instead of caching one
  in a field it could only lend out.
- Headers' constructor gives set copies of the caller's strings.
- HashHelpers.hashCodeAny takes the address of its parameter, not of a local copy.

Release gc and rc builds pass tests.ps1 (release compile and JIT).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Boolean, Number, BigInt, Date, MatchIndicesResults, MatchResults, RegExp, String, Headers
and Response are @Final in lib.ts and lib.d.ts (ArrayBuffer in lib.ts only: it has no
declaration). Calls on them are direct (TypeScriptCompiler branch own-final-classes), so
-mm=own knows their facts: lib.ts under own goes from 14 errors to 5 (release; 17 to 7
with --di), all of them matchAll, String[Symbol.iterator] and Response.constructor, which
keep or borrow a parameter of an exported function.

The Headers constructor still copies the caller's strings, with its comment corrected: set
is a direct call now, but it may overwrite an element of this.values.

Release gc and rc builds pass tests.ps1 (compile and JIT).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 84f0894 into main Oct 19, 2026
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