Skip to content

Commit e02ac99

Browse files
ahoppenJDevlieghere
authored andcommitted
[lldb] Use getters to retrieve Swift module search paths
A corresponding PR on apple/swift makes module search paths only accessible using getters to only expose mutability through setters which can make sure that we maintain a module to module path lookup table. (cherry picked from commit e87c62d)
1 parent 74fd303 commit e02ac99

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

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

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,9 +2089,9 @@ ProcessModule(ModuleSP module_sp, std::string m_description,
20892089

20902090
const auto &opts = invocation.getSearchPathOptions();
20912091
module_search_paths.insert(module_search_paths.end(),
2092-
opts.ImportSearchPaths.begin(),
2093-
opts.ImportSearchPaths.end());
2094-
for (const auto &fwsp : opts.FrameworkSearchPaths)
2092+
opts.getImportSearchPaths().begin(),
2093+
opts.getImportSearchPaths().end());
2094+
for (const auto &fwsp : opts.getFrameworkSearchPaths())
20952095
framework_search_paths.push_back({fwsp.Path, fwsp.IsSystem});
20962096
auto &clang_opts = invocation.getClangImporterOptions().ExtraArgs;
20972097
for (const std::string &arg : clang_opts) {
@@ -2672,8 +2672,8 @@ void SwiftASTContext::InitializeSearchPathOptions(
26722672
}
26732673

26742674
llvm::StringMap<bool> processed;
2675-
std::vector<std::string> &invocation_import_paths =
2676-
invocation.getSearchPathOptions().ImportSearchPaths;
2675+
std::vector<std::string> invocation_import_paths(
2676+
invocation.getSearchPathOptions().getImportSearchPaths());
26772677
// Add all deserialized paths to the map.
26782678
for (const auto &path : invocation_import_paths)
26792679
processed.insert({path, false});
@@ -2684,11 +2684,14 @@ void SwiftASTContext::InitializeSearchPathOptions(
26842684
if (it_notseen.second)
26852685
invocation_import_paths.push_back(path);
26862686
}
2687+
invocation.getSearchPathOptions().setImportSearchPaths(
2688+
invocation_import_paths);
26872689

26882690
// This preserves the IsSystem bit, but deduplicates entries ignoring it.
26892691
processed.clear();
2690-
auto &invocation_framework_paths =
2691-
invocation.getSearchPathOptions().FrameworkSearchPaths;
2692+
std::vector<swift::SearchPathOptions::FrameworkSearchPath>
2693+
invocation_framework_paths(
2694+
invocation.getSearchPathOptions().getFrameworkSearchPaths());
26922695
// Add all deserialized paths to the map.
26932696
for (const auto &path : invocation_framework_paths)
26942697
processed.insert({path.Path, path.IsSystem});
@@ -2699,6 +2702,8 @@ void SwiftASTContext::InitializeSearchPathOptions(
26992702
if (it_notseen.second)
27002703
invocation_framework_paths.push_back({path.first, path.second});
27012704
}
2705+
invocation.getSearchPathOptions().setFrameworkSearchPaths(
2706+
invocation_framework_paths);
27022707
}
27032708

27042709
namespace lldb_private {
@@ -3358,7 +3363,8 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
33583363
std::string moduleCachePath = "";
33593364
std::unique_ptr<swift::ClangImporter> clang_importer_ap;
33603365
auto &clang_importer_options = GetClangImporterOptions();
3361-
if (!m_ast_context_ap->SearchPathOpts.SDKPath.empty() || TargetHasNoSDK()) {
3366+
if (!m_ast_context_ap->SearchPathOpts.getSDKPath().empty() ||
3367+
TargetHasNoSDK()) {
33623368
if (!clang_importer_options.OverrideResourceDir.empty()) {
33633369
// Create the DWARFImporterDelegate.
33643370
const auto &props = ModuleList::GetGlobalModuleListProperties();
@@ -3416,7 +3422,7 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
34163422
if (!sdk_version) {
34173423
auto SDKInfoOrErr = clang::parseDarwinSDKInfo(
34183424
*llvm::vfs::getRealFileSystem(),
3419-
m_ast_context_ap->SearchPathOpts.SDKPath);
3425+
m_ast_context_ap->SearchPathOpts.getSDKPath());
34203426
if (SDKInfoOrErr) {
34213427
if (auto SDKInfo = *SDKInfoOrErr)
34223428
sdk_version = swift::getTargetSDKVersion(*SDKInfo, triple);
@@ -3717,16 +3723,17 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const FileSpec &module_spec,
37173723

37183724
std::string module_directory(module_spec.GetDirectory().GetCString());
37193725
bool add_search_path = true;
3720-
for (auto path : ast->SearchPathOpts.ImportSearchPaths) {
3726+
for (auto path : ast->SearchPathOpts.getImportSearchPaths()) {
37213727
if (path == module_directory) {
37223728
add_search_path = false;
37233729
break;
37243730
}
37253731
}
37263732
// Add the search path if needed so we can find the module by basename.
3727-
if (add_search_path)
3728-
ast->SearchPathOpts.ImportSearchPaths.push_back(
3729-
std::move(module_directory));
3733+
if (add_search_path) {
3734+
ast->addSearchPath(module_directory, /*isFramework=*/false,
3735+
/*isSystem=*/false);
3736+
}
37303737

37313738
typedef swift::Located<swift::Identifier> ModuleNameSpec;
37323739
llvm::StringRef module_basename_sref(module_basename.GetCString());
@@ -3925,7 +3932,8 @@ void SwiftASTContext::LoadModule(swift::ModuleDecl *swift_module,
39253932
std::vector<std::string> uniqued_paths;
39263933

39273934
for (const auto &framework_search_dir :
3928-
swift_module->getASTContext().SearchPathOpts.FrameworkSearchPaths) {
3935+
swift_module->getASTContext()
3936+
.SearchPathOpts.getFrameworkSearchPaths()) {
39293937
// The framework search dir as it comes from the AST context
39303938
// often has duplicate entries, don't try to load along the
39313939
// same path twice.
@@ -5123,8 +5131,9 @@ void SwiftASTContext::LogConfiguration() {
51235131

51245132
HEALTH_LOG_PRINTF(" Architecture : %s",
51255133
m_ast_context_ap->LangOpts.Target.getTriple().c_str());
5126-
HEALTH_LOG_PRINTF(" SDK path : %s",
5127-
m_ast_context_ap->SearchPathOpts.SDKPath.c_str());
5134+
HEALTH_LOG_PRINTF(
5135+
" SDK path : %s",
5136+
m_ast_context_ap->SearchPathOpts.getSDKPath().str().c_str());
51285137
HEALTH_LOG_PRINTF(
51295138
" Runtime resource path : %s",
51305139
m_ast_context_ap->SearchPathOpts.RuntimeResourcePath.c_str());
@@ -5139,26 +5148,29 @@ void SwiftASTContext::LogConfiguration() {
51395148

51405149
HEALTH_LOG_PRINTF(" Runtime library import paths : (%llu items)",
51415150
(unsigned long long)m_ast_context_ap->SearchPathOpts
5142-
.RuntimeLibraryImportPaths.size());
5151+
.getRuntimeLibraryImportPaths()
5152+
.size());
51435153

51445154
for (const auto &runtime_import_path :
5145-
m_ast_context_ap->SearchPathOpts.RuntimeLibraryImportPaths) {
5155+
m_ast_context_ap->SearchPathOpts.getRuntimeLibraryImportPaths()) {
51465156
HEALTH_LOG_PRINTF(" %s", runtime_import_path.c_str());
51475157
}
51485158

51495159
HEALTH_LOG_PRINTF(" Framework search paths : (%llu items)",
51505160
(unsigned long long)m_ast_context_ap->SearchPathOpts
5151-
.FrameworkSearchPaths.size());
5161+
.getFrameworkSearchPaths()
5162+
.size());
51525163
for (const auto &framework_search_path :
5153-
m_ast_context_ap->SearchPathOpts.FrameworkSearchPaths) {
5164+
m_ast_context_ap->SearchPathOpts.getFrameworkSearchPaths()) {
51545165
HEALTH_LOG_PRINTF(" %s", framework_search_path.Path.c_str());
51555166
}
51565167

51575168
HEALTH_LOG_PRINTF(" Import search paths : (%llu items)",
51585169
(unsigned long long)m_ast_context_ap->SearchPathOpts
5159-
.ImportSearchPaths.size());
5160-
for (std::string &import_search_path :
5161-
m_ast_context_ap->SearchPathOpts.ImportSearchPaths) {
5170+
.getImportSearchPaths()
5171+
.size());
5172+
for (const std::string &import_search_path :
5173+
m_ast_context_ap->SearchPathOpts.getImportSearchPaths()) {
51625174
HEALTH_LOG_PRINTF(" %s", import_search_path.c_str());
51635175
}
51645176

0 commit comments

Comments
 (0)