<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 24 Aug 2024 at 10:11, Nicholas Wilson via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Friday, 23 August 2024 at 20:08:53 UTC, kinke wrote:<br>
> I suggest adding a `core.builtins.expect()` intrinsic to <br>
> standardize the existing LDC and GDC intrinsics, adding a dummy <br>
> (`pragma(inline, true)`!) identity function for DMD. No need <br>
> for introducing statement-level UDAs, other compiler magic, <br>
> complicating language/spec etc. `core.attribute` already does <br>
> this for magic UDAs.<br>
<br>
<a href="https://github.com/dlang/dmd/pull/16807" rel="noreferrer" target="_blank">https://github.com/dlang/dmd/pull/16807</a></blockquote><div><br></div><div>Thanks Nick! That's good to have.</div><div><br></div><div>That said, I still feel using expect() is pretty invasive.</div><div>If you have a bunch of existing code, marking it up is a fiddly transformation, and hurts readability:</div><div><br></div><div>if (fails_validation)</div><div>  return -1;</div><div>if (check_for_lilely_case)</div><div>  return v;</div><div>return calculate(v);</div><div><br></div><div><br></div><div>// invasive and pretty severely damages readibility<br></div><div>
<div>if (expect(fails_validation, false))</div><div>  return -1;</div><div>if (expect(check_for_lilely_case, true))</div><div>  return v;</div><div>return calculate(v);</div><div><br></div><div><br></div><div>// paste token on end of line, doesn't really affect readibility at all<br></div><div>
<div>
<div>if (fails_validation) @unlikely<br></div><div>  return -1;</div><div>if (check_for_lilely_case) <a class="gmail_plusreply" id="plusReplyChip-1">@likely</a><br></div><div>  return v;</div><div>return calculate(v);</div><div><br></div>

</div>

</div>

</div><div><br></div><div>An attribute attaching to control statements would definitely be nice for my money...<br></div></div></div>