Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/swift/Sema/CSBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,18 @@ class BindingSet {
/// Check whether the given binding set covers any of the
/// literal protocols associated with this type variable.
void determineLiteralCoverage();

StringRef getLiteralBindingKind(LiteralBindingKind K) const {
#define ENTRY(Kind, String) case LiteralBindingKind::Kind: return String
switch (K) {
ENTRY(None, "none");
ENTRY(Collection, "collection");
ENTRY(Float, "float");
ENTRY(Atom, "atom");
}
#undef ENTRY
}

};

} // end namespace inference
Expand Down
13 changes: 13 additions & 0 deletions include/swift/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,19 @@ class TypeVariableType::Implementation {

/// Print the type variable to the given output stream.
void print(llvm::raw_ostream &OS);

private:
StringRef getTypeVariableOptions(TypeVariableOptions TVO) const {
#define ENTRY(Kind, String) case TypeVariableOptions::Kind: return String
switch (TVO) {
ENTRY(TVO_CanBindToLValue, "lvalue");
ENTRY(TVO_CanBindToInOut, "inout");
ENTRY(TVO_CanBindToNoEscape, "noescape");
ENTRY(TVO_CanBindToHole, "hole");
ENTRY(TVO_PrefersSubtypeBinding, "");
}
#undef ENTRY
}
};

namespace constraints {
Expand Down
37 changes: 24 additions & 13 deletions lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1620,28 +1620,37 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
PO.PrintTypesForDebugging = true;

out.indent(indent);
std::vector<std::string> attributes;
if (isDirectHole())
out << "hole ";
attributes.push_back("hole");
if (isPotentiallyIncomplete())
out << "potentially_incomplete ";
attributes.push_back("potentially_incomplete");
if (isDelayed())
out << "delayed ";
attributes.push_back("delayed");
if (isSubtypeOfExistentialType())
out << "subtype_of_existential ";
attributes.push_back("subtype_of_existential");
auto literalKind = getLiteralKind();
if (literalKind != LiteralBindingKind::None)
out << "literal=" << static_cast<int>(literalKind) << " ";
if (literalKind != LiteralBindingKind::None) {
auto literalAttrStr = ("[literal: " + getLiteralBindingKind(literalKind)
+ "]").str();
attributes.push_back(literalAttrStr);
}
if (!attributes.empty()) {
out << "[attributes: ";
interleave(attributes, out, ", ");
out << "] ";
}
if (involvesTypeVariables()) {
out << "involves_type_vars=[";
out << "[involves_type_vars: ";
interleave(AdjacentVars,
[&](const auto *typeVar) { out << typeVar->getString(PO); },
[&out]() { out << " "; });
[&out]() { out << ", "; });
out << "] ";
}

auto numDefaultable = getNumViableDefaultableBindings();
if (numDefaultable > 0)
out << "#defaultable_bindings=" << numDefaultable << " ";
out << "#defaultable_bindings: " << numDefaultable << " ";

auto printBinding = [&](const PotentialBinding &binding) {
auto type = binding.BindingType;
Expand All @@ -1662,19 +1671,21 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
out << type.getString(PO);
};

out << "bindings={";
out << "[with possible bindings: ";
interleave(Bindings, printBinding, [&]() { out << "; "; });
out << "}";
if (Bindings.empty())
out << "<empty>";
out << "]";

if (!Defaults.empty()) {
out << " defaults={";
out << "[defaults: ";
for (const auto &entry : Defaults) {
auto *constraint = entry.second;
PotentialBinding binding{constraint->getSecondType(),
AllowedBindingKind::Exact, constraint};
printBinding(binding);
}
out << "}";
out << "] ";
}
}

Expand Down
28 changes: 19 additions & 9 deletions lib/Sema/TypeCheckConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ using namespace constraints;

void TypeVariableType::Implementation::print(llvm::raw_ostream &OS) {
getTypeVariable()->print(OS, PrintOptions());

SmallVector<TypeVariableOptions, 4> bindingOptions;
if (canBindToLValue())
bindingOptions.push_back(TypeVariableOptions::TVO_CanBindToLValue);
if (canBindToInOut())
bindingOptions.push_back(TypeVariableOptions::TVO_CanBindToInOut);
if (canBindToNoEscape())
bindingOptions.push_back(TypeVariableOptions::TVO_CanBindToNoEscape);
if (canBindToHole())
bindingOptions.push_back(TypeVariableOptions::TVO_CanBindToHole);
if (!bindingOptions.empty()) {
OS << " [allows bindings to: ";
interleave(bindingOptions, OS,
[&](TypeVariableOptions option) {
(OS << getTypeVariableOptions(option));},
", ");
OS << "]";
}
}

SavedTypeVariableBinding::SavedTypeVariableBinding(TypeVariableType *typeVar)
Expand Down Expand Up @@ -1415,15 +1433,7 @@ void ConstraintSystem::print(raw_ostream &out) const {
});
for (auto tv : typeVariables) {
out.indent(2);
Type(tv).print(out, PO);
if (tv->getImpl().canBindToLValue())
out << " [lvalue allowed]";
if (tv->getImpl().canBindToInOut())
out << " [inout allowed]";
if (tv->getImpl().canBindToNoEscape())
out << " [noescape allowed]";
if (tv->getImpl().canBindToHole())
out << " [hole allowed]";
tv->getImpl().print(out);
auto rep = getRepresentative(tv);
if (rep == tv) {
if (auto fixed = getFixedType(tv)) {
Expand Down