<div dir="ltr"><div>I started taking a look at <a href="https://bugs.swift.org/browse/SR-493">SR-493</a>,  which is triggered with this code:<br><br><div><font face="monospace, monospace">    struct Foo&lt;G&gt; { var l1: G? }</font></div><div><font face="monospace, monospace">    extension </font><span style="font-family:monospace,monospace">Foo</span><font face="monospace, monospace"> { init(x: Int) { } }</font></div></div><div><br></div><div>It turns out that for the init in the extension, SILGenFunction::emitSemanticStore is being called with src &amp; dest types which <b>should</b> be the same, but aren&#39;t, so it goes down the wrong code path.</div><div><br></div><div>This is for the implicit initialization, which looks to be effectively &quot;self.l1 = { Optional&lt;G&gt;(nilLiteral: ()) }()&quot;</div><div><br></div><div><div><font face="monospace, monospace">(lldb) p <b>rvalue</b>.getType().getSwiftType()-&gt;getInOutObjectType()-&gt;getOptionalObjectType()</font></div><div><font face="monospace, monospace">(swift::Type) $191 = {</font></div><div><font face="monospace, monospace">  Ptr = 0x000000010d0a28d8</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace">(lldb) p <b>dest</b>.getType().getSwiftType()-&gt;getInOutObjectType()-&gt;getOptionalObjectType()</font></div><div><font face="monospace, monospace">(swift::Type) $192 = {</font></div><div><font face="monospace, monospace">  Ptr = 0x000000010b00dd68</font></div><div><font face="monospace, monospace">}</font></div></div><div><br></div><div>But these types &quot;look&quot; the same (they are both the archetype for G):</div><div><br></div><div><div><font face="monospace, monospace">(lldb) p <b>rvalue</b>.getType().getSwiftType()-&gt;getInOutObjectType()-&gt;getOptionalObjectType()-&gt;getString(PrintOptions::printEverything())</font></div><div><font face="monospace, monospace">(std::__1::string) $201 = &quot;G&quot;</font></div><div><font face="monospace, monospace">(lldb) p <b>dest</b>.getType().getSwiftType()-&gt;getInOutObjectType()-&gt;getOptionalObjectType()-&gt;getString(PrintOptions::printEverything())</font></div><div><font face="monospace, monospace">(std::__1::string) $202 = &quot;G&quot;</font></div></div><div><br></div><div>Now I&#39;m stuck. This is my first attempt to understand anything in SILGen, but I think the problem might trace back to Sema. Why would it end up with different Archetypes? Perhaps because the generic params are <a href="https://github.com/apple/swift/blob/c794609d29f85c76c7a6b1aba81b99cd213fd721/lib/Sema/TypeChecker.cpp#L333">cloned</a> for the extension decl?</div><div><br></div><div>Or a better question: is there a more correct way of comparing these types for the purpose of emitSemanticStore than simply <a href="https://github.com/apple/swift/blob/c794609d29f85c76c7a6b1aba81b99cd213fd721/include/swift/SIL/SILType.h#L526">by pointer equality</a>?</div><div><br></div><div>Thanks,</div><div>Jacob<br></div>
</div>