@@ -148,7 +148,10 @@ bool SILModule::isTypeMetadataAccessible(CanType type) {
148
148
}
149
149
150
150
// / Return the formal linkage of the component restrictions of this
151
- // / generic signature. Never returns PublicUnique.
151
+ // / generic signature. This is the appropriate linkage for a lazily-
152
+ // / emitted entity derived from the generic signature.
153
+ // /
154
+ // / This function never returns PublicUnique.
152
155
FormalLinkage swift::getGenericSignatureLinkage (CanGenericSignature sig) {
153
156
// This can only be PublicNonUnique or HiddenUnique. Signatures can
154
157
// never be PublicUnique in the first place, and we short-circuit on
@@ -166,7 +169,7 @@ FormalLinkage swift::getGenericSignatureLinkage(CanGenericSignature sig) {
166
169
case RequirementKind::Conformance:
167
170
case RequirementKind::SameType:
168
171
case RequirementKind::Superclass:
169
- switch (getTypeLinkage (CanType (req.getSecondType ()))) {
172
+ switch (getTypeLinkage_correct (CanType (req.getSecondType ()))) {
170
173
case FormalLinkage::PublicUnique:
171
174
case FormalLinkage::PublicNonUnique:
172
175
continue ;
@@ -183,22 +186,43 @@ FormalLinkage swift::getGenericSignatureLinkage(CanGenericSignature sig) {
183
186
return linkage;
184
187
}
185
188
186
- // / Return the minimum linkage structurally required to reference the given formal type.
189
+ // / Return the formal linkage of the given formal type.
190
+ // /
191
+ // / Note that this function is buggy and generally should not be
192
+ // / used in new code; we should migrate all callers to
193
+ // / getTypeLinkage_correct and then consolidate them.
187
194
FormalLinkage swift::getTypeLinkage (CanType t) {
188
195
assert (t->isLegalFormalType ());
196
+ // Due to a bug, this always returns PublicUnique.
197
+ // It's a bit late in the 5.7 timeline to be changing that, but
198
+ // we can optimize it!
199
+ return FormalLinkage::PublicUnique;
200
+ }
201
+
202
+ // / Return the formal linkage of the given formal type.
203
+ // / This in the appropriate linkage for a lazily-emitted entity
204
+ // / derived from the type.
205
+ // /
206
+ // / This function never returns PublicUnique, which means that,
207
+ // / even if a type is simply a reference to a non-generic
208
+ // / uniquely-emitted nominal type, the formal linkage of that
209
+ // / type may differ from the formal linkage of the underlying
210
+ // / type declaration.
211
+ FormalLinkage swift::getTypeLinkage_correct (CanType t) {
212
+ assert (t->isLegalFormalType ());
189
213
190
214
class Walker : public TypeWalker {
191
215
public:
192
216
FormalLinkage Linkage;
193
- Walker () : Linkage(FormalLinkage::PublicUnique ) {}
217
+ Walker () : Linkage(FormalLinkage::PublicNonUnique ) {}
194
218
195
219
Action walkToTypePre (Type ty) override {
196
220
// Non-nominal types are always available.
197
221
auto decl = ty->getNominalOrBoundGenericNominal ();
198
222
if (!decl)
199
223
return Action::Continue;
200
224
201
- Linkage = std::min (Linkage, getDeclLinkage (decl));
225
+ Linkage = std::max (Linkage, getDeclLinkage (decl));
202
226
return Action::Continue;
203
227
}
204
228
};
0 commit comments