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



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




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



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




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



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



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





 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



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




 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