mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Suppose we have these rules: (1) [P].[P] => [P] (2) [P].[P:X] => [P:X] (3) [P].[P:Y] => [P:Y] (4) [P:X].[concrete: G<τ_0_0> with <[P:Y]>] Rule (2) and (4) overlap on the following term, which has had the concrete type adjustment applied: [P].[P:X].[concrete: G<τ_0_0> with <[P].[P:Y]>] The critical pair is obtained by applying rule (2) to both sides of the branching is [P:X].[concrete: G<τ_0_0> with <[P].[P:Y]>] => [P:X] Note that this is a distinct rule from (4), and again this new rule overlaps with (2), producing another rule [P:X].[concrete: G<τ_0_0> with <[P].[P].[P:Y]>] => [P:X] This process doesn't terminate. The root cause of this problem is the existence of rule (1), which appears when there are multiple non-trivial conformance paths witnessing the conformance Self : P. This occurs when a same-type requirement is defined between Self and some other type conforming to P. To make this work, we need to simplify concrete substitutions when adding a new rule in completion. Now that rewrite paths can represent this form of simplification, this is easy to add.