@@ -1299,6 +1299,9 @@ static bool diagnoseCycle(CompilerInstance &instance,
1299
1299
[&buffer](const ModuleDependencyID &id) {
1300
1300
buffer.append (id.ModuleName );
1301
1301
switch (id.Kind ) {
1302
+ case swift::ModuleDependencyKind::SwiftSource:
1303
+ buffer.append (" (Source Target)" );
1304
+ break ;
1302
1305
case swift::ModuleDependencyKind::SwiftInterface:
1303
1306
buffer.append (" .swiftinterface" );
1304
1307
break ;
@@ -1318,11 +1321,12 @@ static bool diagnoseCycle(CompilerInstance &instance,
1318
1321
[&buffer] { buffer.append (" -> " ); });
1319
1322
};
1320
1323
1321
- auto emitCycleDiagnostic = [&](const ModuleDependencyID &dep) {
1322
- auto startIt = std::find (openSet.begin (), openSet.end (), dep);
1324
+ auto emitCycleDiagnostic = [&](const ModuleDependencyID &sourceId,
1325
+ const ModuleDependencyID &sinkId) {
1326
+ auto startIt = std::find (openSet.begin (), openSet.end (), sourceId);
1323
1327
assert (startIt != openSet.end ());
1324
1328
std::vector<ModuleDependencyID> cycleNodes (startIt, openSet.end ());
1325
- cycleNodes.push_back (*startIt );
1329
+ cycleNodes.push_back (sinkId );
1326
1330
llvm::SmallString<64 > errorBuffer;
1327
1331
emitModulePath (cycleNodes, errorBuffer);
1328
1332
instance.getASTContext ().Diags .diagnose (
@@ -1361,13 +1365,20 @@ static bool diagnoseCycle(CompilerInstance &instance,
1361
1365
auto beforeSize = openSet.size ();
1362
1366
assert (cache.findDependency (lastOpen).has_value () &&
1363
1367
" Missing dependency info during cycle diagnosis." );
1364
- for (const auto &dep : cache.getAllDependencies (lastOpen)) {
1365
- if (closeSet.count (dep ))
1368
+ for (const auto &depId : cache.getAllDependencies (lastOpen)) {
1369
+ if (closeSet.count (depId ))
1366
1370
continue ;
1367
- if (openSet.insert (dep)) {
1371
+ // Ensure we detect dependency of the Source target
1372
+ // on an existing Swift module with the same name
1373
+ if (kindIsSwiftDependency (depId) &&
1374
+ depId.ModuleName == mainId.ModuleName && openSet.contains (mainId)) {
1375
+ emitCycleDiagnostic (mainId, depId);
1376
+ return true ;
1377
+ }
1378
+ if (openSet.insert (depId)) {
1368
1379
break ;
1369
1380
} else {
1370
- emitCycleDiagnostic (dep );
1381
+ emitCycleDiagnostic (depId, depId );
1371
1382
return true ;
1372
1383
}
1373
1384
}
0 commit comments