Repository navigation
Object literal into an interface union; fewer-parameter callback fixes; design notes - #738
Merged
Merged
Conversation
`"swim" in a` for `a: Fish | Bird` was "not supported", and `a instanceof Fish` was always false (the types compared, `Fish | Bird` against `Fish`). Every interface's union tag reads "interface", so nothing at run time said which interface the union held. Which members have the key, or are the interface, is decided when compiling: every one or none folds to a constant. Otherwise the union's tag is asked: an interface's descriptor now has an id of its name in TYPE_DESCR_LAYOUT, and ts.IsTypeTagOf compares a tag's with a type's. `"k" in a` narrows `a` to the members with the key (and the `else` to the others), as `instanceof` already narrowed. Test: 00in_interface_union (compile and JIT; gc, rc, none, own). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`move({ swim: () => "s" })` for `move(a: Fish | Bird)` failed with
"'ts.Cast' op type [...] can't be stored in [...]", and so did a class
object. castToTaggedUnionType now casts such a value to the first
interface member whose every required field and method it has
(interfaceMemberFitting, by name, as `"k" in v` asks), and the union's
tag says which (`"swim" in a`, #737).
Test: 00interface_union_literal (compile and JIT; gc, rc, none, own).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two bugs in the fewer-parameters thunk (#733, #735), found by giving the default library's array callbacks an index parameter: - A closure given for a generic callback `(v: T, i: number) => void` had its captures paired with `T` (`string | Reference<{...}>`): its type is its function bound over its captures. Inference now drops the bound first parameter, of the closure's type and of the arrow type rebuilt. - Under -mm=own a heap result the thunk hands on (a string a `map` callback builds) was "a second reference": the thunk's call is now marked owned and consumed by its return, as `return f(x)` is. Test: 00closure_fewer_parameters (a generic callback, a string result). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- docs/generic-interface-methods-design.md: generic methods in interfaces (rejected today) and in class hierarchies (not virtual: an override is never reached through a base reference, silently). Options: erased `any` slots, a closed-world table, dictionary passing; recommends an error for overridden generic class methods now, erased slots later. - docs/classes-as-values-design.md: `typeof A` values (ts.ClassRef has no value lowering) and local classes that capture (members lifted with an extra parameter nobody passes). Recommends the vtable as the class value with a `.constructor` slot, and the captures in a hidden `.captured` field of the instance. - docs/tuple-object-shape-ambiguity-design.md: re-checked, still open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Oct 31, 2026
…ttent tslang crash) (#764) * A generic callback's T no longer takes in the closure's captures An arrow that reads `this`, given to a generic function in a class method (`this.particles.filter((p) => p.d > this.lifetime)`), is rebuilt while the method's return type is discovered, and its type then has the captures ahead of its parameters. Inference dropped that input only when the arrow was already bound (#738), not on this first pass, where it is still a bare generic reference: `T` became `Element | captures`. With the element's class declared later in the file that failed every time ("cast from array type ... to array type '!ts.array<!ts.union<..., !ts.ref<!ts.tuple<{"this",...'"); with the default library's Array.filter the union's members came in an order of their types' addresses, and when the captures came first the arrow's parameter was taken for them: tslang crashed (0xC0000005; "Invalid index!" in a debug build) in about one run in four on native_ts_graphics' core/ray_tracing_extended_scene.ts, and pre-alpha111's own build too. The type helper now says whether the type it built has captures first, and inference drops them in either case. Test: tests/00generic_callback_closure_late_class.ts (gc, and rc/none through the corpus). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Anonymous function names hash the file's name, not its attribute's address hash_value of the location's StringAttr hashes the attribute's storage, so an arrow's name (`..afL89C49FH<hash>`) was different in every run. It is now xxh3 of the file name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Register the llvm dialect's inliner interface (debug JIT failed its promise check) The llvm dialect promises a DialectInlinerInterface that only registerAllDialects provides. A debug (assertions) tslang ended every --emit=jit with "checking for an interface (`mlir::DialectInlinerInterface`) that was promised by dialect 'llvm' but never implemented". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * .gitignore: every JIT cache folder (__jit*/), the debug one (__jit_dbg_gc) too Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- 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.
Stacked on #737 (
in/instanceofon interface unions). After #737 merges, the base moves tomain.1. An object literal or class object passed to a union of interfaces. For example,
move({ swim: () => "s" })ormove(new Crow())formove(a: Fish | Bird)."swim" in aworks on it (inandinstanceofon a union of interfaces #737).00interface_union_literal.2. Two bugs in the fewer-parameters wrapper (#733, #735). Giving the default library's array callbacks an index parameter turned these up (companion DefaultLib PR).
(v: T, i: number) => voidhad its captures paired withT, soTcame out asstring | Reference<...>. Inference now skips the parameter that holds the captures.return f(x).00closure_fewer_parameters, extended.3. Design notes for later.
docs/generic-interface-methods-design.mdcovers generic methods in interfaces, and the silent bug that generic class methods aren't virtual: an override is never reached through a base-class reference.docs/classes-as-values-design.mdcovers class values (typeof A) and local classes that capture variables.docs/tuple-object-shape-ambiguity-design.mdis re-checked and still open.Validation: ctest 6333/6333. DefaultLib, with its companion change, release JIT: gc 182/182, rc and none 181 (1 skipped), own 171 (11 skipped).
🤖 Generated with Claude Code