Thread overview
[Issue 14901] [reg 2.067/2.068] template static shared this() run multiple times with separate compilation
Aug 11, 2015
Kenji Hara
Aug 11, 2015
Walter Bright
Aug 11, 2015
Kenji Hara
Aug 11, 2015
Kenji Hara
Aug 13, 2015
Kenji Hara
August 11, 2015
https://issues.dlang.org/show_bug.cgi?id=14901

--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> ---
The bug behavior has introduced by the excessive instantiation and codegen for the non-root instances. From 2.067, the make!"bar" instance code which aliased in b.d will be instantiated and stored into [bcde].obj. With 2.066 and earlier, it had stored only into b.obj.

Those regressions have the same root:

Issue 14431 - [REG 2.067.0] huge slowdown of compilation speed
Issue 14508 - [REG2.067.0] compiling with -unittest instantiates templates in
non-root modules
Issue 14564 - [REG2.067] dmd -property -unittest combination causes compiler
error

and it will be fixed by:

https://github.com/D-Programming-Language/dmd/pull/4784

But unfortunately, my PR is not released into 2.068.0, because Walter couldn't
understand the fix.
David, I wish to you to join its code review, if you have a time.

----

> As far as the cause for this goes, for reasons I'm not entirely clear about a unique identifier is used for function name of the static ctor (e.g. _sharedStaticCtor55). For (amongst others) -unittest builds, the ctor function is always emitted to fix issue 11239. Thus, different object files end up with differently named copies of the same function, which consequently also gets run multiple times.

That's an another, fragile naming mechanism issue in current dmd front-end. Some unnamed symbols (static this, unittest, anonymous class, etc) are numbered by the `Identifier::generateId()`. It's result not *stable* because it fully depends on the order of semantic analysis and it will be changed by the conditional compilation.

For lambdas and unnamed mixin declarations, I added "scope local unique number"
(See FuncExp::genIdent and TemplateMixin::semantic).
For them, the frequency of the issue has been reduced by them, but it's not yet
perfect answer...

--
August 11, 2015
https://issues.dlang.org/show_bug.cgi?id=14901

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> ---
The cause of this is not excessive instantiation, it is the fragile name generation system.

--
August 11, 2015
https://issues.dlang.org/show_bug.cgi?id=14901

--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to Walter Bright from comment #2)
> The cause of this is not excessive instantiation, it is the fragile name generation system.

Yes, the ultimate root issue is it. But if the code for the instance make!"bar" is generated and stored only in b.obj, the problem does not happen.

So, the regression from 2.067 is introduced by the excessive instantiation. The issue should be fixed ASAP.

--
August 11, 2015
https://issues.dlang.org/show_bug.cgi?id=14901

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #4 from Steven Schveighoffer <schveiguy@yahoo.com> ---
Does this have any bearing/relation to https://issues.dlang.org/show_bug.cgi?id=14517 ?

--
August 11, 2015
https://issues.dlang.org/show_bug.cgi?id=14901

--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to Steven Schveighoffer from comment #4)
> Does this have any bearing/relation to https://issues.dlang.org/show_bug.cgi?id=14517 ?

Unfortunately, it is not related with.

--
August 13, 2015
https://issues.dlang.org/show_bug.cgi?id=14901

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, wrong-code
           Hardware|x86                         |All
                 OS|Mac OS X                    |All

--
August 30, 2015
https://issues.dlang.org/show_bug.cgi?id=14901

github-bugzilla@puremagic.com changed:

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

--
August 30, 2015
https://issues.dlang.org/show_bug.cgi?id=14901

--- Comment #6 from github-bugzilla@puremagic.com ---
Commit pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/5b464f3393980a0229c079ff6e646ef843681996
fix Issue 14901 - template static shared this() run multiple times with
separate compilation

--
September 02, 2015
https://issues.dlang.org/show_bug.cgi?id=14901

--- Comment #7 from github-bugzilla@puremagic.com ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/5b464f3393980a0229c079ff6e646ef843681996
fix Issue 14901 - template static shared this() run multiple times with
separate compilation

--