Skip to content

Swift: add more debug logs #19384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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().get(),
sourceFile->getFilename());
continue;
}
LOG_DEBUG("extracting module {} from input file {}", module->getName().get(),
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().get());
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
Preview

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