Getting back to this after working on something else.
I've looked at the details of what I would need to do, and I'd appreciate feedback on my plan.
I see two main issues to solve:
-
arrangeCXXConstructorCall()
takes aCXXConstructorDecl
, butSignatureExpansion::expandExternalSignatureTypes()
doesn't have access to that.Indeed, as
SignatureExpansion
deals in function types, not function declarations, it shouldn't have access to theCXXConstructorDecl
.Luckily,
arrangeCXXConstructorCall()
doesn't need very much from theCXXConstructorDecl
. It really just wants theclang::FunctionProtoType
(which I think we can get throughSILFunctionType::getClangFunctionType()
) and aclang::GlobalDecl
, which it passes toCGCXXABI::HasReturn
andCGCXXABI::hasMostDerivedReturn
. Those two functions really just need theclang::Decl::Kind
(which we could hardcode asDecl::Kind::CXXConstructor
) and theclang::CXXCtorType
(which I believe we could hardcode asCtor_Complete
). So if we change these functions in Clang, I think we should have everything we need to pass intoarrangeCXXConstructorCall()
. -
SignatureExpansion::expandExternalSignatureTypes()
would need to know whether to callarrangeFreeFunctionCall()
,arrangeCXXMethodCall()
orarrangeCXXConstructorCall()
.There are two ways I can see to do this:
-
Try to infer from the
SILFunctionType
what we're calling. If the function takes a thin metatype and returns an object of the same type, it's probably a C++ constructor. If it takes a self parameter, it's probably a C++ method. Otherwise, it's a free function.This approach would not require any more far-reaching changes, but it arguably encodes too much knowledge about expected SIL signatures in
expandExternalSignatureTypes()
. -
Introduce two new
SILFunctionTypeRepresentation
cases:CXXMethod
andCXXConstructor
. This is cleaner, and the new cases are a nice parallel to the existingObjCMethod
case. However, there are a lot of places that switch overSILFunctionTypeRepresenation
and would need to be extended, so I'd like to know whether people think this is the right approach before starting work on it.
-