@@ -197,44 +197,6 @@ class RewriteSystem final {
197
197
// / type is an index into the Rules array defined above.
198
198
Trie<unsigned , MatchKind::Shortest> Trie;
199
199
200
- // / Constructed from a rule of the form X.[P2:T] => X.[P1:T] by
201
- // / checkMergedAssociatedType().
202
- struct MergedAssociatedType {
203
- // / The *right* hand side of the original rule, X.[P1:T].
204
- Term rhs;
205
-
206
- // / The associated type symbol appearing at the end of the *left*
207
- // / hand side of the original rule, [P2:T].
208
- Symbol lhsSymbol;
209
-
210
- // / The merged associated type symbol, [P1&P2:T].
211
- Symbol mergedSymbol;
212
- };
213
-
214
- // / A list of pending terms for the associated type merging completion
215
- // / heuristic. Entries are added by checkMergedAssociatedType(), and
216
- // / consumed in processMergedAssociatedTypes().
217
- std::vector<MergedAssociatedType> MergedAssociatedTypes;
218
-
219
- // / Pairs of rules which have already been checked for overlap.
220
- llvm::DenseSet<std::pair<unsigned , unsigned >> CheckedOverlaps;
221
-
222
- // / Homotopy generators for this rewrite system. These are the
223
- // / rewrite loops which rewrite a term back to itself.
224
- // /
225
- // / In the category theory interpretation, a rewrite rule is a generating
226
- // / 2-cell, and a rewrite path is a 2-cell made from a composition of
227
- // / generating 2-cells.
228
- // /
229
- // / Homotopy generators, in turn, are 3-cells. The special case of a
230
- // / 3-cell discovered during completion can be viewed as two parallel
231
- // / 2-cells; this is actually represented as a single 2-cell forming a
232
- // / loop around a base point.
233
- // /
234
- // / This data is used by the homotopy reduction and generating conformances
235
- // / algorithms.
236
- std::vector<RewriteLoop> Loops;
237
-
238
200
DebugOptions Debug;
239
201
240
202
// / Whether we've initialized the rewrite system with a call to initialize().
@@ -288,10 +250,6 @@ class RewriteSystem final {
288
250
return Rules[ruleID];
289
251
}
290
252
291
- ArrayRef<RewriteLoop> getLoops () const {
292
- return Loops;
293
- }
294
-
295
253
bool addRule (MutableTerm lhs, MutableTerm rhs,
296
254
const RewritePath *path=nullptr );
297
255
@@ -309,6 +267,9 @@ class RewriteSystem final {
309
267
// /
310
268
// ////////////////////////////////////////////////////////////////////////////
311
269
270
+ // / Pairs of rules which have already been checked for overlap.
271
+ llvm::DenseSet<std::pair<unsigned , unsigned >> CheckedOverlaps;
272
+
312
273
std::pair<CompletionResult, unsigned >
313
274
computeConfluentCompletion (unsigned maxIterations,
314
275
unsigned maxDepth);
@@ -325,21 +286,6 @@ class RewriteSystem final {
325
286
void verifyRewriteRules (ValidityPolicy policy) const ;
326
287
327
288
private:
328
- void recordRewriteLoop (RewriteLoop loop) {
329
- if (!RecordLoops)
330
- return ;
331
-
332
- Loops.push_back (loop);
333
- }
334
-
335
- void recordRewriteLoop (MutableTerm basepoint,
336
- RewritePath path) {
337
- if (!RecordLoops)
338
- return ;
339
-
340
- Loops.emplace_back (basepoint, path);
341
- }
342
-
343
289
bool
344
290
computeCriticalPair (
345
291
ArrayRef<Symbol>::const_iterator from,
@@ -348,16 +294,96 @@ class RewriteSystem final {
348
294
std::vector<RewritePath> &paths,
349
295
std::vector<RewriteLoop> &loops) const ;
350
296
297
+ // / Constructed from a rule of the form X.[P2:T] => X.[P1:T] by
298
+ // / checkMergedAssociatedType().
299
+ struct MergedAssociatedType {
300
+ // / The *right* hand side of the original rule, X.[P1:T].
301
+ Term rhs;
302
+
303
+ // / The associated type symbol appearing at the end of the *left*
304
+ // / hand side of the original rule, [P2:T].
305
+ Symbol lhsSymbol;
306
+
307
+ // / The merged associated type symbol, [P1&P2:T].
308
+ Symbol mergedSymbol;
309
+ };
310
+
311
+ // / A list of pending terms for the associated type merging completion
312
+ // / heuristic. Entries are added by checkMergedAssociatedType(), and
313
+ // / consumed in processMergedAssociatedTypes().
314
+ std::vector<MergedAssociatedType> MergedAssociatedTypes;
315
+
351
316
void processMergedAssociatedTypes ();
352
317
353
318
void checkMergedAssociatedType (Term lhs, Term rhs);
354
319
320
+ // ////////////////////////////////////////////////////////////////////////////
321
+ // /
322
+ // / "Pseudo-rules" for the property map
323
+ // /
324
+ // ////////////////////////////////////////////////////////////////////////////
325
+
326
+ public:
327
+ struct ConcreteTypeWitness {
328
+ Symbol ConcreteConformance;
329
+ Symbol AssocType;
330
+ Symbol ConcreteType;
331
+
332
+ ConcreteTypeWitness (Symbol concreteConformance,
333
+ Symbol assocType,
334
+ Symbol concreteType);
335
+
336
+ friend bool operator ==(const ConcreteTypeWitness &lhs,
337
+ const ConcreteTypeWitness &rhs);
338
+ };
339
+
340
+ private:
341
+ // / Cache for concrete type witnesses. The value in the map is an index
342
+ // / into the vector.
343
+ llvm::DenseMap<std::pair<Symbol, Symbol>, unsigned > ConcreteTypeWitnessMap;
344
+ std::vector<ConcreteTypeWitness> ConcreteTypeWitnesses;
345
+
346
+ public:
347
+ unsigned recordConcreteTypeWitness (ConcreteTypeWitness witness);
348
+ const ConcreteTypeWitness &getConcreteTypeWitness (unsigned index) const ;
349
+
355
350
// ////////////////////////////////////////////////////////////////////////////
356
351
// /
357
352
// / Homotopy reduction
358
353
// /
359
354
// ////////////////////////////////////////////////////////////////////////////
360
355
356
+ // / Homotopy generators for this rewrite system. These are the
357
+ // / rewrite loops which rewrite a term back to itself.
358
+ // /
359
+ // / In the category theory interpretation, a rewrite rule is a generating
360
+ // / 2-cell, and a rewrite path is a 2-cell made from a composition of
361
+ // / generating 2-cells.
362
+ // /
363
+ // / Homotopy generators, in turn, are 3-cells. The special case of a
364
+ // / 3-cell discovered during completion can be viewed as two parallel
365
+ // / 2-cells; this is actually represented as a single 2-cell forming a
366
+ // / loop around a base point.
367
+ // /
368
+ // / This data is used by the homotopy reduction and generating conformances
369
+ // / algorithms.
370
+ std::vector<RewriteLoop> Loops;
371
+
372
+ void recordRewriteLoop (RewriteLoop loop) {
373
+ if (!RecordLoops)
374
+ return ;
375
+
376
+ Loops.push_back (loop);
377
+ }
378
+
379
+ void recordRewriteLoop (MutableTerm basepoint,
380
+ RewritePath path) {
381
+ if (!RecordLoops)
382
+ return ;
383
+
384
+ Loops.emplace_back (basepoint, path);
385
+ }
386
+
361
387
void propagateExplicitBits ();
362
388
363
389
bool
@@ -377,6 +403,10 @@ class RewriteSystem final {
377
403
llvm::DenseSet<unsigned > &redundantConformances);
378
404
379
405
public:
406
+ ArrayRef<RewriteLoop> getLoops () const {
407
+ return Loops;
408
+ }
409
+
380
410
void minimizeRewriteSystem ();
381
411
382
412
bool hadError () const ;
0 commit comments