Skip to content

Commit b4f28b4

Browse files
committed
[ConstraintSystem] NFC: Move implementation of PotentialBindings::dump(...) into cpp
1 parent afec252 commit b4f28b4

File tree

2 files changed

+73
-71
lines changed

2 files changed

+73
-71
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4964,79 +4964,10 @@ class ConstraintSystem {
49644964
&inferredBindings);
49654965

49664966
void dump(llvm::raw_ostream &out,
4967-
unsigned indent = 0) const LLVM_ATTRIBUTE_USED {
4968-
out.indent(indent);
4969-
if (isDirectHole())
4970-
out << "hole ";
4971-
if (isPotentiallyIncomplete())
4972-
out << "potentially_incomplete ";
4973-
if (isDelayed())
4974-
out << "delayed ";
4975-
if (isSubtypeOfExistentialType())
4976-
out << "subtype_of_existential ";
4977-
auto literalKind = getLiteralKind();
4978-
if (literalKind != inference::LiteralBindingKind::None)
4979-
out << "literal=" << static_cast<int>(literalKind) << " ";
4980-
if (involvesTypeVariables())
4981-
out << "involves_type_vars ";
4982-
4983-
auto numDefaultable = getNumViableDefaultableBindings();
4984-
if (numDefaultable > 0)
4985-
out << "#defaultable_bindings=" << numDefaultable << " ";
4986-
4987-
PrintOptions PO;
4988-
PO.PrintTypesForDebugging = true;
4989-
4990-
auto printBinding = [&](const inference::PotentialBinding &binding) {
4991-
auto type = binding.BindingType;
4992-
switch (binding.Kind) {
4993-
case inference::AllowedBindingKind::Exact:
4994-
break;
4995-
4996-
case inference::AllowedBindingKind::Subtypes:
4997-
out << "(subtypes of) ";
4998-
break;
4999-
5000-
case inference::AllowedBindingKind::Supertypes:
5001-
out << "(supertypes of) ";
5002-
break;
5003-
}
5004-
if (auto *literal = binding.getDefaultedLiteralProtocol())
5005-
out << "(default from " << literal->getName() << ") ";
5006-
out << type.getString(PO);
5007-
};
5008-
5009-
out << "bindings={";
5010-
interleave(Bindings, printBinding, [&]() { out << "; "; });
5011-
out << "}";
5012-
5013-
if (!Defaults.empty()) {
5014-
out << " defaults={";
5015-
for (const auto &entry : Defaults) {
5016-
auto *constraint = entry.second;
5017-
inference::PotentialBinding binding{
5018-
constraint->getSecondType(), inference::AllowedBindingKind::Exact,
5019-
constraint};
5020-
printBinding(binding);
5021-
}
5022-
out << "}";
5023-
}
5024-
}
5025-
5026-
void dump(ConstraintSystem *cs,
5027-
unsigned indent = 0) const LLVM_ATTRIBUTE_USED {
5028-
dump(llvm::errs());
5029-
}
4967+
unsigned indent = 0) const LLVM_ATTRIBUTE_USED;
50304968

50314969
void dump(TypeVariableType *typeVar, llvm::raw_ostream &out,
5032-
unsigned indent = 0) const LLVM_ATTRIBUTE_USED {
5033-
out.indent(indent);
5034-
out << "(";
5035-
if (typeVar)
5036-
out << "$T" << typeVar->getImpl().getID();
5037-
dump(out, 1);
5038-
out << ")\n";
5039-
}
4970+
unsigned indent = 0) const LLVM_ATTRIBUTE_USED;
50404971
};
50414972

50424973
Optional<Type> checkTypeOfBinding(TypeVariableType *typeVar, Type type) const;

lib/Sema/CSBindings.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/Sema/ConstraintGraph.h"
1919
#include "swift/Sema/ConstraintSystem.h"
2020
#include "llvm/ADT/SetVector.h"
21+
#include "llvm/Support/raw_ostream.h"
2122
#include <tuple>
2223

2324
using namespace swift;
@@ -1232,6 +1233,76 @@ ConstraintSystem::PotentialBindings::getNumViableLiteralBindings() const {
12321233
});
12331234
}
12341235

1236+
void ConstraintSystem::PotentialBindings::dump(TypeVariableType *typeVar,
1237+
llvm::raw_ostream &out,
1238+
unsigned indent) const {
1239+
out.indent(indent);
1240+
out << "(";
1241+
if (typeVar)
1242+
out << "$T" << typeVar->getImpl().getID();
1243+
dump(out, 1);
1244+
out << ")\n";
1245+
}
1246+
1247+
void ConstraintSystem::PotentialBindings::dump(llvm::raw_ostream &out,
1248+
unsigned indent) const {
1249+
out.indent(indent);
1250+
if (isDirectHole())
1251+
out << "hole ";
1252+
if (isPotentiallyIncomplete())
1253+
out << "potentially_incomplete ";
1254+
if (isDelayed())
1255+
out << "delayed ";
1256+
if (isSubtypeOfExistentialType())
1257+
out << "subtype_of_existential ";
1258+
auto literalKind = getLiteralKind();
1259+
if (literalKind != inference::LiteralBindingKind::None)
1260+
out << "literal=" << static_cast<int>(literalKind) << " ";
1261+
if (involvesTypeVariables())
1262+
out << "involves_type_vars ";
1263+
1264+
auto numDefaultable = getNumViableDefaultableBindings();
1265+
if (numDefaultable > 0)
1266+
out << "#defaultable_bindings=" << numDefaultable << " ";
1267+
1268+
PrintOptions PO;
1269+
PO.PrintTypesForDebugging = true;
1270+
1271+
auto printBinding = [&](const PotentialBinding &binding) {
1272+
auto type = binding.BindingType;
1273+
switch (binding.Kind) {
1274+
case AllowedBindingKind::Exact:
1275+
break;
1276+
1277+
case AllowedBindingKind::Subtypes:
1278+
out << "(subtypes of) ";
1279+
break;
1280+
1281+
case AllowedBindingKind::Supertypes:
1282+
out << "(supertypes of) ";
1283+
break;
1284+
}
1285+
if (auto *literal = binding.getDefaultedLiteralProtocol())
1286+
out << "(default from " << literal->getName() << ") ";
1287+
out << type.getString(PO);
1288+
};
1289+
1290+
out << "bindings={";
1291+
interleave(Bindings, printBinding, [&]() { out << "; "; });
1292+
out << "}";
1293+
1294+
if (!Defaults.empty()) {
1295+
out << " defaults={";
1296+
for (const auto &entry : Defaults) {
1297+
auto *constraint = entry.second;
1298+
PotentialBinding binding{constraint->getSecondType(),
1299+
AllowedBindingKind::Exact, constraint};
1300+
printBinding(binding);
1301+
}
1302+
out << "}";
1303+
}
1304+
}
1305+
12351306
/// Check whether the given type can be used as a binding for the given
12361307
/// type variable.
12371308
///

0 commit comments

Comments
 (0)