@@ -38,33 +38,51 @@ enum class SILLinkage : uint8_t {
3838 // / This object definition is visible to multiple Swift modules (and
3939 // / thus potentially across linkage-unit boundaries). There are no
4040 // / other object definitions with this name in the program.
41+ // /
42+ // / Public functions must be definitions, i.e. must have a body, except the
43+ // / body is emitted by clang.
4144 Public,
4245
4346 // / This is a special linkage used for symbols which are treated
4447 // / as public for the purposes of SIL serialization and optimization,
4548 // / but do not have public entry points in the generated binary.
4649 // /
50+ // / This linkage is used for @_alwaysEmitIntoClient functions.
51+ // /
4752 // / There is no external variant of this linkage, because from other
4853 // / translation units in the same module, this behaves identically
4954 // / to the HiddenExternal linkage.
5055 // /
5156 // / When deserialized, such declarations receive Shared linkage.
57+ // /
58+ // / PublicNonABI functions must be definitions.
5259 PublicNonABI,
5360
5461 // / This object definition is visible only to the current Swift
5562 // / module (and thus should not be visible across linkage-unit
5663 // / boundaries). There are no other object definitions with this
5764 // / name in the module.
65+ // /
66+ // / Hidden functions must be definitions, i.e. must have a body, except the
67+ // / body is emitted by clang.
5868 Hidden,
5969
6070 // / This object definition is visible only within a single Swift
6171 // / module. There may be other object definitions with this name in
6272 // / the module; those definitions are all guaranteed to be
6373 // / semantically equivalent to this one.
74+ // /
75+ // / This linkage is used e.g. for thunks and for specialized functions.
76+ // /
77+ // / Public functions must be definitions, i.e. must have a body, except the
78+ // / body is emitted by clang.
6479 Shared,
6580
6681 // / This object definition is visible only within a single Swift
6782 // / file.
83+ // /
84+ // / Private functions must be definitions, i.e. must have a body, except the
85+ // / body is emitted by clang.
6886 Private,
6987
7088 // / A Public definition with the same name as this object will be
@@ -74,17 +92,12 @@ enum class SILLinkage : uint8_t {
7492 PublicExternal,
7593
7694 // / A Public or Hidden definition with the same name as this object
77- // / will be defined by the current Swift module at runtime. If this
78- // / object is a definition, it is semantically equivalent to that
79- // / definition.
95+ // / will be defined by the current Swift module at runtime.
96+ // /
97+ // / This linkage is only used for non-whole-module compilations to refer to
98+ // / functions in other files of the same module.
8099 HiddenExternal,
81100
82- // / This Shared definition was imported from another module. It is not
83- // / necessary to serialize it since it can be deserialized from the original
84- // / module. Besides that caveat this should be treated exactly the same as
85- // / shared.
86- SharedExternal,
87-
88101 // / The default linkage for a definition.
89102 DefaultForDefinition = Public,
90103
@@ -97,14 +110,40 @@ enum {
97110 NumSILLinkageBits = 4
98111};
99112
100- // / Related to linkage: flag if a function or global variable is serialized,
101- // / either unconditionally, or if referenced from another serialized function.
113+ // / Related to linkage: flag if a function, global variable, vtable or witness
114+ // / table is serialized.
115+ // /
116+ // / Used, e.g. for @inlinable functions.
117+ // /
118+ // / This flag serves for two purposes:
119+ // / * Imposes restrictions for optimizations. For example, non-serialized functions
120+ // / cannot be inlined into serialized functions, because that could expose
121+ // / internal types/functions to client modules.
122+ // / * Tells the serializer which functions (and tables) need to be serialized:
123+ // / - all public functions with the IsSerialized flag and
124+ // / - all IsSerialized shared functions which are referenced from such functions.
125+ // /
126+ // / After the swiftmodule file is written, the IsSerialized flag is cleared from
127+ // / all functions. This means that optimizations after the serialization point
128+ // / are not limited anymore regarding serialized functions.
102129enum IsSerialized_t : unsigned char {
103- // Never serialized.
130+
131+ // / The function is not inlinable and will not be serialized.
104132 IsNotSerialized,
105- // Serialized if referenced from another serialized function.
106- IsSerializable,
107- // Always serialized.
133+
134+ // / The function (or table) will be serialized.
135+ // /
136+ // / This flag is only valid for Public, PublicNonABI, PublicExternal,
137+ // / HiddenExternal and Shared functions.
138+ // / Functions with external linkage (PublicExternl, HiddenExternal) will not
139+ // / be serialized, because they are available in a different module (from which
140+ // / they were de-serialized).
141+ // /
142+ // / Functions with Shared linkage will only be serialized if they are referenced
143+ // / from another serialized function (or table).
144+ // /
145+ // / This flag is removed from all functions after the serialization point in
146+ // / the optimizer pipeline.
108147 IsSerialized
109148};
110149
@@ -131,8 +170,6 @@ inline SILLinkage stripExternalFromLinkage(SILLinkage linkage) {
131170 return SILLinkage::Public;
132171 if (linkage == SILLinkage::HiddenExternal)
133172 return SILLinkage::Hidden;
134- if (linkage == SILLinkage::SharedExternal)
135- return SILLinkage::Shared;
136173 return linkage;
137174}
138175
@@ -146,13 +183,11 @@ inline SILLinkage addExternalToLinkage(SILLinkage linkage) {
146183 // if the function was emitted in another translation unit of the
147184 // same Swift module, so we treat it as hidden here.
148185 return SILLinkage::HiddenExternal;
149- case SILLinkage::Shared:
150- return SILLinkage::SharedExternal;
151186 case SILLinkage::Hidden:
152187 return SILLinkage::HiddenExternal;
188+ case SILLinkage::Shared:
153189 case SILLinkage::Private:
154190 case SILLinkage::PublicExternal:
155- case SILLinkage::SharedExternal:
156191 case SILLinkage::HiddenExternal:
157192 return linkage;
158193 }
@@ -186,7 +221,6 @@ inline bool hasPublicVisibility(SILLinkage linkage) {
186221 return true ;
187222 case SILLinkage::Hidden:
188223 case SILLinkage::Shared:
189- case SILLinkage::SharedExternal:
190224 case SILLinkage::Private:
191225 case SILLinkage::HiddenExternal:
192226 return false ;
@@ -198,7 +232,6 @@ inline bool hasPublicVisibility(SILLinkage linkage) {
198232inline bool hasSharedVisibility (SILLinkage linkage) {
199233 switch (linkage) {
200234 case SILLinkage::Shared:
201- case SILLinkage::SharedExternal:
202235 return true ;
203236 case SILLinkage::Public:
204237 case SILLinkage::PublicExternal:
@@ -222,7 +255,6 @@ inline bool hasPrivateVisibility(SILLinkage linkage) {
222255 case SILLinkage::Hidden:
223256 case SILLinkage::HiddenExternal:
224257 case SILLinkage::Shared:
225- case SILLinkage::SharedExternal:
226258 return false ;
227259 }
228260
0 commit comments