Bug 17590 – Unnecessary GC alloc on returning static local struct

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-03T20:41:27Z
Last change time
2017-08-16T13:23:18Z
Keywords
industry
Assigned to
No Owner
Creator
johanengelen

Comments

Comment #0 by johanengelen — 2017-07-03T20:41:27Z
The following code does not compile: ``` auto foo(int a, bool b) @nogc { static struct SInside {} SInside res; lazyfun(a); return res; } void lazyfun(scope lazy int a) @nogc; ``` Because the return type is a local struct, the frontend thinks a GC allocated closure is needed. But, the local struct is static, so no reference to the local frame and a closure is not needed.
Comment #1 by johanengelen — 2017-07-03T20:49:43Z
Comment #2 by github-bugzilla — 2017-07-21T20:04:53Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/9940f4ce5e82f783b3c41c260c32b56b11e37f8a Fix Issue 17590 - Unnecessary GC alloc on returning static local struct https://github.com/dlang/dmd/commit/c3c8a71e085c16d56a359d5007590e4737292ee4 Merge pull request #6963 from JohanEngelen/closurenonstatic Fix Issue 17590 - Unnecessary GC alloc on returning static local struct merged-on-behalf-of: Sebastian Wilzbach <[email protected]>
Comment #3 by github-bugzilla — 2017-08-07T13:17:13Z
Commits pushed to newCTFE at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/9940f4ce5e82f783b3c41c260c32b56b11e37f8a Fix Issue 17590 - Unnecessary GC alloc on returning static local struct https://github.com/dlang/dmd/commit/c3c8a71e085c16d56a359d5007590e4737292ee4 Merge pull request #6963 from JohanEngelen/closurenonstatic
Comment #4 by github-bugzilla — 2017-08-16T13:23:18Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/9940f4ce5e82f783b3c41c260c32b56b11e37f8a Fix Issue 17590 - Unnecessary GC alloc on returning static local struct https://github.com/dlang/dmd/commit/c3c8a71e085c16d56a359d5007590e4737292ee4 Merge pull request #6963 from JohanEngelen/closurenonstatic