Skip to content

[interop] update names and add docs for the interop C++ helper macros #64911

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

Merged
merged 3 commits into from
Apr 7, 2023

Conversation

hyp
Copy link
Contributor

@hyp hyp commented Apr 4, 2023

No description provided.

@hyp hyp added the c++ interop Feature: Interoperability with C++ label Apr 4, 2023
@hyp hyp requested review from zoecarver and egorzhdan as code owners April 4, 2023 17:59
Copy link
Contributor

@zoecarver zoecarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤴

@hyp hyp force-pushed the eng/grand-macro-rename branch from 69a9149 to 5c03b36 Compare April 4, 2023 21:28
@hyp hyp requested review from hborla, xedin and slavapestov as code owners April 4, 2023 21:28
@hyp
Copy link
Contributor Author

hyp commented Apr 4, 2023

@swift-ci please test

@hyp hyp removed request for xedin, slavapestov and hborla April 4, 2023 21:28
@hyp
Copy link
Contributor Author

hyp commented Apr 4, 2023

@swift-ci please test source compatibility

@hyp
Copy link
Contributor Author

hyp commented Apr 4, 2023

@swift-ci please test macOS platform

@hyp
Copy link
Contributor Author

hyp commented Apr 4, 2023

@swift-ci please test source compatibility

@hyp
Copy link
Contributor Author

hyp commented Apr 4, 2023

@swift-ci please test macOS platform

@hyp hyp force-pushed the eng/grand-macro-rename branch from 5c03b36 to 30d0c17 Compare April 4, 2023 22:14
@hyp
Copy link
Contributor Author

hyp commented Apr 4, 2023

@swift-ci please test

@haoNoQ
Copy link

haoNoQ commented Apr 4, 2023

Hmm, did you consider prefixing them with a bunch of __underscores, to avoid collisions with existing user code? I could totally see it both ways. Like, NS_RETURNS_RETAINED isn't prefixed with __underscores, so maybe it's fine. But given that you're building a language feature that could be useful outside of Apple's constrained ecosystem, it might make sense to keep these macros in language-feature-y style. While extremely unlikely, it's theoretically possible that even the C++ standard itself could want to reserve some of these identifiers in the future, so it could get really awkward.

@haoNoQ
Copy link

haoNoQ commented Apr 4, 2023

I also really like it that these names aren't alluding to Swift! These attributes tell us things about the C++ classes regardless of Swift interop, they can be useful for other applications, such as static analysis.

I still think there could be a catchy prefix for these attributes all together, so that the reader could clearly see that they're part of the same facility and didn't need to look up each one separately, in order to learn that when they're reading the code. But it looks like other compiler features (eg. https://clang.llvm.org/docs/ThreadSafetyAnalysis.html) didn't go down that route; so maybe my intuition isn't quite correct here.

@ktoso
Copy link
Contributor

ktoso commented Apr 5, 2023

When we used such attrs elsewhere we prefixed with SWIFT_ I guess, so that might be a possibility?

@hyp
Copy link
Contributor Author

hyp commented Apr 5, 2023

When we used such attrs elsewhere we prefixed with SWIFT_ I guess, so that might be a possibility?

For now we thought that we would rather avoid SWIFT_ prefix.

@hyp
Copy link
Contributor Author

hyp commented Apr 5, 2023

@swift-ci please test

@hyp
Copy link
Contributor Author

hyp commented Apr 5, 2023

@swift-ci please test source compatibility

@hyp
Copy link
Contributor Author

hyp commented Apr 5, 2023

@swift-ci please build toolchain

@hyp
Copy link
Contributor Author

hyp commented Apr 5, 2023

@swift-ci please test macOS platform

@hyp
Copy link
Contributor Author

hyp commented Apr 5, 2023

@swift-ci please build toolchain

@hyp
Copy link
Contributor Author

hyp commented Apr 6, 2023

@swift-ci please test

@hyp
Copy link
Contributor Author

hyp commented Apr 6, 2023

@swift-ci please test source compatibility

@@ -30,15 +30,15 @@ import Test
// CHECK: note: record 'A' is not automatically available: does not have a copy constructor or destructor. Does this type have reference semantics?
// CHECK: struct A {
// CHECK: ^
// CHECK: SWIFT_REFERENCE_TYPE(<#retain#>, <#release#>)
// CHECK: SHARED_REFERENCE(<#retain#>, <#release#>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these need SWIFT_

NOTE(mark_safe_to_import, none, "Mark method '%0' as 'SAFE_TO_IMPORT' in C++ to "
"make it available in Swift. ",
NOTE(mark_safe_to_import, none, "annotate method '%0' with 'SWIFT_RETURNS_INDEPENDENT_VALUE' in C++ to "
"make it available in Swift",
(StringRef))

NOTE(at_to_subscript, none, "Do you want to replace it with a call "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non blocking, but if it's easy, there's a reference to "import_reference" in this file that should probably be updated. Not a big deal, though.

@zoecarver
Copy link
Contributor

Still LGTM once tests are passing :)

@hyp hyp force-pushed the eng/grand-macro-rename branch from 7b7062f to 64a4b31 Compare April 6, 2023 19:11
@hyp
Copy link
Contributor Author

hyp commented Apr 6, 2023

@swift-ci please test

@hyp
Copy link
Contributor Author

hyp commented Apr 6, 2023

@swift-ci please test source compatibility

@hyp
Copy link
Contributor Author

hyp commented Apr 7, 2023

source compat failures are unrelated.

@hyp hyp merged commit 612eeff into swiftlang:main Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants