First Draft: opUnwrapIfTrue

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Wed Mar 4 16:46:48 UTC 2026


On 04/03/2026 9:50 PM, Per Nordlöw wrote:
> On Thursday, 26 February 2026 at 13:53:41 UTC, Richard (Rikki) Andrew 
> Cattermole wrote:
>> The DIP: https://gist.github.com/ 
>> rikkimax/21242118e3bc1bf5f28024c2cdc33557
> 
> Nice.
> 
> Regarding the lowering
> 
> ```d
> if (Result!int result2 = result, result2.opCast!bool) {
>      scope(exit) result2.destroy;
>      ...
> } else {
>      result2.destroy;
> }
> ```
> 
> are
> 
> ```d
>      scope(exit) result2.destroy;
>      result2.destroy;
> ```
> 
> eagerly elided when `__traits(needsDestruction, typeof(result2))` is 
> false or are the injected the lower regardless and then later elided? 
> Just checking to make sure the lowering doesn't inject AST unneccesary 
> nodes.

I didn't add this particular bit of code, its already present and 
operational in dmd. I've tried to make the design and implementation 
very minimal, and I have succeeded at this! See PR.

It does check if dtor is needed.



More information about the dip.development mailing list