Skip to content

[SourceKit] If diagnostics are 'stale' for a particular snapshot then ignore them and only return the syntactic parser diagnostics #10388

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
Jun 20, 2017

Conversation

akyrtzi
Copy link
Contributor

@akyrtzi akyrtzi commented Jun 19, 2017

rdar://32769873

… ignore them and only return the syntactic parser diagnostics

rdar://32769873
@akyrtzi
Copy link
Contributor Author

akyrtzi commented Jun 19, 2017

@swift-ci smoke test

@akyrtzi akyrtzi requested a review from benlangmuir June 19, 2017 23:54
@@ -23,9 +24,14 @@ typedef std::function<void(StringRef DocumentName)>
DocumentUpdateNotificationReceiver;

class NotificationCenter {
bool DispatchToMain;
Copy link
Contributor

Choose a reason for hiding this comment

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

Tab instead of spaces?


public:
explicit NotificationCenter(bool dispatchToMain);
~NotificationCenter();

Copy link
Contributor

Choose a reason for hiding this comment

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

More tabs

sortedParserDiags.reserve(ParserDiags.size());
sortedParserDiags.insert(sortedParserDiags.end(), ParserDiags.begin(),
ParserDiags.end());
std::stable_sort(sortedParserDiags.begin(), sortedParserDiags.end(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of sorting twice and using binary_search, could you merge and sort all the diagnostics together once then use std::unique to remove the duplicates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered this but I chose not to because I didn't want to remove duplicates from within the same set of diagnostics (e.g. remove duplicates from the set of typechecked-AST diagnostics). If the compiler emits some duplicate diagnostic it may be desirable or not to remove the duplicate but I prefer that we just funnel-through what the compiler provided without such kind of filtering.
Also note that duplication check will check for location+description, but it may be some case where the compiler emits 2 diagnostics with same description but with different fixit. That would be weird for the compiler to do of course, but as I mentioned I'd prefer we don't try to de-dup within the same set and just provide the diagnostics that the compiler provided.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, makes sense. Could you add a comment that explains that?

@@ -4,7 +4,7 @@ let a = 0; let b = 0 }; unresolved
// Test that offsets of diagnostic ranges and fixits get updated correctly after the edit request

// RUN: %sourcekitd-test -req=open %s -- %s == -req=print-diags %s \
// RUN: == -req=edit -pos=2:1 -replace="_" -length=5 %s -print-raw-response \
// RUN: == -req=edit -pos=2:1 -replace="_" -length=5 %s == -req=print-diags %s \
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain what happened here? I think I understand all the other test changes, but not clear on this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test was specifically checking the previous behavior, that 'stale' diagnostics still show up, after correctly adjusting their source locations to accommodate for an edit. With this change it essentially switches to testing that after the edit and the document-update notification that we get the 'sema' diagnostics with the expected locations.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, thanks.

Remove tabs and add a comment.
Copy link
Contributor

@benlangmuir benlangmuir left a comment

Choose a reason for hiding this comment

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

LGTM

@akyrtzi
Copy link
Contributor Author

akyrtzi commented Jun 20, 2017

@swift-ci smoke test

@akyrtzi akyrtzi merged commit 0cfc56e into swiftlang:master Jun 20, 2017
@akyrtzi akyrtzi deleted the sourcekit-stale-diags-fix branch June 20, 2017 19:26
akyrtzi added a commit that referenced this pull request Jun 20, 2017
… ignore them and only return the syntactic parser diagnostics (#10388)

This makes sure that diagnostics returned for a particular state of source buffer are consistent and accurate.
rdar://32769873
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants