-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[🍒][cxx-interop] Only mark projections of self-contained types as unsafe. #67413
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] Only mark projections of self-contained types as unsafe. #67413
Conversation
Projections of trivial types and view types aren't unsafe. This matches what was described in the vision document.
…ift compiler sources changes on it.
…y; fix a few remaining tests that use raw pointers.
…tomatic rac conformance); update tests accordingly.
ee37bf3
to
65dc0d3
Compare
@swift-ci please test |
@swift-ci Please Build Toolchain macOS Platform |
count: count) | ||
#else | ||
let buffer = UnsafeBufferPointer<UInt8>(start: _bridged.bytes_begin(), | ||
count: count) |
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.
@zoecarver both #if and #else branches seems to have the same code? Did you mean to say _bridged.__bytes_beginUnsafe()
in the #else case?
lib/ClangImporter/ClangImporter.cpp
Outdated
|
||
// Mark this as safe to help our diganostics down the road. | ||
if (!cxxRecordReturnType->getDefinition()) { | ||
return true; | ||
} | ||
|
||
if (!hasCustomCopyOrMoveConstructor(cxxRecordReturnType) && | ||
// A projection of a view type (such as a string_view) from a self | ||
// contained parent is a proejction (unsafe). |
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.
Minor typo: "proejction", we can combine the fix with later fixes.
@swift-ci please test |
@swift-ci Please Build Toolchain macOS Platform |
7ac2e7e
to
30c929f
Compare
@swift-ci Please Build Toolchain macOS Platform |
@swift-ci please test |
@swift-ci please test macOS |
@swift-ci please test windows |
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.
Thanks Zoe! LGTM.
Description: Projections of trivial types and view types aren't unsafe. This matches what was described in the vision document. A view type like StringRef is already referencing memory it does not own, so if it projects its data again (via the data method for example), there's no additional unsafety. The really unsafe thing is when a self contained (owned) type projects its owned memory because there are subtle difference in C++ and Swift lifetime models (along with different safety expectations). I have discussed with the interop code owners and we all agree that this is the correct change to make. This has been corroborated by feedback from adopters. Finally, this is the behavior that was agreed upon by the workgroup and the broader community and is what is outlined in the forward vision document.
Scope: C++ interop
Risk: Medium. This change will break source. It changes an important part of importing and affects safety. It also has a high risk of breaking parts of the overlay. This change will be hard to walk back if we determine that it is unsafe (for example). It has not been testing with any adopters and this new behavior has not been tested in the wild.
Testing: Unit testing (CI)
Original PR: #67296
Radar: rdar://112220411