https://wiki.dlang.org/?title=DIP22.1&feed=atom&action=historyDIP22.1 - Revision history2024-03-29T14:27:06ZRevision history for this page on the wikiMediaWiki 1.31.2https://wiki.dlang.org/?title=DIP22.1&diff=4155&oldid=prevO3o at 18:56, 28 May 20142014-05-28T18:56:23Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 18:56, 28 May 2014</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l78" >Line 78:</td>
<td colspan="2" class="diff-lineno">Line 78:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This document has been placed in the Public Domain.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This document has been placed in the Public Domain.</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Category: DIP]]</ins></div></td></tr>
</table>O3ohttps://wiki.dlang.org/?title=DIP22.1&diff=1853&oldid=prevDicebot: Created page with "{| class="wikitable" !Title: !'''Internal linkage attribute''' |- |DIP: |22.1 |- |Version: |2 |- |Status: |Draft |- |Created: |2013-01-28 |- |Last Modified: |2013-02-04 |- |..."2013-02-04T15:06:54Z<p>Created page with "{| class="wikitable" !Title: !'''Internal linkage attribute''' |- |DIP: |22.1 |- |Version: |2 |- |Status: |Draft |- |Created: |2013-01-28 |- |Last Modified: |2013-02-04 |- |..."</p>
<p><b>New page</b></p><div>{| class="wikitable"<br />
!Title: <br />
!'''Internal linkage attribute'''<br />
|-<br />
|DIP: <br />
|22.1<br />
|-<br />
|Version:<br />
|2<br />
|-<br />
|Status:<br />
|Draft<br />
|-<br />
|Created:<br />
|2013-01-28<br />
|-<br />
|Last Modified:<br />
|2013-02-04<br />
|-<br />
|Author:<br />
|Михаил Страшун (m.strashun gmail.com) (Dicebot)<br />
|-<br />
|Links:<br />
|[[Access specifiers and visibility]] : data gathered before creating proposal<br />
|}<br />
<br />
== Changelog ==<br />
<br />
=== Version 2 ===<br />
<br />
* Separated internal linkage proposal from combined [[DIP22]] as it was much more controversal<br />
* Other issues raised remain unchanged because best solution for them has not not yet been decided<br />
<br />
== Abstract ==<br />
Currently there is no way to force internal linkage for a symbol, similar to C '''static''' and C++ '''unnamed namespaces'''.<br />
New definition of '''static''' storage class for module-scope symbol is proposed.<br />
<br />
== Rationale ==<br />
<br />
If '''private''' is a source code level encapsulation tool then '''static''' is object file / binary level encapsulation tool. It allows even more struct separation of implementation-specific code and cleans up object files from unneeded symbols, providing more freedom for compiler optimizations.<br />
<br />
== Description ==<br />
<br />
Currently static storage class is no-op for global symbols. It is a big luck as we can use it in the way similar to plain C:<br />
<br />
* All global static symbols are implicitly private<br />
* It is forbidden to leak static symbols outside of the module, i.e.<br />
<syntaxhighlight lang="D"><br />
static struct Internal { }<br />
void func1(Internal) { } // compile error<br />
private void func2(Internal) { } // compile error, private still leaks its symbols to object file<br />
void func3() { Internal t; } // fine, does not leak to func3 signature<br />
alias Internal External; // compile error<br />
static alias Internal InternalPrim; // fine<br />
</syntaxhighlight><br />
* As can have just been seen, nested symbols can also be marked as '''static''' in case there were already static entities: enums, structs, classes, aliases. Variables and functions already have '''static''' defined for other usaged<br />
* No '''static''' symbols can be found in resulting object file. They are not shown in traits like <code>__traits(allMembers)</code>. From the point of view of other modules they simply do not exist and may be all inlined or optimized away or whatever.<br />
* Only module-level symbols can be marked with global '''static''', for example, nested struct types can't. It is minor limitation that greatly simplifies interaction with other language features like <code>alias this</code>.<br />
<br />
== Possible code breakage and solutions ==<br />
<br />
* global '''static''' had no meaning before and should not have been used like that. It may happen that is used by accident or in generic code gen. To be absolutely sure this brings no surprises I suggest to create a dmd option that will find and print all usages of '''static''' in global context. It should appear in a release _before_ this DIP release and kept for one release after, then removed.<br />
<br />
* Counter-example of valid generic code from Timon Gehr:<br />
<syntaxhighlight lang="D"><br />
mixin template X(){<br />
static int x = 2;<br />
}<br />
<br />
class C{<br />
mixin X; // x is a public TLS variable<br />
}<br />
<br />
mixin X; // x is a public TLS variable.<br />
</syntaxhighlight><br />
<br />
== Copyright ==<br />
<br />
This document has been placed in the Public Domain.</div>Dicebot