Skip to content

Commit 226552b

Browse files
[Caching] Improve diagnostics around swift caching
Improve diagnostics message for swift caching build by trying to emit the diagnostics early when there is more context to differentiate the different kind of problems. After the improvement, CAS Error should be more closer to when there is functional problem with the CAS, rather than mixing in other kinds of problem (like scanning dependency failures) when operating with a CAS. rdar://145676736
1 parent 11cf263 commit 226552b

9 files changed

+178
-127
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,13 @@ REMARK(replay_output, none, "replay output file '%0': key '%1'", (StringRef, Str
525525
REMARK(output_cache_miss, none, "cache miss for input file '%0': key '%1'", (StringRef, StringRef))
526526

527527
// CAS related diagnostics
528-
ERROR(error_cas, none, "CAS error encountered: %0", (StringRef))
528+
ERROR(error_invalid_cas_id, none, "CAS cannot parse id '%0': %1", (StringRef, StringRef))
529+
ERROR(error_cas, none, "CAS error encountered during %0: %1", (StringRef, StringRef))
530+
ERROR(error_cas_fs_creation, none, "cannot create CAS filesystem: %0", (StringRef))
531+
ERROR(error_cache_key_creation, none, "cannot create cache key for compilation %0: %1", (StringRef, StringRef))
532+
ERROR(error_cas_file_ref, none, "cannot load file %0 from CAS filesystem", (StringRef))
533+
ERROR(error_cas_conflict_options, none, "cannot setup CAS due to conflicting '-cas-*' options", ())
534+
ERROR(error_cas_initialization, none, "CAS cannot be initialized from the specified '-cas-*' options: %0", (StringRef))
529535
WARNING(cache_replay_failed, none, "cache replay failed: %0", (StringRef))
530536

531537
ERROR(error_failed_cached_diag, none, "failed to serialize cached diagnostics: %0", (StringRef))

lib/AST/ModuleDependencies.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,11 @@ SwiftDependencyTracker::createTreeFromDependencies() {
680680
for (auto &file : TrackedFiles) {
681681
auto includeTreeFile = clang::cas::IncludeTree::File::create(
682682
FS->getCAS(), file.first, file.second.FileRef);
683-
if (!includeTreeFile)
684-
return includeTreeFile.takeError();
683+
if (!includeTreeFile) {
684+
return llvm::createStringError("CASFS createTree failed for " +
685+
file.first + ": " +
686+
toString(includeTreeFile.takeError()));
687+
}
685688
Files.push_back(
686689
{includeTreeFile->getRef(),
687690
(clang::cas::IncludeTree::FileList::FileSizeTy)file.second.Size});
@@ -690,7 +693,8 @@ SwiftDependencyTracker::createTreeFromDependencies() {
690693
auto includeTreeList =
691694
clang::cas::IncludeTree::FileList::create(FS->getCAS(), Files, {});
692695
if (!includeTreeList)
693-
return includeTreeList.takeError();
696+
return llvm::createStringError("casfs include-tree filelist error: " +
697+
toString(includeTreeList.takeError()));
694698

695699
return *includeTreeList;
696700
}
@@ -706,9 +710,7 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
706710
return false;
707711

708712
// CASOption mismatch, return error.
709-
Instance.getDiags().diagnose(
710-
SourceLoc(), diag::error_cas,
711-
"conflicting CAS options used in scanning service");
713+
Instance.getDiags().diagnose(SourceLoc(), diag::error_cas_conflict_options);
712714
return true;
713715
}
714716

@@ -720,7 +722,7 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
720722
auto CachingFS =
721723
llvm::cas::createCachingOnDiskFileSystem(Instance.getObjectStore());
722724
if (!CachingFS) {
723-
Instance.getDiags().diagnose(SourceLoc(), diag::error_cas,
725+
Instance.getDiags().diagnose(SourceLoc(), diag::error_cas_fs_creation,
724726
toString(CachingFS.takeError()));
725727
return true;
726728
}

0 commit comments

Comments
 (0)