|
1 |
| -//===--- PropertyUnification.cpp - Rules added w/ building property map ---===// |
| 1 | +//===--- SimplifySubstitutions.cpp - Simplify concrete type rules ---------===// |
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift.org open source project
|
4 | 4 | //
|
|
9 | 9 | // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
| 12 | +// |
| 13 | +// Implements a pass for simplifying substitutions in concrete type symbols. |
| 14 | +// Substitutions can be simplifed in one of two ways; either a substitution |
| 15 | +// term can be replaced by a more canonical term, or it can be replaced by a |
| 16 | +// concrete type. |
| 17 | +// |
| 18 | +// For example, given pair of rewrite rules: |
| 19 | +// |
| 20 | +// T.[concrete: G<Y>] => T |
| 21 | +// Y => X |
| 22 | +// |
| 23 | +// We can apply (Y => X) to the term appearing in the concrete type symbol |
| 24 | +// [concrete: G<Y>] to obtain the rule: |
| 25 | +// |
| 26 | +// T.[concrete: G<X>] => T |
| 27 | +// |
| 28 | +// Similarly, if we have a pair of rewrite rules: |
| 29 | +// |
| 30 | +// T.[concrete: G<Y>] => T |
| 31 | +// Y.[concrete: Int] => Y |
| 32 | +// |
| 33 | +// We can obtain the new rule: |
| 34 | +// |
| 35 | +// T.[concrete: G<Int>] => T |
| 36 | +// |
| 37 | +// Substitution simplification occurs during the Knuth-Bendix completion |
| 38 | +// procedure, and after property map construction. |
| 39 | +// |
| 40 | +// In the first case, no property map is available yet, so substitution terms |
| 41 | +// are simplified to other terms, but concrete type replacement is not |
| 42 | +// performed. In the second case, the property map is consulted to perform |
| 43 | +// concrete type replacement where appropriate. |
| 44 | +// |
| 45 | +// Either the new rule or the old rule can become redundant; they are related |
| 46 | +// by rewrite loops. Additionally, rewrite loops are introduced for each |
| 47 | +// transformation applied to the substitutions to relate them to the concrete |
| 48 | +// type rules via "projections". |
| 49 | +// |
| 50 | +// These rewrite loops are in a sense dual to the property map's concrete type |
| 51 | +// unification, and share a lot of the code; whereas the property map will |
| 52 | +// relate two rules (T.[concrete: G<X>] => T) with (T.[concrete: G<Y>] => T) |
| 53 | +// and add the induced rule (Y => X), substitution simplification will use |
| 54 | +// (Y => X) to transform (T.[concrete: G<Y>] => T) into |
| 55 | +// (T.[concrete: G<X>] => T). |
| 56 | +// |
| 57 | +// This logic (and concrete type unification) heavily relies on the "type |
| 58 | +// difference" abstraction implemented in TypeDifference.cpp. Technical details |
| 59 | +// about the various rewrite loops introduced here can be found in comments at |
| 60 | +// the top of various functions below. |
| 61 | +// |
| 62 | +//===----------------------------------------------------------------------===// |
12 | 63 |
|
13 | 64 | #include "PropertyMap.h"
|
14 | 65 | #include "RewriteSystem.h"
|
|
0 commit comments