On Phobos GC hunt

Johannes Pfau via Digitalmars-d digitalmars-d at puremagic.com
Thu Oct 9 02:43:04 PDT 2014


Am Wed, 08 Oct 2014 13:01:43 -0700
schrieb Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:

> On 10/8/14, 1:13 AM, Johannes Pfau wrote:
> >
> > Code in if(__ctfe) blocks could be (and should be) allowed:
> > https://github.com/D-Programming-Language/dmd/pull/3572
> >
> > But if you have got a normal function (string generateMixin()) the
> > compiler can't really know that it's only used at compile time. And
> > if it's not a template the code using the GC will be compiled, even
> > if it's never called. This might be enough to get undefined symbol
> > errors if you don't have an GC, so the error messages are kinda
> > valid.
> 
> That's a bummer. Can we get the compiler to remove the "if (__ctfe)" 
> code after semantic checking?
> 
> Andrei

I think you misunderstood, code in if(__ctfe) is already removed, it
never gets into the binary. But the @nogc/-vgc checks still complain
about GC allocations in if(__ctfe). This is easy to fix, but as ctfe is
a runtime variable you could also do (if(__ctfe || dice() == 1 )) and
the decision about complex cases stopped pull #3572.

What I meant is that the compiler can't know that this code is
CTFE-only and -vgc must complain:

string generateMixin(string a)
{return "int " ~ a ~ ";";}
mixin(generateMixin());

But there are workarounds:
http://dpaste.dzfl.pl/e689585c0a95
(Note that dead-code elimination should be able to remove all functions
marked as private)


More information about the Digitalmars-d mailing list