Bug 11220 – Regression in master: XXX__lambda2 cannot access frame of function XXX

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-10T12:23:00Z
Last change time
2013-11-21T23:16:22Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
deadalnix

Comments

Comment #0 by deadalnix — 2013-10-10T12:23:42Z
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).
Comment #1 by k.hara.pg — 2013-10-10T18:26:27Z
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() {}
Comment #2 by deadalnix — 2013-10-10T18:32:06Z
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.
Comment #3 by bugzilla — 2013-10-10T20:05:50Z
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)); }
Comment #4 by bugzilla — 2013-10-10T20:39:04Z
And smaller still: int parsePrimaryExpression(int x) { parseAmbiguous!( (parsed){ x += 1; } )(); return 1; } typeof(handler(1)) parseAmbiguous(alias handler)() { return handler(parsePrimaryExpression(1)); }
Comment #5 by bugzilla — 2013-10-10T20:41:53Z
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.
Comment #6 by bugzilla — 2013-10-10T21:29:11Z
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().
Comment #7 by k.hara.pg — 2013-10-10T21:36:35Z
Comment #8 by bugzilla — 2013-10-10T21:56:11Z
(In reply to comment #7) > https://github.com/D-Programming-Language/dmd/pull/2652 It's sure a pleasure working with you, Kenji!
Comment #9 by deadalnix — 2013-10-10T23:15:50Z
(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.
Comment #10 by k.hara.pg — 2013-10-10T23:42:57Z
(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?
Comment #11 by deadalnix — 2013-10-11T00:21:00Z
(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.
Comment #12 by github-bugzilla — 2013-10-11T11:40:54Z
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
Comment #13 by deadalnix — 2013-10-18T19:00:42Z
I reoppen as, sadly, this one is back in master.
Comment #14 by deadalnix — 2013-10-18T19:07:49Z
(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.
Comment #15 by k.hara.pg — 2013-11-21T23:16:22Z
*** Issue 8994 has been marked as a duplicate of this issue. ***