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

FindAllReferences on Deconstruct should consider all documents #24223

Merged
merged 1 commit into from
Jan 16, 2018

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Jan 13, 2018

Customer scenario

Use FindAllReferences on a Deconstruct method. Only references in the same document will be found, but all documents (that are indexed as having at least one deconstruction) should be considered.

Bugs this fixes

Fixes #24184

Workarounds, if any

None

Risk

Performance impact

Low. This is following the design of FindAllReferences for GetEnumerator methods very closely. The new code is only invoked when using FAR on a method called Deconstruct.

Is this a regression from a previous update?

No.

Root cause analysis

I should have included a test case with multiple documents, and also done some testing with dev hive on Roslyn codebase.

How was the bug found?

FAR for Deconstruct has not shipped yet (I implemented it in 15.6, in PR #22934) and I found this problem while using it on Roslyn codebase.

Verified the fix on Roslyn:
image

@jcouv jcouv added the Area-IDE label Jan 13, 2018
@jcouv jcouv added this to the 15.6 milestone Jan 13, 2018
@jcouv jcouv self-assigned this Jan 13, 2018
@jcouv jcouv requested a review from a team as a code owner January 13, 2018 04:19
@CyrusNajmabadi
Copy link
Member

i'm a bit confused in how any of this worked before. where was the code that was searching for deconstructs previously?

@CyrusNajmabadi
Copy link
Member

n/m. i see how it was working before.

@jcouv
Copy link
Member Author

jcouv commented Jan 16, 2018

@dotnet/roslyn-ide for review. A 15.6 fix. Thanks

Copy link
Member

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

Request changes pending answer to the comment in the diff marked with '❓'

@@ -93,7 +93,11 @@ protected override bool CanFind(IMethodSymbol symbol)
? await FindDocumentsWithForEachStatementsAsync(project, documents, cancellationToken).ConfigureAwait(false)
: ImmutableArray<Document>.Empty;

return ordinaryDocuments.Concat(forEachDocuments);
var deconstructDocuments = IsDeconstructMethod(methodSymbol)
Copy link
Member

@sharwell sharwell Jan 16, 2018

Choose a reason for hiding this comment

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

❓ Can/should we further narrow this down to cases where the parameter list only contains out parameters (or for static methods, only out parameters after a this parameter)? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

We could, but I'm not sure it's worth it. The purpose here is to prune potential documents and this simple heuristic is effective for that purpose.
For comparison, we apply a similar (simplistic) heuristic for detecting possible enumerator methods (see IsForEachMethod a few lines below), without checkout parameters or return type.
I feel that's ok to leave as-is.


In reply to: 161816905 [](ancestors = 161816905)

@@ -394,6 +394,15 @@ protected Task<ImmutableArray<Document>> FindDocumentsWithForEachStatementsAsync
}, cancellationToken);
}

protected Task<ImmutableArray<Document>> FindDocumentsWithDeconstructionAsync(Project project, IImmutableSet<Document> documents, CancellationToken cancellationToken)
Copy link
Member

Choose a reason for hiding this comment

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

💡 Consider refactoring these two similar methods to use a helper that takes a Func<WhateverTheIndexTypeIs, bool>. At this point I wouldn't move the helper to a different class or anything, but it does help show the common pattern for this type of document lookup.

@jcouv
Copy link
Member Author

jcouv commented Jan 16, 2018

@Pilchie Please approve for 15.6 ask-mode. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants