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