www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7428] New: regression (DMD 2.058head) ICE on slightly convoluted setup including closures

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

           Summary: regression (DMD 2.058head) ICE on slightly convoluted
                    setup including closures
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch


--- Comment #0 from timon.gehr gmx.ch 2012-02-02 15:45:57 PST ---
The following code compiles and runs fine with DMD 2.057, but fails on DMD
2.058head with

Internal error: toir.c 178

// import std.stdio, std.algorithm, std.range;
auto Y(R,T...)(R delegate(T) delegate (R delegate(T)) f){
    struct F{R delegate(F,T) f;};
    return (R delegate(T)delegate(F) a){return a(F((F b,T i){return
f(a(b))(i);}));
    }((F b){return (T n){return b.f(b,n);};});
}


void main(){
    auto factorial=Y((long delegate(long) self){return (long i){return
i?self(i-1)*i:1;};});
    auto fibonacci=Y((int delegate(int) self){return (int i){return
i<2?i:self(i-1)+self(i-2);};});
    auto ackermann=Y((long delegate(long,long) self){return (long n,long
m){return n?m?self(n-1,self(n,m-1)):self(n-1,1):m+1;};});
    // writeln(map!factorial(iota(0,20)));
    // writeln(map!fibonacci(iota(0,20)));
    // writeln(map!((a){return ackermann(a%4,a/4);})(iota(0,20)));
}

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


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #1 from Walter Bright <bugzilla digitalmars.com> 2012-02-04
18:41:52 PST ---
I simplified this a bit (still hurts my brain, though). The bug is tripped when
a lambda is used rather than the equivalent nested function:

alias long delegate(long) dg_t;

void Y(dg_t delegate (dg_t) y)
{
    struct F { long delegate(F) f; };

  version (all)
  { // generates error
    (dg_t delegate(F) a){return a(F((F b){return y(a(b))(1);})); }
    ((F b){return (long n){return b.f(b);};});
  }
  else
  {
    auto abc(dg_t delegate(F) a)
    {
        return a(F((F b){return y(a(b))(1);}));
    }

    abc((F b){return (long n){return b.f(b);};});
  }
}


void main(){
    auto foo(dg_t self)
    {
        auto bar(long i) { return self(1); }
        return &bar;
    }

    Y(&foo);
}

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



--- Comment #2 from github-bugzilla puremagic.com 2012-02-04 23:44:16 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/8b8abab85a916153211c902aa41b23786cda6062
fix Issue 7428 - regression (DMD 2.058head) ICE on slightly convoluted setup
including closures

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


Walter Bright <bugzilla digitalmars.com> changed:

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


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