Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTlakaelel Axayakatl Ceja <tlakaelel.ceja@microsoft.com>2021-11-03 01:50:38 +0300
committerGitHub <noreply@github.com>2021-11-03 01:50:38 +0300
commit8e455f03b6a196ea4096f3eacdcc9b146be1e866 (patch)
treed1ee837ac5e9a2ada18a995e62d7c14e4a85dfbe /src
parentc702d0337dc1db26a74c482f19a367ad9ddb7b89 (diff)
Test Restructure (#2336)
Move RequiresAssemblyFiles from Analyzer to the linker RequiresCapability file Move the new constraint code from RequiresUnreferencedCode to be on the base Requires file Add Warning Id to messages from the analyzer to distinguish in a test which analyzer missed/found a warning Add RequiresAssemblyFilesMismatchAttribute Title and Message to fix bug Add testing in linker for mismatching attributes Add testing in linker for Delegates in CompilerGenerated file Add support for static constructor compiler-generated calls Add additional warnings from DAM and RUC interaction. Not supported by the analyzer yet
Diffstat (limited to 'src')
-rw-r--r--src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs46
-rw-r--r--src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs6
-rw-r--r--src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs56
-rw-r--r--src/ILLink.Shared/DiagnosticId.cs2
-rw-r--r--src/ILLink.Shared/SharedStrings.resx6
5 files changed, 56 insertions, 60 deletions
diff --git a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
index 05e97d464..c57a8aecd 100644
--- a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
+++ b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
@@ -8,6 +8,7 @@ using System.Linq;
using ILLink.Shared;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Operations;
@@ -144,6 +145,51 @@ namespace ILLink.RoslynAnalyzer
CheckCalledMember (operationContext, methodSymbol, incompatibleMembers);
}, OperationKind.DelegateCreation);
+ context.RegisterSyntaxNodeAction (syntaxNodeAnalysisContext => {
+ var model = syntaxNodeAnalysisContext.SemanticModel;
+ if (syntaxNodeAnalysisContext.ContainingSymbol is not ISymbol containingSymbol || containingSymbol.HasAttribute (RequiresAttributeName))
+ return;
+
+ GenericNameSyntax genericNameSyntaxNode = (GenericNameSyntax) syntaxNodeAnalysisContext.Node;
+ var typeParams = ImmutableArray<ITypeParameterSymbol>.Empty;
+ var typeArgs = ImmutableArray<ITypeSymbol>.Empty;
+ switch (model.GetSymbolInfo (genericNameSyntaxNode).Symbol) {
+ case INamedTypeSymbol typeSymbol:
+ typeParams = typeSymbol.TypeParameters;
+ typeArgs = typeSymbol.TypeArguments;
+ break;
+
+ case IMethodSymbol methodSymbol:
+ typeParams = methodSymbol.TypeParameters;
+ typeArgs = methodSymbol.TypeArguments;
+ break;
+
+ default:
+ return;
+ }
+
+ for (int i = 0; i < typeParams.Length; i++) {
+ var typeParam = typeParams[i];
+ var typeArg = typeArgs[i];
+ if (!typeParam.HasConstructorConstraint)
+ continue;
+
+ var typeArgCtors = ((INamedTypeSymbol) typeArg).InstanceConstructors;
+ foreach (var instanceCtor in typeArgCtors) {
+ if (instanceCtor.Arity > 0)
+ continue;
+
+ if (instanceCtor.TryGetAttribute (RequiresAttributeName, out var requiresUnreferencedCodeAttribute)) {
+ syntaxNodeAnalysisContext.ReportDiagnostic (Diagnostic.Create (RequiresDiagnosticRule,
+ syntaxNodeAnalysisContext.Node.GetLocation (),
+ containingSymbol.GetDisplayName (),
+ (string) requiresUnreferencedCodeAttribute.ConstructorArguments[0].Value!,
+ GetUrlFromAttribute (requiresUnreferencedCodeAttribute)));
+ }
+ }
+ }
+ }, SyntaxKind.GenericName);
+
// Register any extra operation actions supported by the analyzer.
foreach (var extraOperationAction in ExtraOperationActions)
context.RegisterOperationAction (extraOperationAction.Action, extraOperationAction.OperationKind);
diff --git a/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs b/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs
index 146eef064..f2e14ff60 100644
--- a/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs
+++ b/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs
@@ -24,9 +24,9 @@ namespace ILLink.RoslynAnalyzer
static readonly DiagnosticDescriptor s_requiresAssemblyFilesRule = DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.RequiresAssemblyFiles,
helpLinkUri: "https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/il3002");
- static readonly DiagnosticDescriptor s_requiresAssembyFilesAttributeMismatch = DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.RequiresAssembyFilesAttributeMismatch);
+ static readonly DiagnosticDescriptor s_requiresAssemblyFilesAttributeMismatch = DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.RequiresAssemblyFilesAttributeMismatch);
- public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create (s_locationRule, s_getFilesRule, s_requiresAssemblyFilesRule, s_requiresAssembyFilesAttributeMismatch);
+ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create (s_locationRule, s_getFilesRule, s_requiresAssemblyFilesRule, s_requiresAssemblyFilesAttributeMismatch);
private protected override string RequiresAttributeName => RequiresAssemblyFilesAttribute;
@@ -36,7 +36,7 @@ namespace ILLink.RoslynAnalyzer
private protected override DiagnosticDescriptor RequiresDiagnosticRule => s_requiresAssemblyFilesRule;
- private protected override DiagnosticDescriptor RequiresAttributeMismatch => s_requiresAssembyFilesAttributeMismatch;
+ private protected override DiagnosticDescriptor RequiresAttributeMismatch => s_requiresAssemblyFilesAttributeMismatch;
protected override bool IsAnalyzerEnabled (AnalyzerOptions options, Compilation compilation)
{
diff --git a/src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs b/src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs
index ba060ccf0..7e4f7e5a2 100644
--- a/src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs
+++ b/src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs
@@ -3,11 +3,8 @@
using System;
using System.Collections.Immutable;
-using System.Diagnostics.CodeAnalysis;
using ILLink.Shared;
using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace ILLink.RoslynAnalyzer
@@ -35,56 +32,6 @@ namespace ILLink.RoslynAnalyzer
operationContext.Operation.Syntax.GetLocation ()));
};
- [SuppressMessage ("MicrosoftCodeAnalysisPerformance", "RS1008",
- Justification = "Storing per-compilation data inside a diagnostic analyzer might cause stale compilations to remain alive." +
- "This action is registered through a compilation start action, so that instances that register this syntax" +
- " node action will not outlive a compilation's lifetime, avoiding the possibility of the locals stored in" +
- " this function to cause for any stale compilations to remain in memory.")]
- static readonly Action<SyntaxNodeAnalysisContext> s_constructorConstraint = syntaxNodeAnalysisContext => {
- var model = syntaxNodeAnalysisContext.SemanticModel;
- if (syntaxNodeAnalysisContext.ContainingSymbol is not ISymbol containingSymbol || containingSymbol.HasAttribute (RequiresUnreferencedCodeAttribute))
- return;
-
- GenericNameSyntax genericNameSyntaxNode = (GenericNameSyntax) syntaxNodeAnalysisContext.Node;
- var typeParams = ImmutableArray<ITypeParameterSymbol>.Empty;
- var typeArgs = ImmutableArray<ITypeSymbol>.Empty;
- switch (model.GetSymbolInfo (genericNameSyntaxNode).Symbol) {
- case INamedTypeSymbol typeSymbol:
- typeParams = typeSymbol.TypeParameters;
- typeArgs = typeSymbol.TypeArguments;
- break;
-
- case IMethodSymbol methodSymbol:
- typeParams = methodSymbol.TypeParameters;
- typeArgs = methodSymbol.TypeArguments;
- break;
-
- default:
- return;
- }
-
- for (int i = 0; i < typeParams.Length; i++) {
- var typeParam = typeParams[i];
- var typeArg = typeArgs[i];
- if (!typeParam.HasConstructorConstraint)
- continue;
-
- var typeArgCtors = ((INamedTypeSymbol) typeArg).InstanceConstructors;
- foreach (var instanceCtor in typeArgCtors) {
- if (instanceCtor.Arity > 0)
- continue;
-
- if (instanceCtor.TryGetAttribute (RequiresUnreferencedCodeAttribute, out var requiresUnreferencedCodeAttribute)) {
- syntaxNodeAnalysisContext.ReportDiagnostic (Diagnostic.Create (s_requiresUnreferencedCodeRule,
- syntaxNodeAnalysisContext.Node.GetLocation (),
- containingSymbol.GetDisplayName (),
- (string) requiresUnreferencedCodeAttribute.ConstructorArguments[0].Value!,
- GetUrlFromAttribute (requiresUnreferencedCodeAttribute)));
- }
- }
- }
- };
-
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
ImmutableArray.Create (s_dynamicTypeInvocationRule, s_makeGenericMethodRule, s_makeGenericTypeRule, s_requiresUnreferencedCodeRule, s_requiresUnreferencedCodeAttributeMismatch);
@@ -133,9 +80,6 @@ namespace ILLink.RoslynAnalyzer
private protected override ImmutableArray<(Action<OperationAnalysisContext> Action, OperationKind[] OperationKind)> ExtraOperationActions =>
ImmutableArray.Create ((s_dynamicTypeInvocation, new OperationKind[] { OperationKind.DynamicInvocation }));
- private protected override ImmutableArray<(Action<SyntaxNodeAnalysisContext> Action, SyntaxKind[] SyntaxKind)> ExtraSyntaxNodeActions =>
- ImmutableArray.Create ((s_constructorConstraint, new SyntaxKind[] { SyntaxKind.GenericName }));
-
protected override bool VerifyAttributeArguments (AttributeData attribute) =>
attribute.ConstructorArguments.Length >= 1 && attribute.ConstructorArguments[0] is { Type: { SpecialType: SpecialType.System_String } } ctorArg;
diff --git a/src/ILLink.Shared/DiagnosticId.cs b/src/ILLink.Shared/DiagnosticId.cs
index 6720edbc4..8fe4fc2fe 100644
--- a/src/ILLink.Shared/DiagnosticId.cs
+++ b/src/ILLink.Shared/DiagnosticId.cs
@@ -14,7 +14,7 @@
AvoidAssemblyLocationInSingleFile = 3000,
AvoidAssemblyGetFilesInSingleFile = 3001,
RequiresAssemblyFiles = 3002,
- RequiresAssembyFilesAttributeMismatch = 3003
+ RequiresAssemblyFilesAttributeMismatch = 3003
}
public static class DiagnosticIdExtensions
diff --git a/src/ILLink.Shared/SharedStrings.resx b/src/ILLink.Shared/SharedStrings.resx
index 807f96a88..36ce24594 100644
--- a/src/ILLink.Shared/SharedStrings.resx
+++ b/src/ILLink.Shared/SharedStrings.resx
@@ -147,6 +147,12 @@
<data name="RequiresUnreferencedCodeAttributeMismatchTitle" xml:space="preserve">
<value>'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides.</value>
</data>
+ <data name="RequiresAssemblyFilesAttributeMismatchMessage" xml:space="preserve">
+ <value>{0}. 'RequiresAssemblyFilesAttribute' annotations must match across all interface implementations or overrides.</value>
+ </data>
+ <data name="RequiresAssemblyFilesAttributeMismatchTitle" xml:space="preserve">
+ <value>'RequiresAssemblyFilesAttribute' annotations must match across all interface implementations or overrides.</value>
+ </data>
<data name="BaseRequiresMismatchMessage" xml:space="preserve">
<value>Base member '{2}' with '{0}' has a derived member '{1}' without '{0}'</value>
</data>