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

Detection of PLINQ nops analyzer #4126

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

Conversation

Mrnikbobjeff
Copy link

@Mrnikbobjeff Mrnikbobjeff commented Sep 3, 2020

@Mrnikbobjeff Mrnikbobjeff requested a review from a team as a code owner September 3, 2020 16:32
@dnfadmin
Copy link

dnfadmin commented Sep 3, 2020

CLA assistant check
All CLA requirements met.

Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

Marking as request changes due to few reasons:

  1. Even though New rule: Detection of PLINQ nops #2812 was marked approved, we now have a process where you will need to file an issue on dotnet/runtime repo for analyzer suggestion. THe issue needs to be approved and also get an approval on the default RuleLevel. Note the bar for an analyzer to be a warning by default is very high, it should be only for correctness issues.
  2. We are holding off on more .NET API analyzers for .NET5 - @jeffhandley to confirm. We will need a new branch for post .NET5 analyzers

@Mrnikbobjeff
Copy link
Author

I see, does that include the analyzers already approved on the dotnet/runtime repo? As a learning exercise I whipped up analyzers for most issue there, if that applies to those analyzer suggestions as well I would stop working on integrating them into roslyn analyzers for a while until point number two is resolved :)

@codecov
Copy link

codecov bot commented Sep 4, 2020

Codecov Report

Merging #4126 into master will increase coverage by 0.04%.
The diff coverage is 93.15%.

@@            Coverage Diff             @@
##           master    #4126      +/-   ##
==========================================
+ Coverage   95.78%   95.83%   +0.04%     
==========================================
  Files        1163     1173      +10     
  Lines      262725   266864    +4139     
  Branches    15829    16160     +331     
==========================================
+ Hits       251656   255738    +4082     
- Misses       9064     9077      +13     
- Partials     2005     2049      +44     

Schilli, Niklas added 4 commits September 8, 2020 19:55
…o replaced text based comparison to symbol based
…nto feature/DetectPLINQNops

# Conflicts:
#	src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

Need to be written as an IOperation analyzer, and should not be a build warning by default. I haven't reviewed the code fix provider yet.

@Mrnikbobjeff
Copy link
Author

Mrnikbobjeff commented Oct 13, 2020

@mavasani I migrated the analyzer to an IOperationAnalyzer which worked rather seemlessly. I will have to work on the fixer though, this is the first time coming into contact with the IOperation analyzer and fixer api

{
var newExpression = ((possibleInvocation as InvocationExpressionSyntax)!.Expression as MemberAccessExpressionSyntax)!.Expression;
possibleInvocation = newExpression;
} while (possibleInvocation is InvocationExpressionSyntax nestedInvocation && nestedInvocation.Expression is MemberAccessExpressionSyntax member && removableEnds.Contains(member.Name.Identifier.ValueText));
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to have only a check on the method name as a string? It might be better to check for the method symbol.

Copy link
Author

Choose a reason for hiding this comment

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

This I was unclear about as it also came up in my other pr, do we have to recheck everything in the fixer that we already did in the analyzer? I.E. if we warn here we already checked the symbol in the actual analyzer

Copy link
Member

Choose a reason for hiding this comment

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

It is also bit unclear for me how much needs to be rechecked for the fixer.

…jeff/roslyn-analyzers into feature/DetectPLINQNops

# Conflicts:
#	src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

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

Nit:

@mavasani
Copy link
Contributor

Closing and re-opening PR to retrigger tests, as we checked in new CI validation step for generated files.

@mavasani mavasani closed this Oct 14, 2020
@mavasani mavasani reopened this Oct 14, 2020

context.RegisterCodeFix(
new AsParallelCodeAction(
title: MicrosoftNetCoreAnalyzersResources.RemoveRedundantCall,
Copy link
Member

Choose a reason for hiding this comment

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

Not sure we do want to reuse this message or create a new specific one.

Copy link
Author

Choose a reason for hiding this comment

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

I have no idea, I'll adapt this to whatever is decided. It seemed to accurately reflect what the code fix does so I just chose that

@Youssef1313
Copy link
Member

@Mrnikbobjeff FYI, you need to run msbuild RoslynAnalyzers.sln /t:pack and msbuild FxCopAnalyzers.sln /t:pack to regenerate auto-generated files. This will fix the CI failures.

@Mrnikbobjeff
Copy link
Author

Some unanswered questions remain: Should we create a new Title for the code fix as we are currently reusing MicrosoftNetCoreAnalyzersResources.RemoveRedundantCall as title and equivalence key. Also, what should be rechecked in the codefix provider? This is relevant for both of my pull requests, as I do less computationally intensive operations by not rechecking much of what is checked in the analyzer

@carlossanlop
Copy link
Member

@Mrnikbobjeff the analyzer has been approved today: dotnet/runtime#33769

Please take a look at the video when you can.

The analyzer has been approved for the Performance category, with Warning severity. The message/title/description can be decided/confirmed in the PR. Whether we want all cases to be covered by one ruleID or more than one, can also be decided here, depending on the complexity of each case to cover.

We should make sure to verify all the possible combinations:

  • The AsParallel invocation is the only invocation.
  • The AsParallel invocation is terminal, of a series of LINQ invocations like Select or Where.
  • The AsParallel invocation is non-terminal, and is preceded and followed by LINQ invocations like Select or Where.
  • The AsParallel invocation is non-terminal, and is followed by non-LINQ invocations like ToArray().
  • The AsParallel invocation is non-terminal, and is preceded by LINQ invocations, then followed by non-LINQ invocations.

Besides adding good unit tests, we must ensure to test actual usage in Visual Studio, to double check that the behavior makes sense, and we don't end up offering an empty or incorrect fix.

cc @mavasani @buyaa-n

@Mrnikbobjeff
Copy link
Author

@Mrnikbobjeff FYI, you need to run msbuild RoslynAnalyzers.sln /t:pack and msbuild FxCopAnalyzers.sln /t:pack to regenerate auto-generated files. This will fix the CI failures.

Should building the FxCopAnalyzers solution work? the normal analyzer solution builds just fine, FxCopAnalyzers throw some errors though. I do not know whether the files were generated correctly

@Youssef1313
Copy link
Member

@Mrnikbobjeff It should build fine. Have you fixed the merge conflicts?

@@ -660,6 +660,18 @@ Calls to 'string.IndexOf' where the result is used to check for the presence/abs
|CodeFix|True|
---

## [CA2250](https://docs.microsoft.com/visualstudio/code-quality/ca2250): 'AsParallel' at the end of a LINQ query does not have an effect
Copy link
Member

Choose a reason for hiding this comment

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

After merging the current master into your branch, you will need to re-run msbuild pack.

The documentation links have moved from VS docs to .NET docs.
In current master you'll see these links are from .NET docs (while your branch is still on the old VS docs links).

Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

@mavasani
Copy link
Contributor

PR needs to target release\6.0.1xx branch.

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.

Use AsParallel() correctly New rule: Detection of PLINQ nops
6 participants