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
diff options
context:
space:
mode:
-rw-r--r--.editorconfig63
-rw-r--r--Directory.Build.props1
-rw-r--r--eng/Analyzers.props7
-rw-r--r--eng/Versions.props1
-rw-r--r--external/Mono.Options/Options.cs (renamed from src/analyzer/common/Mono.Options/Options.cs)2
-rw-r--r--external/corert/src/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFormatter.cs6
-rw-r--r--external/corert/src/System.Private.CoreLib/shared/System/Reflection/AssemblyNameParser.cs8
-rw-r--r--external/corert/src/System.Private.CoreLib/src/System/Reflection/Runtime/TypeParsing/TypeParser.cs1
-rw-r--r--src/ILLink.Tasks/ILLink.Tasks.csproj1
-rw-r--r--src/ILLink.Tasks/LinkTask.cs2
-rw-r--r--src/ILLink.Tasks/Utils.cs31
-rw-r--r--src/analyzer/analyzer.csproj4
-rw-r--r--src/linker/Linker.Dataflow/ValueNode.cs2
-rw-r--r--src/linker/Linker.Steps/BodySubstituterStep.cs2
-rw-r--r--src/linker/Linker.Steps/LinkAttributesStep.cs20
-rw-r--r--src/linker/Linker.Steps/OutputStep.cs5
-rw-r--r--src/linker/Linker.Steps/ResolveFromXmlStep.cs6
-rw-r--r--src/linker/Linker/AssemblyResolver.cs4
-rw-r--r--src/linker/Linker/DirectoryAssemblyResolver.cs4
-rw-r--r--src/linker/Linker/Driver.cs4
-rw-r--r--src/linker/Linker/DynamicDependency.cs1
-rw-r--r--src/linker/Linker/Inflater.cs97
-rw-r--r--src/linker/Linker/LinkContext.cs2
-rw-r--r--src/linker/Linker/MessageContainer.cs2
-rw-r--r--src/linker/Linker/MethodBodyScanner.cs2
-rw-r--r--src/linker/Linker/Tracer.cs3
-rw-r--r--src/linker/Mono.Linker.csproj1
-rw-r--r--test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.csproj1
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedExceptionHandlerSequenceAttribute.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceAttribute.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedLocalsSequenceAttribute.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInitializerData.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/NoLinkedOutputAttribute.cs1
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj1
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Support/PlatformAssemblies.cs11
-rw-r--r--test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj1
-rw-r--r--test/Mono.Linker.Tests/Mono.Linker.Tests.csproj1
37 files changed, 151 insertions, 157 deletions
diff --git a/.editorconfig b/.editorconfig
index 6750e823a..526def7ad 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -39,3 +39,66 @@ csharp_style_conditional_delegate_call = true:suggestion
# Avoid redundant accessibility modifiers when they're default
dotnet_style_require_accessibility_modifiers = omit_if_default:suggestion
+
+### Code Style Analyzers
+
+# IDE0004: Remove unnecessary cast
+#dotnet_diagnostic.IDE0004.severity = warning
+
+# IDE0005: Remove unnecessary usings/imports
+dotnet_diagnostic.IDE0005.severity = warning
+
+# IDE0019: Use pattern matching
+#dotnet_diagnostic.IDE0019.severity = warning
+
+# IDE0020:
+dotnet_diagnostic.IDE0020.severity = warning
+
+# IDE0035: Remove unreachable code
+dotnet_diagnostic.IDE0035.severity = warning
+
+# IDE0036: Order modifiers
+#dotnet_diagnostic.IDE0036.severity = warning
+
+# IDE0043: Format string contains invalid placeholder
+dotnet_diagnostic.IDE0043.severity = warning
+
+# IDE0044: Make field readonly
+#dotnet_diagnostic.IDE0044.severity = warning
+
+# IDE0051: Remove unused private members (no reads or writes)
+dotnet_diagnostic.IDE0051.severity = warning
+
+# IDE0052: Remove unread private member
+dotnet_diagnostic.IDE0052.severity = warning
+
+# IDE0053: Prefer expression bodies for lambdas
+dotnet_diagnostic.IDE0053.severity = warning
+
+# IDE0055: Fix formatting
+dotnet_diagnostic.IDE0055.severity = none
+
+# IDE0059: Unnecessary assignment to a value
+#dotnet_diagnostic.IDE0059.severity = warning
+
+# IDE0060: Remove unused parameter
+#dotnet_diagnostic.IDE0060.severity = warning
+
+# IDE0073: File header
+dotnet_diagnostic.IDE0073.severity = suggestion
+file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.\nSee the LICENSE file in the project root for more information.
+
+## CA analyzer rules
+dotnet_analyzer_diagnostic.category-performance.severity = warning
+dotnet_analyzer_diagnostic.category-maintainability.severity = warning
+dotnet_analyzer_diagnostic.category-reliability.severity = warning
+
+# CA1834: Use 'StringBuilder.Append(char)'
+dotnet_diagnostic.CA1834.severity = none
+
+# CA1822: Make member static
+dotnet_diagnostic.CA1822.severity = none
+
+[external/**/*.cs]
+dotnet_analyzer_diagnostic.severity = none
+generated_code = true
diff --git a/Directory.Build.props b/Directory.Build.props
index e1fcd8960..4f3900653 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -20,6 +20,7 @@
<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" Condition="'$(MonoBuild)' == ''" />
<!-- Still use global versions even if not using arcade. -->
<Import Project="eng/Versions.props" Condition="'$(MonoBuild)' != ''" />
+ <Import Project="eng/Analyzers.props" />
<PropertyGroup>
<IsPackable>false</IsPackable>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
diff --git a/eng/Analyzers.props b/eng/Analyzers.props
new file mode 100644
index 000000000..cf407bcfc
--- /dev/null
+++ b/eng/Analyzers.props
@@ -0,0 +1,7 @@
+<Project>
+ <ItemGroup Condition="'$(RunAnalyzers)' == 'true'">
+ <PackageReference Include="Microsoft.DotNet.CodeAnalysis" Version="$(MicrosoftDotNetCodeAnalysisVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
+ <PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.8.0-4.20469.1" PrivateAssets="all" />
+ <!-- <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.205" PrivateAssets="all" /> -->
+ </ItemGroup>
+</Project>
diff --git a/eng/Versions.props b/eng/Versions.props
index 37b5bbcb8..a82a6535f 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -21,6 +21,7 @@
<MicrosoftBuildFrameworkVersion>15.4.8</MicrosoftBuildFrameworkVersion>
<MicrosoftBuildUtilitiesCoreVersion>15.4.8</MicrosoftBuildUtilitiesCoreVersion>
<MicrosoftDotNetApiCompatVersion>5.0.0-beta.20467.6</MicrosoftDotNetApiCompatVersion>
+ <MicrosoftDotNetCodeAnalysisVersion>5.0.0-beta.20471.1</MicrosoftDotNetCodeAnalysisVersion>
<!-- We depend on (and redistribute) the official Mono.Cecil NuGet package built from https://github.com/jbevain/cecil -->
<MonoCecilVersion>0.11.2</MonoCecilVersion>
<UseVSTestRunner>true</UseVSTestRunner>
diff --git a/src/analyzer/common/Mono.Options/Options.cs b/external/Mono.Options/Options.cs
index a289e6281..e37e6001d 100644
--- a/src/analyzer/common/Mono.Options/Options.cs
+++ b/external/Mono.Options/Options.cs
@@ -1,3 +1,5 @@
+#pragma warning disable CA1507,CA1825,CA1834,CA2208
+
//
// Options.cs
//
diff --git a/external/corert/src/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFormatter.cs b/external/corert/src/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFormatter.cs
index 821a8d3c8..4873318d3 100644
--- a/external/corert/src/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFormatter.cs
+++ b/external/corert/src/System.Private.CoreLib/shared/System/Reflection/AssemblyNameFormatter.cs
@@ -14,7 +14,7 @@ namespace System.Reflection
{
const int PUBLIC_KEY_TOKEN_LEN = 8;
- if (a.Name == string.Empty)
+ if (string.IsNullOrEmpty(a.Name))
throw new FileLoadException();
StringBuilder sb = new StringBuilder();
@@ -54,7 +54,7 @@ namespace System.Reflection
string cultureName = a.CultureName;
if (cultureName != null)
{
- if (cultureName == string.Empty)
+ if (cultureName.Length == 0)
cultureName = "neutral";
sb.Append(", Culture=");
sb.AppendQuoted(cultureName);
@@ -64,7 +64,7 @@ namespace System.Reflection
if (pkt != null)
{
if (pkt.Length > PUBLIC_KEY_TOKEN_LEN)
- throw new ArgumentException();
+ throw new ArgumentException("Invalid token length", nameof(a));
sb.Append(", PublicKeyToken=");
if (pkt.Length == 0)
diff --git a/external/corert/src/System.Private.CoreLib/shared/System/Reflection/AssemblyNameParser.cs b/external/corert/src/System.Private.CoreLib/shared/System/Reflection/AssemblyNameParser.cs
index fdf5b8f06..7bb53199b 100644
--- a/external/corert/src/System.Private.CoreLib/shared/System/Reflection/AssemblyNameParser.cs
+++ b/external/corert/src/System.Private.CoreLib/shared/System/Reflection/AssemblyNameParser.cs
@@ -21,7 +21,7 @@ namespace System.Reflection
if (indexOfNul != -1)
s = s.Substring(0, indexOfNul);
if (s.Length == 0)
- throw new ArgumentException();
+ throw new ArgumentException("Empty string", nameof(s));
AssemblyNameLexer lexer = new AssemblyNameLexer(s);
@@ -31,7 +31,7 @@ namespace System.Reflection
if (token != AssemblyNameLexer.Token.String)
throw new FileLoadException();
- if (name == string.Empty || name.IndexOfAny(s_illegalCharactersInSimpleName) != -1)
+ if (string.IsNullOrEmpty(name) || name.IndexOfAny(s_illegalCharactersInSimpleName) != -1)
throw new FileLoadException();
Version version = null;
@@ -64,7 +64,7 @@ namespace System.Reflection
if (token != AssemblyNameLexer.Token.String)
throw new FileLoadException();
- if (attributeName == string.Empty)
+ if (String.IsNullOrEmpty(attributeName))
throw new FileLoadException();
for (int i = 0; i < alreadySeen.Count; i++)
@@ -168,7 +168,7 @@ namespace System.Reflection
private static byte[] ParsePKT(string attributeValue)
{
- if (attributeValue.Equals("null", StringComparison.OrdinalIgnoreCase) || attributeValue == string.Empty)
+ if (attributeValue.Equals("null", StringComparison.OrdinalIgnoreCase) || attributeValue.Length == 0)
return Array.Empty<byte>();
if (attributeValue.Length != 8 * 2)
diff --git a/external/corert/src/System.Private.CoreLib/src/System/Reflection/Runtime/TypeParsing/TypeParser.cs b/external/corert/src/System.Private.CoreLib/src/System/Reflection/Runtime/TypeParsing/TypeParser.cs
index c06cf7667..218c25260 100644
--- a/external/corert/src/System.Private.CoreLib/src/System/Reflection/Runtime/TypeParsing/TypeParser.cs
+++ b/external/corert/src/System.Private.CoreLib/src/System/Reflection/Runtime/TypeParsing/TypeParser.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+#pragma warning disable CA2208
using System.Collections.Generic;
namespace System.Reflection.Runtime.TypeParsing
diff --git a/src/ILLink.Tasks/ILLink.Tasks.csproj b/src/ILLink.Tasks/ILLink.Tasks.csproj
index 36a49f016..dcff939a4 100644
--- a/src/ILLink.Tasks/ILLink.Tasks.csproj
+++ b/src/ILLink.Tasks/ILLink.Tasks.csproj
@@ -19,6 +19,7 @@
<AutoGenerateAssemblyVersion>true</AutoGenerateAssemblyVersion>
<!-- Place linker and cecil alongside ILLink.Tasks in the output, for integration tests. -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
+ <RunAnalyzers>true</RunAnalyzers>
</PropertyGroup>
<ItemGroup>
diff --git a/src/ILLink.Tasks/LinkTask.cs b/src/ILLink.Tasks/LinkTask.cs
index a2960f1c4..a9b360fb6 100644
--- a/src/ILLink.Tasks/LinkTask.cs
+++ b/src/ILLink.Tasks/LinkTask.cs
@@ -200,7 +200,7 @@ namespace ILLink.Tasks
/// </summary>
public ITaskItem[] CustomSteps { get; set; }
- private readonly static string DotNetHostPathEnvironmentName = "DOTNET_HOST_PATH";
+ private const string DotNetHostPathEnvironmentName = "DOTNET_HOST_PATH";
private string _dotnetPath;
diff --git a/src/ILLink.Tasks/Utils.cs b/src/ILLink.Tasks/Utils.cs
index bbaf45613..afd544245 100644
--- a/src/ILLink.Tasks/Utils.cs
+++ b/src/ILLink.Tasks/Utils.cs
@@ -2,22 +2,25 @@ using System;
using Mono.Cecil;
using System.Linq;
-public static class Utils
+namespace ILLink.Tasks
{
- public static bool IsManagedAssembly (string fileName)
+ public static class Utils
{
- try {
- ModuleDefinition module = ModuleDefinition.ReadModule (fileName);
- return !IsCPPCLIAssembly (module);
- } catch (BadImageFormatException) {
- return false;
+ public static bool IsManagedAssembly (string fileName)
+ {
+ try {
+ ModuleDefinition module = ModuleDefinition.ReadModule (fileName);
+ return !IsCPPCLIAssembly (module);
+ } catch (BadImageFormatException) {
+ return false;
+ }
}
- }
- private static bool IsCPPCLIAssembly (ModuleDefinition module)
- {
- return module.Types.Any (t =>
- t.Namespace == "<CppImplementationDetails>" ||
- t.Namespace == "<CrtImplementationDetails>");
+ private static bool IsCPPCLIAssembly (ModuleDefinition module)
+ {
+ return module.Types.Any (t =>
+ t.Namespace == "<CppImplementationDetails>" ||
+ t.Namespace == "<CrtImplementationDetails>");
+ }
}
-}
+} \ No newline at end of file
diff --git a/src/analyzer/analyzer.csproj b/src/analyzer/analyzer.csproj
index 3166183ec..90eeaa7da 100644
--- a/src/analyzer/analyzer.csproj
+++ b/src/analyzer/analyzer.csproj
@@ -17,6 +17,10 @@
</PropertyGroup>
<ItemGroup>
+ <Compile Include="..\..\external\Mono.Options\*.cs" />
+ </ItemGroup>
+
+ <ItemGroup>
<PackageReference Condition="'$(UseCecilPackage)' == 'true'" Include="Mono.Cecil" Version="$(MonoCecilVersion)" />
<ProjectReference Condition="'$(UseCecilPackage)' != 'true'" Include="../../external/cecil/Mono.Cecil.csproj" />
</ItemGroup>
diff --git a/src/linker/Linker.Dataflow/ValueNode.cs b/src/linker/Linker.Dataflow/ValueNode.cs
index 7ca6c09fc..7aec0bcac 100644
--- a/src/linker/Linker.Dataflow/ValueNode.cs
+++ b/src/linker/Linker.Dataflow/ValueNode.cs
@@ -954,6 +954,8 @@ namespace Mono.Linker.Dataflow
/// The result of a Type.GetType.
/// AssemblyIdentity is the scope in which to resolve if the type name string is not assembly-qualified.
/// </summary>
+
+#pragma warning disable CA1812 // GetTypeFromStringValue is never instantiated
class GetTypeFromStringValue : ValueNode
{
private readonly TypeResolver _resolver;
diff --git a/src/linker/Linker.Steps/BodySubstituterStep.cs b/src/linker/Linker.Steps/BodySubstituterStep.cs
index 773af56f6..e598b8ba9 100644
--- a/src/linker/Linker.Steps/BodySubstituterStep.cs
+++ b/src/linker/Linker.Steps/BodySubstituterStep.cs
@@ -85,7 +85,7 @@ namespace Mono.Linker.Steps
return;
case "stub":
string value = GetAttribute (iterator.Current, "value");
- if (value != "") {
+ if (!string.IsNullOrEmpty (value)) {
if (!TryConvertValue (value, method.ReturnType, out object res)) {
Context.LogWarning ($"Invalid value for '{method.GetDisplayName ()}' stub", 2010, _xmlDocumentLocation);
return;
diff --git a/src/linker/Linker.Steps/LinkAttributesStep.cs b/src/linker/Linker.Steps/LinkAttributesStep.cs
index 309535156..a874d3ddd 100644
--- a/src/linker/Linker.Steps/LinkAttributesStep.cs
+++ b/src/linker/Linker.Steps/LinkAttributesStep.cs
@@ -39,7 +39,7 @@ namespace Mono.Linker.Steps
}
string attributeFullName = GetFullName (iterator.Current);
- if (attributeFullName == string.Empty) {
+ if (string.IsNullOrEmpty (attributeFullName)) {
Context.LogWarning ($"'attribute' element does not contain attribute 'fullname' or it's empty", 2029, _xmlDocumentLocation);
continue;
}
@@ -87,7 +87,7 @@ namespace Mono.Linker.Steps
List<CustomAttributeNamedArgument> attributeProperties = new List<CustomAttributeNamedArgument> ();
while (iterator.MoveNext ()) {
string propertyName = GetName (iterator.Current);
- if (propertyName == string.Empty) {
+ if (string.IsNullOrEmpty (propertyName)) {
Context.LogWarning ($"Property element does not contain attribute 'name'", 2051, _xmlDocumentLocation);
continue;
}
@@ -202,7 +202,7 @@ namespace Mono.Linker.Steps
protected override void ProcessAssembly (AssemblyDefinition assembly, XPathNodeIterator iterator, bool warnOnUnresolvedTypes)
{
IEnumerable<CustomAttribute> attributes = ProcessAttributes (iterator.Current, assembly);
- if (attributes.Count () > 0)
+ if (attributes.Any ())
Context.CustomAttributes.AddCustomAttributes (assembly, attributes);
ProcessTypes (assembly, iterator, warnOnUnresolvedTypes);
}
@@ -212,7 +212,7 @@ namespace Mono.Linker.Steps
Debug.Assert (ShouldProcessElement (nav));
IEnumerable<CustomAttribute> attributes = ProcessAttributes (nav, type);
- if (attributes.Count () > 0)
+ if (attributes.Any ())
Context.CustomAttributes.AddCustomAttributes (type, attributes);
ProcessTypeChildren (type, nav);
@@ -231,14 +231,14 @@ namespace Mono.Linker.Steps
protected override void ProcessField (TypeDefinition type, FieldDefinition field, XPathNavigator nav)
{
IEnumerable<CustomAttribute> attributes = ProcessAttributes (nav, field);
- if (attributes.Count () > 0)
+ if (attributes.Any ())
Context.CustomAttributes.AddCustomAttributes (field, attributes);
}
protected override void ProcessMethod (TypeDefinition type, MethodDefinition method, XPathNavigator nav, object customData)
{
IEnumerable<CustomAttribute> attributes = ProcessAttributes (nav, method);
- if (attributes.Count () > 0)
+ if (attributes.Any ())
Context.CustomAttributes.AddCustomAttributes (method, attributes);
ProcessReturnParameters (method, nav);
ProcessParameters (method, nav);
@@ -249,7 +249,7 @@ namespace Mono.Linker.Steps
var iterator = nav.SelectChildren ("parameter", string.Empty);
while (iterator.MoveNext ()) {
IEnumerable<CustomAttribute> attributes = ProcessAttributes (iterator.Current, method);
- if (attributes.Count () > 0) {
+ if (attributes.Any ()) {
string paramName = GetAttribute (iterator.Current, "name");
foreach (ParameterDefinition parameter in method.Parameters) {
if (paramName == parameter.Name) {
@@ -273,7 +273,7 @@ namespace Mono.Linker.Steps
if (firstAppearance) {
firstAppearance = false;
IEnumerable<CustomAttribute> attributes = ProcessAttributes (iterator.Current, method.MethodReturnType);
- if (attributes.Count () > 0)
+ if (attributes.Any ())
Context.CustomAttributes.AddCustomAttributes (method.MethodReturnType, attributes);
} else {
Context.LogWarning (
@@ -326,14 +326,14 @@ namespace Mono.Linker.Steps
protected override void ProcessProperty (TypeDefinition type, PropertyDefinition property, XPathNavigator nav, object customData, bool fromSignature)
{
IEnumerable<CustomAttribute> attributes = ProcessAttributes (nav, property);
- if (attributes.Count () > 0)
+ if (attributes.Any ())
Context.CustomAttributes.AddCustomAttributes (property, attributes);
}
protected override void ProcessEvent (TypeDefinition type, EventDefinition @event, XPathNavigator nav, object customData)
{
IEnumerable<CustomAttribute> attributes = ProcessAttributes (nav, @event);
- if (attributes.Count () > 0)
+ if (attributes.Any ())
Context.CustomAttributes.AddCustomAttributes (@event, attributes);
}
diff --git a/src/linker/Linker.Steps/OutputStep.cs b/src/linker/Linker.Steps/OutputStep.cs
index ebad3e1c4..da93461b0 100644
--- a/src/linker/Linker.Steps/OutputStep.cs
+++ b/src/linker/Linker.Steps/OutputStep.cs
@@ -169,10 +169,9 @@ namespace Mono.Linker.Steps
return;
using (var fs = File.Open (Path.Combine (Context.OutputDirectory, Context.PInvokesListFile), FileMode.Create)) {
- Context.PInvokes.Distinct ();
- Context.PInvokes.Sort ();
+ var values = Context.PInvokes.Distinct ().OrderBy (l => l);
var jsonSerializer = new DataContractJsonSerializer (typeof (List<PInvokeInfo>));
- jsonSerializer.WriteObject (fs, Context.PInvokes);
+ jsonSerializer.WriteObject (fs, values);
}
}
diff --git a/src/linker/Linker.Steps/ResolveFromXmlStep.cs b/src/linker/Linker.Steps/ResolveFromXmlStep.cs
index d202c8ba2..f7cd9a5e5 100644
--- a/src/linker/Linker.Steps/ResolveFromXmlStep.cs
+++ b/src/linker/Linker.Steps/ResolveFromXmlStep.cs
@@ -41,9 +41,9 @@ namespace Mono.Linker.Steps
{
const string NamespaceElementName = "namespace";
- static readonly string _required = "required";
- static readonly string _preserve = "preserve";
- static readonly string _accessors = "accessors";
+ const string _required = "required";
+ const string _preserve = "preserve";
+ const string _accessors = "accessors";
static readonly string[] _accessorsAll = new string[] { "all" };
static readonly char[] _accessorsSep = new char[] { ';' };
diff --git a/src/linker/Linker/AssemblyResolver.cs b/src/linker/Linker/AssemblyResolver.cs
index 7ba22df57..5034a5344 100644
--- a/src/linker/Linker/AssemblyResolver.cs
+++ b/src/linker/Linker/AssemblyResolver.cs
@@ -124,9 +124,9 @@ namespace Mono.Linker
{
// Validate arguments, similarly to how the base class does it.
if (name == null)
- throw new ArgumentNullException ("name");
+ throw new ArgumentNullException (nameof (name));
if (parameters == null)
- throw new ArgumentNullException ("parameters");
+ throw new ArgumentNullException (nameof (parameters));
if (!_assemblies.TryGetValue (name.Name, out AssemblyDefinition asm) && (_unresolvedAssemblies == null || !_unresolvedAssemblies.Contains (name.Name))) {
try {
diff --git a/src/linker/Linker/DirectoryAssemblyResolver.cs b/src/linker/Linker/DirectoryAssemblyResolver.cs
index f6cb91d31..cd7e77137 100644
--- a/src/linker/Linker/DirectoryAssemblyResolver.cs
+++ b/src/linker/Linker/DirectoryAssemblyResolver.cs
@@ -71,9 +71,9 @@ namespace Mono.Linker {
public virtual AssemblyDefinition Resolve (AssemblyNameReference name, ReaderParameters parameters)
{
if (name == null)
- throw new ArgumentNullException ("name");
+ throw new ArgumentNullException (nameof (name));
if (parameters == null)
- throw new ArgumentNullException ("parameters");
+ throw new ArgumentNullException (nameof (parameters));
var assembly = SearchDirectory (name, directories, parameters);
if (assembly != null)
diff --git a/src/linker/Linker/Driver.cs b/src/linker/Linker/Driver.cs
index 84b204e3c..9da7cfd1b 100644
--- a/src/linker/Linker/Driver.cs
+++ b/src/linker/Linker/Driver.cs
@@ -43,10 +43,10 @@ namespace Mono.Linker
#if FEATURE_ILLINK
const string resolvers = "-a|-r|-x";
- static readonly string _linker = "IL Linker";
+ const string _linker = "IL Linker";
#else
const string resolvers = "-a|-i|-r|-x";
- static readonly string _linker = "Mono IL Linker";
+ const string _linker = "Mono IL Linker";
#endif
public static int Main (string[] args)
diff --git a/src/linker/Linker/DynamicDependency.cs b/src/linker/Linker/DynamicDependency.cs
index 2d162e8b6..25057a2c2 100644
--- a/src/linker/Linker/DynamicDependency.cs
+++ b/src/linker/Linker/DynamicDependency.cs
@@ -12,6 +12,7 @@ namespace Mono.Linker
/// TypeReference instead of a Type, and it has a reference to the original
/// CustomAttribute for dependency tracing. It is also a place for helper
/// methods related to the attribute.
+ [System.AttributeUsage (System.AttributeTargets.Constructor | System.AttributeTargets.Field | System.AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
internal class DynamicDependency : Attribute
{
public CustomAttribute? OriginalAttribute { get; set; }
diff --git a/src/linker/Linker/Inflater.cs b/src/linker/Linker/Inflater.cs
deleted file mode 100644
index 9097cc1b9..000000000
--- a/src/linker/Linker/Inflater.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Mono.Cecil;
-
-namespace Mono.Linker
-{
- class Inflater
- {
- public static TypeReference InflateType (GenericContext context, TypeReference typeReference)
- {
- var typeDefinition = InflateTypeWithoutException (context, typeReference);
- if (typeDefinition == null)
- throw new InvalidOperationException ($"Unable to resolve a reference to the type '{typeReference.GetDisplayName ()}' in the assembly '{typeReference.Module.Assembly.FullName}'. Does this type exist in a different assembly in the project?");
-
- return typeDefinition;
- }
-
- public static GenericInstanceType InflateType (GenericContext context, TypeDefinition typeDefinition)
- {
- return ConstructGenericType (context, typeDefinition, typeDefinition.GenericParameters);
- }
-
- public static GenericInstanceType InflateType (GenericContext context, GenericInstanceType genericInstanceType)
- {
- var inflatedType = ConstructGenericType (context, genericInstanceType.Resolve (), genericInstanceType.GenericArguments);
- inflatedType.MetadataToken = genericInstanceType.MetadataToken;
- return inflatedType;
- }
-
- public static TypeReference InflateTypeWithoutException (GenericContext context, TypeReference typeReference)
- {
- if (typeReference is GenericParameter genericParameter) {
- if (context.Method == null && genericParameter.Type != GenericParameterType.Type) {
- // If no method is specified assume only partial inflation is desired.
- return typeReference;
- }
-
- var genericArgumentType = genericParameter.Type == GenericParameterType.Type
- ? context.Type.GenericArguments[genericParameter.Position]
- : context.Method.GenericArguments[genericParameter.Position];
-
- var inflatedType = genericArgumentType;
- return inflatedType;
- }
- if (typeReference is GenericInstanceType genericInstanceType)
- return InflateType (context, genericInstanceType);
-
- if (typeReference is ArrayType arrayType)
- return new ArrayType (InflateType (context, arrayType.ElementType), arrayType.Rank);
-
- if (typeReference is ByReferenceType byReferenceType)
- return new ByReferenceType (InflateType (context, byReferenceType.ElementType));
-
- if (typeReference is PointerType pointerType)
- return new PointerType (InflateType (context, pointerType.ElementType));
-
- if (typeReference is RequiredModifierType reqModType)
- return InflateTypeWithoutException (context, reqModType.ElementType);
-
- if (typeReference is OptionalModifierType optModType)
- return InflateTypeWithoutException (context, optModType.ElementType);
-
- return typeReference.Resolve ();
- }
-
- static GenericInstanceType ConstructGenericType (GenericContext context, TypeDefinition typeDefinition, IEnumerable<TypeReference> genericArguments)
- {
- var inflatedType = new GenericInstanceType (typeDefinition);
-
- foreach (var genericArgument in genericArguments)
- inflatedType.GenericArguments.Add (InflateType (context, genericArgument));
-
- return inflatedType;
- }
-
- public class GenericContext
- {
- private readonly GenericInstanceType _type;
- private readonly GenericInstanceMethod _method;
-
- public GenericContext (GenericInstanceType type, GenericInstanceMethod method)
- {
- _type = type;
- _method = method;
- }
-
- public GenericInstanceType Type {
- get { return _type; }
- }
-
- public GenericInstanceMethod Method {
- get { return _method; }
- }
- }
- }
-} \ No newline at end of file
diff --git a/src/linker/Linker/LinkContext.cs b/src/linker/Linker/LinkContext.cs
index 013dcb7c8..bcaccbc64 100644
--- a/src/linker/Linker/LinkContext.cs
+++ b/src/linker/Linker/LinkContext.cs
@@ -348,7 +348,7 @@ namespace Mono.Linker
return;
if (_symbolReaderProvider == null)
- throw new ArgumentNullException (nameof (_symbolReaderProvider));
+ throw new InvalidOperationException ("Symbol provider is not set");
try {
var symbolReader = _symbolReaderProvider.GetSymbolReader (
diff --git a/src/linker/Linker/MessageContainer.cs b/src/linker/Linker/MessageContainer.cs
index fd81f732a..e42ed95ed 100644
--- a/src/linker/Linker/MessageContainer.cs
+++ b/src/linker/Linker/MessageContainer.cs
@@ -10,7 +10,7 @@ namespace Mono.Linker
{
public readonly struct MessageContainer
{
- public static readonly MessageContainer Empty = new MessageContainer ();
+ public static readonly MessageContainer Empty;
/// <summary>
/// Optional data with a filename, line and column that triggered the
diff --git a/src/linker/Linker/MethodBodyScanner.cs b/src/linker/Linker/MethodBodyScanner.cs
index e79426db1..1fe406fed 100644
--- a/src/linker/Linker/MethodBodyScanner.cs
+++ b/src/linker/Linker/MethodBodyScanner.cs
@@ -85,7 +85,7 @@ namespace Mono.Linker
static HashSet<TypeDefinition> AllPossibleStackTypes (MethodDefinition method)
{
if (!method.HasBody)
- throw new ArgumentException ();
+ throw new ArgumentException ("Method does not have body", nameof (method));
var body = method.Body;
var types = new HashSet<TypeDefinition> ();
diff --git a/src/linker/Linker/Tracer.cs b/src/linker/Linker/Tracer.cs
index 43c8aa7df..32876937c 100644
--- a/src/linker/Linker/Tracer.cs
+++ b/src/linker/Linker/Tracer.cs
@@ -35,18 +35,15 @@ namespace Mono.Linker
{
protected readonly LinkContext context;
- Stack<object> dependency_stack;
List<IDependencyRecorder> recorders;
public Tracer (LinkContext context)
{
this.context = context;
- dependency_stack = new Stack<object> ();
}
public void Finish ()
{
- dependency_stack = null;
if (recorders != null) {
foreach (var recorder in recorders) {
if (recorder is IDisposable disposableRecorder)
diff --git a/src/linker/Mono.Linker.csproj b/src/linker/Mono.Linker.csproj
index 471e6d0b3..4d4161e5f 100644
--- a/src/linker/Mono.Linker.csproj
+++ b/src/linker/Mono.Linker.csproj
@@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<ServerGarbageCollection>true</ServerGarbageCollection>
+ <RunAnalyzers>true</RunAnalyzers>
</PropertyGroup>
<PropertyGroup Condition="'$(MonoBuild)' == ''">
diff --git a/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.csproj b/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.csproj
index 871a186c3..d800ade3a 100644
--- a/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.csproj
+++ b/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.csproj
@@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
+ <RunAnalyzers>false</RunAnalyzers>
</PropertyGroup>
<ItemGroup>
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedExceptionHandlerSequenceAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedExceptionHandlerSequenceAttribute.cs
index a90456dc6..0c9f10e4a 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedExceptionHandlerSequenceAttribute.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedExceptionHandlerSequenceAttribute.cs
@@ -8,7 +8,7 @@ namespace Mono.Linker.Tests.Cases.Expectations.Assertions
public ExpectedExceptionHandlerSequenceAttribute (string[] types)
{
if (types == null)
- throw new ArgumentNullException ();
+ throw new ArgumentNullException (nameof (types));
}
}
} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceAttribute.cs
index 5254351f5..7afdbb3b5 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceAttribute.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedInstructionSequenceAttribute.cs
@@ -8,7 +8,7 @@ namespace Mono.Linker.Tests.Cases.Expectations.Assertions
public ExpectedInstructionSequenceAttribute (string[] opCodes)
{
if (opCodes == null)
- throw new ArgumentNullException ();
+ throw new ArgumentNullException (nameof (opCodes));
}
}
} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedLocalsSequenceAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedLocalsSequenceAttribute.cs
index 6eea5b561..17f9cae1c 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedLocalsSequenceAttribute.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedLocalsSequenceAttribute.cs
@@ -8,13 +8,13 @@ namespace Mono.Linker.Tests.Cases.Expectations.Assertions
public ExpectedLocalsSequenceAttribute (string[] types)
{
if (types == null)
- throw new ArgumentNullException ();
+ throw new ArgumentNullException (nameof (types));
}
public ExpectedLocalsSequenceAttribute (Type[] types)
{
if (types == null)
- throw new ArgumentNullException ();
+ throw new ArgumentNullException (nameof (types));
}
}
} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInitializerData.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInitializerData.cs
index b2c5647f0..6c448617c 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInitializerData.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptInitializerData.cs
@@ -13,7 +13,7 @@ namespace Mono.Linker.Tests.Cases.Expectations.Assertions
public KeptInitializerData (int occurrenceIndexInBody)
{
if (occurrenceIndexInBody < 0)
- throw new ArgumentException ();
+ throw new ArgumentOutOfRangeException (nameof (occurrenceIndexInBody));
}
}
} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/NoLinkedOutputAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/NoLinkedOutputAttribute.cs
index 0537a62e1..77574cad6 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/NoLinkedOutputAttribute.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/NoLinkedOutputAttribute.cs
@@ -2,6 +2,7 @@
namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
+ [AttributeUsage (AttributeTargets.Class)]
public class NoLinkedOutputAttribute : Attribute
{
public NoLinkedOutputAttribute () { }
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj b/test/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj
index fe28def77..211c1540b 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj
@@ -2,6 +2,7 @@
<PropertyGroup>
<LangVersion>latest</LangVersion>
+ <RunAnalyzers>false</RunAnalyzers>
</PropertyGroup>
<PropertyGroup Condition="'$(MonoBuild)' == ''">
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Support/PlatformAssemblies.cs b/test/Mono.Linker.Tests.Cases.Expectations/Support/PlatformAssemblies.cs
index 11c2f259c..d3c2dfcbd 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Support/PlatformAssemblies.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Support/PlatformAssemblies.cs
@@ -1,8 +1,11 @@
-public static class PlatformAssemblies
+namespace Mono.Linker.Tests.Cases.Expectations.Metadata
{
+ public static class PlatformAssemblies
+ {
#if NETCOREAPP
- public const string CoreLib = "System.Private.CoreLib.dll";
+ public const string CoreLib = "System.Private.CoreLib.dll";
#else
- public const string CoreLib = "mscorlib.dll";
+ public const string CoreLib = "mscorlib.dll";
#endif
-}
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj b/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj
index 645f3523e..6ebfb9890 100644
--- a/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj
+++ b/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj
@@ -6,6 +6,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<LangVersion>Latest</LangVersion>
+ <RunAnalyzers>false</RunAnalyzers>
</PropertyGroup>
<PropertyGroup Condition="'$(MonoBuild)' == ''">
diff --git a/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj b/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj
index ff19e3e6e..56c70481a 100644
--- a/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj
+++ b/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj
@@ -3,6 +3,7 @@
<PropertyGroup>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <RunAnalyzers>false</RunAnalyzers>
</PropertyGroup>
<PropertyGroup Condition="'$(MonoBuild)' == ''">