[Issue 3921] Compile time evaluation requirements not well-specified

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 11 15:21:51 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3921



--- Comment #2 from Jerry Quinn <jlquinn at optonline.net> 2010-03-11 15:21:50 PST ---
(In reply to comment #1)
> Quoting the spec:
> 
> "In order to be executed at compile time, the function must appear in a context
> where it must be so executed"
> 
> Note the word MUST. I don't see anything in the spec to indicate that it is
> optional.

No, the language above says that the correct function context is necessary, not
sufficient.  CTFE won't succeed unless the condition is met.  It definitely
does not say that the compiler is required to try.

> It's pretty simple actually -- if the compiler *needs* a constant,
> and it sees an expression, it attempts to constant-fold that expression. If the
> expression contains a function call, CTFE will be used. CTFE is not used in any
> other context - it never happens unless requested.

In principle, it's simple.  But typically constant folding is an optimization,
not a requirement in languages, so D is relatively unique in this regard.  It's
important for the spec to explicitly say so rather than imply through example.


> > Other writing I've seen suggests that CTFE is an optimization, not a language
> requirement.
> 
> Can you remember where you saw that writing, or got that impression? If it's
> anywhere public, we need to get rid of it, since it is not correct.

I can't find what I thought I read about.  So it's possible I hallucinated that
and it's a false impression.  I still think that the fact that the compiler is
guaranteed to execute expressions and functions at compile time has to be more
clearly stated, though.  Also, the rules for expressions to be executed at
compile time should also be explicitly stated, separate from the function
rules.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list