Thread overview
[Issue 3243] instantiated 'static this()' bring on a compiler message ': __gate is thread local'
[Issue 3243] Mixin 'static this()' bring on a compiler message ': __gate is thread local'
Aug 10, 2015
David Nadlinger
Aug 11, 2015
Kenji Hara
Aug 11, 2015
Kenji Hara
Aug 30, 2015
bb.temp@gmx.com
Mar 21, 2020
Basile-z
August 10, 2015
https://issues.dlang.org/show_bug.cgi?id=3243

David Nadlinger <code@klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |code@klickverbot.at
         Resolution|---                         |INVALID

--- Comment #4 from David Nadlinger <code@klickverbot.at> ---
This is indeed an invalid bug as far as D2 is concerned, because the static constructor is run once per thread and needs a gate variable to prevent being run multiple times in the face of separate compilation. I suppose we could improve the diagnostic message, though?

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|patch                       |diagnostic
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---
            Summary|Mixin 'static this()' bring |instantiated 'static
                   |on a compiler message ':    |this()' bring on a compiler
                   |__gate is thread local'     |message ': __gate is thread
                   |                            |local'

--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to David Nadlinger from comment #4)
> This is indeed an invalid bug as far as D2 is concerned, because the static constructor is run once per thread and needs a gate variable to prevent being run multiple times in the face of separate compilation. I suppose we could improve the diagnostic message, though?

The original issue, the mixed-in `static this()` will report ': __gate is thread local' message with -vtls, is properly fixed from 2.065, by the side-effect of the commit:

https://github.com/D-Programming-Language/dmd/commit/9f9e4690d6abcfee5858f48a7eb80d1b7eca5a06

Because the mixin is not a proper template instance, the instantiated code is inserted in the enclosing scope, so the generated `static this()` will be a non-instantiated function and should not have gate.

But, if the template is properly instantiated, the static this() still needs TLS __gate variable implicitly as you said, and it will be listed by -vtls. For example:

template T()
{
    static this() {}
}

class C
{
    alias ti = T!();
}

With 2.068.0,

  dmd -c -vtls test.d

Will show:

  : __gate is thread local

I think this is a minor diagnostic issue. -vlts does not have to list the internal generated variables like __gate, because it's just confusing.

I change the title and reopen.

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #6 from Kenji Hara <k.hara.pg@gmail.com> ---
https://github.com/D-Programming-Language/dmd/pull/4877

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

bb.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bb.temp@gmx.com

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

github-bugzilla@puremagic.com changed:

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

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

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

https://github.com/D-Programming-Language/dmd/commit/01979b088cd967e5d8e02f7cc2e742400179dc64
fix Issue 3243 - instantiated 'static this()' bring on a compiler message ':
__gate is thread local'

https://github.com/D-Programming-Language/dmd/commit/ad137f0f356b0c550bc8de7251eecf9bf152a7c6 Merge pull request #4877 from 9rnsr/fix3243

Issue 3243 - instantiated 'static this()' bring on a compiler message ': __gate
is thread local'

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=3243

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--