@@ -22,6 +22,9 @@ using namespace swift;
22
22
using namespace ide ;
23
23
using TypeRelation = CodeCompletionResultTypeRelation;
24
24
25
+ #define DEBUG_TYPE " CodeCompletionResultType"
26
+ #include " llvm/Support/Debug.h"
27
+
25
28
// MARK: - Utilities
26
29
27
30
// / Returns the kind of attributes \c Ty can be used as.
@@ -217,13 +220,21 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
217
220
return ExistingTypeIt->second ;
218
221
}
219
222
223
+ LLVM_DEBUG (llvm::dbgs () << " enter USRBasedType(" << Ty << " , USR = "
224
+ << USR << " )\n " ;
225
+ Ty->dump (llvm::dbgs ()););
226
+
220
227
SmallVector<const USRBasedType *, 2 > Supertypes;
221
228
;
222
229
if (auto Nominal = Ty->getAnyNominal ()) {
223
230
if (auto *Proto = dyn_cast<ProtocolDecl>(Nominal)) {
224
231
Proto->walkInheritedProtocols ([&](ProtocolDecl *inherited) {
225
232
if (Proto != inherited &&
226
- !inherited->isSpecificProtocol (KnownProtocolKind::Sendable)) {
233
+ !inherited->isSpecificProtocol (KnownProtocolKind::Sendable) &&
234
+ !inherited->getInvertibleProtocolKind ()) {
235
+ LLVM_DEBUG (llvm::dbgs () << " Adding inherited protocol "
236
+ << inherited->getName ()
237
+ << " \n " ;);
227
238
Supertypes.push_back (USRBasedType::fromType (
228
239
inherited->getDeclaredInterfaceType (), Arena));
229
240
}
@@ -234,21 +245,33 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
234
245
auto Conformances = Nominal->getAllConformances ();
235
246
Supertypes.reserve (Conformances.size ());
236
247
for (auto Conformance : Conformances) {
248
+ if (isa<InheritedProtocolConformance>(Conformance)) {
249
+ // Skip inherited conformances; we'll collect them when we visit the
250
+ // superclass.
251
+ continue ;
252
+ }
237
253
if (Conformance->getDeclContext ()->getParentModule () !=
238
254
Nominal->getModuleContext ()) {
239
255
// Only include conformances that are declared within the module of the
240
256
// type to avoid caching retroactive conformances which might not
241
257
// exist when using the code completion cache from a different module.
242
258
continue ;
243
259
}
244
- if (Conformance->getProtocol ()->isSpecificProtocol (KnownProtocolKind::Sendable)) {
260
+ if (Conformance->getProtocol ()->isSpecificProtocol (KnownProtocolKind::Sendable) ||
261
+ Conformance->getProtocol ()->getInvertibleProtocolKind ()) {
245
262
// FIXME: Sendable conformances are lazily synthesized as they are
246
263
// needed by the compiler. Depending on whether we checked whether a
247
264
// type conforms to Sendable before constructing the USRBasedType, we
248
265
// get different results for its conformance. For now, always drop the
249
266
// Sendable conformance.
267
+ //
268
+ // FIXME: Copyable and Escapable conformances are skipped because the
269
+ // USR mangling produces the type 'Any' for the protocol type.
250
270
continue ;
251
271
}
272
+ LLVM_DEBUG (llvm::dbgs () << " Adding conformed protocol "
273
+ << Conformance->getProtocol ()->getName ()
274
+ << " \n " ;);
252
275
Supertypes.push_back (USRBasedType::fromType (
253
276
Conformance->getProtocol ()->getDeclaredInterfaceType (), Arena));
254
277
}
@@ -284,11 +307,17 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
284
307
285
308
Type Superclass = getSuperclass (Ty);
286
309
while (Superclass) {
310
+ LLVM_DEBUG (llvm::dbgs () << " Adding superclass "
311
+ << Superclass
312
+ << " \n " ;);
287
313
Supertypes.push_back (USRBasedType::fromType (Superclass, Arena));
288
314
Superclass = getSuperclass (Superclass);
289
315
}
290
316
291
317
assert (llvm::all_of (Supertypes, [&USR](const USRBasedType *Ty) {
318
+ if (Ty->getUSR () == USR) {
319
+ LLVM_DEBUG (llvm::dbgs () << " Duplicate USR: " << USR << " \n " ;);
320
+ }
292
321
return Ty->getUSR () != USR;
293
322
}) && " Circular supertypes?" );
294
323
@@ -301,6 +330,9 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
301
330
return ImpliedSupertypes.contains (Ty);
302
331
});
303
332
333
+ LLVM_DEBUG (llvm::dbgs () << " leave USRBasedType(" << Ty << " )\n " ;
334
+ Ty->dump (llvm::dbgs ()););
335
+
304
336
return USRBasedType::fromUSR (USR, Supertypes, ::getCustomAttributeKinds (Ty),
305
337
Arena);
306
338
}
0 commit comments