mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ConstraintGraph] Collect and print changes in current Active Scope.
This commit is contained in:
@@ -1558,6 +1558,123 @@ void ConstraintGraph::dump(llvm::raw_ostream &out) {
|
||||
print(CS.getTypeVariables(), out);
|
||||
}
|
||||
|
||||
void ConstraintGraph::dumpActiveScopeChanges(llvm::raw_ostream &out,
|
||||
unsigned indent) {
|
||||
if (Changes.empty())
|
||||
return;
|
||||
|
||||
// Collect Changes for printing.
|
||||
std::map<TypeVariableType *, TypeBase *> tvWithboundTypes;
|
||||
std::vector<TypeVariableType *> addedTypeVars;
|
||||
std::vector<TypeVariableType *> equivTypeVars;
|
||||
std::set<Constraint *> addedConstraints;
|
||||
std::set<Constraint *> removedConstraints;
|
||||
for (unsigned int i = ActiveScope->getStartIdx(); i < Changes.size(); i++) {
|
||||
auto change = Changes[i];
|
||||
switch (change.Kind) {
|
||||
case ChangeKind::BoundTypeVariable:
|
||||
tvWithboundTypes.insert(std::pair<TypeVariableType *, TypeBase *>(
|
||||
change.Binding.TypeVar, change.Binding.FixedType));
|
||||
break;
|
||||
case ChangeKind::AddedTypeVariable:
|
||||
addedTypeVars.push_back(change.TypeVar);
|
||||
break;
|
||||
case ChangeKind::ExtendedEquivalenceClass:
|
||||
equivTypeVars.push_back(change.EquivClass.TypeVar);
|
||||
break;
|
||||
case ChangeKind::AddedConstraint:
|
||||
addedConstraints.insert(change.TheConstraint);
|
||||
break;
|
||||
case ChangeKind::RemovedConstraint:
|
||||
removedConstraints.insert(change.TheConstraint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If there are any constraints that were both added and removed in this set
|
||||
// of Changes, remove them from both.
|
||||
std::set<Constraint *> intersects;
|
||||
set_intersection(addedConstraints.begin(), addedConstraints.end(),
|
||||
removedConstraints.begin(), removedConstraints.end(),
|
||||
std::inserter(intersects, intersects.begin()));
|
||||
llvm::set_subtract(addedConstraints, intersects);
|
||||
llvm::set_subtract(removedConstraints, intersects);
|
||||
|
||||
// Print out Changes.
|
||||
PrintOptions PO;
|
||||
PO.PrintTypesForDebugging = true;
|
||||
out.indent(indent);
|
||||
out << "(Changes:\n";
|
||||
if (!tvWithboundTypes.empty()) {
|
||||
out.indent(indent + 2);
|
||||
out << "(Newly Bound: \n";
|
||||
for (const auto &tvWithType : tvWithboundTypes) {
|
||||
out.indent(indent + 4);
|
||||
out << "> $T" << tvWithType.first->getImpl().getID() << " := ";
|
||||
tvWithType.second->print(out, PO);
|
||||
out << '\n';
|
||||
}
|
||||
out.indent(indent + 2);
|
||||
out << ")\n";
|
||||
}
|
||||
if (!addedTypeVars.empty()) {
|
||||
out.indent(indent + 2);
|
||||
auto heading = (addedTypeVars.size() > 1) ? "(New Type Variables: \n"
|
||||
: "(New Type Variable: \n";
|
||||
out << heading;
|
||||
for (const auto &typeVar : addedTypeVars) {
|
||||
out.indent(indent + 4);
|
||||
out << "> $T" << typeVar->getImpl().getID();
|
||||
out << '\n';
|
||||
}
|
||||
out.indent(indent + 2);
|
||||
out << ")\n";
|
||||
}
|
||||
if (!equivTypeVars.empty()) {
|
||||
out.indent(indent + 2);
|
||||
auto heading = (equivTypeVars.size() > 1) ? "(New Equivalences: \n"
|
||||
: "(New Equivalence: \n";
|
||||
out << heading;
|
||||
for (const auto &typeVar : equivTypeVars) {
|
||||
out.indent(indent + 4);
|
||||
out << "> $T" << typeVar->getImpl().getID();
|
||||
out << '\n';
|
||||
}
|
||||
out.indent(indent + 2);
|
||||
out << ")\n";
|
||||
}
|
||||
if (!addedConstraints.empty()) {
|
||||
out.indent(indent + 2);
|
||||
auto heading = (addedConstraints.size() > 1) ? "(Added Constraints: \n"
|
||||
: "(Added Constraint: \n";
|
||||
out << heading;
|
||||
for (const auto &constraint : addedConstraints) {
|
||||
out.indent(indent + 4);
|
||||
out << "> ";
|
||||
constraint->print(out, &CS.getASTContext().SourceMgr);
|
||||
out << '\n';
|
||||
}
|
||||
out.indent(indent + 2);
|
||||
out << ")\n";
|
||||
}
|
||||
if (!removedConstraints.empty()) {
|
||||
out.indent(indent + 2);
|
||||
auto heading = (removedConstraints.size() > 1) ? "(Removed Constraints: \n"
|
||||
: "(Removed Constraint: \n";
|
||||
out << heading;
|
||||
for (const auto &constraint : removedConstraints) {
|
||||
out.indent(indent + 4);
|
||||
out << "> ";
|
||||
constraint->print(out, &CS.getASTContext().SourceMgr);
|
||||
out << '\n';
|
||||
}
|
||||
out.indent(indent + 2);
|
||||
out << ")\n";
|
||||
}
|
||||
out.indent(indent);
|
||||
out << ")\n";
|
||||
}
|
||||
|
||||
void ConstraintGraph::printConnectedComponents(
|
||||
ArrayRef<TypeVariableType *> typeVars,
|
||||
llvm::raw_ostream &out) {
|
||||
|
||||
Reference in New Issue
Block a user