@@ -1410,6 +1410,9 @@ static bool diagnoseCycle(CompilerInstance &instance,
1410
1410
[&buffer](const ModuleDependencyID &id) {
1411
1411
buffer.append (id.ModuleName );
1412
1412
switch (id.Kind ) {
1413
+ case swift::ModuleDependencyKind::SwiftSource:
1414
+ buffer.append (" (Source Target)" );
1415
+ break ;
1413
1416
case swift::ModuleDependencyKind::SwiftInterface:
1414
1417
buffer.append (" .swiftinterface" );
1415
1418
break ;
@@ -1429,11 +1432,12 @@ static bool diagnoseCycle(CompilerInstance &instance,
1429
1432
[&buffer] { buffer.append (" -> " ); });
1430
1433
};
1431
1434
1432
- auto emitCycleDiagnostic = [&](const ModuleDependencyID &dep) {
1433
- auto startIt = std::find (openSet.begin (), openSet.end (), dep);
1435
+ auto emitCycleDiagnostic = [&](const ModuleDependencyID &sourceId,
1436
+ const ModuleDependencyID &sinkId) {
1437
+ auto startIt = std::find (openSet.begin (), openSet.end (), sourceId);
1434
1438
assert (startIt != openSet.end ());
1435
1439
std::vector<ModuleDependencyID> cycleNodes (startIt, openSet.end ());
1436
- cycleNodes.push_back (*startIt );
1440
+ cycleNodes.push_back (sinkId );
1437
1441
llvm::SmallString<64 > errorBuffer;
1438
1442
emitModulePath (cycleNodes, errorBuffer);
1439
1443
instance.getASTContext ().Diags .diagnose (
@@ -1472,13 +1476,20 @@ static bool diagnoseCycle(CompilerInstance &instance,
1472
1476
auto beforeSize = openSet.size ();
1473
1477
assert (cache.findDependency (lastOpen).has_value () &&
1474
1478
" Missing dependency info during cycle diagnosis." );
1475
- for (const auto &dep : cache.getAllDependencies (lastOpen)) {
1476
- if (closeSet.count (dep ))
1479
+ for (const auto &depId : cache.getAllDependencies (lastOpen)) {
1480
+ if (closeSet.count (depId ))
1477
1481
continue ;
1478
- if (openSet.insert (dep)) {
1482
+ // Ensure we detect dependency of the Source target
1483
+ // on an existing Swift module with the same name
1484
+ if (kindIsSwiftDependency (depId) &&
1485
+ depId.ModuleName == mainId.ModuleName && openSet.contains (mainId)) {
1486
+ emitCycleDiagnostic (mainId, depId);
1487
+ return true ;
1488
+ }
1489
+ if (openSet.insert (depId)) {
1479
1490
break ;
1480
1491
} else {
1481
- emitCycleDiagnostic (dep );
1492
+ emitCycleDiagnostic (depId, depId );
1482
1493
return true ;
1483
1494
}
1484
1495
}
0 commit comments