Skip to content

TSLANG 212: generic class for a constructor type, own instanceof narrowing and forward captures, constructor interfaces, rc leak of calls through function values - #1046

Merged
ASDAlexander77 merged 3 commits into
mainfrom
leftovers-1127b
Nov 27, 2026
Merged

ASDAlexander77 merged 3 commits into
mainfrom
leftovers-1127b

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Leftovers from 211's triage (TSLANG 212), plus a leak found along the way. It affected every call through a function value under -mm=rc.

Fixed

  • 132. A generic class given for a constructor type (fruitFactory1(Banana) for new (...args: any[]) => TFruit) failed with "Can't find class Banana". Its type arguments now come from the constructor type's parameters. A rest parameter's element type goes to each constructor parameter the others don't reach, including the constructor's own rest, so any gives Banana<any>, as in TypeScript. The tsc test contextualSignatureInstantiation4 compiles.
  • 164, under -mm=own. An interface narrowed to a class by instanceof (v: IA or IA | IB) failed with "'v' is a parameter, kept here". The narrowed value is now the object the interface holds, a borrow like the interface itself. 00union_interfaces_instanceof.ts now runs under own as well.
  • instanceof on a generic class. v instanceof G narrowed to the generic class itself. For an interface v that crashed the compiler; for a union it failed with "Can't resolve property". It now narrows a union to the members that are a G<T> (or derive from one), and otherwise doesn't narrow.
  • 152, under -mm=own. A record's strings spread into a dictionary, or given to Object.assign, failed with "a value that borrows a field cannot be stored". The strings are now copied. A literal given to Object.assign goes into a local of its own, which releases what it holds.
  • 144, under -mm=own. A const read by a function declared before it (const f = () => g(); const g = () => 10;) failed with "'g' is captured by a closure, but -mm=own cannot tell who owns its value". The variable now owns the value its declaration gives it. A const initialized with a borrow (const q = p) is still refused, as before.
  • 191. An array of a union asserted as an array of some of its members (x.slice(1) as readonly string[], tsc sliceResultCast) failed at lowering with no location. It is now converted element by element into a new array, but only for an explicit as or <T> assertion of a union that carries a tag. An implicit conversion (const s: string[] = m), which TypeScript refuses, fails as before.
  • 139. A class given to an interface whose only member is a construct signature (interface PtCtor { new (x: number): Pt }, const c: Constructor<A> = A) is now accepted. Before, it was TSLANG 204's error, which only replaced an internal error. An interface with other members as well is still refused, and class_itself_interface_error.ts now tests that. Under own this is still refused, as it already was for a construct signature in a type literal.
  • Calls of a function held in an object literal (o.make(i)). The call now names its callee, so its result is released. It leaked under rc and own.

Leak in the DefaultLib (DefaultLib #122)

  • DefaultLib Bug fixes - this scope for params #108 added Temporal.Now without @owned. Its functions were the only heap results in the library the compiler couldn't classify.
  • One such function is enough to turn off the rule that a call through a function value hands its result over owned.
  • So since 11-19, under rc, every program linking the library leaked the result of every callback call, object-literal method call and interface method backed by a function field.
  • Leak probes went from 129 MB back to 33 MB at 2M calls.

Not done (recorded in TSLANG_ISSUES 212)

  • Under own, an interface method backed by an object literal's function field still leaks its result.
  • Under rc, new c(i) through a type literal's construct signature crashes at run time. It did before this change too.
  • Several own refusals found along the way.
  • The remaining triage items and the two design questions (overloads in declared functions and classes).

Checks

  • Windows ctest: 9942/9942. After the last two changes to the 191 conversion (only for a union that carries a tag, only when asserted), a 916-test slice covering casts, arrays, tuples, the 2xx tests and the ownership verifier passed too.
  • tsc compiler-tests sweep: 3711 pass against the 3710 baseline. contextualSignatureInstantiation4 now passes, and no test went from pass to fail.
  • Linux (WSL): the 207–212 tests pass with release and debug programs (77/77 each).
  • DefaultLib, rebuilt with this compiler (with linux fixes #122, now merged): the release tests pass in all four models (compile and JIT). The tests not run are the ones each model skips by design.
  • Leak probes, 200k vs 2M iterations, all flat at about 33 MB:
    • own: 132, 164, 152, 144, 191 shapes and o.make(i).
    • rc: an object literal's functions that return a borrowed argument or its field run correctly (no over-release). Under own they are refused at compile time.
    • rc: 139 and the field-call shapes, with the DefaultLib fix.

🤖 Generated with Claude Code

ASDAlexander77 and others added 3 commits November 27, 2026 08:40
…arrowing borrows + generic instanceof (164), own record strings into dictionaries (152), own forward-captured consts (144), array of a union as members (191), class to a constructor interface (139), object literal function callee named

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ree one keeps its cast)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…); an implicit conversion stays as it was

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 117b595 into main Nov 27, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the leftovers-1127b branch November 27, 2026 09:51
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