<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<G> { 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 & dest types which <b>should</b> be the same, but aren'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 "self.l1 = { Optional<G>(nilLiteral: ()) }()"</div><div><br></div><div><div><font face="monospace, monospace">(lldb) p <b>rvalue</b>.getType().getSwiftType()->getInOutObjectType()->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()->getInOutObjectType()->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 "look" 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()->getInOutObjectType()->getOptionalObjectType()->getString(PrintOptions::printEverything())</font></div><div><font face="monospace, monospace">(std::__1::string) $201 = "G"</font></div><div><font face="monospace, monospace">(lldb) p <b>dest</b>.getType().getSwiftType()->getInOutObjectType()->getOptionalObjectType()->getString(PrintOptions::printEverything())</font></div><div><font face="monospace, monospace">(std::__1::string) $202 = "G"</font></div></div><div><br></div><div>Now I'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>