www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7815] New: Mixin template forward reference (?) regression

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

           Summary: Mixin template forward reference (?) regression
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: code klickverbot.at


--- Comment #0 from klickverbot <code klickverbot.at> 2012-04-03 10:08:27 PDT
---
DMD 2.058 accepted the following snippet, while DMD c2824d43 executes the else
branch of the static if. In there, though, instantiating the template will
(apparently) just work fine.

---
mixin template Helpers() {
  alias typeof(this) This;

  static if (is(Flags!This)) {
    Flags!This flags;
  } else {
    // DMD will happily instantiate the allegedly
    // non-existent Flags!This here. (!)
    pragma(msg, __traits(derivedMembers, Flags!This));
  }
}

template Flags(T) {
  mixin({
    string defs;
    foreach (name; __traits(derivedMembers, T)) {
        defs ~= "bool " ~ name ~ ";\n";
    }
    if (defs.length > 0) {
      return "struct Flags {" ~ defs ~ "}";
    } else {
      return "";
    }
  }());
}

struct Move {
  int a;
  mixin Helpers!();
}

enum a = Move.init.flags; // isSetFlags should exist.
---

(Note that while the above code is probably not the minimal possible example
needed to trigger the bug, it has been reduced beyond repair as far as its
original intent goes, so don't try to make sense of it in that regard.)

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



--- Comment #1 from github-bugzilla puremagic.com 2012-04-05 21:07:38 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7a81d73021c456fd546cb241f40420717d2ec365
fix Issue 7815 - Mixin template forward reference (?) regression

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 05 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7815


Walter Bright <bugzilla digitalmars.com> changed:

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


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 05 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7815


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha yahoo.com


--- Comment #2 from David Simcha <dsimcha yahoo.com> 2012-04-07 15:52:59 PDT ---
I think the fix may have only fixed certain cases of this bug.  I'm running
into another case of what looks to be the same bug using 2.059 beta 2, but I'm
still working on reducing it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 07 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7815


David Simcha <dsimcha yahoo.com> changed:

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


--- Comment #3 from David Simcha <dsimcha yahoo.com> 2012-04-07 17:22:21 PDT ---
I reduced the case where it's still failing, reopened.

enum Closure {
    Matrix
}

struct BasicMatrix {
    mixin Operand!( Closure.Matrix );
}

template Operand( Closure closure_ ) {
    alias closure_ closure;
}

struct Expression( string op_, Lhs, Rhs = void ) {
    enum lhsClosure = closureOf!Lhs;
}

template closureOf( T ) {
    enum closureOf = T.closure;
}

alias Expression!("+", BasicMatrix) Foo;


test.d(18): Error: no property 'closure' for type 'BasicMatrix'
test.d(14): Error: template instance test.closureOf!(BasicMatrix) error
instantiating
test.d(21):        instantiated from here: Expression!("+",BasicMatrix)
test.d(21): Error: template instance test.Expression!("+",BasicMatrix) error
instantiating

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 07 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7815



--- Comment #4 from Walter Bright <bugzilla digitalmars.com> 2012-04-07
18:06:42 PDT ---
Please, the original two bugs were fixed and are fixed. A new bug should
entered for new bugs, not reopening fixed ones. For next time.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 07 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7815


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|regression                  |normal


--- Comment #5 from Walter Bright <bugzilla digitalmars.com> 2012-04-07
18:18:42 PDT ---
This new case fails also on dmd 2.058, so it is not a regression.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 07 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7815



--- Comment #6 from Walter Bright <bugzilla digitalmars.com> 2012-04-07
18:19:31 PDT ---
Reduced test case:
-----------------------
enum Closure {
    Matrix
}

struct BasicMatrix {
    mixin Operand!( Closure.Matrix );
}

template Operand( Closure closure_ ) {
    alias closure_ closure;
}

alias BasicMatrix.closure Foo;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 07 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7815


David Simcha <dsimcha yahoo.com> changed:

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


--- Comment #8 from David Simcha <dsimcha yahoo.com> 2012-04-08 06:49:20 PDT ---
The fix that was just checked in fixes the test case I submitted but doesn't
fix the bug in the code that I reduced the test case from.  I'm working on
reducing another test case that still fails.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 08 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7815



--- Comment #9 from klickverbot <code klickverbot.at> 2012-04-08 10:10:43 PDT
---
The original code I reduced the test case from still doesn't work either, will
report a new bug once I managed to reduce it again.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 08 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7815



--- Comment #10 from David Simcha <dsimcha yahoo.com> 2012-04-08 11:55:35 PDT
---
Created an attachment (id=1085)
A not-very-reduced test case.

I'll try harder to reduce this later if necessary, but I don't have time right
now and every time someone reduces this bug it seems like something important
gets left out.  Here's a zip file of my mostly unreduced.  Just go into the
main directory (bug7815/) and do a dmd test.d.  This will instantiate all the
necessary templates to reproduce the bug even on 2.059 Beta 3.  Hopefully this
will be easier to reduce for someone who has a better understanding of what
changed between releases.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 08 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7815



--- Comment #11 from klickverbot <code klickverbot.at> 2012-04-08 15:13:41 PDT
---
Issue 7862 might be related to what I'm seeing.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 08 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7815



--- Comment #12 from David Simcha <dsimcha yahoo.com> 2012-04-09 07:31:57 PDT
---
Created an attachment (id=1086)
DMD 2.059 Beta 4 testcase

Here's a new test case that works around a change in Phobos that apparently
occurred between betas.  This reproduces the failure on DMD 2.059 Beta 4. 
Usage is the same as the old test case.

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Attachment #1085|0                           |1
        is obsolete|                            |


--- Comment #13 from Walter Bright <bugzilla digitalmars.com> 2012-04-10
10:19:52 PDT ---
Created an attachment (id=1088)
reduced test.d and scid/matrix.d

this replaces the files scid/matrix.d and test.d in the test case. They are
somewhat reduced.

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



--- Comment #14 from klickverbot <code klickverbot.at> 2012-04-10 22:38:19 PDT
---
Drastically reduced test case:

———
struct Expression(string op_, Lhs) {
  enum lhsClosure = closureOf!Lhs;
}

template closureOf(T) {
  static if (is(typeof({
    T x;
    x + x;
  }))) {}
  enum closureOf = 1;
}

struct BasicVector {
  void t() {
    auto r = Expression!("t", typeof(this))();
  }

  auto opBinary( string op, NewRhs )( NewRhs ) {
    return Expression!("+", typeof(this))();
  }
}
———

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



--- Comment #15 from Walter Bright <bugzilla digitalmars.com> 2012-04-11
10:40:51 PDT ---
I reduced the test case a little more:

struct Expression(int op) {
  enum lhsClosure = closureOf!();
}

template closureOf() {
  static if (is(typeof({
    BasicVector x;
    x.bar(x);
  }))) {}
  enum closureOf = 1;
}

struct BasicVector {
  void t() {
    auto r = Expression!(1)();
  }

  void bar(T)(T) {
    auto x = Expression!(2)();
  }
}

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



--- Comment #16 from Walter Bright <bugzilla digitalmars.com> 2012-04-11
10:49:07 PDT ---
Ok, here's the problem.

Attempt to compile BasicVector.
Expand Expression!(1)().
Expand closureOf!() which is needed to initialize lhsClosure.
  1. closureOf has two members 1. the static if 2. the enum closureOf
  2. in order to initialize lhsClosure, closureOf must be eponymous
therefore, we must evaluate the static if.
Evaluating the static if evaluates bar(T)(T)
bar(T)(T) evaluates Expression!(2)()
Expression!(2)() needs to eponymously expand closureOf!()

And so we wind up in a circle, hence the confusing error message.

It "worked" prior because the circular reference error was ignored.

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



--- Comment #17 from github-bugzilla puremagic.com 2012-04-11 14:43:23 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/f793ed4e3dd7b85c9a0cc703252146f0e7611dbc
better error message for Issue 7815 - Mixin template forward reference (?)
regression

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |WONTFIX


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