Skip to content

Commit 4f05903

Browse files
[Caching][NFC] Using llvm::cas::CASConfiguration
Prefer llvm::cas::CASConfiguration where it used to clang::CASOption.
1 parent 9120a53 commit 4f05903

File tree

9 files changed

+32
-23
lines changed

9 files changed

+32
-23
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "llvm/ADT/DenseSet.h"
3333
#include "llvm/ADT/IntrusiveRefCntPtr.h"
3434
#include "llvm/ADT/StringSet.h"
35+
#include "llvm/CAS/CASConfiguration.h"
3536
#include "llvm/CAS/CachingOnDiskFileSystem.h"
3637
#include "llvm/Support/Mutex.h"
3738
#include <optional>
@@ -1036,8 +1037,8 @@ using BridgeClangDependencyCallback = llvm::function_ref<ModuleDependencyInfo(
10361037
/// A carrier of state shared among possibly multiple invocations of the
10371038
/// dependency scanner.
10381039
class SwiftDependencyScanningService {
1039-
/// The CASOption created the Scanning Service if used.
1040-
std::optional<clang::CASOptions> CASOpts;
1040+
/// The CAS configuration created the Scanning Service if used.
1041+
std::optional<llvm::cas::CASConfiguration> CASConfig;
10411042

10421043
/// The persistent Clang dependency scanner service
10431044
std::optional<clang::tooling::dependencies::DependencyScanningService>

include/swift/Basic/CASOptions.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "clang/CAS/CASOptions.h"
2222
#include "llvm/ADT/Hashing.h"
23+
#include "llvm/CAS/CASConfiguration.h"
2324

2425
namespace swift {
2526

@@ -37,8 +38,8 @@ class CASOptions final {
3738
/// Import modules from CAS.
3839
bool ImportModuleFromCAS = false;
3940

40-
/// CASOptions
41-
clang::CASOptions CASOpts;
41+
/// CAS Configuration.
42+
llvm::cas::CASConfiguration Config;
4243

4344
/// Clang Include Trees.
4445
std::string ClangIncludeTree;

lib/AST/ModuleDependencies.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,9 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
637637
if (!Instance.getInvocation().getCASOptions().EnableCaching)
638638
return false;
639639

640-
if (CASOpts) {
640+
if (CASConfig) {
641641
// If CASOption matches, the service is initialized already.
642-
if (*CASOpts == Instance.getInvocation().getCASOptions().CASOpts)
642+
if (*CASConfig == Instance.getInvocation().getCASOptions().Config)
643643
return false;
644644

645645
// CASOption mismatch, return error.
@@ -648,13 +648,18 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
648648
}
649649

650650
// Setup CAS.
651-
CASOpts = Instance.getInvocation().getCASOptions().CASOpts;
651+
CASConfig = Instance.getInvocation().getCASOptions().Config;
652+
653+
clang::CASOptions CASOpts;
654+
CASOpts.CASPath = CASConfig->CASPath;
655+
CASOpts.PluginPath = CASConfig->PluginPath;
656+
CASOpts.PluginOptions = CASConfig->PluginOptions;
652657

653658
ClangScanningService.emplace(
654659
clang::tooling::dependencies::ScanningMode::DependencyDirectivesScan,
655660
clang::tooling::dependencies::ScanningOutputFormat::FullIncludeTree,
656-
Instance.getInvocation().getCASOptions().CASOpts,
657-
Instance.getSharedCASInstance(), Instance.getSharedCacheInstance(),
661+
CASOpts, Instance.getSharedCASInstance(),
662+
Instance.getSharedCacheInstance(),
658663
/*CachingOnDiskFileSystem=*/nullptr,
659664
// The current working directory optimization (off by default)
660665
// should not impact CAS. We set the optization to all to be

lib/Basic/CASOptions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ void CASOptions::enumerateCASConfigurationFlags(
2323
llvm::function_ref<void(llvm::StringRef)> Callback) const {
2424
if (EnableCaching) {
2525
Callback("-cache-compile-job");
26-
if (!CASOpts.CASPath.empty()) {
26+
if (!Config.CASPath.empty()) {
2727
Callback("-cas-path");
28-
Callback(CASOpts.CASPath);
28+
Callback(Config.CASPath);
2929
}
30-
if (!CASOpts.PluginPath.empty()) {
30+
if (!Config.PluginPath.empty()) {
3131
Callback("-cas-plugin-path");
32-
Callback(CASOpts.PluginPath);
33-
for (auto Opt : CASOpts.PluginOptions) {
32+
Callback(Config.PluginPath);
33+
for (auto Opt : Config.PluginOptions) {
3434
Callback("-cas-plugin-option");
3535
Callback((llvm::Twine(Opt.first) + "=" + Opt.second).str());
3636
}

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,9 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
11891189
// compiler can be more efficient to compute swift cache key without having
11901190
// the knowledge about clang command-line options.
11911191
if (ctx.CASOpts.EnableCaching || ctx.CASOpts.ImportModuleFromCAS) {
1192-
CI->getCASOpts() = ctx.CASOpts.CASOpts;
1192+
CI->getCASOpts().CASPath = ctx.CASOpts.Config.CASPath;
1193+
CI->getCASOpts().PluginPath = ctx.CASOpts.Config.PluginPath;
1194+
CI->getCASOpts().PluginOptions = ctx.CASOpts.Config.PluginOptions;
11931195
// When clangImporter is used to compile (generate .pcm or .pch), need to
11941196
// inherit the include tree from swift args (last one wins) and clear the
11951197
// input file.

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,15 +786,15 @@ static bool ParseCASArgs(CASOptions &Opts, ArgList &Args,
786786
Opts.EnableCachingRemarks |= Args.hasArg(OPT_cache_remarks);
787787
Opts.CacheSkipReplay |= Args.hasArg(OPT_cache_disable_replay);
788788
if (const Arg *A = Args.getLastArg(OPT_cas_path))
789-
Opts.CASOpts.CASPath = A->getValue();
789+
Opts.Config.CASPath = A->getValue();
790790

791791
if (const Arg *A = Args.getLastArg(OPT_cas_plugin_path))
792-
Opts.CASOpts.PluginPath = A->getValue();
792+
Opts.Config.PluginPath = A->getValue();
793793

794794
for (StringRef Opt : Args.getAllArgValues(OPT_cas_plugin_option)) {
795795
StringRef Name, Value;
796796
std::tie(Name, Value) = Opt.split('=');
797-
Opts.CASOpts.PluginOptions.emplace_back(std::string(Name),
797+
Opts.Config.PluginOptions.emplace_back(std::string(Name),
798798
std::string(Value));
799799
}
800800

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,12 @@ bool CompilerInstance::setupCASIfNeeded(ArrayRef<const char *> Args) {
474474
return false;
475475

476476
const auto &Opts = getInvocation().getCASOptions();
477-
if (Opts.CASOpts.CASPath.empty() && Opts.CASOpts.PluginPath.empty()) {
477+
if (Opts.Config.CASPath.empty() && Opts.Config.PluginPath.empty()) {
478478
Diagnostics.diagnose(SourceLoc(), diag::error_cas_initialization,
479479
"no CAS options provided");
480480
return true;
481481
}
482-
auto MaybeDB = Opts.CASOpts.getOrCreateDatabases();
482+
auto MaybeDB = Opts.Config.createDatabases();
483483
if (!MaybeDB) {
484484
Diagnostics.diagnose(SourceLoc(), diag::error_cas_initialization,
485485
toString(MaybeDB.takeError()));

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
18111811

18121812
if (casOpts.EnableCaching) {
18131813
genericSubInvocation.getCASOptions().EnableCaching = casOpts.EnableCaching;
1814-
genericSubInvocation.getCASOptions().CASOpts = casOpts.CASOpts;
1814+
genericSubInvocation.getCASOptions().Config = casOpts.Config;
18151815
genericSubInvocation.getCASOptions().HasImmutableFileSystem =
18161816
casOpts.HasImmutableFileSystem;
18171817
casOpts.enumerateCASConfigurationFlags(

lib/FrontendTool/FrontendTool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,8 +1431,8 @@ static bool generateReproducer(CompilerInstance &Instance,
14311431
llvm::sys::path::append(casPath, "cas");
14321432
clang::CASOptions newCAS;
14331433
newCAS.CASPath = casPath.str();
1434-
newCAS.PluginPath = casOpts.CASOpts.PluginPath;
1435-
newCAS.PluginOptions = casOpts.CASOpts.PluginOptions;
1434+
newCAS.PluginPath = casOpts.Config.PluginPath;
1435+
newCAS.PluginOptions = casOpts.Config.PluginOptions;
14361436
auto db = newCAS.getOrCreateDatabases();
14371437
if (!db) {
14381438
diags.diagnose(SourceLoc(), diag::error_cas_initialization,

0 commit comments

Comments
 (0)