-
Notifications
You must be signed in to change notification settings - Fork 128
Redundant suppressions detection #2922
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
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
999b336
Added redundant suppressions detection
jkurdek 728f958
Added license to the tests
jkurdek 8be1c17
Apply suggestions from code review
jkurdek 192c777
Added tests for compiler generated code
jkurdek 84a3939
linter
jkurdek 21c9bd4
Made functionality optional & added tests
jkurdek 0401a81
fixed test
jkurdek c0ffdd4
Removed empty spaces from SharedStrings.resx
jkurdek 51e28b7
Removed redundant empty line SharedStrings.resx
jkurdek 51a87e3
removed empty line
jkurdek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using ILLink.Shared; | ||
| using Mono.Cecil; | ||
|
|
||
| namespace Mono.Linker.Steps | ||
| { | ||
| public class CheckSuppressionsDispatcher : SubStepsDispatcher | ||
| { | ||
| public CheckSuppressionsDispatcher () : base (new List<ISubStep> { new CheckSuppressionsStep () }) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| public override void Process (LinkContext context) | ||
| { | ||
| base.Process (context); | ||
| var redundantSuppressions = context.Suppressions.GetUnusedSuppressions (); | ||
|
|
||
| // Suppressions targeting warning caused by anything but the linker should not be reported. | ||
| // Suppressions targeting RedundantSuppression warning should not be reported. | ||
| redundantSuppressions = redundantSuppressions | ||
| .Where (suppression => ((DiagnosticId) suppression.suppressMessageInfo.Id).GetDiagnosticCategory () == DiagnosticCategory.Trimming) | ||
| .Where (suppression => ((DiagnosticId) suppression.suppressMessageInfo.Id) != DiagnosticId.RedundantSuppression); | ||
|
|
||
| foreach (var (provider, suppressMessageInfo) in redundantSuppressions) { | ||
| var source = GetSuppresionProvider (provider); | ||
|
|
||
| context.LogWarning (new MessageOrigin (source), DiagnosticId.RedundantSuppression, $"IL{suppressMessageInfo.Id:0000}"); | ||
| } | ||
| } | ||
|
|
||
| private static ICustomAttributeProvider GetSuppresionProvider (ICustomAttributeProvider provider) => provider is ModuleDefinition module ? module.Assembly : provider; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using Mono.Cecil; | ||
|
|
||
| namespace Mono.Linker.Steps | ||
| { | ||
| public class CheckSuppressionsStep : BaseSubStep | ||
| { | ||
| public override SubStepTargets Targets { | ||
| get { | ||
| return SubStepTargets.Type | | ||
| SubStepTargets.Field | | ||
| SubStepTargets.Method | | ||
| SubStepTargets.Property; | ||
| } | ||
| } | ||
|
|
||
| public override bool IsActiveFor (AssemblyDefinition assembly) | ||
| { | ||
| // Only process assemblies which went through marking. | ||
| // The code relies on MarkStep to identify the useful suppressions. | ||
| // Assemblies which didn't go through marking would not produce any warnings and thus would report all suppressions as redundant. | ||
| var assemblyAction = Annotations.GetAction (assembly); | ||
| return assemblyAction == AssemblyAction.Link || assemblyAction == AssemblyAction.Copy; | ||
vitek-karas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public override void ProcessType (TypeDefinition type) | ||
| { | ||
| Context.Suppressions.GatherSuppressions (type); | ||
| } | ||
|
|
||
| public override void ProcessField (FieldDefinition field) | ||
| { | ||
| Context.Suppressions.GatherSuppressions (field); | ||
| } | ||
|
|
||
| public override void ProcessMethod (MethodDefinition method) | ||
| { | ||
| if (Context.Annotations.GetAction (method) != MethodAction.ConvertToThrow) | ||
| Context.Suppressions.GatherSuppressions (method); | ||
| } | ||
|
|
||
| public override void ProcessProperty (PropertyDefinition property) | ||
| { | ||
| Context.Suppressions.GatherSuppressions (property); | ||
| } | ||
vitek-karas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public override void ProcessEvent (EventDefinition @event) | ||
| { | ||
| Context.Suppressions.GatherSuppressions (@event); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.