Skip to content

[6.2][CAS] Improve error message when module cache key is missing #10609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: swift/release/6.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clang/include/clang/Basic/DiagnosticCASKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ def err_cas_depscan_daemon_connection: Error<
def err_cas_depscan_failed: Error<
"CAS-based dependency scan failed: %0">, DefaultFatal;
def err_cas_store: Error<"failed to store to CAS: %0">, DefaultFatal;
def err_cas_cannot_get_module_cache_key : Error<
"CAS cannot load module with key '%0' from %1: %2">, DefaultFatal;
def err_cas_unloadable_module : Error<
"module file '%0' not found: unloadable module cache key %1: %2">, DefaultFatal;
def err_cas_missing_module : Error<
"module file '%0' not found: missing module cache key %1: %2">, DefaultFatal;
def err_cas_missing_root_id : Error<
"CAS missing expected root-id '%0'">, DefaultFatal;
def err_cas_cannot_parse_root_id_for_module : Error<
Expand Down
9 changes: 2 additions & 7 deletions clang/lib/Frontend/CompileJobCacheKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,7 @@ Error clang::printCompileJobCacheKey(ObjectStore &CAS, const CASID &Key,
if (!H)
return H.takeError();
TreeSchema Schema(CAS);
if (!Schema.isNode(*H)) {
std::string ErrStr;
llvm::raw_string_ostream Err(ErrStr);
Err << "expected cache key to be a CAS tree; got ";
H->getID().print(Err);
return createStringError(inconvertibleErrorCode(), Err.str());
}
if (!Schema.isNode(*H))
return createStringError("unexpected cache key schema");
return ::printCompileJobCacheKey(CAS, *H, OS);
}
47 changes: 26 additions & 21 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2543,40 +2543,45 @@ static bool addCachedModuleFileToInMemoryCache(

auto ID = CAS.parseID(CacheKey);
if (!ID) {
Diags.Report(diag::err_cas_cannot_get_module_cache_key)
<< CacheKey << Provider << ID.takeError();
Diags.Report(diag::err_cas_unloadable_module)
<< Path << CacheKey << ID.takeError();
return true;
}

auto Value = Cache.get(*ID);
if (!Value || !*Value) {
auto Diag = Diags.Report(diag::err_cas_cannot_get_module_cache_key)
<< CacheKey << Provider;
if (!Value) {
Diag << Value.takeError();
} else {
std::string ErrStr("no such entry in action cache; expected compile:\n");
llvm::raw_string_ostream Err(ErrStr);
if (auto E = printCompileJobCacheKey(CAS, *ID, Err))
Diag << std::move(E);
else
Diag << Err.str();
}
if (!Value) {
Diags.Report(diag::err_cas_unloadable_module)
<< Path << CacheKey << Value.takeError();
return true;
}
if (!*Value) {
auto Diag = Diags.Report(diag::err_cas_missing_module)
<< Path << CacheKey;
std::string ErrStr("expected to be produced by:\n");
llvm::raw_string_ostream Err(ErrStr);
if (auto E = printCompileJobCacheKey(CAS, *ID, Err)) {
// Ignore the error and skip printing the cache key. The cache key can
// be setup by a different compiler that is using an unknown schema.
llvm::consumeError(std::move(E));
Diag << "module file is not available in the CAS";
} else
Diag << Err.str();

return true;
}
auto ValueRef = CAS.getReference(**Value);
if (!ValueRef) {
Diags.Report(diag::err_cas_cannot_get_module_cache_key)
<< CacheKey << Provider << "result module doesn't exist in CAS";
Diags.Report(diag::err_cas_unloadable_module)
<< Path << CacheKey << "result module cannot be loaded from CAS";

return true;
}

std::optional<cas::CompileJobCacheResult> Result;
cas::CompileJobResultSchema Schema(CAS);
if (llvm::Error E = Schema.load(*ValueRef).moveInto(Result)) {
Diags.Report(diag::err_cas_cannot_get_module_cache_key)
<< CacheKey << Provider << std::move(E);
Diags.Report(diag::err_cas_unloadable_module)
<< Path << CacheKey << std::move(E);
return true;
}
auto Output =
Expand All @@ -2589,8 +2594,8 @@ static bool addCachedModuleFileToInMemoryCache(
// better network utilization.
auto OutputProxy = CAS.getProxy(Output->Object);
if (!OutputProxy) {
Diags.Report(diag::err_cas_cannot_get_module_cache_key)
<< CacheKey << Provider << OutputProxy.takeError();
Diags.Report(diag::err_cas_unloadable_module)
<< Path << CacheKey << OutputProxy.takeError();
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,11 @@ static void checkCompileCacheKeyMatch(cas::ObjectStore &CAS,
llvm::report_fatal_error(OldKey.takeError());
SmallString<256> Err;
llvm::raw_svector_ostream OS(Err);
OS << "Compile cache key for module changed; previously:";
OS << "Compile cache key for module changed; previously: "
<< OldKey->toString() << ": ";
if (auto E = printCompileJobCacheKey(CAS, *OldKey, OS))
OS << std::move(E);
OS << "\nkey is now:";
OS << "\nkey is now: " << NewKey.toString() << ": ";
if (auto E = printCompileJobCacheKey(CAS, NewKey, OS))
OS << std::move(E);
llvm::report_fatal_error(OS.str());
Expand Down
8 changes: 4 additions & 4 deletions clang/test/CAS/fmodule-file-cache-key-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// RUN: -fcache-compile-job -Rcompile-job-cache &> %t/invalid2.txt
// RUN: FileCheck %s -check-prefix=INVALID2 -input-file=%t/invalid2.txt

// INVALID2: error: CAS cannot load module with key '-fsyntax-only' from -fmodule-file-cache-key
// INVALID2: error: module file 'INVALID' not found: unloadable module cache key -fsyntax-only: invalid cas-id '-fsyntax-only'

// RUN: not %clang_cc1 -triple x86_64-apple-macos11 \
// RUN: -fmodules -fno-implicit-modules \
Expand All @@ -46,7 +46,7 @@
// RUN: -fcache-compile-job -Rcompile-job-cache &> %t/bad_key.txt
// RUN: cat %t/bad_key.txt | FileCheck %s -check-prefix=BAD_KEY

// BAD_KEY: error: CAS cannot load module with key 'KEY' from -fmodule-file-cache-key: invalid cas-id 'KEY'
// BAD_KEY: error: module file 'PATH' not found: unloadable module cache key KEY: invalid cas-id 'KEY'

// RUN: echo -n '-fmodule-file-cache-key PATH ' > %t/bad_key2.rsp
// RUN: cat %t/casid >> %t/bad_key2.rsp
Expand All @@ -59,7 +59,7 @@
// RUN: -fcache-compile-job -Rcompile-job-cache &> %t/bad_key2.txt
// RUN: cat %t/bad_key2.txt | FileCheck %s -check-prefix=BAD_KEY2

// BAD_KEY2: error: CAS cannot load module with key '{{.*}}' from -fmodule-file-cache-key: cas object is not a valid cache key
// BAD_KEY2: error: module file 'PATH' not found: missing module cache key {{.*}}: module file is not available in the CAS

// == Build A

Expand Down Expand Up @@ -87,7 +87,7 @@
// RUN: -fcache-compile-job -Rcompile-job-cache &> %t/not_in_cache.txt
// RUN: cat %t/not_in_cache.txt | FileCheck %s -check-prefix=NOT_IN_CACHE -DPREFIX=%/t

// NOT_IN_CACHE: error: CAS cannot load module with key '{{.*}}' from -fmodule-file-cache-key: no such entry in action cache; expected compile:
// NOT_IN_CACHE: error: module file 'PATH' not found: missing module cache key {{.*}}: expected to be produced by:
// NOT_IN_CACHE: command-line:
// NOT_IN_CACHE: -cc1
// NOT_IN_CACHE: filesystem:
Expand Down
2 changes: 1 addition & 1 deletion clang/test/ClangScanDeps/modules-cas-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
// Missing pcm in action cache
// RUN: not %clang @%t/Left.rsp 2> %t/error.txt
// RUN: cat %t/error.txt | FileCheck %s -check-prefix=MISSING
// MISSING: error: CAS cannot load module with key '{{.*}}' from -fmodule-file-cache-key: no such entry in action cache
// MISSING: error: module file '{{.*}}.pcm' not found: missing module cache key {{.*}}: expected to be produced by:

// Build everything
// RUN: %clang @%t/Top.rsp 2>&1 | FileCheck %s -check-prefix=CACHE-MISS
Expand Down