D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16627 - [Reg 2.072] non-static structs with postblit/dtor fields are now nested
Summary: [Reg 2.072] non-static structs with postblit/dtor fields are now nested
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-19 23:11 UTC by Martin Nowak
Modified: 2018-12-21 05:29 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2016-10-19 23:11:59 UTC
cat > bug.d << CODE
void bug(A...)(ref A args)
{
    struct S { A expand; } // no references
    static assert(!__traits(isNested, S)); // suddenly nested
}

struct SNoCopy
{
    @disable this(this);
}

void test()
{
    SNoCopy itm;
    bug(itm);
}
CODE
dmd -c bug
----

Apparently caused by https://github.com/dlang/dmd/pull/5500.
Comment 1 Martin Nowak 2016-10-19 23:25:45 UTC
Caused by the 2nd commit of that PR https://github.com/dlang/dmd/pull/5500/commits/75b5b691555bef2d2f21b44821f297f93ddfbc77.
Comment 2 Martin Nowak 2016-10-24 01:36:06 UTC
This happens because structs are converted to nested structs by the semantic analysis of their member functions.
The idea behind this seems to be that struct without methods can't access the outer frame, hence never need nesting. Could be reconsidered to be deprecated in favor of explicit `static struct` or a proper detection of closure access.

With dlang/dmd#5500 the dependency of the generate postblits/dtors on a finalized struct size was removed, now semantic just collects a list of fields and finalizes the size later on. This resolves some problems w/ forward references.

Previously __fieldPostblit and __fieldDtor were generated after finalizing the size and didn't convert structs to a nested one due to a `if (sizeok == SIZEOKdone) return;` check in makeNested. Now semantic for those functions runs before the finalization and does convert structs to nested.

This bug only affects structs w/o any other function (b/c those would be nested already) and at least one field w/ dtor/postblit.
Comment 3 github-bugzilla 2016-10-25 04:44:16 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/868ce84e30a3d4e1157e9e72bc3e308b0cd0b1db
fix Issue 16627 - non-static structs with postblit/dtor fields now nested

- Since dlang/dmd#5500 buildPostblit/Dtor/OpAssign are run before
  the struct size is finalized, thereby now making structs nested
  that previously were not.
- Not sure if the old behavior was an intended feature. If not
  we might want to deprecate it.

https://github.com/dlang/dmd/commit/8e8541a941bb8fdacf6c8b7a042a69cf77d4676c
Merge pull request #6212 from MartinNowak/fix16627

fix Issue 16627 - non-static structs with postblit/dtor fields now nested
Comment 4 github-bugzilla 2016-11-05 03:41:37 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/868ce84e30a3d4e1157e9e72bc3e308b0cd0b1db
fix Issue 16627 - non-static structs with postblit/dtor fields now nested

https://github.com/dlang/dmd/commit/8e8541a941bb8fdacf6c8b7a042a69cf77d4676c
Merge pull request #6212 from MartinNowak/fix16627
Comment 5 github-bugzilla 2016-12-27 14:40:46 UTC
Commits pushed to scope at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/868ce84e30a3d4e1157e9e72bc3e308b0cd0b1db
fix Issue 16627 - non-static structs with postblit/dtor fields now nested

https://github.com/dlang/dmd/commit/8e8541a941bb8fdacf6c8b7a042a69cf77d4676c
Merge pull request #6212 from MartinNowak/fix16627
Comment 6 github-bugzilla 2017-01-16 23:24:00 UTC
Commits pushed to newCTFE at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/868ce84e30a3d4e1157e9e72bc3e308b0cd0b1db
fix Issue 16627 - non-static structs with postblit/dtor fields now nested

https://github.com/dlang/dmd/commit/8e8541a941bb8fdacf6c8b7a042a69cf77d4676c
Merge pull request #6212 from MartinNowak/fix16627