www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11220] New: Regression in master: XXX__lambda2 cannot access frame of function XXX

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

           Summary: Regression in master: XXX__lambda2 cannot access frame
                    of function XXX
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: deadalnix gmail.com


--- Comment #0 from deadalnix <deadalnix gmail.com> 2013-10-10 12:23:42 PDT ---
auto lex(R)(R ) {
    struct Lexer {
        int t;

         property
        auto front() {
            return t;
        }
    }

    auto lexer = Lexer();

    return lexer;
}

auto flattenMixin() {
    auto trange = lex('\0');
    trange.parsePrimaryExpression();
}

void parsePrimaryExpression(R)(R trange) {
    trange.parseAmbiguous!((parsed) {
        trange.front;
    });
}

typeof(handler(null)) parseAmbiguous(alias handler, R)(R trange) {
    return handler(trange.parsePrimaryExpression());
}

Trying to compile this with DMD from master gives
src/d/semantic/declaration.d(24): Error: function
declaration.parsePrimaryExpression!(Lexer).parsePrimaryExpression.__lambda2!(typeof(null)).__lambda2
cannot access frame of function
declaration.parsePrimaryExpression!(Lexer).parsePrimaryExpression

This used to compile (this is a reduction of actual code in SDC).

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


deadalnix <deadalnix gmail.com> changed:

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


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



--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2013-10-10 18:26:27 PDT ---
Slightly verified test case.
1. Remove UFCS in order to compile the code by using old compiler.
2. Add dummy return type 'int' to parsePrimaryExpression function.

Compilation succeeds until 2.059. but with 2.060 and later, it causes "cannot
access frame of function" error.

auto lex(R)(R ) {
    struct Lexer {
        int t;
         property
        auto front() { return t; }
    }
    auto lexer = Lexer();
    return lexer;
}

auto flattenMixin() {
    auto trange = lex('\0');
    parsePrimaryExpression(trange);
}

int parsePrimaryExpression(R)(R trange) {
    parseAmbiguous!(/*delegate*/(parsed) {
        trange.front;
    })(trange);
    return 1;
}

typeof(handler(null)) parseAmbiguous(alias handler, R)(R trange) {
    return handler(parsePrimaryExpression(trange));
}

void main() {}

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



--- Comment #2 from deadalnix <deadalnix gmail.com> 2013-10-10 18:32:06 PDT ---
This is surprising because I'm working with 2.063.2 . I guess I'm somehow being
lucky. It may be dependant on the compilation order or the way things are
spread accross modules.

Anyway, this is quite a showstopper.

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



--- Comment #3 from Walter Bright <bugzilla digitalmars.com> 2013-10-10
20:05:50 PDT ---
Even smaller test case:

struct Lexer {
    int x;
}

int parsePrimaryExpression(Lexer trange) {
    parseAmbiguous!( (parsed){ trange.x += 1; } )(trange);
    return 1;
}

typeof(handler(null)) parseAmbiguous(alias handler)(Lexer trange) {
    return handler(parsePrimaryExpression(trange));
}

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



--- Comment #4 from Walter Bright <bugzilla digitalmars.com> 2013-10-10
20:39:04 PDT ---
And smaller still:

int parsePrimaryExpression(int x) {
    parseAmbiguous!( (parsed){ x += 1; } )();
    return 1;
}

typeof(handler(1)) parseAmbiguous(alias handler)() {
    return handler(parsePrimaryExpression(1));
}

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



--- Comment #5 from Walter Bright <bugzilla digitalmars.com> 2013-10-10
20:41:53 PDT ---
The trouble is in the "typeof(handler(1))". The type is "void", but the
compiler instantiates the template "handler" along the way, and "handler" needs
a frame pointer, and doesn't have one, hence the error.

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



--- Comment #6 from Walter Bright <bugzilla digitalmars.com> 2013-10-10
21:29:11 PDT ---
If I write it this way:

int parsePrimaryExpression(int x) {
    parseAmbiguous!( (parsed){ x += 1; } )();
    return 1;
}

template parseAmbiguous(alias handler)
{
    typeof(handler(1))
    //void
    parseAmbiguous() {
        return handler(1);
    }
}

We can see that instantiating handler(1) outside the function parseAmbiguous()
is what causes the error, because it needs the frame of parseAmbiguous().

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid


--- Comment #7 from Kenji Hara <k.hara.pg gmail.com> 2013-10-10 21:36:35 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2652

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



--- Comment #8 from Walter Bright <bugzilla digitalmars.com> 2013-10-10
21:56:11 PDT ---
(In reply to comment #7)
 https://github.com/D-Programming-Language/dmd/pull/2652
It's sure a pleasure working with you, Kenji! -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11220



--- Comment #9 from deadalnix <deadalnix gmail.com> 2013-10-10 23:15:50 PDT ---
(In reply to comment #7)
 https://github.com/D-Programming-Language/dmd/pull/2652
Awesome ! You really impress me Kenji ! Sadly I know have dmd: struct.c:876: virtual void StructDeclaration::semantic(Scope*): Assertion `type->ty != Tstruct || ((TypeStruct *)type)->sym == this' failed. I'll try to reduce that new error to something manageable. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11220



--- Comment #10 from Kenji Hara <k.hara.pg gmail.com> 2013-10-10 23:42:57 PDT
---
(In reply to comment #9)
 (In reply to comment #7)
 https://github.com/D-Programming-Language/dmd/pull/2652
Awesome ! You really impress me Kenji ! Sadly I know have dmd: struct.c:876: virtual void StructDeclaration::semantic(Scope*): Assertion `type->ty != Tstruct || ((TypeStruct *)type)->sym == this' failed. I'll try to reduce that new error to something manageable.
Right now, I fixed bug 11075 by merging Walter's PR. Could you try again with the current git head? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11220



--- Comment #11 from deadalnix <deadalnix gmail.com> 2013-10-11 00:21:00 PDT ---
(In reply to comment #10)
 (In reply to comment #9)
 (In reply to comment #7)
 https://github.com/D-Programming-Language/dmd/pull/2652
Awesome ! You really impress me Kenji ! Sadly I know have dmd: struct.c:876: virtual void StructDeclaration::semantic(Scope*): Assertion `type->ty != Tstruct || ((TypeStruct *)type)->sym == this' failed. I'll try to reduce that new error to something manageable.
Right now, I fixed bug 11075 by merging Walter's PR. Could you try again with the current git head?
Ok, I did some digging, and it turns out that this is another regression, completely unrelated to this problem. Awesome work Kenji ! You can close that one. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 11 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11220



--- Comment #12 from github-bugzilla puremagic.com 2013-10-11 11:40:54 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b83b82f635bc6f4f59f63bf2273de0923841cb65
fix Issue 11220 - XXX__lambda2 cannot access frame of function XXX

https://github.com/D-Programming-Language/dmd/commit/2df10899d4ae364abc42e9dd611b6982b2bb52fc
Merge pull request #2652 from 9rnsr/fix11220

[REG2.060] Issue 11220 - XXX__lambda2 cannot access frame of function XXX

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


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: -------
Oct 11 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11220


deadalnix <deadalnix gmail.com> changed:

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


--- Comment #13 from deadalnix <deadalnix gmail.com> 2013-10-18 19:00:42 PDT ---
I reoppen as, sadly, this one is back in master.

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


deadalnix <deadalnix gmail.com> changed:

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


--- Comment #14 from deadalnix <deadalnix gmail.com> 2013-10-18 19:07:49 PDT ---
(In reply to comment #13)
 I reoppen as, sadly, this one is back in master.
And reclose because I messed up my dmd repo, and it is really closed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 18 2013