@@ -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 {
13141315public:
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
13611359GetCASConfiguration (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
17111706FindCASConfiguration (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) {
@@ -1764,10 +1759,9 @@ ModuleList::GetOrCreateCAS(const ModuleSP &module_sp) {
17641759 auto &shared_module_list = GetSharedModuleListInfo ();
17651760 std::scoped_lock<std::mutex> lock (shared_module_list.shared_lock );
17661761 auto &module_configs = shared_module_list.module_list .m_module_configs ;
1767- auto &cas_configs = shared_module_list.module_list .m_cas_configs ;
17681762 auto &cas_cache = shared_module_list.module_list .m_cas_cache ;
17691763
1770- std::shared_ptr< llvm::cas::CASConfiguration> cas_config;
1764+ llvm::cas::CASConfiguration cas_config;
17711765 {
17721766 auto cached_config = module_configs.find (module_sp.get ());
17731767 if (cached_config != module_configs.end ()) {
@@ -1779,15 +1773,6 @@ ModuleList::GetOrCreateCAS(const ModuleSP &module_sp) {
17791773
17801774 if (!cas_config) {
17811775 cas_config = FindCASConfiguration (module_sp);
1782- if (cas_config) {
1783- // Unique the configuration. This assumes that no two configs
1784- // with different plugins share the same path.
1785- auto it = cas_configs.find (cas_config->CASPath );
1786- if (it != cas_configs.end ())
1787- if (auto unique_config = it->second .lock ())
1788- cas_config = unique_config;
1789- cas_configs.insert ({cas_config->CASPath , cas_config});
1790- }
17911776 // Cache the config or lack thereof.
17921777 module_configs.insert ({module_sp.get (), cas_config});
17931778 }
@@ -1797,7 +1782,7 @@ ModuleList::GetOrCreateCAS(const ModuleSP &module_sp) {
17971782
17981783 // Look in the cache.
17991784 {
1800- auto cached = cas_cache.find (cas_config. get () );
1785+ auto cached = cas_cache.find (cas_config);
18011786 if (cached != cas_cache.end ()) {
18021787 if (!cached->second .first )
18031788 return llvm::createStringError (
@@ -1808,15 +1793,15 @@ ModuleList::GetOrCreateCAS(const ModuleSP &module_sp) {
18081793 }
18091794
18101795 // Create the CAS.
1811- auto cas = cas_config-> createDatabases ();
1796+ auto cas = cas_config. createDatabases ();
18121797 if (!cas) {
1813- cas_cache.insert ({cas_config. get () , {}});
1798+ cas_cache.insert ({cas_config, {}});
18141799 return cas.takeError ();
18151800 }
18161801
18171802 LLDB_LOG (GetLog (LLDBLog::Modules | LLDBLog::Symbols),
1818- " Initialized CAS at {0}" , cas_config-> CASPath );
1819- cas_cache.insert ({cas_config. get () , {cas->first , cas->second }});
1803+ " Initialized CAS at {0}" , cas_config. CASPath );
1804+ cas_cache.insert ({cas_config, {cas->first , cas->second }});
18201805 return ModuleList::CAS{cas_config, cas->first , cas->second };
18211806}
18221807
0 commit comments