Skip to content
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

Swift: extract diagnostics #11101

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

AlexDenisov
Copy link
Contributor

@AlexDenisov AlexDenisov commented Nov 3, 2022

No description provided.

@github-actions github-actions bot added the Swift label Nov 3, 2022
swift/extractor/main.cpp Outdated Show resolved Hide resolved
swift/extractor/invocation/CodeQLDiagnosticsConsumer.cpp Outdated Show resolved Hide resolved
swift/schema.py Show resolved Hide resolved
@AlexDenisov AlexDenisov force-pushed the alexdenisov/extractor-errors branch 2 times, most recently from 8997450 to 7c6aaa8 Compare Nov 4, 2022
@AlexDenisov AlexDenisov requested a review from redsun82 Nov 4, 2022
@AlexDenisov AlexDenisov marked this pull request as ready for review Nov 4, 2022
@AlexDenisov AlexDenisov requested a review from a team as a code owner Nov 4, 2022
Copy link
Contributor

@redsun82 redsun82 left a comment

Looks good! I mostly commented with nits, but I'd also like to have an explanation on the unused ranges and fixIts 🙂

@@ -11,6 +11,7 @@
#include "swift/extractor/infra/SwiftTagTraits.h"
#include "swift/extractor/trap/generated/TrapClasses.h"
#include "swift/extractor/infra/file/PathHash.h"
Copy link
Contributor

@redsun82 redsun82 Nov 8, 2022

Choose a reason for hiding this comment

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

nit: this include is not needed any more I think


class TrapDomain;

class SwiftLocationExtractor {
Copy link
Contributor

@redsun82 redsun82 Nov 8, 2022

Choose a reason for hiding this comment

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

nit: as this class has no template member function (🎉), we could split all its member functions definitions into a separate cpp file, which is a bit friendlier for the build


class TrapDomain;

class CodeQLDiagnosticsConsumer : public swift::DiagnosticConsumer {
Copy link
Contributor

@redsun82 redsun82 Nov 8, 2022

Choose a reason for hiding this comment

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

nit: shouldn't this be SwiftDiagnosticsConsumer to be consistent with other names?

// Translate ranges.
llvm::SmallVector<llvm::SMRange, 2> ranges;
for (auto R : diagInfo.Ranges)
ranges.push_back(getRawRange(sourceManager, R));

// Translate fix-its.
llvm::SmallVector<llvm::SMFixIt, 2> fixIts;
for (const swift::DiagnosticInfo::FixIt& F : diagInfo.FixIts)
fixIts.push_back(getRawFixIt(sourceManager, F));
Copy link
Contributor

@redsun82 redsun82 Nov 8, 2022

Choose a reason for hiding this comment

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

ranges and fixIts are not used anywhere, what is this code for? If there is some obscure side effect it should be described with comments

Copy link
Contributor Author

@AlexDenisov AlexDenisov Nov 8, 2022

Choose a reason for hiding this comment

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

Good catch, they were used originally, but then I tweaked the diagnostics message and they are not needed anymore.

if (!maybeFile) {
std::cerr << "Cannot create invocation trap file: " << target << "\n";
abort();
}
Copy link
Contributor

@redsun82 redsun82 Nov 8, 2022

Choose a reason for hiding this comment

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

what if for some reason we are calling the swift frontend with exactly the same arguments? Should we really abort in such a case? Also, now that I think about it hashing the command line flags might miss changes to the files provided to the call...

As there is no need to reference this output trap file outside of this very call of the extractor, maybe it'd be better to just use a random new file name every time?

Copy link
Contributor Author

@AlexDenisov AlexDenisov Nov 8, 2022

Choose a reason for hiding this comment

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

Yeah, you are right, some random name would work better.

Copy link
Contributor

@redsun82 redsun82 Nov 8, 2022

Choose a reason for hiding this comment

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

as discussed on chat, probably timestamp + getpid is a good fit for the trap target. Also, maybe use invocations as a directory containing the traps rather than as a filename prefix?

@AlexDenisov AlexDenisov force-pushed the alexdenisov/extractor-errors branch from 92c432d to 42004d9 Compare Nov 8, 2022
@AlexDenisov AlexDenisov force-pushed the alexdenisov/extractor-errors branch from f98f586 to 3f2f328 Compare Nov 8, 2022
@AlexDenisov AlexDenisov requested a review from redsun82 Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants