Named unittests and __traits(getModules)

Andrei Alexandrescu SeeWebsiteForEmail at erdani.com
Mon May 20 14:37:02 UTC 2019


On 5/19/19 8:55 PM, Mike Franklin wrote:
> 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.

Having the compiler detect constructs in code would work, as would 
built-in attributes such as:

@noRTTI module mymodule;

and/or

@noRTTI class BareBones { ... }

The disadvantage is that the compiler would need to be modified for each 
of these, whereas if we define and avail ourselves of powerful 
introspection, we can achieve this kind of stuff in library code.



More information about the Digitalmars-d mailing list