Skip to content

Commit 8e68fab

Browse files
Revert "[Caching][NFC] Using llvm::cas::CASConfiguration"
This reverts commit 4f05903. 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
1 parent c337446 commit 8e68fab

File tree

9 files changed

+23
-32
lines changed

9 files changed

+23
-32
lines changed

include/swift/AST/ModuleDependencies.h

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

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

include/swift/Basic/CASOptions.h

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

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

2524
namespace swift {
2625

@@ -38,8 +37,8 @@ class CASOptions final {
3837
/// Import modules from CAS.
3938
bool ImportModuleFromCAS = false;
4039

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

4443
/// Clang Include Trees.
4544
std::string ClangIncludeTree;

lib/AST/ModuleDependencies.cpp

Lines changed: 5 additions & 10 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 (CASConfig) {
640+
if (CASOpts) {
641641
// If CASOption matches, the service is initialized already.
642-
if (*CASConfig == Instance.getInvocation().getCASOptions().Config)
642+
if (*CASOpts == Instance.getInvocation().getCASOptions().CASOpts)
643643
return false;
644644

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

650650
// Setup CAS.
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;
651+
CASOpts = Instance.getInvocation().getCASOptions().CASOpts;
657652

658653
ClangScanningService.emplace(
659654
clang::tooling::dependencies::ScanningMode::DependencyDirectivesScan,
660655
clang::tooling::dependencies::ScanningOutputFormat::FullIncludeTree,
661-
CASOpts, Instance.getSharedCASInstance(),
662-
Instance.getSharedCacheInstance(),
656+
Instance.getInvocation().getCASOptions().CASOpts,
657+
Instance.getSharedCASInstance(), Instance.getSharedCacheInstance(),
663658
/*CachingOnDiskFileSystem=*/nullptr,
664659
// The current working directory optimization (off by default)
665660
// 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 (!Config.CASPath.empty()) {
26+
if (!CASOpts.CASPath.empty()) {
2727
Callback("-cas-path");
28-
Callback(Config.CASPath);
28+
Callback(CASOpts.CASPath);
2929
}
30-
if (!Config.PluginPath.empty()) {
30+
if (!CASOpts.PluginPath.empty()) {
3131
Callback("-cas-plugin-path");
32-
Callback(Config.PluginPath);
33-
for (auto Opt : Config.PluginOptions) {
32+
Callback(CASOpts.PluginPath);
33+
for (auto Opt : CASOpts.PluginOptions) {
3434
Callback("-cas-plugin-option");
3535
Callback((llvm::Twine(Opt.first) + "=" + Opt.second).str());
3636
}

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,9 +1198,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
11981198
// compiler can be more efficient to compute swift cache key without having
11991199
// the knowledge about clang command-line options.
12001200
if (ctx.CASOpts.EnableCaching || ctx.CASOpts.ImportModuleFromCAS) {
1201-
CI->getCASOpts().CASPath = ctx.CASOpts.Config.CASPath;
1202-
CI->getCASOpts().PluginPath = ctx.CASOpts.Config.PluginPath;
1203-
CI->getCASOpts().PluginOptions = ctx.CASOpts.Config.PluginOptions;
1201+
CI->getCASOpts() = ctx.CASOpts.CASOpts;
12041202
// When clangImporter is used to compile (generate .pcm or .pch), need to
12051203
// inherit the include tree from swift args (last one wins) and clear the
12061204
// input file.

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,15 +804,15 @@ static bool ParseCASArgs(CASOptions &Opts, ArgList &Args,
804804
Opts.EnableCachingRemarks |= Args.hasArg(OPT_cache_remarks);
805805
Opts.CacheSkipReplay |= Args.hasArg(OPT_cache_disable_replay);
806806
if (const Arg *A = Args.getLastArg(OPT_cas_path))
807-
Opts.Config.CASPath = A->getValue();
807+
Opts.CASOpts.CASPath = A->getValue();
808808

809809
if (const Arg *A = Args.getLastArg(OPT_cas_plugin_path))
810-
Opts.Config.PluginPath = A->getValue();
810+
Opts.CASOpts.PluginPath = A->getValue();
811811

812812
for (StringRef Opt : Args.getAllArgValues(OPT_cas_plugin_option)) {
813813
StringRef Name, Value;
814814
std::tie(Name, Value) = Opt.split('=');
815-
Opts.Config.PluginOptions.emplace_back(std::string(Name),
815+
Opts.CASOpts.PluginOptions.emplace_back(std::string(Name),
816816
std::string(Value));
817817
}
818818

lib/Frontend/Frontend.cpp

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

479479
const auto &Opts = getInvocation().getCASOptions();
480-
if (Opts.Config.CASPath.empty() && Opts.Config.PluginPath.empty()) {
480+
if (Opts.CASOpts.CASPath.empty() && Opts.CASOpts.PluginPath.empty()) {
481481
Diagnostics.diagnose(SourceLoc(), diag::error_cas_initialization,
482482
"no CAS options provided");
483483
return true;
484484
}
485-
auto MaybeDB = Opts.Config.createDatabases();
485+
auto MaybeDB = Opts.CASOpts.getOrCreateDatabases();
486486
if (!MaybeDB) {
487487
Diagnostics.diagnose(SourceLoc(), diag::error_cas_initialization,
488488
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().Config = casOpts.Config;
1808+
genericSubInvocation.getCASOptions().CASOpts = casOpts.CASOpts;
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
@@ -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.Config.PluginPath;
1435-
newCAS.PluginOptions = casOpts.Config.PluginOptions;
1434+
newCAS.PluginPath = casOpts.CASOpts.PluginPath;
1435+
newCAS.PluginOptions = casOpts.CASOpts.PluginOptions;
14361436
auto db = newCAS.getOrCreateDatabases();
14371437
if (!db) {
14381438
diags.diagnose(SourceLoc(), diag::error_cas_initialization,

0 commit comments

Comments
 (0)