Skip to content

Support @_predatesConcurrency on import declarations #40679

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

Conversation

DougGregor
Copy link
Member

A @_predatesConcurrency import declaration suppresses or downgrades Sendable-related diagnostics, providing a way to more smoothly adopt concurrency even when one depends on modules that have yet to adopt Sendable. Allow @_predatesConcurrency import declarations and provide them with the appropriate semantics:

  • In a minimal context, a @_predatesConcurrency import of a module X suppresses Sendable diagnostics for nominal types defined in X.
  • In a Swift 6 strict context, a @_predatesConcurrency import of a module X downgrades Sendable diagnostics for nominal types defined in X to warnings.

When we emit a Sendable-related diagnostic for a nominal type outside of the current module, produce a remark that suggests @_predatesConcurrency on the corresponding import to silence the diagnostic, but only do this once per file. This will help folks make Sendable diagnostics more manageable. When a @_predatesConcurrency attribute on an import isn't doing anything (because there were no failed Sendable checks from that module), emit a remark that removes the now-unnecessary @_predatesConcurrency.

Implements rdar://84449015.

When diagnosing a `Sendable` violation, suggest the use of
`@_predatesConcurrency` on the corresponding import to suppress those
diagnostics.

(cherry picked from commit 23cc638)
…e remark

Rather than tacking the "add `@_predatesConcurrecy` to import"
diagnostic on to the prior diagnostic as a note, make it its own
remark. Then, ensure that we only emit this remark once per source
file per imported module, so we're not overwhelming the user.

(cherry picked from commit 2832aed)
We'll already suggest the addition of `@_predatesConcurrency` on an import
to downgrade or silence `Sendable`-related diagnostics, so we'll be
adding these to people's code. Over time, this attribute can go stale,
if the imported module's adopt `Sendable`. When the attribute isn't
doing anything, because it didn't suppress any `Sendable`-related
diagnostics, suggest that it be removed.

(cherry picked from commit 884e72a)
The change to add the `import` keyword location to AttributedImport also
removed the module name location in UnboundImport. However, we want to
keep both locations, for different diagnostic reasons, so reinstate the
module name location.

(cherry picked from commit 7552cf9)
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit d131c37 into swiftlang:release/5.6 Dec 22, 2021
@DougGregor DougGregor deleted the predates-concurrency-import-5.6 branch December 22, 2021 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant