www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10586] New: DMD unable to interpret cascaded template calls at compile time

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

           Summary: DMD unable to interpret cascaded template calls at
                    compile time
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: puneet coverify.org


--- Comment #0 from Puneet Goel <puneet coverify.org> 2013-07-09 11:31:58 PDT
---
I am using latest github dmd -- 712c3e256b1198523bb8a5c49e5e08d3f8409855

Here is the minimized code for the regression. 

$ dmd -c bvec.d
foo.d(12): Error: Cannot interpret FooSize!N at compile time
foo.d(13):        while evaluating SIZE.init
foo.d(13):        while looking for match for FooParams!(1LU)
foo.d(9): Error: template instance foo.foo!1 error instantiating

I think the regression got introduced while fixing 10579.


// Regression Code starts here
private template FooParams(size_t SIZE) {
  private alias ubyte StoreT;
}

template FooSize(size_t N=1) {
  enum size_t FooSize = N;
}

enum foo!1 BIT_0   = foo!1.init;

struct foo(size_t N)  {
    enum size_t SIZE = FooSize!N;
    private alias FooParams!(SIZE).StoreT store_t;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 09 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10586


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice


--- Comment #1 from Don <clugdbug yahoo.com.au> 2013-07-10 01:40:50 PDT ---
(In reply to comment #0)
 I think the regression got introduced while fixing 10579.
No, that's unrelated. This isn't a CTFE bug, it's a bug in enums. Semantic has not yet been run on the enum initializer. My guess is that this is a forward reference issue. If you change it: struct foo(size_t N) { - enum size_t SIZE = FooSize!N; + enum size_t SIZE = 0 + FooSize!N; then you get a segfault, because the type is still NULL. My guess is that this was exposed by my "do const-folding in CTFE" patch. Previously these kinds of errors went undetected. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10586



--- Comment #2 from Don <clugdbug yahoo.com.au> 2013-07-10 02:54:12 PDT ---
Further reduced shows I'm wrong about it being enums:
------------
template FooParams(size_t K) {
  alias int X;
}

struct foo  {
    static const int SIZE = int.sizeof;
    alias FooParams!(SIZE).X Y;
}
-----------
bug.d(6): Error: Cannot interpret int at compile time
bug.d(7):        while evaluating SIZE.init
bug.d(7):        while looking for match for FooParams!(4)

---
A very difficult related case is this one:

const int Z = baz(3);
const int W = baz(2);

int baz(int k) {
    if (k == 3) return W;
    return 6;
}

static assert(Z == 6);

because it means that baz cannot be JIT-compiled. Arguably this is a circular
reference. It would be much simpler and would give better performance if we
disallowed pseudo-circular refs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 10 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10586


Kenji Hara <k.hara.pg gmail.com> changed:

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


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2013-08-25 17:44:43 PDT ---
The same regression was reported in 10669, and it was already fixed by Rainer
Schuetze in git-head.

*** This issue has been marked as a duplicate of issue 10669 ***

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