-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Support __available__((swift_attr("@Sendable"))) #40170
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
This is not yet used by anything.
This change applies SwiftAttr attributes as soon as possible after creating an instance of a Decl, rather than waiting until the declaration is "finished". That makes sure the attributes can influence the declaration very early in its lifecycle, and in particular, before its conformance table is initialized. Mostly NFC in this commit (other than affecting the order that attributes are printed in), but necessary for future changes in this PR.
...by using `__attribute__((swift_attr("@sendable")))`. `@_nonSendable` will "beat" `@Sendable`, while `@_nonSendable(_assumed)` will not. This commit also checks if `SwiftAttr` supports `#pragma clang attribute` and, if it does, defines `__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS` in imported headers so they know they can apply these attributes in an auditing style.
Gives us a place to stuff synthesized declarations for, among other things, imported Clang decls.
An explicit swift_attr("@_nonSendable") will override it (except for ns_error_domain where the type is embedded in another type that's forced to be Sendable), but swift_attr("@_nonSendable(_assumed)") will not.
With swiftlang/llvm-project#3547 @swift-ci please smoke test |
With swiftlang/llvm-project#3547 @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.
Some minor comments, but this looks great!
// GetImplicitSendableRequest::evaluate() creates its extension with the | ||
// attribute's AtLoc, so this is a good way to quickly check if the extension | ||
// was synthesized for an '@_nonSendable' attribute. | ||
return ED->getLocFromSource() == nonSendable->AtLoc; |
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 feels a little... brittle... but okay.
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.
Yeah. :/ I couldn’t think of anything better that would be quick, but maybe I can revisit this; arguably we should just print any unavailable Sendable conformance even if it doesn’t come from @_nonSendable
.
This PR implements most of the sendability auditing support for ClangImporter. Specifically:
__attribute__((swift_attr("@Sendable")))
is now allowed on Clang decls, even when it would not be allowed on equivalent Swift decls.@unchecked Sendable
conformance if it:@Sendable
, but not plain@_nonSendable
.enum_extensibility
,flag_enum
,swift_newtype
, orswift_wrapper
Clang attributes, but not plain@_nonSendable
.ns_error_domain
Clang attribute, regardless of the presence of plain@_nonSendable
. (Error
is alwaysSendable
, so error codes must also beSendable
.)Sendable
conformances before printing the contents of a module, and we print the extensions generated by@_nonSendable
even if we would normally skip unavailable or implicit extensions.__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS
to be1
.It includes a number of related refactorings:
SynthesizedProtocolAttr
s can now create@unchecked
conformances.SynthesizedFileUnit
s can now be attached to anyFileUnit
, not justSourceFile
.ClangImporter::Implementation::diagnose()
has been overloaded so that, if aHeaderLoc
(wrapping aclang::SourceLocation
and related info) is passed in place of aSourceLoc
, it will emit a diagnostic in the header file. This replaces several lines of boilerplate per use site.Fixes rdar://84431708. It does not implement two things that I will defer to 85569247:
@_nonSendable
in parameter position.@Sendable
(probably@_unsafeSendable
in practice) on completion handler parameters.Some tests will not pass without https://reviews.llvm.org/D112773, which I am in the process of cherry-picking to our clang branches.
This should only cause language behavior changes if you consume headers that include the currently-invalid
__attribute__((swift_attr("@Sendable")))
,__attribute__((swift_attr("@_nonSendable")))
, or__attribute__((swift_attr("@_nonSendable(_assumed)")))
attributes.