Bug 10276 – Nested structs with constructors get a context pointer even if they don't need one

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-05T09:40:41Z
Last change time
2024-12-13T18:07:42Z
Keywords
performance
Assigned to
No Owner
Creator
Andrej Mitrovic
Moved to GitHub: dmd#18600 →

Comments

Comment #0 by andrej.mitrovich — 2013-06-05T09:40:41Z
----- import std.traits; unittest { /* static */ struct S1 { int x; } /* static */ struct S2 { this(int) { } int x; } static assert(!isNested!S1); static assert(!isNested!S2); // fails } void main() { } ----- There is absolutely no need to make a struct nested *unless* it needs the context pointer. The compiler seems to make it a nested type as soon as it has any function or ctor implemented. This seems like arbitrary behavior. This is a problem with structs defined within unittests, because they end up breaking template code in weird ways (for example nested types can't be used with T.init). Using static explicitly is of course the workaround, but it should never be a requirement. The compiler should prefer making a struct static *unless* it has to do otherwise.
Comment #1 by andrej.mitrovich — 2014-04-20T10:34:22Z
*** Issue 12601 has been marked as a duplicate of this issue. ***
Comment #2 by andrej.mitrovich — 2016-08-27T23:40:10Z
I'm marking this as a performance issue. It should in theory be simple to implement this in the compiler: 1. Check if the struct definition compiles 2. Check if a `static` version of it compiles 3. If 2 fails make the struct nested
Comment #3 by simen.kjaras — 2019-05-20T06:23:52Z
*** Issue 15343 has been marked as a duplicate of this issue. ***
Comment #4 by simen.kjaras — 2020-02-07T12:29:03Z
*** Issue 20564 has been marked as a duplicate of this issue. ***
Comment #5 by simen.kjaras — 2021-01-25T12:27:39Z
*** Issue 21580 has been marked as a duplicate of this issue. ***
Comment #6 by robert.schadek — 2024-12-13T18:07:42Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18600 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB