DMD2 vs LDC2 inliner
Nicholas Wilson
iamthewilsonator at hotmail.com
Mon Feb 25 07:09:28 UTC 2019
On Monday, 25 February 2019 at 02:49:36 UTC, James Blachly wrote:
> Any ideas why DMD2 cannot inline this, but LDC2 has no problem
> doing so -- or suggestions for what I can do to make DMD2
> inline it?
>
> Alternatively, I could version(DigitalMars) and version(LDC),
> but AFAICT this requires me to duplicate the entire template,
> because I cannot figure out how to make the version() directive
> apply only to the pragma.
>
> Template instantiation is with a simple struct having integer
> members start and end.
>
> Thanks in advance for tips.
> ---
> pragma(inline, true)
> bool overlaps(IntervalType1, IntervalType2)(IntervalType1 int1,
> IntervalType2 int2)
Leaving aside the issue of why DMD can't handle this, the entire
reason
pragma(inline, bool) takes a bool is for it to be (potentially)
predicated.
In this case you want:
version(DigitalMars)
private enum inline_overlaps = false;
else // assuming GDC is good
private enum inline_overlaps = true;
pragma(inline, inline_overlaps)
bool overlaps(IntervalType1, IntervalType2)(IntervalType1 int1,
IntervalType2 int2)
{
return ...;
}
More information about the Digitalmars-d-learn
mailing list