-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Interop][SwiftToCxx] Support enum creation from Cxx #60842
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
Conversation
@hyp Could you please test and review this pull request? Thanks. |
@swift-ci please test |
@swift-ci please test macOS platform |
@swift-ci please test source compatibility |
int main() { | ||
{ | ||
auto e = E::x(3.14); | ||
switchTest(e); |
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.
we're asserting in each case, but we should also verify that we actually went through the right switch case. How about returning some sentinel value from switchTest
e.g. a string, and asserting here that it's expected, e.g.
case E::x:
assert(e.isX());
assert(e.getX() == 3.14);
return "x";
...
auto e = E::x(3.14);
auto res = switchTest(e);
assert(res == "e");
// CHECK-NEXT: } | ||
// CHECK-NEXT: inline E E::_impl_foobar::operator()() const { | ||
// CHECK-NEXT: auto result = E::_make(); | ||
// CHECK-NEXT: result._destructiveInjectEnumTag(5); |
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.
Can you also add a test for resilient enum where we call _destructiveInjectEnumTag
using extern "C" tag values as well?
// CHECK-NEXT: using _impl_auto = decltype(auto_); | ||
// CHECK-NEXT: using _impl_foobar = decltype(foobar); | ||
// CHECK: }; | ||
// CHECK-NEXT: decltype(E::x) E::x; |
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.
can you make supporting structs emitted as inline const
variables? that way they're actually unique to each TU and won't conflict at link time.
@swift-ci please test |
@swift-ci please test source compatibility |
@swift-ci please test |
@swift-ci please test linux platform |
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.
LGTM
Hooray! |
@swift-ci please test linux platform |
@swift-ci please test windows platform |
@swift-ci please smoke test macos platform |
@swift-ci please test macos platform |
This pull request adds support for Swift enum creation from C++:
cxx_synthesis
to printswift
namespace in C++.DeclAndTypePrinter
to print functions needed for enum creation.DeclAndTypeClangFuncPrinter
to print a custom generated function in C++