Commits

Doug Gregor committed 9271a24a924
Introduce a protocol conformance registry for nominal types. (Note that this registry isn't fully enabled yet; it's built so that we can test it, but has not yet taken over the primary task of managing conformances from the existing system). The conformance registry tracks all of the protocols to which a particular nominal type conforms, including those for which conformance was explicitly specified, implied by other explicit conformances, inherited from a superclass, or synthesized by the implementation. The conformance registry is a lazily-built data structure designed for multi-file support (which has been a problematic area for protocol conformances). It allows one to query for the conformances of a type to a particular protocol, enumerate all protocols to which a type conforms, and enumerate all of the conformances that are associated with a particular declaration context (important to eliminate duplicated witness tables). The conformance registry diagnoses conflicts and ambiguities among different conformances of the same type to the same protocol. There are three common cases where we'll see a diagnostic: 1) Redundant explicit conformance of a type to a protocol: protocol P { } struct X : P { } extension X : P { } // error: redundant explicit conformance 2) Explicit conformance to a protocol that collides with an inherited conformance: protocol P { } class Super : P { } class Sub : Super, P { } // error: redundant explicit conformance 3) Ambiguous placement of an implied conformance: protocol P1 { } protocol P2 : P1 { } protocol P3 : P1 { } struct Y { } extension Y : P2 { } extension Y : P3 { } // error: ambiguous implied conformance to 'P1' This happens when two different explicit conformances (here, P2 and P3) placed on different declarations (e.g., two extensions, or the original definition and other extension) both imply the same conformance (P1), and neither of the explicit conformances imply each other. We require the user to explicitly specify the ambiguous conformance to break the ambiguity and associate the witness table with a specific context. Swift SVN r26067