Skip to content

Commit f4cb13f

Browse files
committed
RequirementMachine: Pack the RequirementID field of Rule into a bitfield
1 parent 77e2f4c commit f4cb13f

File tree

1 file changed

+14
-4
lines changed
  • lib/AST/RequirementMachine

1 file changed

+14
-4
lines changed

lib/AST/RequirementMachine/Rule.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ class Rule final {
3838
/// The written requirement ID, which can be used to index into the
3939
/// \c WrittenRequirements array in the rewrite system to retrieve
4040
/// the structural requirement.
41-
Optional<unsigned> requirementID;
41+
///
42+
/// This uses a biased representation where an ID of 0 means 'no ID',
43+
/// otherwise the value is the actual ID plus one.
44+
unsigned RequirementID : 16;
4245

4346
/// A 'permanent' rule cannot be deleted by homotopy reduction. These
4447
/// do not correspond to generic requirements and are re-added when the
@@ -83,6 +86,7 @@ class Rule final {
8386
public:
8487
Rule(Term lhs, Term rhs)
8588
: LHS(lhs), RHS(rhs) {
89+
RequirementID = 0;
8690
Permanent = false;
8791
Explicit = false;
8892
LHSSimplified = false;
@@ -97,12 +101,18 @@ class Rule final {
97101
const Term &getRHS() const { return RHS; }
98102

99103
Optional<unsigned> getRequirementID() const {
100-
return requirementID;
104+
if (RequirementID == 0)
105+
return None;
106+
else
107+
return RequirementID - 1;
101108
}
102109

103110
void setRequirementID(Optional<unsigned> requirementID) {
104111
assert(!Frozen);
105-
this->requirementID = requirementID;
112+
if (!requirementID)
113+
RequirementID = 0;
114+
else
115+
RequirementID = *requirementID + 1;
106116
}
107117

108118
Optional<Symbol> isPropertyRule() const;
@@ -209,7 +219,7 @@ class Rule final {
209219

210220
void freeze() {
211221
Redundant = false;
212-
requirementID = None;
222+
RequirementID = 0;
213223
Frozen = true;
214224
}
215225

0 commit comments

Comments
 (0)