Skip to content

Commit e48f419

Browse files
committed
[GSB] Add EquivalenceClass::dump(). NFC
1 parent 504b6f2 commit e48f419

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ class GenericSignatureBuilder {
192192
/// Determine whether conformance to the given protocol is satisfied by
193193
/// a superclass requirement.
194194
bool isConformanceSatisfiedBySuperclass(ProtocolDecl *proto) const;
195+
196+
/// Dump a debugging representation of this equivalence class.
197+
void dump(llvm::raw_ostream &out) const;
198+
199+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
200+
"only for use in the debugger");
195201
};
196202

197203
friend class RequirementSource;

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,50 @@ bool EquivalenceClass::isConformanceSatisfiedBySuperclass(
10831083
return false;
10841084
}
10851085

1086+
void EquivalenceClass::dump(llvm::raw_ostream &out) const {
1087+
out << "Equivalence class represented by "
1088+
<< members.front()->getRepresentative()->getDebugName() << ":\n";
1089+
out << "Members: ";
1090+
interleave(members, [&](PotentialArchetype *pa) {
1091+
out << pa->getDebugName();
1092+
}, [&]() {
1093+
out << ", ";
1094+
});
1095+
out << "\nConformances:";
1096+
interleave(conformsTo,
1097+
[&](const std::pair<
1098+
ProtocolDecl *,
1099+
std::vector<Constraint<ProtocolDecl *>>> &entry) {
1100+
out << entry.first->getNameStr();
1101+
},
1102+
[&] { out << ", "; });
1103+
out << "\nSame-type constraints:";
1104+
for (const auto &entry : sameTypeConstraints) {
1105+
out << "\n " << entry.first->getDebugName() << " == ";
1106+
interleave(entry.second,
1107+
[&](const Constraint<PotentialArchetype *> &constraint) {
1108+
out << constraint.value->getDebugName();
1109+
1110+
if (constraint.source->isDerivedRequirement())
1111+
out << " [derived]";
1112+
}, [&] {
1113+
out << ", ";
1114+
});
1115+
}
1116+
if (concreteType)
1117+
out << "\nConcrete type: " << concreteType.getString();
1118+
if (superclass)
1119+
out << "\nSuperclass: " << superclass.getString();
1120+
if (layout)
1121+
out << "\nLayout: " << layout.getString();
1122+
1123+
out << "\n";
1124+
}
1125+
1126+
void EquivalenceClass::dump() const {
1127+
dump(llvm::errs());
1128+
}
1129+
10861130
ConstraintResult GenericSignatureBuilder::handleUnresolvedRequirement(
10871131
RequirementKind kind,
10881132
UnresolvedType lhs,

0 commit comments

Comments
 (0)