<div dir="ltr"><div>Happy holidays :-)</div><div><br></div><div>I started looking at this bug to see if I could figure out how to fix it:  <a href="https://bugs.swift.org/browse/SR-3500">https://bugs.swift.org/browse/SR-3500</a></div><div><div><br></div><div>As the bug author points out, there is a TODO in GenericSignature::getSubstitutionMap, saying it needs to handle same-type requirements:  <a href="https://github.com/apple/swift/blob/474096b9cbd6ff7ac998d7cea41d629512e25570/lib/AST/GenericSignature.cpp#L276">https://github.com/apple/swift/blob/474096b9cbd6ff7ac998d7cea41d629512e25570/lib/AST/GenericSignature.cpp#L276</a></div></div><div><br></div><div>Most of the stuff going on here is way over my head right now, but maybe I can get there by asking some questions. Here is my repro case:</div><div><br></div><div><div><font face="monospace, monospace">    protocol P { associatedtype Pmember }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    struct Bar {}</font></div><div><font face="monospace, monospace">    struct Foo: P { typealias Pmember = Bar }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    protocol A {</font></div><div><font face="monospace, monospace">      associatedtype Amember: P</font></div><div><font face="monospace, monospace">      func doSomething() -&gt; Amember.Pmember</font></div><div><font face="monospace, monospace">    }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    extension A where Amember == Foo {</font></div><div><font face="monospace, monospace">      func extensionFunc() {</font></div><div><font face="monospace, monospace">        doSomething()  // crash occurs when trying to subst() this call&#39;s return type</font></div><div><font face="monospace, monospace">      }</font></div><div><font face="monospace, monospace">    }</font></div></div><div><br></div><div>Ultimately the problem is that, during SILFunctionType::substGenericArgs, getMemberForBaseType() returns null when called on the DependentMemberType (the function result type), because the result of lookupConformances is not concrete: <a href="https://github.com/apple/swift/blob/474096b9cbd6ff7ac998d7cea41d629512e25570/lib/AST/Type.cpp#L2843-L2845">https://github.com/apple/swift/blob/474096b9cbd6ff7ac998d7cea41d629512e25570/lib/AST/Type.cpp#L2843-L2845</a></div><div><br></div><div>Here are some things I don&#39;t understand:</div><div><br></div><div>1. Why does LookupConformanceFn return only a single conformance? Couldn&#39;t there be more than one conformance for a particular generic param?</div><div><br></div><div>2. Why does finding an abstract conformance constitute a failure of getMemberForBaseType?</div><div><br></div><div>3. At the <a href="https://github.com/apple/swift/blob/474096b9cbd6ff7ac998d7cea41d629512e25570/lib/AST/Type.cpp#L2843-L2845">lookupConformances call</a>, origBase is &quot;τ_0_0.Amember&quot;, and substBase is the concrete type &quot;Foo&quot;. However, the LookUpConformanceInSubstitutionMap <a href="https://github.com/apple/swift/blob/474096b9cbd6ff7ac998d7cea41d629512e25570/lib/AST/Type.cpp#L2891">drops the substBase (</a><font color="#1155cc"><u>conformingReplacementType)</u></font><a href="https://github.com/apple/swift/blob/474096b9cbd6ff7ac998d7cea41d629512e25570/lib/AST/Type.cpp#L2891"> on the floor</a>. Why?</div><div><br></div><div>4. Finally, is SubstitutionMap really the right place for same-type requirements? Maybe getMemberForBaseType would need more context passed to it than just the LookupConformanceFn?</div><div><br></div>Thanks,<br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
</div>