@@ -1282,7 +1282,7 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
1282
1282
auto enqueueDeclName = DeclName (C, DeclBaseName (C.Id_enqueue ), { Identifier () });
1283
1283
1284
1284
FuncDecl *moveOnlyEnqueueRequirement = nullptr ;
1285
- FuncDecl *legacyMoveOnlyEnqueueRequirement = nullptr ; // TODO: preferably we'd want to remove handling of `enqueue(Job)` when able to
1285
+ FuncDecl *legacyMoveOnlyEnqueueRequirement = nullptr ;
1286
1286
FuncDecl *unownedEnqueueRequirement = nullptr ;
1287
1287
for (auto req: proto->getProtocolRequirements ()) {
1288
1288
auto *funcDecl = dyn_cast<FuncDecl>(req);
@@ -1325,8 +1325,7 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
1325
1325
assert (unownedEnqueueRequirement && " could not find the enqueue(UnownedJob) requirement, which should be always there" );
1326
1326
1327
1327
// try to find at least a single implementations of enqueue(_:)
1328
- // auto unownedEnqueueWitness = concreteConformance->getWitnessDeclRef(unownedEnqueueRequirement);
1329
- ValueDecl *unownedEnqueueWitnessDecl = concreteConformance->getWitnessDecl (unownedEnqueueRequirement); // unownedEnqueueWitness.getDecl();
1328
+ ValueDecl *unownedEnqueueWitnessDecl = concreteConformance->getWitnessDecl (unownedEnqueueRequirement);
1330
1329
ValueDecl *moveOnlyEnqueueWitnessDecl = nullptr ;
1331
1330
ValueDecl *legacyMoveOnlyEnqueueWitnessDecl = nullptr ;
1332
1331
@@ -1359,39 +1358,57 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
1359
1358
canRemoveOldDecls = declInfo.isContainedIn (requirementInfo);
1360
1359
}
1361
1360
1361
+ auto concurrencyModule = C.getLoadedModule (C.Id_Concurrency );
1362
+ auto isStdlibDefaultImplDecl = [executorDecl, concurrencyModule](ValueDecl *witness) -> bool {
1363
+ if (auto declContext = witness->getDeclContext ()) {
1364
+ if (auto *extension = dyn_cast<ExtensionDecl>(declContext)) {
1365
+ auto extensionModule = extension->getParentModule ();
1366
+ if (extensionModule != concurrencyModule) {
1367
+ return false ;
1368
+ }
1369
+
1370
+ if (auto extendedNominal = extension->getExtendedNominal ()) {
1371
+ return extendedNominal->getDeclaredInterfaceType ()->isEqual (
1372
+ executorDecl->getDeclaredInterfaceType ());
1373
+ }
1374
+ }
1375
+ }
1376
+ return false ;
1377
+ };
1378
+
1362
1379
// If both old and new enqueue are implemented, but the old one cannot be removed,
1363
1380
// emit a warning that the new enqueue is unused.
1364
1381
if (!canRemoveOldDecls && unownedEnqueueWitnessDecl && moveOnlyEnqueueWitnessDecl) {
1365
- diags.diagnose (moveOnlyEnqueueWitnessDecl->getLoc (), diag::executor_enqueue_unused_implementation);
1382
+ if (!isStdlibDefaultImplDecl (moveOnlyEnqueueWitnessDecl)) {
1383
+ diags.diagnose (moveOnlyEnqueueWitnessDecl->getLoc (),
1384
+ diag::executor_enqueue_unused_implementation);
1385
+ }
1366
1386
}
1367
1387
1368
1388
// Old UnownedJob based impl is present, warn about it suggesting the new protocol requirement.
1369
1389
if (canRemoveOldDecls && unownedEnqueueWitnessDecl) {
1370
- diags.diagnose (unownedEnqueueWitnessDecl->getLoc (), diag::executor_enqueue_unowned_implementation, nominalTy);
1390
+ if (!isStdlibDefaultImplDecl (unownedEnqueueWitnessDecl)) {
1391
+ diags.diagnose (unownedEnqueueWitnessDecl->getLoc (),
1392
+ diag::executor_enqueue_deprecated_unowned_implementation,
1393
+ nominalTy);
1394
+ }
1371
1395
}
1372
1396
// Old Job based impl is present, warn about it suggesting the new protocol requirement.
1373
1397
if (legacyMoveOnlyEnqueueWitnessDecl) {
1374
- diags.diagnose (legacyMoveOnlyEnqueueWitnessDecl->getLoc (), diag::executor_enqueue_deprecated_owned_job_implementation, nominalTy);
1375
- }
1376
-
1377
- auto isStdlibDefaultImplDecl = [executorDecl](ValueDecl *witness) -> bool {
1378
- if (auto declContext = witness->getDeclContext ()) {
1379
- if (auto *extension = dyn_cast<ExtensionDecl>(declContext)) {
1380
- if (auto extendedNominal = extension->getExtendedNominal ()) {
1381
- return extendedNominal->getDeclaredInterfaceType ()->isEqual (
1382
- executorDecl->getDeclaredInterfaceType ());
1383
- }
1384
- }
1398
+ if (!isStdlibDefaultImplDecl (legacyMoveOnlyEnqueueWitnessDecl)) {
1399
+ diags.diagnose (legacyMoveOnlyEnqueueWitnessDecl->getLoc (),
1400
+ diag::executor_enqueue_deprecated_owned_job_implementation,
1401
+ nominalTy);
1385
1402
}
1386
- return false ;
1387
- };
1388
- auto missingWitness = !unownedEnqueueWitnessDecl &&
1389
- !moveOnlyEnqueueWitnessDecl &&
1390
- !legacyMoveOnlyEnqueueWitnessDecl;
1403
+ }
1391
1404
1392
1405
bool unownedEnqueueWitnessIsDefaultImpl = isStdlibDefaultImplDecl (unownedEnqueueWitnessDecl);
1393
1406
bool moveOnlyEnqueueWitnessIsDefaultImpl = isStdlibDefaultImplDecl (moveOnlyEnqueueWitnessDecl);
1394
1407
bool legacyMoveOnlyEnqueueWitnessDeclIsDefaultImpl = isStdlibDefaultImplDecl (legacyMoveOnlyEnqueueWitnessDecl);
1408
+
1409
+ auto missingWitness = !unownedEnqueueWitnessDecl &&
1410
+ !moveOnlyEnqueueWitnessDecl &&
1411
+ !legacyMoveOnlyEnqueueWitnessDecl;
1395
1412
auto allWitnessesAreDefaultImpls = unownedEnqueueWitnessIsDefaultImpl &&
1396
1413
moveOnlyEnqueueWitnessIsDefaultImpl &&
1397
1414
legacyMoveOnlyEnqueueWitnessDeclIsDefaultImpl;
0 commit comments