This method wasn’t returning the protocol on which the that the witness
method would satisfy, as documented. Rather, it was returning the protocol
to which the `Self` type conforms, which could be completely unrelated. For
example, in IndexingIterator’s conformance to IteratorProtocol, this method
would produce the protocol “Collection”, because that’s where the witness
itself was implemented. However, there isn’t necessarily a single such
protocol, so checking for/returning a single protocol was incorrect.
It turns out that there were only a few SIL verifier assertions of it
(that are trivially true) and two actual uses in code:
(1) The devirtualizer was using this computation to decide when it didn’t
need to perform any additional substitutions, but it’s predicate for doing
so was essentially incorrect. Instead, it really wanted to check whether
the Self type is still a type parameter.
(2) Our polymorphic convention was using it to essentially check whether
the ’Self’ instance type of a witness_method was a GenericTypeParamType,
which we can check directly.
Fixes rdar://problem/47767506 and possibly the hard-to-reproduce
rdar://problem/47772899.
Through a same-type constraint on an associated type, the Self type of
a protocol can conform to multiple protocols that are not related by
direct inheritance. There were two places that incorrectly assumed
that this didn't happen:
1) The SIL verifier checked that the archetype for Self conformed to
only a single protocol. This only tripped up +Asserts builds, and had
no effect on code generation. Change it to ensure that the archetype
for Self conforms to the expected protocol.
2) SILFunctionType's getDefaultWitnessMethodProtocol() asserted that
the Self type of a protocol only conformed to a single protocol, and
then returned the first protocol in the list. This could end up
returning the wrong protocol, in turn producing an incorrect
substitution list in IRGen. Change it to return the protocol from the
constraint in the generic signature.
Fixes SR-9848 / rdar://problem/47767506.