@ctfeonly
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Thu Dec 7 03:18:57 UTC 2017
On Thursday, December 07, 2017 02:09:56 lobo via Digitalmars-d 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.
As I understand it, if you're statically linking it should, but it can't
with dynamic linking - at least not right now. With the export improvements
that Martin Nowak and Benjamin Thaut want to do (where IIUC, export would
then be required for anything in a shared library to be accessible outside
it), then it would be possible, but right now, everything gets exported (at
least on all systems other than Windows), so none of it can be stripped out
as unused, since the linker doesn't know what's actually going to be used.
Executables should be in the same boat as static libraries though.
Also, I think that in some cases, stuff like ModuleInfo ends up referring to
stuff and keeping it around even though it isn't necessarily really used,
but I'm not sure.
Folks have talked about all kinds of template code and stuff being kept
around in binaries even though it was only used at compile time (e.g. stuff
like isInputRange), but I don't know how much that's actually true.
Personally, I don't care much about binary sizes. I certainly agree that
having unused symbols stripped out where possible is a good thing, but
AFAIK, it doesn't really matter for most of the stuff I do, and having a
binary be 5MiB instead of 1MiB doesn't matter much to me, much as I agree
that having the binary smaller is good. It just isn't usually enough disk
space or memory to matter much in practice. Clearly, some people care quite
a bit about that sort of thing, but I don't know how much it actually
matters in practice unless you're doing something with embedded systems.
Regardless, needing something like an attribute to tell the compiler to
strip stuff out of the binary seems like a hack to me. It may actually be
necessary in some cases, but it just feels like it should be unnecessary.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list