mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Verify that _Concurrency *can* be imported on implicit import.
In case the compiler is used with concurrency features enabled (by-default or otherwise), and an older SDK is used which does not include the `_Concurrency` module, do not load this module implicitly. Instead, emit a diagnostic indicating that no such module is found. rdar://76967260
This commit is contained in:
@@ -800,6 +800,19 @@ bool CompilerInvocation::shouldImportSwiftONoneSupport() const {
|
||||
FrontendOptions::doesActionGenerateSIL(options.RequestedAction);
|
||||
}
|
||||
|
||||
void CompilerInstance::verifyImplicitConcurrencyImport() {
|
||||
if (Invocation.shouldImportSwiftConcurrency() &&
|
||||
!canImportSwiftConcurrency()) {
|
||||
Diagnostics.diagnose(SourceLoc(),
|
||||
diag::warn_implicit_concurrency_import_failed);
|
||||
}
|
||||
}
|
||||
|
||||
bool CompilerInstance::canImportSwiftConcurrency() const {
|
||||
return getASTContext().canImportModule(
|
||||
{getASTContext().getIdentifier(SWIFT_CONCURRENCY_NAME), SourceLoc()});
|
||||
}
|
||||
|
||||
ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
|
||||
auto &frontendOpts = Invocation.getFrontendOptions();
|
||||
|
||||
@@ -824,6 +837,9 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
|
||||
pushImport(SWIFT_ONONE_SUPPORT);
|
||||
}
|
||||
|
||||
// FIXME: The canImport check is required for compatibility
|
||||
// with older SDKs. Longer term solution is to have the driver make
|
||||
// the decision on the implicit import: rdar://76996377
|
||||
if (Invocation.shouldImportSwiftConcurrency()) {
|
||||
switch (imports.StdlibKind) {
|
||||
case ImplicitStdlibKind::Builtin:
|
||||
@@ -831,7 +847,8 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
|
||||
break;
|
||||
|
||||
case ImplicitStdlibKind::Stdlib:
|
||||
pushImport(SWIFT_CONCURRENCY_NAME);
|
||||
if (canImportSwiftConcurrency())
|
||||
pushImport(SWIFT_CONCURRENCY_NAME);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1043,6 +1060,8 @@ bool CompilerInstance::loadStdlibIfNeeded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
verifyImplicitConcurrencyImport();
|
||||
|
||||
// If we failed to load, we should have already diagnosed.
|
||||
if (M->failedToLoad()) {
|
||||
assert(Diagnostics.hadAnyError() &&
|
||||
|
||||
Reference in New Issue
Block a user