Repository navigation
TSLANG 207/208: generic literal receivers, any to number tuples, own optional fields, rest of T | null, s32 members for interfaces, own literals to keeping callees - #1043
Merged
Conversation
…ic call's receiver (not working yet) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uples of numbers, own optional fields, rest of T | null
- takeG({ produce: () => 44 }, 1.5): the literal is typed by its parameter once the other arguments give the type
parameter; inferObjectLiteralArgumentReceivers reads its members without making them (one made then kept `() => s32`)
- <{ code: number }>a of an `any` holding { code: 7 }: layouts with s32 in place of up to three number fields are read
and converted (castAnyToTupleOfNumbers); not under -mm=own
- -mm=own: a literal leaving out an optional field of its tuple receiver (`{ cb }` for `{ disc?: false; cb }`) is made
with it, undefined, instead of converted out of its slot ("a value that borrows a field cannot be stored")
- the rest of a `T | null` (declared and assigned) is T's
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d object literals given to callees that keep them
- `const t = { produce: () => 45 }; const o: Options<number> = t` (and `read(t)`): the interface clone gives a
this-less function field that does not match the member the member's type (getInterfaceCloneFields), and the cast
adapts it, widening the s32 result (user ruling 11-26: adapt, literals stay s32). A field of a constant object is
its function, named (fewerParametersThunk), so no box: -mm=own takes it too.
- -mm=own `k.keepOne(["a" + i, i])`, `k.keepObj({ s: "b" + i, n: i })`: "this function does not own it". A literal
of new values or string constants given to a call goes into an owned local of its own (ownedLiteralArgument), as
`const t = [...]; k.keepOne(t)` does. Borrowing records, closures and literals inside `&&`/`?:` are left as they
were. 2M calls (keeping or borrowing) stay at about 5 MB.
- 00any_to_tuple.ts: the s32 case is only in 00tslang_issue_207_any.ts (the wasm own run failed on it: under own the
cast still throws).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ead on Linux) User functions are global symbols, so a program's `read` is the `read` Boehm GC calls while it starts (GC_get_nprocs in GC_init): the Linux debug exe segfaulted before main ran. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wn literals and locals in a try body
- `let t = { produce: () => 45 }; const o: Options<number> = t` (a `const` as well): the interface's slot calls the
field through its thunk, as for a closure field, and the thunk converts the s32 result to the member's number
(isResultWideningFieldFunction). The object is given as it is, with no copy and no boxed adapter, so -mm=own
takes a `let` too (it refused the box: "a value takes a second reference").
- -mm=own, directly in a `try` body: `k.keepOne(["t" + n, 0])` and `const t = ["u" + n, 1]; k.keepOne(t)` were
refused ("an object literal that holds a value it owns is moved only into a local"). The hoisted local is given
its value by a store right before its retain (slotDeclarationStore); that retain is now the literal's, as an
initializer's is (recordRetainOf). ownedLiteralArgument hoists its local there as a declared one is.
Still open (TSLANG_ISSUES 208): a move in the middle of a multi-statement try body, and a kept parameter leaked when
its callee throws before keeping it (pre-existing, class instances too).
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.
Leftovers of TSLANG 195, 196, 198 and 205 (TSLANG 207), and the two cases 207 left open (TSLANG 208).
TSLANG 207
takeG({ produce: () => 44 }, 1.5)failed with "can't assign '() => s32' to '() => number'". With the arguments the other way round,Dcame out as1.5 | s32. Now the literal is typed by its parameter once the other arguments giveD. To inferD,inferObjectLiteralArgumentReceiversreads the literal's members one by one without creating them. A member created at that stage kept the() => s32type it was first made with.anyto an object type of numbers (195).<{ code: number }>a, where theanyholds{ code: 7 }, threw "the object's fields are not those of type". Layouts with s32 in place of up to three number fields are now read and converted (castAnyToTupleOfNumbers). Not under-mm=own, where merging the values from those reads is a second reference: there the cast still throws. That case is tested in00tslang_issue_207_any.tsonly (not in00any_to_tuple.ts, which the wasm runner also runs under own).-mm=own(196).const o: { disc?: false; cb: Cb } = { cb }failed with "a value that borrows a field cannot be stored". The literal is now built with the missing optional fields set to undefined, so it already has the receiver's layout and isn't converted out of its slot.T | null(198).const { a, ...rest } = u, and the assignment form, failed with "the rest of a value of type 'null | T' can't be taken". The rest is now taken fromT, the same way the pattern's other names readT's fields.TSLANG 208
const t = { produce: () => 45 }; const o: Options<number> = t(andread(t)) failed with "field "produce" not matching type". Per the 11-26 ruling, integer literals stay s32 and the function is adapted: the interface clone gives such a field the member's type (getInterfaceCloneFields) and the cast widens the result. A field of a constant object is its function, named (fewerParametersThunk), so no box is made and-mm=ownaccepts it.-mm=own, a tuple or object literal given to a callee that keeps it.k.keepOne(["a" + i, i])andk.keepObj({ s: "b" + i, n: i })failed with "this function does not own it". A literal of new values or string constants given to a call now goes into an owned local of its own (ownedLiteralArgument), asconst t = [...]; k.keepOne(t)does. Borrowing records, closures, and literals inside&&/?:are left as they were. 2M calls, keeping or borrowing, stay at about 5 MB.Still not done (in TSLANG_ISSUES 208):
-mm=own, an object in aletcast to such an interface (its function is adapted through a box: "second reference"). Aconstobject works.-mm=own, a literal argument directly in atrybody. A declared local there is refused the same way.Tests:
00tslang_issue_207.ts,00tslang_issue_208.ts(all models),00tslang_issue_207_any.ts(gc, rc, none). Windows ctest 9893/9893.🤖 Generated with Claude Code