-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] allow shared ref retain function to return self #77837
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
Note to self: need separate error message for invalid retain return value. |
c077f57
to
85ea760
Compare
d9903f1
to
46c2da4
Compare
Tests are now failing, investigating. |
46c2da4
to
8d56f5a
Compare
Tests passing again. |
LGTM |
Just double checking we don't need to do anything extra at the retain call site to ignore the return value. |
lib/ClangImporter/ImportDecl.cpp
Outdated
auto resultInterfaceType = operationFn->getResultInterfaceType(); | ||
if (!resultInterfaceType->isVoid()) { | ||
if (operationKind == CustomRefCountingOperationKind::release || | ||
resultInterfaceType->getAnyNominal() != paramDecl) |
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 check isn't correct: it's comparing the declaration result's nominal type (if there is one) against the parameter declaration itself (which has, e.g., the name of the parameter in it). Instead, you need to compare the result type against the parameter type. I also expect that we need to look through an optional type on the result type, in case the retain function handles null pointers in some manner. Specifically, I think it should be:
resultInterfaceType->getAnyNominal() != paramDecl) | |
!resultInterfaceType->lookThroughSingleOptionalType()->isEqual(paramType)) |
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.
I'm confused about why this PR worked without this change suggested above. Running tests in CI without the change because I would expect it to fail.
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.
Fix applied (shouldn't disrupt running builds to check previous commit).
@@ -2534,24 +2534,23 @@ namespace { | |||
void validateForeignReferenceType(const clang::CXXRecordDecl *decl, | |||
ClassDecl *classDecl) { | |||
|
|||
enum class RetainReleaseOperatonKind { | |||
enum class RetainReleaseOperationKind { |
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.
Ah, thank you for the typo fix here!
@swift-ci please smoke test macOS |
Many existing C APIs for retaining references, including Apple's own, return the reference. Support this pattern, along with the existing void return signature, with when importing reference types from C++.
8d56f5a
to
da23bcf
Compare
@swift-ci please smoke test |
What's the next release one might expect to see this in? |
Once it's merged to main, we can cherry-pick to the |
@swift-ci please smoke test |
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 seems very reasonable, LGTM, thank you!
@swift-ci please smoke test Linux |
@lhoward I'm going to merge now. Would you cherry-pick this to the release/6.1 branch? There are instructions at https://forums.swift.org/t/swift-6-1-release-process/75442#p-344524-pull-requests-for-release-branch-8 |
Retain functions that return self need to be manually annotated with |
Many existing C APIs for retaining references, including Apple's own, return the reference. Support this pattern, along with the existing
void
return signature, with when importing reference types from C++.More: https://forums.swift.org/t/swift-shared-reference-signature-error/76194/7