Implement customizable Sendable conformance diagnostics.

Rework Sendable checking to be completely based on "missing"
conformances, so that we can individually diagnose missing Sendable
conformances based on both the module in which the conformance check
happened as well as where the type was declared. The basic rules here
are to only diagnose if either the module where the non-Sendable type
was declared or the module where it was checked was compiled with a
mode that consistently diagnoses `Sendable`, either by virtue of
being Swift 6 or because `-warn-concurrency` was provided on the
command line. And have that diagnostic be an error in Swift 6 or
warning in Swift 5.x.

There is much tuning to be done here.
This commit is contained in:
Doug Gregor
2021-08-11 00:14:50 -07:00
parent 392ba002c8
commit d54abea922
28 changed files with 437 additions and 223 deletions

View File

@@ -2627,7 +2627,6 @@ public:
void analyzeActorIsolation(const ValueDecl *VD, Type T, bool &implicitlyAsync,
Optional<NotRecommendedReason> &NotRecommended) {
auto isolation = getActorIsolation(const_cast<ValueDecl *>(VD));
auto &ctx = VD->getASTContext();
switch (isolation.getKind()) {
case ActorIsolation::DistributedActorInstance: {
@@ -2646,7 +2645,7 @@ public:
// if the context has adopted concurrency.
if (!CanCurrDeclContextHandleAsync &&
!completionContextUsesConcurrencyFeatures(CurrDeclContext) &&
!ctx.LangOpts.WarnConcurrency) {
!CurrDeclContext->getParentModule()->isConcurrencyChecked()) {
return;
}
LLVM_FALLTHROUGH;
@@ -2664,7 +2663,8 @@ public:
}
// If the reference is 'async', all types must be 'Sendable'.
if (ctx.LangOpts.WarnConcurrency && implicitlyAsync && T) {
if (CurrDeclContext->getParentModule()->isConcurrencyChecked() &&
implicitlyAsync && T) {
auto *M = CurrDeclContext->getParentModule();
if (isa<VarDecl>(VD)) {
if (!isSendableType(M, T)) {