Skip to content

Add __traits(vtblSymbol) and __traits(getInterfaces) - #23940

Open
TurkeyMan wants to merge 1 commit into
dlang:masterfrom
TurkeyMan:pr4_symbol_slices
Open

TurkeyMan wants to merge 1 commit into
dlang:masterfrom
TurkeyMan:pr4_symbol_slices

Conversation

@TurkeyMan

@TurkeyMan TurkeyMan commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

I'm writing alternative ClassInfo, so these traits make it possible to name the relevant symbols.
A following PR will make ClassInfo defined by the runtime rather than compiler magic.

__traits(vtblSymbol, T) is the vtbl of T as const(void*[]), and __traits(getInterfaces, T) is the Interface[] array of class or interface T as const(Interface[]), i.e. the array the compiler places right after the ClassInfo. Like __traits(initSymbol, T) they are slices of symbols whose contents are only known at link time.

CTFE now passes such slices through as opaque constants instead of erroring, so they can be stored (e.g. in a static initializer built at compile time), cast to another array type, and have their .length read; their contents can't be read.

@dkorpel dkorpel added Review:Needs Spec PR A PR updating the language specification needs to be submitted to dlang.org Review:Needs Changelog A changelog entry needs to be added to /changelog Review:Needs Approval labels Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

DMD perf check

Metric Base PR Δ
compile Phobos codegen (instr) 1,423.7 M 1,427.7 M +0.285%
All measurements
Metric Base PR Δ
compile hello.d (instr) 211.6 M 211.5 M -0.043%
compile hello.d -O -release (instr) 229.2 M 229.1 M -0.042%
compile Phobos (instr) 4,896.0 M 4,900.4 M +0.088%
compile Phobos codegen (instr) 1,423.7 M 1,427.7 M +0.285%
compile vibe.d (instr) 14,468.3 M 14,479.1 M +0.075%
dmd binary size (stripped) 8.12 MB 8.12 MB +0.05%
hello binary size (stripped) 0.72 MB 0.72 MB 0.00%
peak RSS (compile hello.d) 44.04 MB 44.25 MB +0.48%
peak RSS (compile Phobos) 613.7 MB 615.0 MB +0.22%
peak RSS (compile vibe.d) 1902 MB 1903 MB +0.04%
page faults (compile hello.d) 8,928 8,934 +0.07%
page faults (compile Phobos) 153,386 153,210 -0.11%
page faults (compile vibe.d) 476,419 476,180 -0.05%
compile dmd itself (wall) 12.3 s 12.1 s -1.54%
compile hello.d (wall) 64.8 ms 63.9 ms -1.30%
compile Phobos (wall) 1,506 ms 1,471 ms -2.33%

30a5e52 vs merge-base 10adc6c · about these metrics

@TurkeyMan
TurkeyMan force-pushed the pr4_symbol_slices branch 3 times, most recently from 5bf9dcb to 599403a Compare September 29, 2026 13:49

@thewilsonator thewilsonator left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs spec update

…symbol slices

__traits(vtblSymbol, T) is the vtbl of class T as a const(void*[]), and
__traits(getInterfaces, T) is the Interface[] array of class or interface T
as a const(Interface[]), i.e. the array the compiler places right after the
ClassInfo. Like __traits(initSymbol, T) they are slices of symbols whose
contents are only known at link time.

CTFE now passes such slices through as opaque constants instead of erroring,
so they can be stored (e.g. in a static initializer built at compile time),
cast to another array type, and have their .length read; their contents
still cannot be read.
@TurkeyMan

Copy link
Copy Markdown
Contributor Author

Oh, when did the spec get merged into DMD? What a luxury!

@TurkeyMan

Copy link
Copy Markdown
Contributor Author

It's pretty terrible that CI takes over an hour...

@Herringway

Copy link
Copy Markdown
Contributor

Terrible, but unsurprising.

@nordlow

nordlow commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

What is the application of alternative ClassInfo? Better C++ interop?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review:Needs Approval Review:Needs Changelog A changelog entry needs to be added to /changelog Review:Needs Spec PR A PR updating the language specification needs to be submitted to dlang.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants