Skip to content

Generic callback T no longer takes in the closure's captures (intermittent tslang crash) - #764

Merged
ASDAlexander77 merged 4 commits into
mainfrom
generic-callback-captures
Oct 31, 2026
Merged

ASDAlexander77 merged 4 commits into
mainfrom
generic-callback-captures

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

A generic callback's T took in the closure's captures (a 1-in-4 tslang crash)

this.particles.filter((particle) => ... this.lifetime) in a class method: while the method's return type is discovered, the arrow's type is rebuilt with its captures as its first input. Inference dropped that input only for an arrow already bound (#738), not on this first pass, where it is still a bare generic reference, so T became FlameParticle | captures. The union's members are ordered by their types' addresses: when the captures came first the arrow's parameter was taken for them, and tslang crashed (0xC0000005; "Invalid index!" in mlirGenFunctionParams in a debug build) in about one run in four on native_ts_graphics' core/ray_tracing_extended_scene.ts — which broke its default build at random. pre-alpha111 built locally crashes too; its release binary happened not to. instantiateSpecializedFunctionTypeHelper now reports whether the type it built has captures first, and inference drops them in either case. Scene file: 0/30 crashes (was ~8/30).

Test: tests/00generic_callback_closure_late_class.ts — its own generic keep<T>, the element class declared later in the file, which makes the bug deterministic (pre-alpha112: "cast from array type ... to array type '!ts.array<!ts.union<..., !ts.ref<!ts.tuple<{"this",...'"). gc, and rc/none through the corpus.

Also

  • Anonymous function names hash the file's name (xxh3), not the StringAttr's storage address: ..afL89C49FH<hash> was different in every run.
  • LLVM::registerInlinerInterface in createMLIRContext: a debug tslang ended every --emit=jit with "checking for an interface (mlir::DialectInlinerInterface) that was promised by dialect 'llvm' but never implemented".
  • .gitignore: __jit*/ (the debug JIT cache folder too).

Found, not fixed (pre-alpha112 has them too), each with a class declared later in the file than its use:

  • the built-in arr.filter(arrow) (--no-default-lib): "the condition has no value";
  • a field of it read in main when main also calls assert(...): "Can't resolve property 'duration' of type any" (print of the same expression works).

Release ctest: 6578/6578. native_ts_graphics default build with this compiler: complete; basic_triangle runs, also under the JIT (release and debug tslang).

🤖 Generated with Claude Code

ASDAlexander77 and others added 4 commits October 31, 2026 18:20
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>
…dress

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>
…romise 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>
…g_gc) too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit f34b9f1 into main Oct 31, 2026
2 of 3 checks passed
@ASDAlexander77
ASDAlexander77 deleted the generic-callback-captures branch October 31, 2026 19:01
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