Skip to content

Commit b497c79

Browse files
committed
RequirementMachine: Check invariants in noassert builds
1 parent 9c2d540 commit b497c79

File tree

5 files changed

+1
-24
lines changed

5 files changed

+1
-24
lines changed

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -864,18 +864,15 @@ RewriteSystem::getMinimizedGenericSignatureRules() const {
864864

865865
/// Verify that each loop begins and ends at its basepoint.
866866
void RewriteSystem::verifyRewriteLoops() const {
867-
#ifndef NDEBUG
868867
for (const auto &loop : Loops) {
869868
loop.verify(*this);
870869
}
871-
#endif
872870
}
873871

874872
/// Assert if homotopy reduction failed to eliminate a redundant conformance,
875873
/// since this suggests a misunderstanding on my part.
876874
void RewriteSystem::verifyRedundantConformances(
877875
const llvm::DenseSet<unsigned> &redundantConformances) const {
878-
#ifndef NDEBUG
879876
for (unsigned ruleID : redundantConformances) {
880877
const auto &rule = getRule(ruleID);
881878
assert(!rule.isPermanent() &&
@@ -893,14 +890,12 @@ void RewriteSystem::verifyRedundantConformances(
893890
abort();
894891
}
895892
}
896-
#endif
897893
}
898894

899895
// Assert if homotopy reduction failed to eliminate a rewrite rule it was
900896
// supposed to delete.
901897
void RewriteSystem::verifyMinimizedRules(
902898
const llvm::DenseSet<unsigned> &redundantConformances) const {
903-
#ifndef NDEBUG
904899
unsigned redundantRuleCount = 0;
905900

906901
for (unsigned ruleID : indices(Rules)) {
@@ -982,5 +977,4 @@ void RewriteSystem::verifyMinimizedRules(
982977
abort();
983978
}
984979
}
985-
#endif
986980
}

lib/AST/RequirementMachine/MinimalConformances.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,6 @@ void MinimalConformances::dumpMinimalConformanceEquation(
742742
}
743743

744744
void MinimalConformances::verifyMinimalConformanceEquations() const {
745-
#ifndef NDEBUG
746745
for (const auto &pair : ConformancePaths) {
747746
const auto &rule = System.getRule(pair.first);
748747
auto *proto = rule.getLHS().back().getProtocol();
@@ -804,7 +803,6 @@ void MinimalConformances::verifyMinimalConformanceEquations() const {
804803
}
805804
}
806805
}
807-
#endif
808806
}
809807

810808
bool MinimalConformances::isDerivedViaCircularConformanceRule(
@@ -884,7 +882,6 @@ void MinimalConformances::computeMinimalConformances() {
884882

885883
/// Check invariants.
886884
void MinimalConformances::verifyMinimalConformances() const {
887-
#ifndef NDEBUG
888885
for (const auto &pair : ConformancePaths) {
889886
unsigned ruleID = pair.first;
890887
const auto &rule = System.getRule(ruleID);
@@ -913,7 +910,6 @@ void MinimalConformances::verifyMinimalConformances() const {
913910
abort();
914911
}
915912
}
916-
#endif
917913
}
918914

919915
void MinimalConformances::dumpMinimalConformances(

lib/AST/RequirementMachine/RewriteLoop.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ void RewritePath::dumpLong(llvm::raw_ostream &out,
203203
}
204204

205205
void RewriteLoop::verify(const RewriteSystem &system) const {
206-
#ifndef NDEBUG
207206
RewritePathEvaluator evaluator(Basepoint);
208207

209208
for (const auto &step : Path) {
@@ -222,7 +221,6 @@ void RewriteLoop::verify(const RewriteSystem &system) const {
222221
evaluator.dump(llvm::errs());
223222
abort();
224223
}
225-
#endif
226224
}
227225

228226
void RewriteLoop::dump(llvm::raw_ostream &out,

lib/AST/RequirementMachine/RewriteSystem.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,14 +631,12 @@ void RewriteSystem::recordRewriteLoop(MutableTerm basepoint,
631631
}
632632

633633
void RewriteSystem::verifyRewriteRules(ValidityPolicy policy) const {
634-
#ifndef NDEBUG
635-
636634
#define ASSERT_RULE(expr) \
637635
if (!(expr)) { \
638636
llvm::errs() << "&&& Malformed rewrite rule: " << rule << "\n"; \
639637
llvm::errs() << "&&& " << #expr << "\n\n"; \
640638
dump(llvm::errs()); \
641-
assert(expr); \
639+
abort(); \
642640
}
643641

644642
for (const auto &rule : Rules) {
@@ -705,7 +703,6 @@ void RewriteSystem::verifyRewriteRules(ValidityPolicy policy) const {
705703
}
706704

707705
#undef ASSERT_RULE
708-
#endif
709706
}
710707

711708
void RewriteSystem::dump(llvm::raw_ostream &out) const {

lib/AST/RequirementMachine/TypeDifference.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ void TypeDifference::dump(llvm::raw_ostream &out) const {
7878
}
7979

8080
void TypeDifference::verify(RewriteContext &ctx) const {
81-
#ifndef NDEBUG
82-
8381
#define VERIFY(expr, str) \
8482
if (!(expr)) { \
8583
llvm::errs() << "TypeDifference::verify(): " << str << "\n"; \
@@ -113,7 +111,6 @@ void TypeDifference::verify(RewriteContext &ctx) const {
113111
}
114112

115113
#undef VERIFY
116-
#endif
117114
}
118115

119116
namespace {
@@ -213,8 +210,6 @@ namespace {
213210
}
214211

215212
void verify() const {
216-
#ifndef NDEBUG
217-
218213
#define VERIFY(expr, str) \
219214
if (!(expr)) { \
220215
llvm::errs() << "ConcreteTypeMatcher::verify(): " << str << "\n"; \
@@ -258,7 +253,6 @@ namespace {
258253
}
259254

260255
#undef VERIFY
261-
#endif
262256
}
263257

264258
void dump(llvm::raw_ostream &out) const {
@@ -460,7 +454,6 @@ RewriteSystem::computeTypeDifference(Term baseTerm, Symbol lhs, Symbol rhs,
460454

461455
bool isConflict = (matcher.ConcreteConflicts.size() > 0);
462456

463-
#ifndef NDEBUG
464457
if (!isConflict) {
465458
// The meet operation should be commutative.
466459
if (lhsMeetRhs.RHS != rhsMeetLhs.RHS) {
@@ -523,7 +516,6 @@ RewriteSystem::computeTypeDifference(Term baseTerm, Symbol lhs, Symbol rhs,
523516
}
524517
}
525518
}
526-
#endif
527519

528520
if (lhs != lhsMeetRhs.RHS)
529521
lhsDifferenceID = recordTypeDifference(lhsMeetRhs);

0 commit comments

Comments
 (0)