Skip to content

Commit e87c62d

Browse files
committed
[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.
1 parent 3f17361 commit e87c62d

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
@@ -2115,9 +2115,9 @@ ProcessModule(ModuleSP module_sp, std::string m_description,
21152115

21162116
const auto &opts = invocation.getSearchPathOptions();
21172117
module_search_paths.insert(module_search_paths.end(),
2118-
opts.ImportSearchPaths.begin(),
2119-
opts.ImportSearchPaths.end());
2120-
for (const auto &fwsp : opts.FrameworkSearchPaths)
2118+
opts.getImportSearchPaths().begin(),
2119+
opts.getImportSearchPaths().end());
2120+
for (const auto &fwsp : opts.getFrameworkSearchPaths())
21212121
framework_search_paths.push_back({fwsp.Path, fwsp.IsSystem});
21222122
auto &clang_opts = invocation.getClangImporterOptions().ExtraArgs;
21232123
for (const std::string &arg : clang_opts) {
@@ -2698,8 +2698,8 @@ void SwiftASTContext::InitializeSearchPathOptions(
26982698
}
26992699

27002700
llvm::StringMap<bool> processed;
2701-
std::vector<std::string> &invocation_import_paths =
2702-
invocation.getSearchPathOptions().ImportSearchPaths;
2701+
std::vector<std::string> invocation_import_paths(
2702+
invocation.getSearchPathOptions().getImportSearchPaths());
27032703
// Add all deserialized paths to the map.
27042704
for (const auto &path : invocation_import_paths)
27052705
processed.insert({path, false});
@@ -2710,11 +2710,14 @@ void SwiftASTContext::InitializeSearchPathOptions(
27102710
if (it_notseen.second)
27112711
invocation_import_paths.push_back(path);
27122712
}
2713+
invocation.getSearchPathOptions().setImportSearchPaths(
2714+
invocation_import_paths);
27132715

27142716
// This preserves the IsSystem bit, but deduplicates entries ignoring it.
27152717
processed.clear();
2716-
auto &invocation_framework_paths =
2717-
invocation.getSearchPathOptions().FrameworkSearchPaths;
2718+
std::vector<swift::SearchPathOptions::FrameworkSearchPath>
2719+
invocation_framework_paths(
2720+
invocation.getSearchPathOptions().getFrameworkSearchPaths());
27182721
// Add all deserialized paths to the map.
27192722
for (const auto &path : invocation_framework_paths)
27202723
processed.insert({path.Path, path.IsSystem});
@@ -2725,6 +2728,8 @@ void SwiftASTContext::InitializeSearchPathOptions(
27252728
if (it_notseen.second)
27262729
invocation_framework_paths.push_back({path.first, path.second});
27272730
}
2731+
invocation.getSearchPathOptions().setFrameworkSearchPaths(
2732+
invocation_framework_paths);
27282733
}
27292734

27302735
namespace lldb_private {
@@ -3384,7 +3389,8 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
33843389
std::string moduleCachePath = "";
33853390
std::unique_ptr<swift::ClangImporter> clang_importer_ap;
33863391
auto &clang_importer_options = GetClangImporterOptions();
3387-
if (!m_ast_context_ap->SearchPathOpts.SDKPath.empty() || TargetHasNoSDK()) {
3392+
if (!m_ast_context_ap->SearchPathOpts.getSDKPath().empty() ||
3393+
TargetHasNoSDK()) {
33883394
if (!clang_importer_options.OverrideResourceDir.empty()) {
33893395
// Create the DWARFImporterDelegate.
33903396
const auto &props = ModuleList::GetGlobalModuleListProperties();
@@ -3442,7 +3448,7 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
34423448
if (!sdk_version) {
34433449
auto SDKInfoOrErr = clang::parseDarwinSDKInfo(
34443450
*llvm::vfs::getRealFileSystem(),
3445-
m_ast_context_ap->SearchPathOpts.SDKPath);
3451+
m_ast_context_ap->SearchPathOpts.getSDKPath());
34463452
if (SDKInfoOrErr) {
34473453
if (auto SDKInfo = *SDKInfoOrErr)
34483454
sdk_version = swift::getTargetSDKVersion(*SDKInfo, triple);
@@ -3743,16 +3749,17 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const FileSpec &module_spec,
37433749

37443750
std::string module_directory(module_spec.GetDirectory().GetCString());
37453751
bool add_search_path = true;
3746-
for (auto path : ast->SearchPathOpts.ImportSearchPaths) {
3752+
for (auto path : ast->SearchPathOpts.getImportSearchPaths()) {
37473753
if (path == module_directory) {
37483754
add_search_path = false;
37493755
break;
37503756
}
37513757
}
37523758
// Add the search path if needed so we can find the module by basename.
3753-
if (add_search_path)
3754-
ast->SearchPathOpts.ImportSearchPaths.push_back(
3755-
std::move(module_directory));
3759+
if (add_search_path) {
3760+
ast->addSearchPath(module_directory, /*isFramework=*/false,
3761+
/*isSystem=*/false);
3762+
}
37563763

37573764
typedef swift::Located<swift::Identifier> ModuleNameSpec;
37583765
llvm::StringRef module_basename_sref(module_basename.GetCString());
@@ -3950,7 +3957,8 @@ void SwiftASTContext::LoadModule(swift::ModuleDecl *swift_module,
39503957
std::vector<std::string> uniqued_paths;
39513958

39523959
for (const auto &framework_search_dir :
3953-
swift_module->getASTContext().SearchPathOpts.FrameworkSearchPaths) {
3960+
swift_module->getASTContext()
3961+
.SearchPathOpts.getFrameworkSearchPaths()) {
39543962
// The framework search dir as it comes from the AST context
39553963
// often has duplicate entries, don't try to load along the
39563964
// same path twice.
@@ -5145,8 +5153,9 @@ void SwiftASTContext::LogConfiguration() {
51455153

51465154
HEALTH_LOG_PRINTF(" Architecture : %s",
51475155
m_ast_context_ap->LangOpts.Target.getTriple().c_str());
5148-
HEALTH_LOG_PRINTF(" SDK path : %s",
5149-
m_ast_context_ap->SearchPathOpts.SDKPath.c_str());
5156+
HEALTH_LOG_PRINTF(
5157+
" SDK path : %s",
5158+
m_ast_context_ap->SearchPathOpts.getSDKPath().str().c_str());
51505159
HEALTH_LOG_PRINTF(
51515160
" Runtime resource path : %s",
51525161
m_ast_context_ap->SearchPathOpts.RuntimeResourcePath.c_str());
@@ -5161,26 +5170,29 @@ void SwiftASTContext::LogConfiguration() {
51615170

51625171
HEALTH_LOG_PRINTF(" Runtime library import paths : (%llu items)",
51635172
(unsigned long long)m_ast_context_ap->SearchPathOpts
5164-
.RuntimeLibraryImportPaths.size());
5173+
.getRuntimeLibraryImportPaths()
5174+
.size());
51655175

51665176
for (const auto &runtime_import_path :
5167-
m_ast_context_ap->SearchPathOpts.RuntimeLibraryImportPaths) {
5177+
m_ast_context_ap->SearchPathOpts.getRuntimeLibraryImportPaths()) {
51685178
HEALTH_LOG_PRINTF(" %s", runtime_import_path.c_str());
51695179
}
51705180

51715181
HEALTH_LOG_PRINTF(" Framework search paths : (%llu items)",
51725182
(unsigned long long)m_ast_context_ap->SearchPathOpts
5173-
.FrameworkSearchPaths.size());
5183+
.getFrameworkSearchPaths()
5184+
.size());
51745185
for (const auto &framework_search_path :
5175-
m_ast_context_ap->SearchPathOpts.FrameworkSearchPaths) {
5186+
m_ast_context_ap->SearchPathOpts.getFrameworkSearchPaths()) {
51765187
HEALTH_LOG_PRINTF(" %s", framework_search_path.Path.c_str());
51775188
}
51785189

51795190
HEALTH_LOG_PRINTF(" Import search paths : (%llu items)",
51805191
(unsigned long long)m_ast_context_ap->SearchPathOpts
5181-
.ImportSearchPaths.size());
5182-
for (std::string &import_search_path :
5183-
m_ast_context_ap->SearchPathOpts.ImportSearchPaths) {
5192+
.getImportSearchPaths()
5193+
.size());
5194+
for (const std::string &import_search_path :
5195+
m_ast_context_ap->SearchPathOpts.getImportSearchPaths()) {
51845196
HEALTH_LOG_PRINTF(" %s", import_search_path.c_str());
51855197
}
51865198

0 commit comments

Comments
 (0)