[cxx-interop] Stop instantiating return types before importing them
In f305ffc69f2fbfc80eaa984c170d3f735f4b5cc4 I added change that eagerly
instantiates return type templates before importing them, which
technically makes ClangImporter *more* eager. I made this change, in
conjunction with 3a213c0085bda80a0b0178311b6cb3252a7ac6c1, in an attempt
to make sure that the `__Unsafe` name mangling does not rely on the
unintentional side effect of importing typedefs eagerly (which I made
lazy in c57863df0cfc092936fa266ebfedcc41d6418b7d). The fact that this is
more eager is not sound, but I hadn't thought of any better ways around
this at the time.
This patch gets rid of the over-eager return type instantiation by
moving it to *after* the function is imported. If and only if the
method is actually imported, Swift will instantiate the return type,
re-import the name, and overwrite the name of the imported decl, in case
the instantiation or some other side effect during import causes it to
gain the `__Unsafe` name mangling. Admittedly, this is an ugly hack, but
an inevitable consequence of how we do name importing.
I've added a test scenario to ensure that deleted functions do not have
their return types instantiated, but other test to pay attention to is
test/Interop/Cxx/templates/using-return-type.swift, which checks that
the `__Unsafe` mangling logic is robust. This test does not change.
rdar://174028575