Skip to content

[clang][cas] Avoid calling freezeConfig for every cache key #9831

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

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
19 changes: 17 additions & 2 deletions clang/lib/Frontend/CompileJobCacheKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ canonicalizeForCaching(llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
//
// TODO: Extract CASOptions.Path first if we need it later since it'll
// disappear here.
Invocation.getCASOpts().freezeConfig(Diags);
Invocation.getCASOpts() = {};
// Set the CASPath to the hash schema to match CASOptions::freezeConfig.
Invocation.getCASOpts().CASPath =
CAS.getContext().getHashSchemaIdentifier().str();

// TODO: Canonicalize DiagnosticOptions here to be "serialized" only. Pass in
// a hook to mirror diagnostics to stderr (when writing there), and handle
Expand All @@ -194,8 +197,20 @@ canonicalizeForCaching(llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
std::optional<llvm::cas::CASID> clang::canonicalizeAndCreateCacheKey(
llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
CompilerInvocation &Invocation, CompileJobCachingOptions &Opts) {
// Preserve and freeze CASOptions so that we do not modify behaviour of
// Invocation.getCASOpts().getOrCreateDatabases().
CASOptions CASOpts(Invocation.getCASOpts());
CASOpts.freezeConfig(Diags);

Opts = canonicalizeForCaching(CAS, Diags, Invocation);
return createCompileJobCacheKeyImpl(CAS, Diags, Invocation);
auto CacheKey = createCompileJobCacheKeyImpl(CAS, Diags, Invocation);
if (!CacheKey)
return std::nullopt;

assert(Invocation.getCASOpts().CASPath == CASOpts.CASPath &&
"cas instance has incompatible hash with cas options");
Invocation.getCASOpts() = std::move(CASOpts);
return CacheKey;
}

std::optional<llvm::cas::CASID>
Expand Down