Named unittests and __traits(getModules)

Mike Franklin slavo5150 at yahoo.com
Mon May 20 00:55:17 UTC 2019


On Monday, 20 May 2019 at 00:14:01 UTC, Andrei Alexandrescu wrote:

> RTTI is different because it instructs the compiler to generate 
> code a specific way without a detectable action in the source 
> code. That kind of feature could be done with import + hook 
> "execute this on the importing module".

I'm not sure I fully understand this, so forgive me if I'm just 
making noise, but does the pattern in this PR give you what you 
need? https://github.com/dlang/dmd/pull/7799

The idea is to put a detectable action in the source code.  In 
the case of the PR referenced above, the detectable action is the 
existence of the `class TypeInfo` declaration.  The compiler has 
been programmed to look for that declaration, and generate code 
based on whether or not it exists.  Because the declaration 
exists in druntime's source code, users can also check for its 
existence in their source code.

Basically, the compiler is doing design-by-introspection just 
like the user.  The runtime's source code informs the compiler 
what to do rather than the other way around.

So the compiler does have a detectable action in the source code 
(i.e. the existence of `class TypeInfo`) and that same detectable 
action is available to the user as well.

Mike



More information about the Digitalmars-d mailing list