Standard way to supply hints to branches
Manu
turkeyman at gmail.com
Sat Aug 24 01:26:43 UTC 2024
On Sat, 24 Aug 2024 at 10:11, Nicholas Wilson via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:
> On Friday, 23 August 2024 at 20:08:53 UTC, kinke wrote:
> > I suggest adding a `core.builtins.expect()` intrinsic to
> > standardize the existing LDC and GDC intrinsics, adding a dummy
> > (`pragma(inline, true)`!) identity function for DMD. No need
> > for introducing statement-level UDAs, other compiler magic,
> > complicating language/spec etc. `core.attribute` already does
> > this for magic UDAs.
>
> https://github.com/dlang/dmd/pull/16807
Thanks Nick! That's good to have.
That said, I still feel using expect() is pretty invasive.
If you have a bunch of existing code, marking it up is a fiddly
transformation, and hurts readability:
if (fails_validation)
return -1;
if (check_for_lilely_case)
return v;
return calculate(v);
// invasive and pretty severely damages readibility
if (expect(fails_validation, false))
return -1;
if (expect(check_for_lilely_case, true))
return v;
return calculate(v);
// paste token on end of line, doesn't really affect readibility at all
if (fails_validation) @unlikely
return -1;
if (check_for_lilely_case) @likely
return v;
return calculate(v);
An attribute attaching to control statements would definitely be nice for
my money...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20240824/e0424f9e/attachment.htm>
More information about the Digitalmars-d
mailing list