Skip to content

TSLANG 215: Record<string, T>, unions of tuples (cast fills missing elements), rc/own leaks, own reads @owned - #1051

Merged
ASDAlexander77 merged 11 commits into
mainfrom
leftovers-1127e
Nov 27, 2026
Merged

ASDAlexander77 merged 11 commits into
mainfrom
leftovers-1127e

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Leftovers of 214 (TSLANG 215): Record<string, T>, unions of tuples, three leaks, and -mm=own now reads @owned as rc does. Two user rulings from 11-27 are implemented here.

Fixed

  • Record<string, T> was an object with no fields, in every model. The literal given to it lost its fields, Object.keys gave none, and r["a"] read nothing.
    • It is now { [key: string]: T }, a dictionary of T.
    • That holds for the built-in Record and for a mapped type { [P in K]: T } of K = string (the default library's Record).
  • Unions of tuples ([number, string] | [number, string, string]):
    • A cast to one member failed with "failed statement" and nothing else. Now the member the value holds is cast.
    • USER RULING 11-27: the elements a shorter member lacks are filled. TypeScript would read undefined there.
      • strict null checks: "" for a string, 0 for a number, false for a boolean, undefined where the type admits it.
      • without strict null checks: null for a string, a class, an interface or an array.
      • An element with nothing to fill it makes the cast a compile error: an object literal's type, or under strict null checks an array, class or interface.
    • x[1] at a constant index every member has, x[i] at a run-time index and for (const e of x) now work. Before, they gave "access expression is not applicable".
    • Members of Array (x.slice(1), join, forEach, map) and [...x] use the member the value holds. Before, they read the value as the first member, so a [0, "c"] joined as "0,c,null".
    • x[1] = v stays refused, with a message that says why: the element is read out of a copy of the member.
  • A union of shapes or tuples cast to a member leaked an any box, about 40 bytes a cast under rc and own. The union's own tag is read now.
  • rc: an array made only to call a method on it leaked, about 100 bytes a call, also with the compiler before 213. Examples: ([i, s] as ...).slice(1), t.slice(1) of a tuple, [...x].
  • own: a spread literal given to a call leaked, about 100 bytes a call. Examples: cnt(...xs), and the default library's join ("".concat(...parts)).
  • own: a tuple read from a variable and used as an array (t.slice(1) of t: [number, string]) was refused. Its strings are now copied for the array.
  • own: no result of a default-library function was ever given back, not even one held in a const. USER RULING 11-27: own reads rc's attributes the same way.
    • Measured leaks per call: s.toUpperCase() 16 bytes, s.split() 107, toFixed 64, JSON.parse about 800.
    • own now reads @owned, the only rc-only attribute, in two places:
      • OwnedReturnConsumptionPass gives back a result nothing takes.
      • The ownership signature pass marks such calls as handing back a new value, so value.get("k").asString() still compiles.
    • Exception: a declaration that says it lends its result (@lends, or a result type this, such as JsonValue.get or ArrayBuffer.__bytes) stays a borrow under own. Treating it as owned would free a value the object still holds. rc is unchanged.
    • Checked: every lending or borrowing public function in lib.ts has its mark in lib.d.ts. Calls through function values, callbacks and getters are flat too.
    • The default library's comments are updated in @owned: read under -mm=own as under -mm=rc (comments) TypeScriptCompilerDefaultLib#123 (comment-only, merged).
  • Record follow-ups, found by the tsc sweep:
    • A Record<string, T> result type read in another function now has its members generated: Object.keys(f()) failed with the default library.
    • T extends Record<string, X> is met by an object of any fields.
    • keyof of a dictionary is string.

Not done (recorded in TSLANG_ISSUES 215)

  • Under own, a function can't return the filled union cast whole (return <Long>x): "merged from several branches". Casting it where it is read, or into a local, works.
  • A dictionary written in a loop over an array under own (for (const it of items) out[it] = 1) is still refused. Its drop facts need to name what is under this.

Checks

  • ctest (local, on the branch before the fill rule and the Record follow-ups): 9992/9996. The 4 were 00tslang_issue_215 JIT legs, run against a test already edited for the fill rule; after it, the 215, fill, dictionary, record and keyof tests pass (317), and so do all 8 ownership-verifier shards. The last full run was stopped so CI tests the final commit.
  • tsc sweep, on the final commit: 3714 pass (214: 3713), 0 pass->fail, 2 fail->pass. The first run had found 7 Record<string, X> regressions (as a constraint, a result type, or under keyof), fixed in the last commit.
  • DefaultLib, release, all 4 models, built by this compiler: own 239, rc 248, gc 253, none 249 of 254. Every test that runs passes, the same as 214.
  • Leak probes (2M vs 8M calls, --opt=false): flat under own and rc for each case above.

Tests:

  • 00tslang_issue_215.ts (all models)
  • test-{rc,own}-owned-declarations (the IR of @owned and @lends calls)
  • tuple_union_cast_fill_error.ts
  • tuple_union_cast_fill_nonstrict.ts (--strict-null-checks=false, all models)

🤖 Generated with Claude Code

ASDAlexander77 and others added 11 commits November 27, 2026 16:00
…a mapped type of string keys)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…elements throws), indexed at a common element; a missing tuple element is an error, not a silent failure

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… own copies a tuple's strings for its array, union-of-shapes tests read the union's tag (no leaked box)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…les of elements, TSLANG_ISSUES measurements

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d literal given to a call, a union of tuples iterated and read at a run-time index

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s result excepted)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s own (a new value, not a part of what the call was given)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a shorter one lacks (user ruling); none to fill them with is a compile error

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… by any object, keyof of a dictionary is string; verifier skips the fill tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 62e50ff into main Nov 27, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the leftovers-1127e branch November 27, 2026 17:16
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