Skip to content

Commit 68747c1

Browse files
committed
Sema: Suppress unavoidable deprecation diagnostics in _Concurrency.
The _Concurrency module must use some deprecated declarations in its implementation in order to maintain backward compatibility. Since these references are unavoidable, the deprecation diagnostics emitted about them are an unhelpful nuisance. This change introduces targetted logic for suppressing these specific deprecation diagnostics as a workaround until there is a language feature for suppressing deprecation diagnostics.
1 parent 0e6a913 commit 68747c1

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,6 +2646,9 @@ void TypeChecker::diagnoseIfDeprecated(SourceRange ReferenceRange,
26462646
}
26472647
}
26482648

2649+
if (shouldIgnoreDeprecationOfConcurrencyDecl(DeprecatedDecl, ReferenceDC))
2650+
return;
2651+
26492652
StringRef Platform = Attr->prettyPlatformString();
26502653
llvm::VersionTuple DeprecatedVersion;
26512654
if (Attr->Deprecated)

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,41 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
15711571
}
15721572
}
15731573

1574+
bool swift::shouldIgnoreDeprecationOfConcurrencyDecl(const Decl *decl,
1575+
DeclContext *declContext) {
1576+
auto &ctx = decl->getASTContext();
1577+
auto concurrencyModule = ctx.getLoadedModule(ctx.Id_Concurrency);
1578+
1579+
// Only suppress these diagnostics in the implementation of _Concurrency.
1580+
if (declContext->getParentModule() != concurrencyModule)
1581+
return false;
1582+
1583+
// Only suppress deprecation diagnostics for decls defined in _Concurrency.
1584+
if (decl->getDeclContext()->getParentModule() != concurrencyModule)
1585+
return false;
1586+
1587+
auto *legacyJobDecl = ctx.getJobDecl();
1588+
auto *unownedJobDecl = ctx.getUnownedJobDecl();
1589+
1590+
if (decl == legacyJobDecl)
1591+
return true;
1592+
1593+
if (auto *funcDecl = dyn_cast<FuncDecl>(decl)) {
1594+
auto enqueueDeclName =
1595+
DeclName(ctx, DeclBaseName(ctx.Id_enqueue), {Identifier()});
1596+
1597+
if (funcDecl->getName() == enqueueDeclName &&
1598+
funcDecl->getParameters()->size() == 1) {
1599+
auto paramTy = funcDecl->getParameters()->front()->getInterfaceType();
1600+
if (paramTy->isEqual(legacyJobDecl->getDeclaredInterfaceType()) ||
1601+
paramTy->isEqual(unownedJobDecl->getDeclaredInterfaceType()))
1602+
return true;
1603+
}
1604+
}
1605+
1606+
return false;
1607+
}
1608+
15741609
/// Determine whether this is the main actor type.
15751610
static bool isMainActor(Type type) {
15761611
if (auto nominal = type->getAnyNominal())

lib/Sema/TypeCheckConcurrency.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ void diagnoseMissingExplicitSendable(NominalTypeDecl *nominal);
324324
/// Warn about deprecated `Executor.enqueue` implementations.
325325
void tryDiagnoseExecutorConformance(ASTContext &C, const NominalTypeDecl *nominal, ProtocolDecl *proto);
326326

327+
/// Whether to suppress deprecation diagnostics for \p decl in \p declContext
328+
/// because \p decl is a deprecated decl from the `_Concurrency` module and is
329+
/// being referenced from the implementation of the `_Concurrency` module. This
330+
/// prevents unaddressable warnings in the standard library build. Ideally, a
331+
/// language feature would obviate the need for this.
332+
bool shouldIgnoreDeprecationOfConcurrencyDecl(const Decl *decl,
333+
DeclContext *declContext);
334+
327335
// Get a concrete reference to a declaration
328336
ConcreteDeclRef getDeclRefInContext(ValueDecl *value);
329337

0 commit comments

Comments
 (0)