Standard way to supply hints to branches

IchorDev zxinsworld at gmail.com
Sat Aug 24 11:41:03 UTC 2024


On Saturday, 24 August 2024 at 09:11:34 UTC, user1234 wrote:
> On Saturday, 24 August 2024 at 08:06:21 UTC, IchorDev wrote:
>> I think everyone in this thread can agree that we need a 
>> compiler-agnostic solution for changing the presumed hot-path, 
>> and one that doesn’t require rewriting existing code more than 
>> just adding on one word. For example, `if((x == 
>> y).expect(false)){}` makes it a pain to rewrite existing 
>> `if`s, where `@unlikely if(x == y) {}` is easy.
>
> You also have the `pragma` option. I think that would be more 
> adequate as not every vendor has to support it. In other words 
> "dmd can just ignore it". Bonus: pragma can be attached to 
> statements, that's not the case of attributes.

Like `pragma(likely, false)`? It’s a bit long, maybe 
`pragma(unlikely)`? It’s something I’d want to use fairly often, 
after all. Or we could just add some new grammar for adding 
special modifiers to if statements. Something like…
```d
if: unlikely(x){
   //…
}
if(!x){
   //…
}else: likely{
   //…
}
```


More information about the Digitalmars-d mailing list