-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Import parameterized public ctors of C++ foreign ref types as Swift Initializer #80449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[cxx-interop] Import parameterized public ctors of C++ foreign ref types as Swift Initializer #80449
Conversation
fa97b38
to
96518c0
Compare
Note: Default arguments are still not supported for both default and parameterized ctors |
@swift-ci please smoke test |
struct __attribute__((swift_attr("import_reference"))) | ||
__attribute__((swift_attr("retain:Retain18"))) | ||
__attribute__((swift_attr("release:Release18"))) NoIdentifierInCtorParam { | ||
public: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have some tests with constructors of user defined types that have user defined copy/move ctors.
Enabling auto merge after addressing all the comments on this patch. I can think of only 2 things right now which can be addressed in a follow up patch:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Thanks for working on this! I have one last comment inline but otherwise everything looks good to me.
"Unable to synthesize `new` expression for c++ foreign reference type"); | ||
auto *synthNewExpr = cast<clang::CXXNewExpr>(synthNewExprResult.get()); | ||
|
||
clang::ReturnStmt *synthRetStmt = clang::ReturnStmt::Create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I wonder if we want to use Sema::BuildReturnStmt
here, and add the SFNAETrap
to all of the sema calls (could be the same trap for all the Build*
calls).
@swift-ci please smoke test |
Enabling auto merge after addressing all the comments on this patch. I can think of only these minor things which can be addressed in follow up patches later:
|
…pes as Swift Initializer (#80449) Extends PR #79986 by adding support for calling parameterized C++ initializers from Swift. This patch synthesizes static factory methods corresponding to C++ parameterized constructors, allowing Swift to call them as Swift initializers (e.g., init(_:), init(_:_:), etc.). This patch also aded tests and logic to make sure that we emit no additional diagnostics when a C++ foreign ref type is just referred from Swift and its initializer is not explicitly called. rdar://148285251
Extends PR #79986 by adding support for calling parameterized C++ initializers from Swift. This patch synthesizes static factory methods corresponding to C++ parameterized constructors, allowing Swift to call them as Swift initializers (e.g.,
init(_:)
,init(_:_:)
, etc.).rdar://148285251