-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Interop][SwiftToCxx] Introduces swift::Expected #61823
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
[Interop][SwiftToCxx] Introduces swift::Expected #61823
Conversation
|
This needs some testing. You can add a Cpp interop test that just tries to use this class with some values. |
ee27a92 to
bbe669d
Compare
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.
The destructor should destroy the value or the error.
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 is noexcept.
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 should be noexcept.
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.
The parameter should probably be const T &val.
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.
the move assignment should be deleted as well.
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 we check has_value explicitly like in value instead of specifying the precondition in the comments?
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.
Yes!
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.
if it doesn't have a value can we abort?
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.
yes.
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 don't want to throw exceptions here.
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.
Ok!
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.
The error and the T can be stored in one memory buffer, e.g.
alignas(std::max(alignof(T), sizeof(swift::Error))) char buffer[std::max(sizeof(T), sizeof(swift::Error)];
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.
Cool, I'll try to use it!
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.
Please move this to a detail namespace like _impl.
|
@swift-ci please test |
3cc9cd6 to
788edb9
Compare
|
@swift-ci please test |
788edb9 to
c409935
Compare
97cf443 to
709a75b
Compare
|
@swift-ci please test |
|
@swift-ci please test source compatibility |
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.
Maybe we can extract the return type printing code into a closure in this function, to avoid repeating this code?
|
@swift-ci please test Windows platform |
|
@swift-ci please test |
…a type or an Error and fixing minor errors
…d assigning `swift-expected-execution.cpp` as unsupported by Windows.
… exceptions are not available.
…erlay.h and fixing code duplication on PrintClangFunction.cpp
2f40d11 to
5fc55b6
Compare
|
@swift-ci please test |
|
@swift-ci please test Windows platform |
|
@swift-ci please test Windows platform |
|
@swift-ci please test Windows platform |
…n SwiftToCxxToSwift/hide-swift-module-namespace-in-swift.swift
|
@swift-ci please test Windows platform |
|
@swift-ci please test |
|
@swift-ci please test source compatibility |
This PR introduces the swift::Expected class.
The main idea is to have another approach to handling Swift Errors in C++ besides the already implemented throwing/catching exceptions.