Skip to content

Commit 5cf3821

Browse files
committed
[Conformance checker] Add debug dumping for inferred type witnesses.
Debugging type witness inference is annoying; add some dumping code to help with debugging.
1 parent cc53f77 commit 5cf3821

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,18 +1591,88 @@ namespace {
15911591
/// requirements.
15921592
SmallVector<std::tuple<AssociatedTypeDecl *, Type, CheckTypeWitnessResult>,
15931593
2> NonViable;
1594+
1595+
void dump(llvm::raw_ostream &out, unsigned indent) const {
1596+
out << "\n";
1597+
out.indent(indent) << "(";
1598+
if (Witness) {
1599+
Witness->dumpRef(out);
1600+
}
1601+
1602+
for (const auto &inferred : Inferred) {
1603+
out << "\n";
1604+
out.indent(indent + 2);
1605+
out << inferred.first->getName() << " := "
1606+
<< inferred.second.getString();
1607+
}
1608+
1609+
for (const auto &inferred : NonViable) {
1610+
out << "\n";
1611+
out.indent(indent + 2);
1612+
out << std::get<0>(inferred)->getName() << " := "
1613+
<< std::get<1>(inferred).getString();
1614+
if (auto nominal = std::get<2>(inferred).getProtocolOrClass())
1615+
out << " [failed constraint " << nominal->getName() << "]";
1616+
}
1617+
1618+
out << ")";
1619+
}
1620+
1621+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
1622+
"only for use in the debugger");
15941623
};
15951624

1625+
void InferredAssociatedTypesByWitness::dump() const {
1626+
dump(llvm::errs(), 0);
1627+
}
1628+
15961629
/// The set of witnesses that were considered when attempting to
15971630
/// infer associated types.
15981631
typedef SmallVector<InferredAssociatedTypesByWitness, 2>
15991632
InferredAssociatedTypesByWitnesses;
16001633

1634+
void dumpInferredAssociatedTypesByWitnesses(
1635+
const InferredAssociatedTypesByWitnesses &inferred,
1636+
llvm::raw_ostream &out,
1637+
unsigned indent) {
1638+
for (const auto &value : inferred) {
1639+
value.dump(out, indent);
1640+
}
1641+
}
1642+
1643+
void dumpInferredAssociatedTypesByWitnesses(
1644+
const InferredAssociatedTypesByWitnesses &inferred) LLVM_ATTRIBUTE_USED;
1645+
1646+
void dumpInferredAssociatedTypesByWitnesses(
1647+
const InferredAssociatedTypesByWitnesses &inferred) {
1648+
dumpInferredAssociatedTypesByWitnesses(inferred, llvm::errs(), 0);
1649+
}
1650+
16011651
/// A mapping from requirements to the set of matches with witnesses.
16021652
typedef SmallVector<std::pair<ValueDecl *,
16031653
InferredAssociatedTypesByWitnesses>, 4>
16041654
InferredAssociatedTypes;
16051655

1656+
void dumpInferredAssociatedTypes(const InferredAssociatedTypes &inferred,
1657+
llvm::raw_ostream &out,
1658+
unsigned indent) {
1659+
for (const auto &value : inferred) {
1660+
out << "\n";
1661+
out.indent(indent) << "(";
1662+
value.first->dumpRef(out);
1663+
dumpInferredAssociatedTypesByWitnesses(value.second, out, indent + 2);
1664+
out << ")";
1665+
}
1666+
out << "\n";
1667+
}
1668+
1669+
void dumpInferredAssociatedTypes(
1670+
const InferredAssociatedTypes &inferred) LLVM_ATTRIBUTE_USED;
1671+
1672+
void dumpInferredAssociatedTypes(const InferredAssociatedTypes &inferred) {
1673+
dumpInferredAssociatedTypes(inferred, llvm::errs(), 0);
1674+
}
1675+
16061676
/// The protocol conformance checker.
16071677
///
16081678
/// This helper class handles most of the details of checking whether a

0 commit comments

Comments
 (0)