@@ -801,7 +801,7 @@ class InheritedProtocolCollector {
801801 }
802802
803803 // / If there were any conditional conformances that couldn't be printed,
804- // / make a dummy extension that conforms to all of them, constrained by a
804+ // / make dummy extension(s) that conforms to all of them, constrained by a
805805 // / fake protocol.
806806 bool printInaccessibleConformanceExtensionIfNeeded (
807807 raw_ostream &out, const PrintOptions &printOptions,
@@ -810,20 +810,35 @@ class InheritedProtocolCollector {
810810 return false ;
811811 assert (nominal->isGenericContext ());
812812
813- if (!printOptions.printPublicInterface ())
814- out << " @_spi(" << DummyProtocolName << " )\n " ;
815- out << " @available(*, unavailable)\n extension " ;
816- nominal->getDeclaredType ().print (out, printOptions);
817- out << " : " ;
818- llvm::interleave (
819- ConditionalConformanceProtocols,
820- [&out, &printOptions](const ProtocolType *protoTy) {
821- protoTy->print (out, printOptions);
822- },
823- [&out] { out << " , " ; });
824- out << " where "
825- << nominal->getGenericSignature ().getGenericParams ().front ()->getName ()
826- << " : " << DummyProtocolName << " {}\n " ;
813+ auto emitExtension =
814+ [&](ArrayRef<const ProtocolType *> conformanceProtos) {
815+ if (!printOptions.printPublicInterface ())
816+ out << " @_spi(" << DummyProtocolName << " )\n " ;
817+ out << " @available(*, unavailable)\n extension " ;
818+ nominal->getDeclaredType ().print (out, printOptions);
819+ out << " : " ;
820+ llvm::interleave (
821+ conformanceProtos,
822+ [&out, &printOptions](const ProtocolType *protoTy) {
823+ protoTy->print (out, printOptions);
824+ },
825+ [&out] { out << " , " ; });
826+ out << " where "
827+ << nominal->getGenericSignature ().getGenericParams ()[0 ]->getName ()
828+ << " : " << DummyProtocolName << " {}\n " ;
829+ };
830+
831+ // We have to print conformances for invertible protocols in separate
832+ // extensions, so do those first and save the rest for one extension.
833+ SmallVector<const ProtocolType *, 8 > regulars;
834+ for (auto *proto : ConditionalConformanceProtocols) {
835+ if (proto->getDecl ()->getInvertibleProtocolKind ()) {
836+ emitExtension (proto);
837+ continue ;
838+ }
839+ regulars.push_back (proto);
840+ }
841+ emitExtension (regulars);
827842 return true ;
828843 }
829844
0 commit comments