@@ -22,6 +22,9 @@ using namespace swift;
2222using namespace ide ;
2323using TypeRelation = CodeCompletionResultTypeRelation;
2424
25+ #define DEBUG_TYPE " CodeCompletionResultType"
26+ #include " llvm/Support/Debug.h"
27+
2528// MARK: - Utilities
2629
2730// / Returns the kind of attributes \c Ty can be used as.
@@ -217,13 +220,21 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
217220 return ExistingTypeIt->second ;
218221 }
219222
223+ LLVM_DEBUG (llvm::dbgs () << " enter USRBasedType(" << Ty << " , USR = "
224+ << USR << " )\n " ;
225+ Ty->dump (llvm::dbgs ()););
226+
220227 SmallVector<const USRBasedType *, 2 > Supertypes;
221228 ;
222229 if (auto Nominal = Ty->getAnyNominal ()) {
223230 if (auto *Proto = dyn_cast<ProtocolDecl>(Nominal)) {
224231 Proto->walkInheritedProtocols ([&](ProtocolDecl *inherited) {
225232 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 " ;);
227238 Supertypes.push_back (USRBasedType::fromType (
228239 inherited->getDeclaredInterfaceType (), Arena));
229240 }
@@ -234,21 +245,33 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
234245 auto Conformances = Nominal->getAllConformances ();
235246 Supertypes.reserve (Conformances.size ());
236247 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+ }
237253 if (Conformance->getDeclContext ()->getParentModule () !=
238254 Nominal->getModuleContext ()) {
239255 // Only include conformances that are declared within the module of the
240256 // type to avoid caching retroactive conformances which might not
241257 // exist when using the code completion cache from a different module.
242258 continue ;
243259 }
244- if (Conformance->getProtocol ()->isSpecificProtocol (KnownProtocolKind::Sendable)) {
260+ if (Conformance->getProtocol ()->isSpecificProtocol (KnownProtocolKind::Sendable) ||
261+ Conformance->getProtocol ()->getInvertibleProtocolKind ()) {
245262 // FIXME: Sendable conformances are lazily synthesized as they are
246263 // needed by the compiler. Depending on whether we checked whether a
247264 // type conforms to Sendable before constructing the USRBasedType, we
248265 // get different results for its conformance. For now, always drop the
249266 // Sendable conformance.
267+ //
268+ // FIXME: Copyable and Escapable conformances are skipped because the
269+ // USR mangling produces the type 'Any' for the protocol type.
250270 continue ;
251271 }
272+ LLVM_DEBUG (llvm::dbgs () << " Adding conformed protocol "
273+ << Conformance->getProtocol ()->getName ()
274+ << " \n " ;);
252275 Supertypes.push_back (USRBasedType::fromType (
253276 Conformance->getProtocol ()->getDeclaredInterfaceType (), Arena));
254277 }
@@ -284,11 +307,17 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
284307
285308 Type Superclass = getSuperclass (Ty);
286309 while (Superclass) {
310+ LLVM_DEBUG (llvm::dbgs () << " Adding superclass "
311+ << Superclass
312+ << " \n " ;);
287313 Supertypes.push_back (USRBasedType::fromType (Superclass, Arena));
288314 Superclass = getSuperclass (Superclass);
289315 }
290316
291317 assert (llvm::all_of (Supertypes, [&USR](const USRBasedType *Ty) {
318+ if (Ty->getUSR () == USR) {
319+ LLVM_DEBUG (llvm::dbgs () << " Duplicate USR: " << USR << " \n " ;);
320+ }
292321 return Ty->getUSR () != USR;
293322 }) && " Circular supertypes?" );
294323
@@ -301,6 +330,9 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
301330 return ImpliedSupertypes.contains (Ty);
302331 });
303332
333+ LLVM_DEBUG (llvm::dbgs () << " leave USRBasedType(" << Ty << " )\n " ;
334+ Ty->dump (llvm::dbgs ()););
335+
304336 return USRBasedType::fromUSR (USR, Supertypes, ::getCustomAttributeKinds (Ty),
305337 Arena);
306338}
0 commit comments