|
16 | 16 | // (Vi.[Pi]), where each Vi.[Pi] is a left hand side of a generating
|
17 | 17 | // conformance.
|
18 | 18 | //
|
| 19 | +// A "conformance-valid" rewrite system is one where if we can write |
| 20 | +// T == U.V for arbitrary non-empty U and V, then U.[domain(V)] is joinable |
| 21 | +// with U. |
| 22 | +// |
| 23 | +// If this holds, then starting with a term T.[P] that is joinable with T, we |
| 24 | +// can reduce T to canonical form T', and find the unique rule (V.[P] => V) such |
| 25 | +// that T' == U.V. Then we repeat this process with U.[domain(V)], which is |
| 26 | +// known to be joinable with U, since T is conformance-valid. |
| 27 | +// |
| 28 | +// Iterating this process produces a decomposition of T.[P] as a product of |
| 29 | +// left hand sides of conformance rules. Some of those rules are not minimal; |
| 30 | +// they are added by completion, or they are redundant rules written by the |
| 31 | +// user. |
| 32 | +// |
| 33 | +// Using the 3-cells that generate the homotopy relation on rewrite paths, |
| 34 | +// decompositions can be found for all "derived" conformance rules, producing |
| 35 | +// a minimal set of generating conformances. |
| 36 | +// |
19 | 37 | //===----------------------------------------------------------------------===//
|
20 | 38 |
|
21 | 39 | #include "swift/Basic/Defer.h"
|
|
30 | 48 | using namespace swift;
|
31 | 49 | using namespace rewriting;
|
32 | 50 |
|
| 51 | +/// Finds all protocol conformance rules appearing in a 3-cell, both without |
| 52 | +/// context, and with a non-empty left context. Applications of rules with a |
| 53 | +/// non-empty right context are ignored. |
33 | 54 | void HomotopyGenerator::findProtocolConformanceRules(
|
34 | 55 | SmallVectorImpl<unsigned> ¬InContext,
|
35 | 56 | SmallVectorImpl<std::pair<MutableTerm, unsigned>> &inContext,
|
@@ -287,6 +308,14 @@ void RewriteSystem::computeCandidateConformancePaths(
|
287 | 308 | }
|
288 | 309 | }
|
289 | 310 |
|
| 311 | +/// Determines if \p path can be expressed without any of the conformance |
| 312 | +/// rules appearing in \p redundantConformances, by possibly substituting |
| 313 | +/// any occurrences of the redundant rules with alternate definitions |
| 314 | +/// appearing in \p conformancePaths. |
| 315 | +/// |
| 316 | +/// The \p conformancePaths map sends conformance rules to a list of |
| 317 | +/// disjunctions, where each disjunction is a product of other conformance |
| 318 | +/// rules. |
290 | 319 | bool RewriteSystem::isValidConformancePath(
|
291 | 320 | llvm::SmallDenseSet<unsigned, 4> &visited,
|
292 | 321 | llvm::DenseSet<unsigned> &redundantConformances,
|
@@ -325,6 +354,9 @@ bool RewriteSystem::isValidConformancePath(
|
325 | 354 | return true;
|
326 | 355 | }
|
327 | 356 |
|
| 357 | +/// Computes a minimal set of generating conformances, assuming that homotopy |
| 358 | +/// reduction has already eliminated all redundant rewrite rules that are not |
| 359 | +/// conformance rules. |
328 | 360 | void RewriteSystem::computeGeneratingConformances(
|
329 | 361 | llvm::DenseSet<unsigned> &redundantConformances) {
|
330 | 362 | llvm::MapVector<unsigned, std::vector<SmallVector<unsigned, 2>>> conformancePaths;
|
|
0 commit comments