Skip to content

Commit 9d420d8

Browse files
authored
Merge pull request #1940 from slavapestov/for-all-visible-modules
[Swift] Update for removal of forAllVisibleModules() apple-llvm-split-commit: d49bc70efdf0fa037cc591c76c1f55aa0877aefb apple-llvm-split-dir: lldb/
2 parents 4334697 + 3ea2695 commit 9d420d8

File tree

2 files changed

+51
-57
lines changed

2 files changed

+51
-57
lines changed

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <functional>
3636
#include <mutex>
3737

38+
#include "swift/AST/ImportCache.h"
3839
#include "swift/AST/Module.h"
3940
#include "swift/AST/Type.h"
4041
#include "swift/AST/Types.h"
@@ -1270,59 +1271,53 @@ std::unique_ptr<Language::TypeScavenger> SwiftLanguage::GetTypeScavenger() {
12701271

12711272
swift::ModuleDecl::AccessPathTy access_path;
12721273

1273-
module->forAllVisibleModules(
1274-
access_path,
1275-
[&ast_ctx, input, name_parts, &results](
1276-
swift::ModuleDecl::ImportedModule imported_module)
1277-
-> bool {
1278-
auto module = imported_module.second;
1279-
TypesOrDecls local_results;
1280-
ast_ctx->FindTypesOrDecls(input, module, local_results,
1281-
false);
1282-
llvm::Optional<TypeOrDecl> candidate;
1283-
if (local_results.empty() && name_parts.size() > 1) {
1284-
size_t idx_of_deeper = 1;
1285-
// if you're looking for Swift.Int in module Swift, try
1286-
// looking for Int
1287-
if (name_parts.front() == module->getName().str()) {
1288-
candidate = ast_ctx->FindTypeOrDecl(
1289-
name_parts[1].str().c_str(), module);
1290-
idx_of_deeper = 2;
1274+
for (auto imported_module : swift::namelookup::getAllImports(module)) {
1275+
auto module = imported_module.second;
1276+
TypesOrDecls local_results;
1277+
ast_ctx->FindTypesOrDecls(input, module, local_results,
1278+
false);
1279+
llvm::Optional<TypeOrDecl> candidate;
1280+
if (local_results.empty() && name_parts.size() > 1) {
1281+
size_t idx_of_deeper = 1;
1282+
// if you're looking for Swift.Int in module Swift, try
1283+
// looking for Int
1284+
if (name_parts.front() == module->getName().str()) {
1285+
candidate = ast_ctx->FindTypeOrDecl(
1286+
name_parts[1].str().c_str(), module);
1287+
idx_of_deeper = 2;
1288+
}
1289+
// this is probably the top-level name of a nested type
1290+
// String.UTF8View
1291+
else {
1292+
candidate = ast_ctx->FindTypeOrDecl(
1293+
name_parts[0].str().c_str(), module);
1294+
}
1295+
if (candidate.hasValue()) {
1296+
TypesOrDecls candidates{candidate.getValue()};
1297+
for (; idx_of_deeper < name_parts.size();
1298+
idx_of_deeper++) {
1299+
TypesOrDecls new_candidates;
1300+
for (auto candidate : candidates) {
1301+
ast_ctx->FindContainedTypeOrDecl(
1302+
name_parts[idx_of_deeper], candidate,
1303+
new_candidates);
12911304
}
1292-
// this is probably the top-level name of a nested type
1293-
// String.UTF8View
1294-
else {
1295-
candidate = ast_ctx->FindTypeOrDecl(
1296-
name_parts[0].str().c_str(), module);
1297-
}
1298-
if (candidate.hasValue()) {
1299-
TypesOrDecls candidates{candidate.getValue()};
1300-
for (; idx_of_deeper < name_parts.size();
1301-
idx_of_deeper++) {
1302-
TypesOrDecls new_candidates;
1303-
for (auto candidate : candidates) {
1304-
ast_ctx->FindContainedTypeOrDecl(
1305-
name_parts[idx_of_deeper], candidate,
1306-
new_candidates);
1307-
}
1308-
candidates = new_candidates;
1309-
}
1310-
for (auto candidate : candidates) {
1311-
if (candidate)
1312-
results.insert(candidate);
1313-
}
1314-
}
1315-
} else if (local_results.size() > 0) {
1316-
for (const auto &result : local_results)
1317-
results.insert(result);
1318-
} else if (local_results.empty() && module &&
1319-
name_parts.size() == 1 &&
1320-
name_parts.front() == module->getName().str())
1321-
results.insert(
1322-
CompilerType(swift::ModuleType::get(module)));
1323-
return true;
1324-
});
1325-
1305+
candidates = new_candidates;
1306+
}
1307+
for (auto candidate : candidates) {
1308+
if (candidate)
1309+
results.insert(candidate);
1310+
}
1311+
}
1312+
} else if (local_results.size() > 0) {
1313+
for (const auto &result : local_results)
1314+
results.insert(result);
1315+
} else if (local_results.empty() && module &&
1316+
name_parts.size() == 1 &&
1317+
name_parts.front() == module->getName().str())
1318+
results.insert(
1319+
CompilerType(swift::ModuleType::get(module)));
1320+
}
13261321
};
13271322

13281323
for (; iter != end; iter++)

lldb/source/Symbol/SwiftASTContext.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "swift/AST/DiagnosticsSema.h"
2828
#include "swift/AST/ExistentialLayout.h"
2929
#include "swift/AST/GenericSignature.h"
30+
#include "swift/AST/ImportCache.h"
3031
#include "swift/AST/IRGenOptions.h"
3132
#include "swift/AST/NameLookup.h"
3233
#include "swift/AST/SearchPathOptions.h"
@@ -4010,11 +4011,9 @@ void SwiftASTContext::LoadModule(swift::ModuleDecl *swift_module,
40104011
all_dlopen_errors.GetData());
40114012
};
40124013

4013-
swift_module->forAllVisibleModules(
4014-
{}, [&](swift::ModuleDecl::ImportedModule import) {
4015-
import.second->collectLinkLibraries(addLinkLibrary);
4016-
return true;
4017-
});
4014+
for (auto import : swift::namelookup::getAllImports(swift_module)) {
4015+
import.second->collectLinkLibraries(addLinkLibrary);
4016+
}
40184017
error = current_error;
40194018
}
40204019

0 commit comments

Comments
 (0)