Skip to content

Commit 83c99d0

Browse files
committed
[LLDB] Simplify CAS configuration handling
1 parent 41badf4 commit 83c99d0

File tree

3 files changed

+29
-40
lines changed

3 files changed

+29
-40
lines changed

lldb/include/lldb/Core/ModuleList.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include "llvm/ADT/DenseSet.h"
2525
#include "llvm/Support/RWMutex.h"
2626

27+
// BEGIN CAS
28+
#include "llvm/CAS/CASConfiguration.h"
29+
// END CAS
30+
2731
#include <functional>
2832
#include <list>
2933
#include <mutex>
@@ -547,7 +551,7 @@ class ModuleList {
547551
// START CAS
548552

549553
struct CAS {
550-
std::shared_ptr<llvm::cas::CASConfiguration> configuration;
554+
llvm::cas::CASConfiguration configuration;
551555
std::shared_ptr<llvm::cas::ObjectStore> object_store;
552556
std::shared_ptr<llvm::cas::ActionCache> action_cache;
553557
};

lldb/source/Core/ModuleList.cpp

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,10 +1289,11 @@ class SharedModuleList {
12891289
// BEGIN CAS
12901290
to_remove.ForEach([&](auto &m) {
12911291
auto it = m_module_configs.find(m.get());
1292-
if (it != m_module_configs.end()) {
1293-
m_cas_cache.erase(it->second.get());
1294-
m_module_configs.erase(it);
1295-
}
1292+
if (it != m_module_configs.end())
1293+
if (auto config = it->second) {
1294+
m_cas_cache.erase(config);
1295+
m_module_configs.erase(it);
1296+
}
12961297
return IterationAction::Continue;
12971298
});
12981299
// END CAS
@@ -1314,13 +1315,10 @@ class SharedModuleList {
13141315
public:
13151316
/// Each module may have a CAS config associated with it.
13161317
/// Often many modules share the same CAS.
1317-
llvm::DenseMap<const Module *, std::shared_ptr<llvm::cas::CASConfiguration>>
1318-
m_module_configs;
1319-
1320-
llvm::StringMap<std::weak_ptr<llvm::cas::CASConfiguration>> m_cas_configs;
1318+
llvm::DenseMap<const Module *, llvm::cas::CASConfiguration> m_module_configs;
13211319

13221320
/// Each CAS config has a CAS associated with it.
1323-
llvm::DenseMap<const llvm::cas::CASConfiguration *,
1321+
llvm::DenseMap<llvm::cas::CASConfiguration,
13241322
std::pair<std::shared_ptr<llvm::cas::ObjectStore>,
13251323
std::shared_ptr<llvm::cas::ActionCache>>>
13261324
m_cas_cache;
@@ -1357,22 +1355,19 @@ static SharedModuleList &GetSharedModuleList() {
13571355
return GetSharedModuleListInfo().module_list;
13581356
}
13591357

1360-
static std::shared_ptr<llvm::cas::CASConfiguration>
1358+
static llvm::cas::CASConfiguration
13611359
GetCASConfiguration(FileSpec CandidateConfigSearchPath) {
13621360
// Config CAS from properties.
13631361
auto &props = ModuleList::GetGlobalModuleListProperties();
13641362
auto path = props.GetCASOnDiskPath().GetPath();
13651363
if (!path.empty()) {
1366-
auto config = std::make_shared<llvm::cas::CASConfiguration>();
1367-
config->CASPath = props.GetCASOnDiskPath().GetPath();
1368-
config->PluginPath = props.GetCASPluginPath().GetPath();
1369-
config->PluginOptions = props.GetCASPluginOptions();
1370-
return config;
1364+
return {props.GetCASOnDiskPath().GetPath(),
1365+
props.GetCASPluginPath().GetPath(), props.GetCASPluginOptions()};
13711366
}
13721367
auto search_config = llvm::cas::CASConfiguration::createFromSearchConfigFile(
13731368
CandidateConfigSearchPath.GetPath());
13741369
if (search_config)
1375-
return std::make_shared<llvm::cas::CASConfiguration>(search_config->second);
1370+
return search_config->second;
13761371

13771372
return {};
13781373
}
@@ -1679,7 +1674,7 @@ static llvm::Expected<bool> loadModuleFromCASImpl(llvm::StringRef cas_id,
16791674

16801675
// Swap out the module_spec with the one loaded via CAS.
16811676
FileSpec cas_spec;
1682-
cas_spec.SetDirectory(ConstString(maybe_cas->configuration->CASPath));
1677+
cas_spec.SetDirectory(ConstString(maybe_cas->configuration.CASPath));
16831678
cas_spec.SetFilename(ConstString(cas_id));
16841679
ModuleSpec loaded(cas_spec, module_spec.GetUUID(), std::move(file_buffer));
16851680
loaded.GetArchitecture() = module_spec.GetArchitecture();
@@ -1707,7 +1702,7 @@ static llvm::Expected<bool> loadModuleFromCAS(llvm::StringRef cas_id,
17071702
return result;
17081703
}
17091704

1710-
static std::shared_ptr<llvm::cas::CASConfiguration>
1705+
static llvm::cas::CASConfiguration
17111706
FindCASConfiguration(const ModuleSP &module_sp) {
17121707
auto get_dir = [](FileSpec path) {
17131708
path.ClearFilename();
@@ -1716,7 +1711,7 @@ FindCASConfiguration(const ModuleSP &module_sp) {
17161711

17171712
// Look near the binary / dSYM.
17181713
std::set<FileSpec> unique_paths;
1719-
std::shared_ptr<llvm::cas::CASConfiguration> cas_config =
1714+
llvm::cas::CASConfiguration cas_config =
17201715
GetCASConfiguration(module_sp->GetFileSpec());
17211716

17221717
if (!cas_config) {
@@ -1762,10 +1757,9 @@ ModuleList::GetOrCreateCAS(const ModuleSP &module_sp) {
17621757
auto &shared_module_list = GetSharedModuleListInfo();
17631758
std::scoped_lock<std::mutex> lock(shared_module_list.shared_lock);
17641759
auto &module_configs = shared_module_list.module_list.m_module_configs;
1765-
auto &cas_configs = shared_module_list.module_list.m_cas_configs;
17661760
auto &cas_cache = shared_module_list.module_list.m_cas_cache;
17671761

1768-
std::shared_ptr<llvm::cas::CASConfiguration> cas_config;
1762+
llvm::cas::CASConfiguration cas_config;
17691763
{
17701764
auto cached_config = module_configs.find(module_sp.get());
17711765
if (cached_config != module_configs.end()) {
@@ -1777,15 +1771,6 @@ ModuleList::GetOrCreateCAS(const ModuleSP &module_sp) {
17771771

17781772
if (!cas_config) {
17791773
cas_config = FindCASConfiguration(module_sp);
1780-
if (cas_config) {
1781-
// Unique the configuration. This assumes that no two configs
1782-
// with different plugins share the same path.
1783-
auto it = cas_configs.find(cas_config->CASPath);
1784-
if (it != cas_configs.end())
1785-
if (auto unique_config = it->second.lock())
1786-
cas_config = unique_config;
1787-
cas_configs.insert({cas_config->CASPath, cas_config});
1788-
}
17891774
// Cache the config or lack thereof.
17901775
module_configs.insert({module_sp.get(), cas_config});
17911776
}
@@ -1795,7 +1780,7 @@ ModuleList::GetOrCreateCAS(const ModuleSP &module_sp) {
17951780

17961781
// Look in the cache.
17971782
{
1798-
auto cached = cas_cache.find(cas_config.get());
1783+
auto cached = cas_cache.find(cas_config);
17991784
if (cached != cas_cache.end()) {
18001785
if (!cached->second.first)
18011786
return llvm::createStringError(
@@ -1806,15 +1791,15 @@ ModuleList::GetOrCreateCAS(const ModuleSP &module_sp) {
18061791
}
18071792

18081793
// Create the CAS.
1809-
auto cas = cas_config->createDatabases();
1794+
auto cas = cas_config.createDatabases();
18101795
if (!cas) {
1811-
cas_cache.insert({cas_config.get(), {}});
1796+
cas_cache.insert({cas_config, {}});
18121797
return cas.takeError();
18131798
}
18141799

18151800
LLDB_LOG(GetLog(LLDBLog::Modules | LLDBLog::Symbols),
1816-
"Initialized CAS at {0}", cas_config->CASPath);
1817-
cas_cache.insert({cas_config.get(), {cas->first, cas->second}});
1801+
"Initialized CAS at {0}", cas_config.CASPath);
1802+
cas_cache.insert({cas_config, {cas->first, cas->second}});
18181803
return ModuleList::CAS{cas_config, cas->first, cas->second};
18191804
}
18201805

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -926,14 +926,14 @@ static void ConfigureCASStorage(const std::string &m_description,
926926
}
927927
m_ast_context->SetCASStorage(std::move(cas->object_store),
928928
std::move(cas->action_cache));
929-
m_ast_context->GetCASOptions().CASOpts.CASPath = cas->configuration->CASPath;
929+
m_ast_context->GetCASOptions().CASOpts.CASPath = cas->configuration.CASPath;
930930
m_ast_context->GetCASOptions().CASOpts.PluginPath =
931-
cas->configuration->PluginPath;
931+
cas->configuration.PluginPath;
932932
m_ast_context->GetCASOptions().CASOpts.PluginOptions =
933-
cas->configuration->PluginOptions;
933+
cas->configuration.PluginOptions;
934934
LOG_PRINTF(GetLog(LLDBLog::Types),
935935
"Setup CAS from module list properties with cas path: %s",
936-
cas->configuration->CASPath.c_str());
936+
cas->configuration.CASPath.c_str());
937937
}
938938

939939
SwiftASTContext::ScopedDiagnostics::ScopedDiagnostics(

0 commit comments

Comments
 (0)