@@ -1558,6 +1558,119 @@ void ConstraintGraph::dump(llvm::raw_ostream &out) {
1558
1558
print (CS.getTypeVariables (), out);
1559
1559
}
1560
1560
1561
+ void ConstraintGraph::print (llvm::raw_ostream &out, unsigned indent) {
1562
+ if (Changes.empty () && (ActiveScope->getStartIdx () == Changes.size ()))
1563
+ return ;
1564
+
1565
+ // Collect Changes for printing.
1566
+ std::map<TypeVariableType *, TypeBase *> tvWithboundTypes;
1567
+ std::vector<TypeVariableType *> addedTypeVars;
1568
+ std::vector<TypeVariableType *> equivTypeVars;
1569
+ std::vector<Constraint *> addedConstraints;
1570
+ std::vector<Constraint *> removedConstraints;
1571
+ for (unsigned int i = ActiveScope->getStartIdx (); i < Changes.size (); i++) {
1572
+ auto change = Changes[i];
1573
+ switch (change.Kind ) {
1574
+ case ChangeKind::BoundTypeVariable:
1575
+ tvWithboundTypes.insert (std::pair<TypeVariableType *, TypeBase *>(
1576
+ change.Binding .TypeVar , change.Binding .FixedType ));
1577
+ break ;
1578
+ case ChangeKind::AddedTypeVariable:
1579
+ addedTypeVars.push_back (change.TypeVar );
1580
+ break ;
1581
+ case ChangeKind::ExtendedEquivalenceClass:
1582
+ equivTypeVars.push_back (change.EquivClass .TypeVar );
1583
+ break ;
1584
+ case ChangeKind::AddedConstraint:
1585
+ addedConstraints.push_back (change.TheConstraint );
1586
+ break ;
1587
+ case ChangeKind::RemovedConstraint:
1588
+ removedConstraints.push_back (change.TheConstraint );
1589
+ break ;
1590
+ }
1591
+ }
1592
+
1593
+ // If there are any constraints that were both added and removed in this set
1594
+ // of Changes, remove them from both.
1595
+ for (std::vector<Constraint *>::const_iterator itr = addedConstraints.begin ();
1596
+ itr != addedConstraints.end ();) {
1597
+ auto repeatedConstraintItr =
1598
+ std::find (removedConstraints.begin (), removedConstraints.end (), *itr);
1599
+ if (repeatedConstraintItr != removedConstraints.end ()) {
1600
+ removedConstraints.erase (repeatedConstraintItr);
1601
+ itr = addedConstraints.erase (itr);
1602
+ } else {
1603
+ itr++;
1604
+ }
1605
+ }
1606
+
1607
+ // Print out Changes.
1608
+ PrintOptions PO;
1609
+ PO.PrintTypesForDebugging = true ;
1610
+ out.indent (indent);
1611
+ out << " (Changes:\n " ;
1612
+ if (!tvWithboundTypes.empty ()) {
1613
+ out.indent (indent + 2 );
1614
+ out << " (New Bound Type: \n " ;
1615
+ for (const auto &tvWithType : tvWithboundTypes) {
1616
+ out.indent (indent + 4 );
1617
+ out << " > $T" << tvWithType.first ->getImpl ().getID () << " := " ;
1618
+ tvWithType.second ->print (out, PO);
1619
+ out << ' \n ' ;
1620
+ }
1621
+ out.indent (indent + 2 );
1622
+ out << " )\n " ;
1623
+ }
1624
+ if (!addedTypeVars.empty ()) {
1625
+ out.indent (indent + 2 );
1626
+ out << " (New Type Variable: \n " ;
1627
+ for (const auto &typeVar : addedTypeVars) {
1628
+ out.indent (indent + 4 );
1629
+ out << " > $T" << typeVar->getImpl ().getID ();
1630
+ out << ' \n ' ;
1631
+ }
1632
+ out.indent (indent + 2 );
1633
+ out << " )\n " ;
1634
+ }
1635
+ if (!equivTypeVars.empty ()) {
1636
+ out.indent (indent + 2 );
1637
+ out << " (New Equivalence Class: \n " ;
1638
+ for (const auto &typeVar : equivTypeVars) {
1639
+ out.indent (indent + 4 );
1640
+ out << " > $T" << typeVar->getImpl ().getID ();
1641
+ out << ' \n ' ;
1642
+ }
1643
+ out.indent (indent + 2 );
1644
+ out << " )\n " ;
1645
+ }
1646
+ if (!addedConstraints.empty ()) {
1647
+ out.indent (indent + 2 );
1648
+ out << " (Added Constraint: \n " ;
1649
+ for (const auto &constraint : addedConstraints) {
1650
+ out.indent (indent + 4 );
1651
+ out << " > " ;
1652
+ constraint->print (out, &CS.getASTContext ().SourceMgr );
1653
+ out << ' \n ' ;
1654
+ }
1655
+ out.indent (indent + 2 );
1656
+ out << " )\n " ;
1657
+ }
1658
+ if (!removedConstraints.empty ()) {
1659
+ out.indent (indent + 2 );
1660
+ out << " (Removed Constraint: \n " ;
1661
+ for (const auto &constraint : removedConstraints) {
1662
+ out.indent (indent + 4 );
1663
+ out << " > " ;
1664
+ constraint->print (out, &CS.getASTContext ().SourceMgr );
1665
+ out << ' \n ' ;
1666
+ }
1667
+ out.indent (indent + 2 );
1668
+ out << " )\n " ;
1669
+ }
1670
+ out.indent (indent);
1671
+ out << " )\n " ;
1672
+ }
1673
+
1561
1674
void ConstraintGraph::printConnectedComponents (
1562
1675
ArrayRef<TypeVariableType *> typeVars,
1563
1676
llvm::raw_ostream &out) {
0 commit comments