-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Diagnostics] Improve {{none}} fix-it verifier #30791
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 smoke test |
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 don't know how often this will be used, but I think you're right that it could be useful for some of the diagnostics like argument renaming which produce many fix-its. I have a few comments which I think could help improve the clarity of the code.
@@ -16,7 +16,7 @@ let y: Int = "hello, world!" // expected-error@:49 {{cannot convert value of typ | |||
// Wrong fix-it | |||
let z: Int = "hello, world!" as Any | |||
// expected-error@-1 {{cannot convert value of type}} {{3-3=foobarbaz}} | |||
// CHECK: expected fix-it not seen; actual fix-its: {{[{][{]}}36-36= as! Int{{[}][}]}} | |||
// CHECK: expected fix-it not seen; actual fix-it seen: {{[{][{]}}36-36= as! Int{{[}][}]}} |
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.
Does this make sense to be actual fix-its seen:
because it can have more than 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.
Thanks. I will support plural form.
I have exactly been working on improving the diagnosis of argument labels recently. |
I updated implementation. I followed the points except for the following. I think it's getting better. |
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 like the new direction, I just have a few more small comments. Also, thanks for adding all the new tests!
lib/Frontend/DiagnosticVerifier.cpp
Outdated
auto makeActualFixitsPhrase = | ||
[&](ArrayRef<DiagnosticInfo::FixIt> actualFixits, | ||
std::string &actualFixitsStr) -> std::string { |
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.
Nit: I think this would be cleaner if it returned an std::pair
of actualFixitsStr
and the phrase instead of using actualFixitsStr
as an out parameter.
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.
OK. I did it.
if (replStartLoc[-1] == ' ') { | ||
replStartLoc--; | ||
} |
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.
Nit: a comment explaining why this is needed might be nice for future readers.
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.
lib/Frontend/DiagnosticVerifier.cpp
Outdated
if (actualFixits.size() >= 2) { | ||
str += "s"; | ||
} | ||
str += " seen: "; | ||
str += actualFixitsStr; |
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 fine, but using llvm::Twine
might make the concatenation a little more efficient
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.
Thanks! I did it.
lib/Frontend/DiagnosticVerifier.cpp
Outdated
const char *noneStartLoc = | ||
expected.ExpectedEnd - | ||
(fixitExpectationNoneString.size() + 4) /* length of '{{none}}' */; |
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 don't think the verifier currently requires {{none}}
is at the end. I think it probably makes sense to report an error if it does not. I think we can diagnose this just before we start parsing a fix-it on line 469 if Expected.noExtraFixitsMayAppear is already true.
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 thought that check is needed too.
I was going to make it another PR.
I implemented it and added test case.
Thank you for review. I will check tomorrow. |
I updated 😄 @swift-ci Please smoke test |
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 left one optional comment for rewording a message, but this looks great. Thank you!
Co-Authored-By: Owen Voorhees <[email protected]>
@owenv Thanks for your review and approval. @swift-ci Please smoke test By the way, I granted a commit access recently, but a bot doesn't respond at all. |
@swift-ci please smoke test |
lib/Frontend/DiagnosticVerifier.cpp
Outdated
// it returns actual fix-its string and diagnostic phrase | ||
auto makeActualFixitsPhrase = | ||
[&](ArrayRef<DiagnosticInfo::FixIt> actualFixits) | ||
-> std::tuple<std::string, std::string> { |
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.
std::tuple
is not quite the vocabulary type you want to use here. Please use a real struct with named fields so we can avoid all of that tuple unpacking noise below and get some decently self-documenting code here.
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 did it 🙂
lib/Frontend/DiagnosticVerifier.cpp
Outdated
} | ||
|
||
bool matchedAllFixIts = | ||
expected.Fixits.size() == FoundDiagnostic.FixIts.size(); | ||
bool isUnexpectedFixitsSeen = |
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.
Nit: const
@CodaFi Thank you for review! |
@shahmishal Thanks for fixing my CI trigger. @swift-ci Please smoke test |
⛵ |
Thank you all! |
This PR improve {{none}} fix-it verifier.
Currently, it means that no fix-it is expected.
I improve it to mean that no more fix-it is expected when use it with normal fix-it verifier at same time.
For example:
They means that diagnosed fix-its include
{{15-18=aa}}
at least.They doesn't care about whether more other fix-its are emitted.
Actually (2) emits second fix-its for label
bbx:
, but it doesn't affect anything.I introduce new feature for such situation to check strictly fix-its are just equal to expected.
For example:
With above code, (3) is passed verification but (4) is not.
We can check fix-its more strictly.
Original code doesn't support using it with normal fix-its.
This is result from Xcode11.4
@CodaFi @gregomni @owenv Could you review this?