Skip to content

Sema: Suppress unavoidable deprecation diagnostics in _Concurrency #70912

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2646,6 +2646,9 @@ void TypeChecker::diagnoseIfDeprecated(SourceRange ReferenceRange,
}
}

if (shouldIgnoreDeprecationOfConcurrencyDecl(DeprecatedDecl, ReferenceDC))
return;

StringRef Platform = Attr->prettyPlatformString();
llvm::VersionTuple DeprecatedVersion;
if (Attr->Deprecated)
Expand Down
35 changes: 35 additions & 0 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,41 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
}
}

bool swift::shouldIgnoreDeprecationOfConcurrencyDecl(const Decl *decl,
DeclContext *declContext) {
auto &ctx = decl->getASTContext();
auto concurrencyModule = ctx.getLoadedModule(ctx.Id_Concurrency);

// Only suppress these diagnostics in the implementation of _Concurrency.
if (declContext->getParentModule() != concurrencyModule)
return false;

// Only suppress deprecation diagnostics for decls defined in _Concurrency.
if (decl->getDeclContext()->getParentModule() != concurrencyModule)
return false;

auto *legacyJobDecl = ctx.getJobDecl();
auto *unownedJobDecl = ctx.getUnownedJobDecl();

if (decl == legacyJobDecl)
return true;

if (auto *funcDecl = dyn_cast<FuncDecl>(decl)) {
auto enqueueDeclName =
DeclName(ctx, DeclBaseName(ctx.Id_enqueue), {Identifier()});

if (funcDecl->getName() == enqueueDeclName &&
funcDecl->getParameters()->size() == 1) {
auto paramTy = funcDecl->getParameters()->front()->getInterfaceType();
if (paramTy->isEqual(legacyJobDecl->getDeclaredInterfaceType()) ||
paramTy->isEqual(unownedJobDecl->getDeclaredInterfaceType()))
return true;
}
}

return false;
}

/// Determine whether this is the main actor type.
static bool isMainActor(Type type) {
if (auto nominal = type->getAnyNominal())
Expand Down
8 changes: 8 additions & 0 deletions lib/Sema/TypeCheckConcurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ void diagnoseMissingExplicitSendable(NominalTypeDecl *nominal);
/// Warn about deprecated `Executor.enqueue` implementations.
void tryDiagnoseExecutorConformance(ASTContext &C, const NominalTypeDecl *nominal, ProtocolDecl *proto);

/// Whether to suppress deprecation diagnostics for \p decl in \p declContext
/// because \p decl is a deprecated decl from the `_Concurrency` module and is
/// being referenced from the implementation of the `_Concurrency` module. This
/// prevents unaddressable warnings in the standard library build. Ideally, a
/// language feature would obviate the need for this.
bool shouldIgnoreDeprecationOfConcurrencyDecl(const Decl *decl,
DeclContext *declContext);

// Get a concrete reference to a declaration
ConcreteDeclRef getDeclRefInContext(ValueDecl *value);

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/Concurrency/ExecutorAssertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ extension GlobalActor {
_ message: @autoclosure () -> String = String(),
file: StaticString = #fileID, line: UInt = #line
) {
try Self.shared.preconditionIsolated(message(), file: file, line: line)
Self.shared.preconditionIsolated(message(), file: file, line: line)
}
}

Expand Down Expand Up @@ -292,7 +292,7 @@ extension GlobalActor {
_ message: @autoclosure () -> String = String(),
file: StaticString = #fileID, line: UInt = #line
) {
try Self.shared.assertIsolated(message(), file: file, line: line)
Self.shared.assertIsolated(message(), file: file, line: line)
}
}

Expand Down