Introduce a New DRuntime Hook Lowering Pass to Unify the Logic for All Hooks

Teodor Dutu teodor.dutu at gmail.com
Thu Feb 8 15:24:15 UTC 2024


On Thursday, 8 February 2024 at 15:08:05 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> On 09/02/2024 3:58 AM, Teodor Dutu wrote:
>> Hence what I am proposing as a global solution to both a and b 
>> and also applicable to other hooks is to create another pass 
>> just for lowering, after semantic analysis has finished and 
>> has produced a definitive AST. This will provide a unified 
>> place to introduce all DRuntime lowerings, thus leading to 
>> more readable and maintainable code in the long run. 
>> Traversing the AST in this manner will hurt performance, which 
>> is why it would be enough to just store the nodes that require 
>> lowerings in an array so that this new pass just iterates this 
>> much smaller array instead of the whole AST.
>
> It might be a good idea to question if a linked list wouldn't 
> be a better solution than an array to store the nodes.
>
> It depends how often lowering has to take place. If its often 
> then the extra ram usage would be worth the linked list.

Indeed. Counting the nodes that require lowering in larger 
codebases (like phobos for example) might be useful to decide 
this. In addition, on second thought, an unordered set would be 
better suited because, in the case of const folds, the old array 
(`[1, 2]` in my example) should be removed from the container (to 
name it generically) and replaced with the folded one (`[1, 2, 
3]`).

Regardless, this is more of an implementation detail in case the 
new pass is to be introduced. The exact nature of how to store 
the expressions that require lowering can be improved once the 
general approach is decided upon.


More information about the Digitalmars-d mailing list