Skip to content

Commit ce00f26

Browse files
[Caching][NFC] Using llvm::cas::CASConfiguration
Prefer llvm::cas::CASConfiguration where it used to clang::CASOption.
1 parent 5fb4a66 commit ce00f26

File tree

9 files changed

+33
-22
lines changed

9 files changed

+33
-22
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/ADT/DenseSet.h"
3232
#include "llvm/ADT/IntrusiveRefCntPtr.h"
3333
#include "llvm/ADT/StringSet.h"
34+
#include "llvm/CAS/CASConfiguration.h"
3435
#include "llvm/CAS/CachingOnDiskFileSystem.h"
3536
#include "llvm/Support/Mutex.h"
3637
#include <optional>
@@ -967,7 +968,7 @@ using ModuleDependenciesKindMap =
967968
/// dependency scanner.
968969
class SwiftDependencyScanningService {
969970
/// The CASOption created the Scanning Service if used.
970-
std::optional<clang::CASOptions> CASOpts;
971+
std::optional<llvm::cas::CASConfiguration> CASConfig;
971972

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

include/swift/Basic/CASOptions.h

Lines changed: 12 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;
@@ -80,6 +81,15 @@ class CASOptions final {
8081
llvm::hash_code getModuleScanningHashComponents() const {
8182
return getPCHHashComponents();
8283
}
84+
85+
/// Return corresponding clang::CASOptions for swift CASOptions.
86+
clang::CASOptions getClangCASOptions() const {
87+
clang::CASOptions CASOpts;
88+
CASOpts.CASPath = Config.CASPath;
89+
CASOpts.PluginPath = Config.PluginPath;
90+
CASOpts.PluginOptions = Config.PluginOptions;
91+
return CASOpts;
92+
}
8393
};
8494

8595
} // namespace swift

lib/AST/ModuleDependencies.cpp

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

639-
if (CASOpts) {
639+
if (CASConfig) {
640640
// If CASOption matches, the service is initialized already.
641-
if (*CASOpts == Instance.getInvocation().getCASOptions().CASOpts)
641+
if (*CASConfig == Instance.getInvocation().getCASOptions().Config)
642642
return false;
643643

644644
// CASOption mismatch, return error.
@@ -647,12 +647,12 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
647647
}
648648

649649
// Setup CAS.
650-
CASOpts = Instance.getInvocation().getCASOptions().CASOpts;
650+
CASConfig = Instance.getInvocation().getCASOptions().Config;
651651

652652
ClangScanningService.emplace(
653653
clang::tooling::dependencies::ScanningMode::DependencyDirectivesScan,
654654
clang::tooling::dependencies::ScanningOutputFormat::FullIncludeTree,
655-
Instance.getInvocation().getCASOptions().CASOpts,
655+
Instance.getInvocation().getCASOptions().getClangCASOptions(),
656656
Instance.getSharedCASInstance(), Instance.getSharedCacheInstance(),
657657
/*CachingOnDiskFileSystem=*/nullptr,
658658
// The current working directory optimization (off by default)

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
11841184
// compiler can be more efficient to compute swift cache key without having
11851185
// the knowledge about clang command-line options.
11861186
if (ctx.CASOpts.EnableCaching || ctx.CASOpts.ImportModuleFromCAS) {
1187-
CI->getCASOpts() = ctx.CASOpts.CASOpts;
1187+
CI->getCASOpts() = ctx.CASOpts.getClangCASOptions();
11881188
// When clangImporter is used to compile (generate .pcm or .pch), need to
11891189
// inherit the include tree from swift args (last one wins) and clear the
11901190
// input file.

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,17 +788,17 @@ static bool ParseCASArgs(CASOptions &Opts, ArgList &Args,
788788
Opts.EnableCachingRemarks |= Args.hasArg(OPT_cache_remarks);
789789
Opts.CacheSkipReplay |= Args.hasArg(OPT_cache_disable_replay);
790790
if (const Arg *A = Args.getLastArg(OPT_cas_path))
791-
Opts.CASOpts.CASPath = A->getValue();
792-
else if (Opts.CASOpts.CASPath.empty())
793-
Opts.CASOpts.CASPath = llvm::cas::getDefaultOnDiskCASPath();
791+
Opts.Config.CASPath = A->getValue();
792+
else if (Opts.Config.CASPath.empty())
793+
Opts.Config.CASPath = llvm::cas::getDefaultOnDiskCASPath();
794794

795795
if (const Arg *A = Args.getLastArg(OPT_cas_plugin_path))
796-
Opts.CASOpts.PluginPath = A->getValue();
796+
Opts.Config.PluginPath = A->getValue();
797797

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

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ bool CompilerInstance::setupCASIfNeeded(ArrayRef<const char *> Args) {
465465
return false;
466466

467467
const auto &Opts = getInvocation().getCASOptions();
468-
auto MaybeDB = Opts.CASOpts.getOrCreateDatabases();
468+
auto MaybeDB = Opts.Config.createDatabases();
469469
if (!MaybeDB) {
470470
Diagnostics.diagnose(SourceLoc(), diag::error_cas_initialization,
471471
toString(MaybeDB.takeError()));

lib/Frontend/ModuleInterfaceLoader.cpp

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

18061806
if (casOpts.EnableCaching) {
18071807
genericSubInvocation.getCASOptions().EnableCaching = casOpts.EnableCaching;
1808-
genericSubInvocation.getCASOptions().CASOpts = casOpts.CASOpts;
1808+
genericSubInvocation.getCASOptions().Config = casOpts.Config;
18091809
genericSubInvocation.getCASOptions().HasImmutableFileSystem =
18101810
casOpts.HasImmutableFileSystem;
18111811
casOpts.enumerateCASConfigurationFlags(

lib/FrontendTool/FrontendTool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,8 +1440,8 @@ static bool generateReproducer(CompilerInstance &Instance,
14401440
llvm::sys::path::append(casPath, "cas");
14411441
clang::CASOptions newCAS;
14421442
newCAS.CASPath = casPath.str();
1443-
newCAS.PluginPath = casOpts.CASOpts.PluginPath;
1444-
newCAS.PluginOptions = casOpts.CASOpts.PluginOptions;
1443+
newCAS.PluginPath = casOpts.Config.PluginPath;
1444+
newCAS.PluginOptions = casOpts.Config.PluginOptions;
14451445
auto db = newCAS.getOrCreateDatabases();
14461446
if (!db) {
14471447
diags.diagnose(SourceLoc(), diag::error_cas_initialization,

0 commit comments

Comments
 (0)