Skip to content

Commit f8fb412

Browse files
committed
RequirementMachine: Add Rule::compare()
1 parent 3185fd8 commit f8fb412

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/AST/RequirementMachine/RewriteSystem.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ bool Rule::isProtocolRefinementRule() const {
7373
LHS[0] != LHS[1]);
7474
}
7575

76+
/// Linear order on rules; compares LHS followed by RHS.
77+
int Rule::compare(const Rule &other, const ProtocolGraph &protos) const {
78+
int compare = LHS.compare(other.LHS, protos);
79+
if (compare != 0)
80+
return compare;
81+
82+
return RHS.compare(other.RHS, protos);
83+
}
84+
7685
void Rule::dump(llvm::raw_ostream &out) const {
7786
out << LHS << " => " << RHS;
7887
if (Permanent)

lib/AST/RequirementMachine/RewriteSystem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class Rule final {
122122
return LHS.size();
123123
}
124124

125+
int compare(const Rule &other, const ProtocolGraph &protos) const;
126+
125127
void dump(llvm::raw_ostream &out) const;
126128

127129
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &out,

0 commit comments

Comments
 (0)