-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[DiagnosticVerifier] Make DiagnosticVerifier a DiagnosticConsumer #28313
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
Conversation
@swift-ci please test |
555b047
to
2bdaf1d
Compare
Was re-reviewing this and found a few additional cleanup opportunities |
@swift-ci please test |
5f2cefa
to
8d5a866
Compare
@brentdax do you mind taking a look at this? |
8d5a866
to
b38b0b1
Compare
@brentdax No problem! I'll respond to your comments from the other PR here:
I'm not sure why it wasn't a The old verifier hooked the output of PrintingDiagnosticConsumer, and this one is independent of all the other consumers. As a result, -serialize-diagnostics-path and -emit-fixits-path continue to work because SerializedDiagnosticConsumer is unchanged. -warnings-as-errors overrides the diagnostic kind in I hadn't thought to test the color flags, it turns out the current verifier doesn't respect them. I've updated this PR to begin taking them into account.
No particular reason, I looked over the code again and was able to move a decent number out of the header. |
Yeah, this comment was in the wrong place. I've moved it |
6a7843d
to
c6ea47c
Compare
@swift-ci please smoke test |
@brentdax I was able to extend the test coverage a bit to cover some of the edge cases you mentioned. Do you mind taking another look? Also, since performance is relevant here, I ran the test suite locally with and without this change applied, and got 415s before and 430s after |
@swift-ci please smoke test macOS |
c6ea47c
to
317d944
Compare
@swift-ci please smoke test |
@brentdax bump |
317d944
to
6c0c858
Compare
6c0c858
to
d464609
Compare
@swift-ci please test |
@swift-ci please test Windows platform |
I'm not quite sure how to resolve these conflicts with the new dependency verifier. @CodaFi does DependencyVerifier rely on hooking the emission of |
@swift-ci please smoke test |
f29d0d9
to
658cca7
Compare
@brentdax there's no rush, but do you mind taking another look at this when you have a chance? I think it's getting closer to being a viable replacement for the existing verifier |
658cca7
to
88d3a6d
Compare
@swift-ci please smoke test |
138d902
to
01a5c39
Compare
@swift-ci test |
01a5c39
to
dfd9158
Compare
@swift-ci test |
lib/FrontendTool/FrontendTool.cpp
Outdated
// The verifier must be setup after CompilerInstance::setup is called above to | ||
// ensure the input buffer IDs have been added. | ||
std::unique_ptr<DiagnosticVerifier> verifier; | ||
if (diagOpts.VerifyMode != DiagnosticOptions::NoVerify) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a really tricky initialization condition - maybe we should move the verifier instance onto CompilerInstance and set it up in the right place then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, moving it onto CompilerInstance seems to work well
lib/FrontendTool/FrontendTool.cpp
Outdated
// If we're in -verify mode, temporarily ignore errors. If verification | ||
// failed, we'll still report an error correctly when finishDiagProcessing | ||
// runs. | ||
HadError = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is universally resetting the error code here a good idea? Granted, it's probably not a good idea for the verifier to have been doing this in the first place, but I imagine we've grown quite a few tests that rely on this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this logic into finishDiagProcessing
instead so we override the error code at the last possible moment, which I think makes this logic easier to understand.
lib/Frontend/DiagnosticVerifier.cpp
Outdated
addError(expected.MessageRange.begin(), "incorrect message found", fixIt); | ||
} else if (I->getColumnNo() + 1 != (int)*expected.ColumnNo) { | ||
} else if (I->Column != *expected.ColumnNo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were we off-by one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a consequence of operating on DiagnosticInfo
instead of SMDiagnostic
. I don't know why their column indexing is inconsistent, but I'm hesitant to change the behavior as part of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A raft of stylistic points. I really appreciate you trying to improve this long-neglected critical component.
…bclass Update DiagnosticVerifier to respect color flags Improve DiagnosticVerifier test coverage verifier updates to support new llvm stable branch
dfd9158
to
465bab0
Compare
@CodaFi thanks for all the feedback, this is really helpful! I believe I've addressed your initial points. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and tidy! Let's get this merged.
@swift-ci test |
@swift-ci please test Windows platform |
⛵️ |
Previously,
DiagnosticVerifier
hooked emission ofllvm::SMDiagnostic
to capture diagnostics for verification. This change makesDiagnosticVerifier
a subclass ofDiagnosticConsumer
instead. This means that instead of checking expected diagnostics against thellvm::SMDiagnostic
s emitted byPrintedDiagnosticConsumer
, it checks them directly against theDiagnosticInfo
s it receives from theDiagnosticEngine
.This is desirable for a couple reasons:
DiagnosticInfo
is translated to anSMDiagnostic
. This will allow adding verifier support for educational notes in a follow-upSMDiagnostic
. The current diagnostic pipeline looks likeDiagnostic -> DiagnosticInfo -> SMDiagnostic -> Text Output
when using thePrintingDiagnosticConsumer
. Eventually I'd like to reduce that to justDiagnostic -> DiagnosticInfo -> Text Output
. In addition to simplifying the diagnostics subsystem, this will make improving multi-byte character support in diagnostics much easier, and enable smaller QoL enhancements like https://bugs.swift.org/browse/SR-6024. (Edit: This will also allow running tests with -enable-experimental-diagnostic-formatting)The downside of making this change now is that we lose test coverage of
PrintingDiagnosticConsumer
itself. Under the old system every test which used the verifier relied on it.