Skip to content

Commit 1e19c09

Browse files
authored
Merge pull request #9831 from benlangmuir/freeze-less-61
[clang][cas] Avoid calling freezeConfig for every cache key
2 parents b81995b + 810ded7 commit 1e19c09

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

clang/lib/Frontend/CompileJobCacheKey.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ canonicalizeForCaching(llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
181181
//
182182
// TODO: Extract CASOptions.Path first if we need it later since it'll
183183
// disappear here.
184-
Invocation.getCASOpts().freezeConfig(Diags);
184+
Invocation.getCASOpts() = {};
185+
// Set the CASPath to the hash schema to match CASOptions::freezeConfig.
186+
Invocation.getCASOpts().CASPath =
187+
CAS.getContext().getHashSchemaIdentifier().str();
185188

186189
// TODO: Canonicalize DiagnosticOptions here to be "serialized" only. Pass in
187190
// a hook to mirror diagnostics to stderr (when writing there), and handle
@@ -194,8 +197,20 @@ canonicalizeForCaching(llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
194197
std::optional<llvm::cas::CASID> clang::canonicalizeAndCreateCacheKey(
195198
llvm::cas::ObjectStore &CAS, DiagnosticsEngine &Diags,
196199
CompilerInvocation &Invocation, CompileJobCachingOptions &Opts) {
200+
// Preserve and freeze CASOptions so that we do not modify behaviour of
201+
// Invocation.getCASOpts().getOrCreateDatabases().
202+
CASOptions CASOpts(Invocation.getCASOpts());
203+
CASOpts.freezeConfig(Diags);
204+
197205
Opts = canonicalizeForCaching(CAS, Diags, Invocation);
198-
return createCompileJobCacheKeyImpl(CAS, Diags, Invocation);
206+
auto CacheKey = createCompileJobCacheKeyImpl(CAS, Diags, Invocation);
207+
if (!CacheKey)
208+
return std::nullopt;
209+
210+
assert(Invocation.getCASOpts().CASPath == CASOpts.CASPath &&
211+
"cas instance has incompatible hash with cas options");
212+
Invocation.getCASOpts() = std::move(CASOpts);
213+
return CacheKey;
199214
}
200215

201216
std::optional<llvm::cas::CASID>

0 commit comments

Comments
 (0)