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