-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[cxx-interop] Remove annotationOnly flag from Escapability request #85643
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] Remove annotationOnly flag from Escapability request #85643
Conversation
|
@swift-ci please smoke test |
j-hui
left a comment
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 reviewed only the changes in 6279d81 and am fine with them as is, but I'm wondering what the plan is for having this analysis actually be accurate and consider structs with pointer fields as non-escaping.
| type->isMemberPointerType() || type->isReferenceType()) { | ||
| // pointer and reference types are currently imported as unknown | ||
| // (importing them as non-escapable broke backward compatibility) | ||
| hasUnknown = true; |
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 fine with this for now, to preserve the current behavior, but assuming pointers have unknown escapability seems like it could be problematic. My understanding is that, semantically, pointers should be treated as non-escapable.
Do we have a plan for how to correctly analyze these types while maintaining backwards compat?
An idea I had was making the analysis depend on whether strict memory safety is turned on or off, essentially using/abusing it as a feature flag. But that may not be a good idea for reasons that I haven't fully thought through yet.
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.
Do we have a plan for how to correctly analyze these types while maintaining backwards compat?
I do not think we can maintain backward compatibility and be precise at the same time. And we do not want strict memory safety to influence the behavior of the code. Making a type suddenly non-escapable when strict memory safety is on would result in some code not compiling. Especially when one is using an API that is owned by someone else this compilation error might be impossible to resolve.
We would not be able to do this any time soon. I tried this and it breaks a lot of code, including code in the standard library. Unfortunately, however, non-escapable types are still not first class citizens in Swift. They are viral, so suddenly even some Swift types would become non-escapable, and many protocols have not been generalized to work with non-escapable types. So the very least we need to wait until non-escapable gets some improvements, and even after that the switch would be really expensive so we will need to demonstrate a lot of value to justify this. |
Xazax-hun
left a comment
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.
Overall looks good. Feel free to merge once the nits are resolved.
6279d81 to
146726b
Compare
|
@swift-ci please smoke test |
Xazax-hun
left a comment
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.
Looks great, thanks!
146726b to
27e0ae8
Compare
|
@swift-ci please smoke test |
| // We only infer escapability for simple types, such as aggregates and | ||
| // RecordDecls that are not CxxRecordDecls. For more complex | ||
| // CxxRecordDecls, we rely solely on escapability annotations. |
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.
In C++ language mode, Clang makes all RecordDecls into CXXRecordDecls. Could this cause source compatibility issues with Obj-C interop? e.g. if someone enables C++ interop for the first time, would some types have different escapability?
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'd expect those record decls to be aggregates in C++, so we should handle them the same way.
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.
Makes sense, thanks!
|
@swift-ci please smoke test macos |
|
@swift-ci please smoke test |
27e0ae8 to
b06631e
Compare
|
@swift-ci please smoke test |
The
annotationOnlyflag was originally introduced to control for which types we would infer escapability, and for which we would rely solely on annotations. However, due to backward compatibility issues, this flag is currently always set totrue. Therefore, this patch removes theannotationOnlyflag and makes the compiler infer escapability from bases and fields only for simple records, such as aggregates.