|
35 | 35 | #include <functional>
|
36 | 36 | #include <mutex>
|
37 | 37 |
|
| 38 | +#include "swift/AST/ImportCache.h" |
38 | 39 | #include "swift/AST/Module.h"
|
39 | 40 | #include "swift/AST/Type.h"
|
40 | 41 | #include "swift/AST/Types.h"
|
@@ -1270,59 +1271,53 @@ std::unique_ptr<Language::TypeScavenger> SwiftLanguage::GetTypeScavenger() {
|
1270 | 1271 |
|
1271 | 1272 | swift::ModuleDecl::AccessPathTy access_path;
|
1272 | 1273 |
|
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); |
1291 | 1304 | }
|
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 | + } |
1326 | 1321 | };
|
1327 | 1322 |
|
1328 | 1323 | for (; iter != end; iter++)
|
|
0 commit comments