www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3556] New: version(CTFE)

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

           Summary: version(CTFE)
           Product: D
           Version: 1.050
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: cbkbbejeap mailinator.com


--- Comment #0 from Nick Sabalausky <cbkbbejeap mailinator.com> 2009-11-28
18:04:32 PST ---
Until CTFE includes all features of runtime and has 100% same semantics as
runtime (and maybe even after then), there is often a need to have separate
codepaths for ctfe and runtime. A version(CTFE) would be an improvement over
the current solution of making alternate CTFE-intended functions and using a
naming convention to distinguish.

version(CTFE)
{
    // Sacrifice speed, flexibility, or anything else
    // necessary to make this code work via CTFE.
}
else
{
    // Use proper D.
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 28 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3556



--- Comment #1 from Don <clugdbug yahoo.com.au> 2010-01-03 14:30:41 PST ---
Created an attachment (id=542)
Patch against DMD2 svn 324

Here is a patch which adds __ctfe as a 'magic variable'. It's a bool which is
true if evaluated in a function at compile-time, but false at run-time.
If evaluated outside a function, it gives a "non-constant expression" error.

Simple example:
---------
import std.stdio;

int foo() {
  if (__ctfe) return 3;  
  writefln("run-time evaluated");
  return 2;
}

static assert(foo()==3);

void main()
{
  assert(foo()==2);
}
--------

The back-end throws out the if(__ctfe){...} part (even without optimisations
turned on), so there is no runtime penalty for adding if(__ctfe) clauses.

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2010-01-11
22:05:10 PST ---
Changeset 332

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



--- Comment #3 from Walter Bright <bugzilla digitalmars.com> 2010-01-11
22:06:43 PST ---
The reason to prefer if(__ctfe) over version(CTFE) is that both code paths need
to be compiled properly, as a function could be executed both at compile and
runtime.

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


Leandro Lucarella <llucax gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |llucax gmail.com


--- Comment #4 from Leandro Lucarella <llucax gmail.com> 2010-01-13 06:21:22
PST ---
Being that D2 is close to finalization, why do you keep introducing language
identifiers starting with __. I think it's a very bad idea, as they are
historically used for implementation specific features.

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


Lars T. Kyllingstad <bugzilla kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla kyllingen.net


--- Comment #5 from Lars T. Kyllingstad <bugzilla kyllingen.net> 2010-01-13
06:35:28 PST ---
How about

  if (meta.inCTFE) { ... }

for instance? (Assuming that __traits(xxx) becomes meta.xxx, of course.)

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



--- Comment #6 from Don <clugdbug yahoo.com.au> 2010-01-13 06:55:16 PST ---
(In reply to comment #4)
 Being that D2 is close to finalization, why do you keep introducing language
 identifiers starting with __. I think it's a very bad idea, as they are
 historically used for implementation specific features.

This *is* an implementation-specific feature. The user interface is not yet determined. Note that you can already write: ----- module meta; alias __ctfe inCTFE; ----- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 13 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3556


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #7 from Walter Bright <bugzilla digitalmars.com> 2010-01-30
22:45:33 PST ---
fixed dmd 2.040

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3556


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com


--- Comment #8 from Stewart Gordon <smjg iname.com> 2010-01-31 06:16:49 PST ---
(In reply to comment #4)
 Being that D2 is close to finalization,

What are you talking about? Not even D1 is finished yet, therefore what you say is impossible. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 31 2010