|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | #include "swift-c/DependencyScan/DependencyScan.h"
|
| 14 | +#include "swift/AST/DiagnosticsCommon.h" |
14 | 15 | #include "swift/Basic/PrettyStackTrace.h"
|
15 | 16 |
|
16 | 17 | #include "swift/AST/ASTContext.h"
|
@@ -1273,32 +1274,27 @@ swift::dependencies::performModuleScan(
|
1273 | 1274 | // Load the dependency cache if -reuse-dependency-scan-cache
|
1274 | 1275 | // is specified
|
1275 | 1276 | if (opts.ReuseDependencyScannerCache) {
|
1276 |
| - // For the time being, incremental scanner cache validation |
1277 |
| - // is not compatible with CAS-enabled builds. |
1278 |
| - if (!ctx.CASOpts.EnableCaching) { |
1279 |
| - auto cachePath = opts.SerializedDependencyScannerCachePath; |
1280 |
| - if (opts.EmitDependencyScannerCacheRemarks) |
1281 |
| - ctx.Diags.diagnose(SourceLoc(), diag::remark_reuse_cache, cachePath); |
1282 |
| - |
1283 |
| - llvm::sys::TimePoint<> serializedCacheTimeStamp; |
1284 |
| - bool loadFailure = module_dependency_cache_serialization:: |
1285 |
| - readInterModuleDependenciesCache(cachePath, cache, |
1286 |
| - serializedCacheTimeStamp); |
1287 |
| - if (opts.EmitDependencyScannerCacheRemarks && loadFailure) |
1288 |
| - ctx.Diags.diagnose(SourceLoc(), diag::warn_scanner_deserialize_failed, |
1289 |
| - cachePath); |
1290 |
| - |
1291 |
| - if (!loadFailure && opts.ValidatePriorDependencyScannerCache) { |
1292 |
| - auto mainModuleID = |
1293 |
| - ModuleDependencyID{instance.getMainModule()->getNameStr().str(), |
1294 |
| - ModuleDependencyKind::SwiftSource}; |
1295 |
| - incremental::validateInterModuleDependenciesCache( |
1296 |
| - mainModuleID, cache, serializedCacheTimeStamp, |
1297 |
| - *instance.getSourceMgr().getFileSystem(), ctx.Diags, |
1298 |
| - opts.EmitDependencyScannerCacheRemarks); |
1299 |
| - } |
1300 |
| - } else if (opts.EmitDependencyScannerCacheRemarks) |
1301 |
| - ctx.Diags.diagnose(SourceLoc(), diag::remark_cache_reuse_disabled_with_cas); |
| 1277 | + auto cachePath = opts.SerializedDependencyScannerCachePath; |
| 1278 | + if (opts.EmitDependencyScannerCacheRemarks) |
| 1279 | + ctx.Diags.diagnose(SourceLoc(), diag::remark_reuse_cache, cachePath); |
| 1280 | + |
| 1281 | + llvm::sys::TimePoint<> serializedCacheTimeStamp; |
| 1282 | + bool loadFailure = |
| 1283 | + module_dependency_cache_serialization::readInterModuleDependenciesCache( |
| 1284 | + cachePath, cache, serializedCacheTimeStamp); |
| 1285 | + if (opts.EmitDependencyScannerCacheRemarks && loadFailure) |
| 1286 | + ctx.Diags.diagnose(SourceLoc(), diag::warn_scanner_deserialize_failed, |
| 1287 | + cachePath); |
| 1288 | + |
| 1289 | + if (!loadFailure && opts.ValidatePriorDependencyScannerCache) { |
| 1290 | + auto mainModuleID = |
| 1291 | + ModuleDependencyID{instance.getMainModule()->getNameStr().str(), |
| 1292 | + ModuleDependencyKind::SwiftSource}; |
| 1293 | + incremental::validateInterModuleDependenciesCache( |
| 1294 | + mainModuleID, cache, serializedCacheTimeStamp, |
| 1295 | + *instance.getSourceMgr().getFileSystem(), ctx.Diags, |
| 1296 | + opts.EmitDependencyScannerCacheRemarks); |
| 1297 | + } |
1302 | 1298 | }
|
1303 | 1299 |
|
1304 | 1300 | auto scanner = ModuleDependencyScanner(
|
@@ -1334,7 +1330,7 @@ swift::dependencies::performModuleScan(
|
1334 | 1330 |
|
1335 | 1331 | // Serialize the dependency cache if -serialize-dependency-scan-cache
|
1336 | 1332 | // is specified
|
1337 |
| - if (opts.SerializeDependencyScannerCache && !ctx.CASOpts.EnableCaching) { |
| 1333 | + if (opts.SerializeDependencyScannerCache) { |
1338 | 1334 | auto savePath = opts.SerializedDependencyScannerCachePath;
|
1339 | 1335 | module_dependency_cache_serialization::writeInterModuleDependenciesCache(
|
1340 | 1336 | ctx.Diags, instance.getOutputBackend(), savePath, cache);
|
@@ -1449,6 +1445,41 @@ bool swift::dependencies::incremental::verifyModuleDependencyUpToDate(
|
1449 | 1445 | return true;
|
1450 | 1446 | };
|
1451 | 1447 |
|
| 1448 | + auto verifyCASID = [&cache, &diags, emitRemarks](StringRef moduleName, |
| 1449 | + const std::string &casID) { |
| 1450 | + if (!cache.getScanService().hasCAS()) { |
| 1451 | + // If the wrong cache is passed. |
| 1452 | + if (emitRemarks) |
| 1453 | + diags.diagnose(SourceLoc(), |
| 1454 | + diag::remark_scanner_invalidate_configuration, |
| 1455 | + moduleName); |
| 1456 | + return false; |
| 1457 | + } |
| 1458 | + auto &CAS = cache.getScanService().getCAS(); |
| 1459 | + auto ID = CAS.parseID(casID); |
| 1460 | + if (!ID) { |
| 1461 | + if (emitRemarks) |
| 1462 | + diags.diagnose(SourceLoc(), diag::remark_scanner_invalidate_cas_error, |
| 1463 | + moduleName, toString(ID.takeError())); |
| 1464 | + return false; |
| 1465 | + } |
| 1466 | + if (!CAS.getReference(*ID)) { |
| 1467 | + if (emitRemarks) |
| 1468 | + diags.diagnose(SourceLoc(), diag::remark_scanner_invalidate_missing_cas, |
| 1469 | + moduleName, casID); |
| 1470 | + return false; |
| 1471 | + } |
| 1472 | + return true; |
| 1473 | + }; |
| 1474 | + |
| 1475 | + // Check CAS inputs exist |
| 1476 | + if (const auto casID = moduleInfo.getClangIncludeTree()) |
| 1477 | + if (!verifyCASID(moduleID.ModuleName, *casID)) |
| 1478 | + return false; |
| 1479 | + if (const auto casID = moduleInfo.getCASFSRootID()) |
| 1480 | + if (!verifyCASID(moduleID.ModuleName, *casID)) |
| 1481 | + return false; |
| 1482 | + |
1452 | 1483 | // Check interface file for Swift textual modules
|
1453 | 1484 | if (const auto &textualModuleDetails = moduleInfo.getAsSwiftInterfaceModule())
|
1454 | 1485 | if (!verifyInputOlderThanCacheTimeStamp(
|
|
0 commit comments