@@ -1021,6 +1021,9 @@ Atom RewriteSystem::simplifySubstitutionsInSuperclassOrConcreteAtom(
1021
1021
}
1022
1022
1023
1023
bool RewriteSystem::addRule (MutableTerm lhs, MutableTerm rhs) {
1024
+ assert (!lhs.empty ());
1025
+ assert (!rhs.empty ());
1026
+
1024
1027
// Simplify the rule as much as possible with the rules we have so far.
1025
1028
//
1026
1029
// This avoids unnecessary work in the completion algorithm.
@@ -1518,6 +1521,62 @@ void RewriteSystem::simplifyRightHandSides() {
1518
1521
simplify (rhs);
1519
1522
rule = Rule (rule.getLHS (), rhs);
1520
1523
}
1524
+
1525
+ #ifndef NDEBUG
1526
+
1527
+ #define ASSERT_RULE (expr ) \
1528
+ if (!(expr)) { \
1529
+ llvm::errs () << " &&& Malformed rewrite rule: " ; \
1530
+ rule.dump (llvm::errs ()); \
1531
+ llvm::errs () << " \n\n " ; \
1532
+ dump (llvm::errs ()); \
1533
+ assert (expr); \
1534
+ }
1535
+
1536
+ for (const auto &rule : Rules) {
1537
+ if (rule.isDeleted ())
1538
+ continue ;
1539
+
1540
+ const auto &lhs = rule.getLHS ();
1541
+ const auto &rhs = rule.getRHS ();
1542
+
1543
+ for (unsigned index : indices (lhs)) {
1544
+ auto atom = lhs[index];
1545
+
1546
+ if (index != lhs.size () - 1 ) {
1547
+ ASSERT_RULE (atom.getKind () != Atom::Kind::Layout);
1548
+ ASSERT_RULE (!atom.isSuperclassOrConcreteType ());
1549
+ }
1550
+
1551
+ if (index != 0 ) {
1552
+ ASSERT_RULE (atom.getKind () != Atom::Kind::GenericParam);
1553
+ }
1554
+
1555
+ if (index != 0 && index != lhs.size () - 1 ) {
1556
+ ASSERT_RULE (atom.getKind () != Atom::Kind::Protocol);
1557
+ }
1558
+ }
1559
+
1560
+ for (unsigned index : indices (rhs)) {
1561
+ auto atom = rhs[index];
1562
+
1563
+ // FIXME: This is only true if the input requirements were valid.
1564
+ // On invalid code, we'll need to skip this assertion (and instead
1565
+ // assert that we diagnosed an error!)
1566
+ ASSERT_RULE (atom.getKind () != Atom::Kind::Name);
1567
+
1568
+ ASSERT_RULE (atom.getKind () != Atom::Kind::Layout);
1569
+ ASSERT_RULE (!atom.isSuperclassOrConcreteType ());
1570
+
1571
+ if (index != 0 ) {
1572
+ ASSERT_RULE (atom.getKind () != Atom::Kind::GenericParam);
1573
+ ASSERT_RULE (atom.getKind () != Atom::Kind::Protocol);
1574
+ }
1575
+ }
1576
+ }
1577
+
1578
+ #undef ASSERT_RULE
1579
+ #endif
1521
1580
}
1522
1581
1523
1582
void RewriteSystem::dump (llvm::raw_ostream &out) const {
0 commit comments