Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions swift/extractor/SwiftExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ void codeql::extractSwiftFiles(SwiftExtractorState& state, swift::CompilerInstan
auto inputFiles = collectInputFilenames(compiler);
std::vector<swift::ModuleDecl*> todo = collectLoadedModules(compiler);
state.encounteredModules.insert(todo.begin(), todo.end());
LOG_DEBUG("{} modules loaded", todo.size());

while (!todo.empty()) {
auto module = todo.back();
Expand All @@ -223,13 +224,18 @@ void codeql::extractSwiftFiles(SwiftExtractorState& state, swift::CompilerInstan
}
isFromSourceFile = true;
if (inputFiles.count(sourceFile->getFilename().str()) == 0) {
LOG_DEBUG("skipping module {} from file {}, not in input files", module->getName(),
sourceFile->getFilename());
continue;
}
LOG_DEBUG("extracting module {} from input file {}", module->getName(),
sourceFile->getFilename());
archiveFile(state.configuration, *sourceFile);
encounteredModules =
extractDeclarations(state, compiler, *module, sourceFile, /*lazy declaration*/ nullptr);
}
if (!isFromSourceFile) {
LOG_DEBUG("extracting module {} from non-source file", module->getName());
encounteredModules = extractDeclarations(state, compiler, *module, /*source file*/ nullptr,
/*lazy declaration*/ nullptr);
}
Expand Down
4 changes: 4 additions & 0 deletions swift/extractor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Observer : public swift::FrontendObserver {
explicit Observer(const codeql::SwiftExtractorConfiguration& config) : state{config} {}

void parsedArgs(swift::CompilerInvocation& invocation) override {
LOG_DEBUG("{}(...)", __func__);
auto& options = invocation.getFrontendOptions();
options.KeepASTContext = true;
lockOutputSwiftModuleTraps(state, options);
Expand All @@ -101,18 +102,21 @@ class Observer : public swift::FrontendObserver {
}

void configuredCompiler(swift::CompilerInstance& instance) override {
LOG_DEBUG("{}(...)", __func__);
// remove default consumers to avoid double messaging
instance.getDiags().takeConsumers();
instance.addDiagnosticConsumer(&diagConsumer);
}

void performedCompilation(swift::CompilerInstance& compiler) override {
LOG_DEBUG("{}(...)", __func__);
codeql::extractSwiftFiles(state, compiler);
codeql::extractSwiftInvocation(state, compiler, invocationTrap);
codeql::extractExtractLazyDeclarations(state, compiler);
}

void markSuccessfullyExtractedFiles() {
LOG_DEBUG("{}()", __func__);
Copy link

Copilot AI Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider standardizing the log message format across Observer methods. For example, if most methods use "{}(...)", you might adjust this log to match for consistency.

Suggested change
LOG_DEBUG("{}()", __func__);
LOG_DEBUG("{}(...)", __func__);

Copilot uses AI. Check for mistakes.
codeql::SwiftLocationExtractor locExtractor{invocationTrap};
for (const auto& src : state.sourceFiles) {
auto fileLabel = locExtractor.emitFile(src);
Expand Down
Loading