Skip to content

Commit 33c4a82

Browse files
committed
Swift: collect encountered modules
1 parent c7f13f1 commit 33c4a82

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

swift/extractor/SwiftExtractor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static std::vector<swift::ModuleDecl*> collectLoadedModules(swift::CompilerInsta
173173
void codeql::extractSwiftFiles(SwiftExtractorState& state, swift::CompilerInstance& compiler) {
174174
auto inputFiles = collectInputFilenames(compiler);
175175
std::vector<swift::ModuleDecl*> todo = collectLoadedModules(compiler);
176-
std::unordered_set<swift::ModuleDecl*> seen{todo.begin(), todo.end()};
176+
state.encounteredModules.insert(todo.begin(), todo.end());
177177

178178
while (!todo.empty()) {
179179
auto module = todo.back();
@@ -196,9 +196,9 @@ void codeql::extractSwiftFiles(SwiftExtractorState& state, swift::CompilerInstan
196196
encounteredModules = extractDeclarations(state, compiler, *module);
197197
}
198198
for (auto encountered : encounteredModules) {
199-
if (seen.count(encountered) == 0) {
199+
if (state.encounteredModules.count(encountered) == 0) {
200200
todo.push_back(encountered);
201-
seen.insert(encountered);
201+
state.encounteredModules.insert(encountered);
202202
}
203203
}
204204
}

swift/extractor/config/SwiftExtractorState.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <vector>
4+
#include <unordered_set>
45
#include <filesystem>
56

67
#include <swift/AST/Decl.h>
@@ -14,6 +15,10 @@ struct SwiftExtractorState {
1415
// All the trap files related to this extraction. This may also include trap files generated in a
1516
// previous run but that this run requested as well. Paths are relative to `configuration.trapDir`
1617
std::vector<std::filesystem::path> traps;
18+
19+
// All modules encountered during this extractor run, which therefore are dependencies of the
20+
// outcomes of this run
21+
std::unordered_set<const swift::ModuleDecl*> encounteredModules;
1722
};
1823

1924
} // namespace codeql

0 commit comments

Comments
 (0)