Repository navigation
@cpp classes: @slot(N) makes a method a C++ virtual method in slot N - #561
Merged
Merged
Conversation
A @cppvtable class numbered its methods as vtable slots by declaration order, so a binding had to declare a placeholder for every slot it didn't call, overloads (which MSVC orders its own way) were numbered by hand, and a slot off by one called another C++ method with no error. The decorator is now @cpp, and only a method with @slot(N) is virtual: slot N of the vtable, a base class's slots counted, in any order. The slots no method names are skipped (null in a class implementing C++ methods), so a binding declares only what it calls; two methods in one slot are an error. As in C++, a method overriding a base's slot by name keeps that slot without @slot. A method without @slot isn't virtual: with a body it is TypeScript's own (a helper, not in the vtable, and it no longer makes the class an implementation of C++ methods); without one it is a C++ non-virtual method, called by the symbol @Linkname gives it, as fn(this, args) with C++'s argument extension. A bodiless method with neither @slot nor @Linkname, and an abstract one without @slot, are errors, so a forgotten @slot isn't a silent wrong call. Exported classes carry each method's @slot in their declarations. @cppvtable is an error saying it is now @cpp: an unknown decorator would have left an old binding an ordinary class. Ordinary classes are unchanged; @slot on one is an error. A non-virtual C++ method returning a struct isn't supported yet (an error). The existing tests move to @cpp with their positional slots, the ABI tests call a real non-virtual C++ method by its MSVC / Itanium mangled name and give Counter a TypeScript helper, the export/import test calls a helper across modules, and docs/cppvtable-classes.md becomes docs/cpp-classes.md. 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.
A
@cppvtableclass numbered its methods as vtable slots by declaration order, so a binding had to declare a placeholder for every slot it didn't call, overloads (which MSVC orders its own way) were numbered by hand, and a slot off by one called another C++ method with no error.The decorator is now
@cpp, and only a method with@slot(N)is virtual:@cppclass@slot(N) f(): T;f(): T;named like a base's slot@linkname("?f@C@@QEAAHH@Z") f(): T;fn(this, args)f(): T { ... }without@slot@slotnor@linkname(a forgotten@slotisn't a silent wrong call), anabstractmethod without@slot, an override's@slotnot matching its base's,@sloton an ordinary class, a non-virtual C++ method returning a struct (not supported yet).@cppvtableis an error saying it is now@cpp: an unknown decorator would have left an old binding an ordinary class.@cppclasses carry each method's@slotin their declarations.Breaking: existing
@cppvtablebindings (native_ts_graphicscore/nvrhi.ts) must move to@cpp+@slot(N)before they're built with a tslang that has this.Tests
@cpptests converted to@slotwith their positional numbers.tests/00cpp_slot.ts: out-of-order and skipped slots, a derived class, a TypeScript helper (AOT and JIT).test-jit-cppvtable-abi: calls a real non-virtual C++ method by its MSVC / Itanium mangled name;Countergets a TypeScript helper (the Itanium vtable check still sees only the C++ slots).Docs:
docs/cppvtable-classes.mdbecomesdocs/cpp-classes.md.🤖 Generated with Claude Code