@@ -41,6 +41,22 @@ lookupDirectWithoutExtensions(NominalTypeDecl *decl, Identifier id) {
41
41
return result;
42
42
}
43
43
44
+ // / Similar to ModuleDecl::conformsToProtocol, but doesn't introduce a
45
+ // / dependency on Sema.
46
+ static bool isConcreteAndValid (ProtocolConformanceRef conformanceRef,
47
+ ModuleDecl *module ) {
48
+ if (conformanceRef.isInvalid ())
49
+ return false ;
50
+ if (!conformanceRef.isConcrete ())
51
+ return false ;
52
+ auto conformance = conformanceRef.getConcrete ();
53
+ auto subMap = conformance->getSubstitutions (module );
54
+ return llvm::all_of (subMap.getConformances (),
55
+ [&](ProtocolConformanceRef each) -> bool {
56
+ return isConcreteAndValid (each, module );
57
+ });
58
+ }
59
+
44
60
static clang::TypeDecl *
45
61
getIteratorCategoryDecl (const clang::CXXRecordDecl *clangDecl) {
46
62
clang::IdentifierInfo *iteratorCategoryDeclName =
@@ -126,7 +142,9 @@ static ValueDecl *getMinusOperator(NominalTypeDecl *decl) {
126
142
if (lhsNominal != rhsNominal || lhsNominal != decl)
127
143
return false ;
128
144
auto returnTy = minus->getResultInterfaceType ();
129
- if (!module ->conformsToProtocol (returnTy, binaryIntegerProto))
145
+ auto conformanceRef =
146
+ module ->lookupConformance (returnTy, binaryIntegerProto);
147
+ if (!isConcreteAndValid (conformanceRef, module ))
130
148
return false ;
131
149
return true ;
132
150
};
@@ -331,9 +349,10 @@ void swift::conformToCxxSequenceIfNeeded(
331
349
return ;
332
350
333
351
// Check if RawIterator conforms to UnsafeCxxInputIterator.
334
- auto rawIteratorConformanceRef = decl->getModuleContext ()->conformsToProtocol (
335
- rawIteratorTy, cxxIteratorProto);
336
- if (!rawIteratorConformanceRef || !rawIteratorConformanceRef.isConcrete ())
352
+ ModuleDecl *module = decl->getModuleContext ();
353
+ auto rawIteratorConformanceRef =
354
+ module ->lookupConformance (rawIteratorTy, cxxIteratorProto);
355
+ if (!isConcreteAndValid (rawIteratorConformanceRef, module ))
337
356
return ;
338
357
auto rawIteratorConformance = rawIteratorConformanceRef.getConcrete ();
339
358
auto pointeeDecl =
@@ -356,7 +375,7 @@ void swift::conformToCxxSequenceIfNeeded(
356
375
return declSelfTy;
357
376
return Type (dependentType);
358
377
},
359
- LookUpConformanceInModule (decl-> getModuleContext () ));
378
+ LookUpConformanceInModule (module ));
360
379
361
380
impl.addSynthesizedTypealias (decl, ctx.Id_Element , pointeeTy);
362
381
impl.addSynthesizedTypealias (decl, ctx.Id_Iterator , iteratorTy);
0 commit comments