@@ -820,6 +820,19 @@ const RequirementSource *RequirementSource::getMinimalConformanceSource(
820820 switch (source->kind ) {
821821 case ProtocolRequirement:
822822 case InferredProtocolRequirement: {
823+ // Special handling for top-level requirement signature requirements;
824+ // pretend the root type is the subject type as written in the
825+ // protocol, and not 'Self', so that we can consider this requirement
826+ // self-derived if it depends on one of the conformances that make
827+ // the root type valid.
828+ if (requirementSignatureSelfProto) {
829+ if (source->getProtocolDecl () == requirementSignatureSelfProto &&
830+ source->parent ->kind == RequirementSource::RequirementSignatureSelf) {
831+ rootType = source->getAffectedType ();
832+ return false ;
833+ }
834+ }
835+
823836 // Note that we've seen a protocol requirement.
824837 sawProtocolRequirement = true ;
825838
@@ -2144,37 +2157,40 @@ void EquivalenceClass::dump(llvm::raw_ostream &out,
21442157 }, [&]() {
21452158 out << " , " ;
21462159 });
2147- out << " \n Conformances:" ;
2148- interleave (conformsTo,
2149- [&](const std::pair<
2150- ProtocolDecl *,
2151- std::vector<Constraint<ProtocolDecl *>>> &entry) {
2152- out << entry.first ->getNameStr ();
2153- },
2154- [&] { out << " , " ; });
2155- out << " \n Same-type constraints:" ;
2156- llvm::interleave (
2157- sameTypeConstraints,
2158- [&](const Constraint<Type> &constraint) {
2159- out << " \n " << constraint.getSubjectDependentType ({})
2160- << " == " << constraint.value ;
2160+ out << " \n " ;
2161+ out << " Conformance constraints:\n " ;
2162+ for (auto entry : conformsTo) {
2163+ out << " " << entry.first ->getNameStr () << " \n " ;
2164+ for (auto constraint : entry.second ) {
2165+ constraint.source ->dump (out, &builder->getASTContext ().SourceMgr , 4 );
2166+ if (constraint.source ->isDerivedRequirement ())
2167+ out << " [derived]" ;
2168+ out << " \n " ;
2169+ }
2170+ }
2171+
2172+ out << " Same-type constraints:\n " ;
2173+ for (auto constraint : sameTypeConstraints) {
2174+ out << " " << constraint.getSubjectDependentType ({})
2175+ << " == " << constraint.value << " \n " ;
2176+ constraint.source ->dump (out, &builder->getASTContext ().SourceMgr , 4 );
2177+ if (constraint.source ->isDerivedRequirement ())
2178+ out << " [derived]" ;
2179+ out << " \n " ;
2180+ }
21612181
2162- if (constraint.source ->isDerivedRequirement ())
2163- out << " [derived]" ;
2164- },
2165- [&] { out << " , " ; });
21662182 if (concreteType)
2167- out << " \n Concrete type: " << concreteType.getString ();
2183+ out << " Concrete type: " << concreteType.getString () << " \n " ;
21682184 if (superclass)
2169- out << " \n Superclass : " << superclass.getString ();
2185+ out << " Superclass : " << superclass.getString () << " \n " ;
21702186 if (layout)
2171- out << " \n Layout : " << layout.getString ();
2187+ out << " Layout : " << layout.getString () << " \n " ;
21722188
21732189 if (!delayedRequirements.empty ()) {
2174- out << " \n Delayed requirements:" ;
2190+ out << " Delayed requirements:\n " ;
21752191 for (const auto &req : delayedRequirements) {
2176- out << " \n " ;
21772192 req.dump (out);
2193+ out << " \n " ;
21782194 }
21792195 }
21802196
0 commit comments