Skip to content

Commit 8ae3c9e

Browse files
authored
Merge pull request #70912 from tshortli/suppress-concurrency-deprecation-diags-in-stdlib
Sema: Suppress unavoidable deprecation diagnostics in _Concurrency
2 parents 467f684 + 1680d57 commit 8ae3c9e

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
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

stdlib/public/Concurrency/ExecutorAssertions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ extension GlobalActor {
151151
_ message: @autoclosure () -> String = String(),
152152
file: StaticString = #fileID, line: UInt = #line
153153
) {
154-
try Self.shared.preconditionIsolated(message(), file: file, line: line)
154+
Self.shared.preconditionIsolated(message(), file: file, line: line)
155155
}
156156
}
157157

@@ -292,7 +292,7 @@ extension GlobalActor {
292292
_ message: @autoclosure () -> String = String(),
293293
file: StaticString = #fileID, line: UInt = #line
294294
) {
295-
try Self.shared.assertIsolated(message(), file: file, line: line)
295+
Self.shared.assertIsolated(message(), file: file, line: line)
296296
}
297297
}
298298

0 commit comments

Comments
 (0)