Skip to content

Commit 5182208

Browse files
authored
Merge pull request #65413 from ktoso/pick-tryDiagnoseExecutor-must-survive-missing-job-type
🍒[5.9][Concurrency] Handle missing Job type in old SDKs in tryDiagnoseExecutor
2 parents c2a096b + c871cc2 commit 5182208

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,19 +1283,21 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
12831283
if (funcDecl->getParameters()->size() != 1)
12841284
continue;
12851285
if (auto param = funcDecl->getParameters()->front()) {
1286-
StructDecl* jobDecl;
1287-
if (auto decl = C.getExecutorJobDecl()) {
1288-
jobDecl = decl;
1289-
} else if (auto decl = C.getJobDecl()) {
1286+
StructDecl *unownedJobDecl = C.getUnownedJobDecl();
1287+
StructDecl *jobDecl = nullptr;
1288+
if (auto executorJobDecl = C.getExecutorJobDecl()) {
1289+
jobDecl = executorJobDecl;
1290+
} else if (auto plainJobDecl = C.getJobDecl()) {
12901291
// old standard library, before we introduced the `typealias Job = ExecutorJob`
1291-
jobDecl = decl;
1292+
jobDecl = plainJobDecl;
12921293
}
12931294

12941295
if (jobDecl &&
12951296
param->getType()->isEqual(jobDecl->getDeclaredInterfaceType())) {
12961297
assert(moveOnlyEnqueueRequirement == nullptr);
12971298
moveOnlyEnqueueRequirement = funcDecl;
1298-
} else if (param->getType()->isEqual(C.getUnownedJobDecl()->getDeclaredInterfaceType())) {
1299+
} else if (unownedJobDecl &&
1300+
param->getType()->isEqual(unownedJobDecl->getDeclaredInterfaceType())) {
12991301
assert(unownedEnqueueRequirement == nullptr);
13001302
unownedEnqueueRequirement = funcDecl;
13011303
}
@@ -1306,7 +1308,6 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
13061308
break; // we're done looking for the requirements
13071309
}
13081310

1309-
13101311
auto conformance = module->lookupConformance(nominalTy, proto);
13111312
auto concreteConformance = conformance.getConcrete();
13121313
assert(unownedEnqueueRequirement && "could not find the enqueue(UnownedJob) requirement, which should be always there");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-concurrency-without-job) -typecheck -parse-as-library %s -verify
2+
3+
// REQUIRES: concurrency
4+
// REQUIRES: libdispatch
5+
6+
// rdar://106849189 move-only types should be supported in freestanding mode
7+
// UNSUPPORTED: freestanding
8+
9+
// UNSUPPORTED: back_deployment_runtime
10+
// REQUIRES: concurrency_runtime
11+
12+
import _Concurrency
13+
14+
// NOTE: This test simulates what happens when we have an SDK with some missing concurrency types.
15+
// Specifically, we're missing the ExecutorJob and Job declarations.
16+
// This simulates a pre-Swift-5.9 SDK being used with a Swift 5.9+ compiler,
17+
// which would have failed previously due to missing handling of missing types.
18+
//
19+
// This is a regression test for that situation
20+
21+
final class FakeExecutor: SerialExecutor {
22+
func enqueue(_ job: UnownedJob) {}
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
// This simulates a pre-Swift5.9 concurrency library with `Job` and `ExecutorJob` not being defined at all.
3+
// This is used to verify missing type handling in the SDK when a latest compiler is used.
4+
5+
public struct UnownedJob {}
6+
7+
public protocol SerialExecutor {
8+
// pretend to be a broken, empty serial executor
9+
func enqueue(_ job: UnownedJob)
10+
}

test/lit.cfg

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,20 @@ config.substitutions.append(('%build-clang-importer-objc-overlays',
607607
'%target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -enable-objc-interop -emit-module -o %t %clang-importer-sdk-path/swift-modules/CoreFoundation.swift && '
608608
'%target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -enable-objc-interop -emit-module -o %t %clang-importer-sdk-path/swift-modules/Foundation.swift'))
609609

610+
611+
# FIXME: BEGIN -enable-source-import hackaround
612+
config.substitutions.append(('%clang-importer-sdk-concurrency-without-job-path',
613+
'%r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))
614+
615+
config.substitutions.append(('%clang-importer-sdk-concurrency-without-job-nosource',
616+
'-sdk %r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))
617+
# FIXME: END -enable-source-import hackaround
618+
619+
config.substitutions.append(('%clang-importer-sdk-concurrency-without-job',
620+
'-enable-source-import -sdk %r -I %r ' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'),
621+
make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk', 'swift-modules-concurrency-without-job'))))
622+
623+
610624
# FIXME: BEGIN -enable-source-import hackaround
611625
config.substitutions.append(('%clang-importer-sdk-path',
612626
'%r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))

0 commit comments

Comments
 (0)