@ctfeonly

Iain Buclaw ibuclaw at gdcproject.org
Thu Dec 7 22:29:09 UTC 2017


On 7 December 2017 at 03:09, lobo via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Thursday, 7 December 2017 at 01:21:11 UTC, Nicholas Wilson wrote:
>>
>> I'd like to add an attribute to indicate that the annotated function is
>> only available at compile time so that in cases where the operation is
>> invalid at runtime (strings and concatenation on a GPU for instance) but the
>> result is only used at compile time (for a mixin) the compiler is free to
>> not codegen that function.
>>
>> I can add this to LDC pretty easily, but does anyone else have a use for
>> this (e.g. shrinking binary sizes for mixin heavy codebases) and would
>> benefit having this as a standard thing?
>
>
> Shouldn't the linker do this already?
>
> Once the compiler has CTFE'd the function any call in the code should be
> replaced with the function evaluation. The linker should then drop the code
> out of the binary because it really is dead code.
>

It should be possible to add heuristics for this (mark a function as
being instantiated and only used at compile-time).  It just doesn't
exist yet.

As for normal functions, regardless of protection, they will always be
compiled as a function visible outside the CU.  You're either going to
rely on LTO support in the compiler, kindly request that DIP45 be
given another thought, or write a new DIP that considers another way
to control symbol visibility.  But I wouldn't hold my breath on
anything happening soon.


More information about the Digitalmars-d mailing list