@@ -50,7 +50,13 @@ enum class CompletionResult {
5050 MaxRuleLength,
5151
5252 // / Maximum concrete type nesting depth exceeded.
53- MaxConcreteNesting
53+ MaxConcreteNesting,
54+
55+ // / Maximum concrete type size exceeded.
56+ MaxConcreteSize,
57+
58+ // / Maximum type difference count exceeded.
59+ MaxTypeDifferences,
5460};
5561
5662// / A term rewrite system for working with types in a generic signature.
@@ -107,13 +113,16 @@ class RewriteSystem final {
107113 // / identities among rewrite rules discovered while resolving critical pairs.
108114 unsigned RecordLoops : 1 ;
109115
110- // / The length of the longest initial rule, used for the MaxRuleLength
111- // / completion non-termination heuristic.
116+ // / The length of the longest initial rule, for the MaxRuleLength limit.
112117 unsigned LongestInitialRule : 16 ;
113118
114- // / The most deeply nested concrete type appearing in an initial rule, used
115- // / for the MaxConcreteNesting completion non-termination heuristic.
116- unsigned DeepestInitialRule : 16 ;
119+ // / The most deeply nested concrete type appearing in an initial rule,
120+ // / for the MaxConcreteNesting limit.
121+ unsigned MaxNestingOfInitialRule : 16 ;
122+
123+ // / The largest concrete type by total tree node count that appears in an
124+ // / initial rule, for the MaxConcreteSize limit.
125+ unsigned MaxSizeOfInitialRule : 16 ;
117126
118127public:
119128 explicit RewriteSystem (RewriteContext &ctx);
@@ -143,8 +152,12 @@ class RewriteSystem final {
143152 return LongestInitialRule;
144153 }
145154
146- unsigned getDeepestInitialRule () const {
147- return DeepestInitialRule;
155+ unsigned getMaxNestingOfInitialRule () const {
156+ return MaxNestingOfInitialRule;
157+ }
158+
159+ unsigned getMaxSizeOfInitialRule () const {
160+ return MaxSizeOfInitialRule;
148161 }
149162
150163 ArrayRef<const ProtocolDecl *> getProtocols () const {
@@ -206,7 +219,7 @@ class RewriteSystem final {
206219 // ////////////////////////////////////////////////////////////////////////////
207220
208221 // / Pairs of rules which have already been checked for overlap.
209- llvm::DenseSet<std::pair< unsigned , unsigned >> CheckedOverlaps;
222+ llvm::DenseSet<std::tuple< unsigned , unsigned , unsigned >> CheckedOverlaps;
210223
211224 std::pair<CompletionResult, unsigned >
212225 performKnuthBendix (unsigned maxRuleCount, unsigned maxRuleLength);
@@ -311,6 +324,10 @@ class RewriteSystem final {
311324 std::optional<unsigned > &lhsDifferenceID,
312325 std::optional<unsigned > &rhsDifferenceID);
313326
327+ unsigned getTypeDifferenceCount () const {
328+ return Differences.size ();
329+ }
330+
314331 const TypeDifference &getTypeDifference (unsigned index) const ;
315332
316333 void processTypeDifference (const TypeDifference &difference,
0 commit comments