How can we make it easier to experiment with the compiler?

Basile B. b2.temp at gmx.com
Thu May 27 08:50:32 UTC 2021


On Thursday, 27 May 2021 at 08:41:49 UTC, Walter Bright wrote:
> On 5/27/2021 12:14 AM, Mathias LANG wrote:
>> Now to talk about what can be done to improve the DMD 
>> codebase, it's fairly obvious: ELIMINATE ALL CASTS. But not by 
>> replacing `cast(XXX)e` with `e.isXXX()`, but by actually using 
>> proper encapsulation.
>> 
>> What I mean is that instead of switching on types, like this:
>> ```D
>> if (auto tf = t.isTypeFunction())
>>      (cast(FunctionDeclaration)t.sym).something();
>> else if (auto td = t.isTypeDelegate())
>> (cast(FunctionDeclaration)(cast(TypeFunction)t).sym).something();
>> else
>>      // Something else
>> ```
>
> The isXXX() functions also make for safe casting.

And this is actually the only way to dyncast cast nodes as DMD 
AST is extern(C++)... But TBH I think that all the isXXX family 
of functions should be free functions, not members funcs. All 
these isXXX calls are virtuals but they dont need to (although 
often devirtualized).




More information about the Digitalmars-d mailing list