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