www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3921] New: Compile time evaluation requirements not well-specified

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3921

           Summary: Compile time evaluation requirements not
                    well-specified
           Product: D
           Version: 2.041
          Platform: All
               URL: file:///home/jlquinn/dmd2/html/d/function.html
        OS/Version: All
            Status: NEW
          Keywords: spec
          Severity: major
          Priority: P2
         Component: www.digitalmars.com
        AssignedTo: nobody puremagic.com
        ReportedBy: jlquinn optonline.net


--- Comment #0 from Jerry Quinn <jlquinn optonline.net> 2010-03-10 04:44:19 PST
---
The language of the spec does not clearly state what a compile must be able to
evaluate at compile time.  Through example, clearly constant folding must be
done, to support mixins as shown in various examples, but the full rules of
what the D language requires to be done at compile time is not given.

Similarly, CTFE states that the compiler can execute functions at compile time
if they meet certain constraints.  However, it doesn't clearly state whether
the D language requires that these functions be executed at compile time.

Other writing I've seen suggests that CTFE is an optimization, not a language
requirement.  What exactly is required of any D compiler?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3921


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au


--- Comment #1 from Don <clugdbug yahoo.com.au> 2010-03-10 11:21:59 PST ---
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. 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.

 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 10 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3921



--- Comment #2 from Jerry Quinn <jlquinn 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: -------
Mar 11 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3921


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |INVALID


--- Comment #3 from Walter Bright <bugzilla digitalmars.com> 2012-01-23
15:41:42 PST ---
(In reply to comment #2)
 (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.
The second 'must' covers it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 23 2012