mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Caching][NFC] Using llvm::cas::CASConfiguration
Prefer llvm::cas::CASConfiguration where it used to clang::CASOption.
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include "llvm/ADT/DenseSet.h"
|
||||
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
||||
#include "llvm/ADT/StringSet.h"
|
||||
#include "llvm/CAS/CASConfiguration.h"
|
||||
#include "llvm/CAS/CachingOnDiskFileSystem.h"
|
||||
#include "llvm/Support/Mutex.h"
|
||||
#include <optional>
|
||||
@@ -1036,8 +1037,8 @@ using BridgeClangDependencyCallback = llvm::function_ref<ModuleDependencyInfo(
|
||||
/// A carrier of state shared among possibly multiple invocations of the
|
||||
/// dependency scanner.
|
||||
class SwiftDependencyScanningService {
|
||||
/// The CASOption created the Scanning Service if used.
|
||||
std::optional<clang::CASOptions> CASOpts;
|
||||
/// The CAS configuration created the Scanning Service if used.
|
||||
std::optional<llvm::cas::CASConfiguration> CASConfig;
|
||||
|
||||
/// The persistent Clang dependency scanner service
|
||||
std::optional<clang::tooling::dependencies::DependencyScanningService>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "clang/CAS/CASOptions.h"
|
||||
#include "llvm/ADT/Hashing.h"
|
||||
#include "llvm/CAS/CASConfiguration.h"
|
||||
|
||||
namespace swift {
|
||||
|
||||
@@ -37,8 +38,8 @@ public:
|
||||
/// Import modules from CAS.
|
||||
bool ImportModuleFromCAS = false;
|
||||
|
||||
/// CASOptions
|
||||
clang::CASOptions CASOpts;
|
||||
/// CAS Configuration.
|
||||
llvm::cas::CASConfiguration Config;
|
||||
|
||||
/// Clang Include Trees.
|
||||
std::string ClangIncludeTree;
|
||||
|
||||
@@ -637,9 +637,9 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
|
||||
if (!Instance.getInvocation().getCASOptions().EnableCaching)
|
||||
return false;
|
||||
|
||||
if (CASOpts) {
|
||||
if (CASConfig) {
|
||||
// If CASOption matches, the service is initialized already.
|
||||
if (*CASOpts == Instance.getInvocation().getCASOptions().CASOpts)
|
||||
if (*CASConfig == Instance.getInvocation().getCASOptions().Config)
|
||||
return false;
|
||||
|
||||
// CASOption mismatch, return error.
|
||||
@@ -648,13 +648,18 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
|
||||
}
|
||||
|
||||
// Setup CAS.
|
||||
CASOpts = Instance.getInvocation().getCASOptions().CASOpts;
|
||||
CASConfig = Instance.getInvocation().getCASOptions().Config;
|
||||
|
||||
clang::CASOptions CASOpts;
|
||||
CASOpts.CASPath = CASConfig->CASPath;
|
||||
CASOpts.PluginPath = CASConfig->PluginPath;
|
||||
CASOpts.PluginOptions = CASConfig->PluginOptions;
|
||||
|
||||
ClangScanningService.emplace(
|
||||
clang::tooling::dependencies::ScanningMode::DependencyDirectivesScan,
|
||||
clang::tooling::dependencies::ScanningOutputFormat::FullIncludeTree,
|
||||
Instance.getInvocation().getCASOptions().CASOpts,
|
||||
Instance.getSharedCASInstance(), Instance.getSharedCacheInstance(),
|
||||
CASOpts, Instance.getSharedCASInstance(),
|
||||
Instance.getSharedCacheInstance(),
|
||||
/*CachingOnDiskFileSystem=*/nullptr,
|
||||
// The current working directory optimization (off by default)
|
||||
// should not impact CAS. We set the optization to all to be
|
||||
|
||||
@@ -23,14 +23,14 @@ void CASOptions::enumerateCASConfigurationFlags(
|
||||
llvm::function_ref<void(llvm::StringRef)> Callback) const {
|
||||
if (EnableCaching) {
|
||||
Callback("-cache-compile-job");
|
||||
if (!CASOpts.CASPath.empty()) {
|
||||
if (!Config.CASPath.empty()) {
|
||||
Callback("-cas-path");
|
||||
Callback(CASOpts.CASPath);
|
||||
Callback(Config.CASPath);
|
||||
}
|
||||
if (!CASOpts.PluginPath.empty()) {
|
||||
if (!Config.PluginPath.empty()) {
|
||||
Callback("-cas-plugin-path");
|
||||
Callback(CASOpts.PluginPath);
|
||||
for (auto Opt : CASOpts.PluginOptions) {
|
||||
Callback(Config.PluginPath);
|
||||
for (auto Opt : Config.PluginOptions) {
|
||||
Callback("-cas-plugin-option");
|
||||
Callback((llvm::Twine(Opt.first) + "=" + Opt.second).str());
|
||||
}
|
||||
|
||||
@@ -1189,7 +1189,9 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
|
||||
// compiler can be more efficient to compute swift cache key without having
|
||||
// the knowledge about clang command-line options.
|
||||
if (ctx.CASOpts.EnableCaching || ctx.CASOpts.ImportModuleFromCAS) {
|
||||
CI->getCASOpts() = ctx.CASOpts.CASOpts;
|
||||
CI->getCASOpts().CASPath = ctx.CASOpts.Config.CASPath;
|
||||
CI->getCASOpts().PluginPath = ctx.CASOpts.Config.PluginPath;
|
||||
CI->getCASOpts().PluginOptions = ctx.CASOpts.Config.PluginOptions;
|
||||
// When clangImporter is used to compile (generate .pcm or .pch), need to
|
||||
// inherit the include tree from swift args (last one wins) and clear the
|
||||
// input file.
|
||||
|
||||
@@ -786,15 +786,15 @@ static bool ParseCASArgs(CASOptions &Opts, ArgList &Args,
|
||||
Opts.EnableCachingRemarks |= Args.hasArg(OPT_cache_remarks);
|
||||
Opts.CacheSkipReplay |= Args.hasArg(OPT_cache_disable_replay);
|
||||
if (const Arg *A = Args.getLastArg(OPT_cas_path))
|
||||
Opts.CASOpts.CASPath = A->getValue();
|
||||
Opts.Config.CASPath = A->getValue();
|
||||
|
||||
if (const Arg *A = Args.getLastArg(OPT_cas_plugin_path))
|
||||
Opts.CASOpts.PluginPath = A->getValue();
|
||||
Opts.Config.PluginPath = A->getValue();
|
||||
|
||||
for (StringRef Opt : Args.getAllArgValues(OPT_cas_plugin_option)) {
|
||||
StringRef Name, Value;
|
||||
std::tie(Name, Value) = Opt.split('=');
|
||||
Opts.CASOpts.PluginOptions.emplace_back(std::string(Name),
|
||||
Opts.Config.PluginOptions.emplace_back(std::string(Name),
|
||||
std::string(Value));
|
||||
}
|
||||
|
||||
|
||||
@@ -474,12 +474,12 @@ bool CompilerInstance::setupCASIfNeeded(ArrayRef<const char *> Args) {
|
||||
return false;
|
||||
|
||||
const auto &Opts = getInvocation().getCASOptions();
|
||||
if (Opts.CASOpts.CASPath.empty() && Opts.CASOpts.PluginPath.empty()) {
|
||||
if (Opts.Config.CASPath.empty() && Opts.Config.PluginPath.empty()) {
|
||||
Diagnostics.diagnose(SourceLoc(), diag::error_cas_initialization,
|
||||
"no CAS options provided");
|
||||
return true;
|
||||
}
|
||||
auto MaybeDB = Opts.CASOpts.getOrCreateDatabases();
|
||||
auto MaybeDB = Opts.Config.createDatabases();
|
||||
if (!MaybeDB) {
|
||||
Diagnostics.diagnose(SourceLoc(), diag::error_cas_initialization,
|
||||
toString(MaybeDB.takeError()));
|
||||
|
||||
@@ -1811,7 +1811,7 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
|
||||
|
||||
if (casOpts.EnableCaching) {
|
||||
genericSubInvocation.getCASOptions().EnableCaching = casOpts.EnableCaching;
|
||||
genericSubInvocation.getCASOptions().CASOpts = casOpts.CASOpts;
|
||||
genericSubInvocation.getCASOptions().Config = casOpts.Config;
|
||||
genericSubInvocation.getCASOptions().HasImmutableFileSystem =
|
||||
casOpts.HasImmutableFileSystem;
|
||||
casOpts.enumerateCASConfigurationFlags(
|
||||
|
||||
@@ -1431,8 +1431,8 @@ static bool generateReproducer(CompilerInstance &Instance,
|
||||
llvm::sys::path::append(casPath, "cas");
|
||||
clang::CASOptions newCAS;
|
||||
newCAS.CASPath = casPath.str();
|
||||
newCAS.PluginPath = casOpts.CASOpts.PluginPath;
|
||||
newCAS.PluginOptions = casOpts.CASOpts.PluginOptions;
|
||||
newCAS.PluginPath = casOpts.Config.PluginPath;
|
||||
newCAS.PluginOptions = casOpts.Config.PluginOptions;
|
||||
auto db = newCAS.getOrCreateDatabases();
|
||||
if (!db) {
|
||||
diags.diagnose(SourceLoc(), diag::error_cas_initialization,
|
||||
|
||||
Reference in New Issue
Block a user