From 11358ce5c0793bf4a82b59d281bdbcf40d8c7df8 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sun, 30 Jan 2022 19:03:08 -0800 Subject: [PATCH] Avoid target-typed new for release tracking analyzer See https://github.com/dotnet/roslyn-analyzers/issues/5828 --- .../Diagnostics/DiagnosticDescriptors.cs | 96 ++++++++++--------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 00da57ab..49a212a9 100644 --- a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -2,6 +2,8 @@ namespace ComputeSharp.SourceGenerators.Diagnostics; +#pragma warning disable IDE0090 // Use 'new(...)' + /// /// A container for all instances for errors reported by analyzers in this project. /// @@ -29,7 +31,7 @@ internal static class DiagnosticDescriptors /// Format: "The compute shader of type {0} contains a group shared field \"{1}\" of an invalid type {2}". /// /// - public static readonly DiagnosticDescriptor InvalidGroupSharedFieldType = new( + public static readonly DiagnosticDescriptor InvalidGroupSharedFieldType = new DiagnosticDescriptor( id: "CMPS0002", title: "Invalid group shared field type", messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" of an invalid type {2} (it must be an array)", @@ -45,7 +47,7 @@ internal static class DiagnosticDescriptors /// Format: "The compute shader of type {0} contains a group shared field \"{1}\" of an invalid element type {2}". /// /// - public static readonly DiagnosticDescriptor InvalidGroupSharedFieldElementType = new( + public static readonly DiagnosticDescriptor InvalidGroupSharedFieldElementType = new DiagnosticDescriptor( id: "CMPS0003", title: "Invalid group shared field element type", messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" of an invalid type {2} (it must be a primitive or unmanaged type)", @@ -61,7 +63,7 @@ internal static class DiagnosticDescriptors /// Format: "The compute shader of type {0} contains a group shared field \"{1}\" that is not static". /// /// - public static readonly DiagnosticDescriptor InvalidGroupSharedFieldDeclaration = new( + public static readonly DiagnosticDescriptor InvalidGroupSharedFieldDeclaration = new DiagnosticDescriptor( id: "CMPS0004", title: "Invalid group shared field declaration", messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" that is not static", @@ -77,7 +79,7 @@ internal static class DiagnosticDescriptors /// Format: "The compute shader of type {0} contains no resources to work on". /// /// - public static readonly DiagnosticDescriptor MissingShaderResources = new( + public static readonly DiagnosticDescriptor MissingShaderResources = new DiagnosticDescriptor( id: "CMPS0005", title: "Missing shader resources", messageFormat: "The compute shader of type {0} contains no resources to work on", @@ -90,7 +92,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for an invalid usage. /// - public static readonly DiagnosticDescriptor InvalidThreadIdsUsage = new( + public static readonly DiagnosticDescriptor InvalidThreadIdsUsage = new DiagnosticDescriptor( id: "CMPS0006", title: "Invalid ThreadIds usage", messageFormat: "The ThreadIds type can only be used within the main body of a compute shader", @@ -103,7 +105,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for an invalid usage. /// - public static readonly DiagnosticDescriptor InvalidGroupIdsUsage = new( + public static readonly DiagnosticDescriptor InvalidGroupIdsUsage = new DiagnosticDescriptor( id: "CMPS0007", title: "Invalid GroupIds usage", messageFormat: "The GroupIds type can only be used within the main body of a compute shader", @@ -116,7 +118,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for an invalid usage. /// - public static readonly DiagnosticDescriptor InvalidGroupSizeUsage = new( + public static readonly DiagnosticDescriptor InvalidGroupSizeUsage = new DiagnosticDescriptor( id: "CMPS0008", title: "Invalid GroupSize usage", messageFormat: "The GroupSize type can only be used within the main body of a compute shader", @@ -129,7 +131,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for an invalid usage. /// - public static readonly DiagnosticDescriptor InvalidGridIdsUsage = new( + public static readonly DiagnosticDescriptor InvalidGridIdsUsage = new DiagnosticDescriptor( id: "CMPS0009", title: "Invalid GridIds usage", messageFormat: "The GridIds type can only be used within the main body of a compute shader", @@ -145,7 +147,7 @@ internal static class DiagnosticDescriptors /// Format: "The type {0} cannot be created in a compute shader". /// /// - public static readonly DiagnosticDescriptor InvalidObjectCreationExpression = new( + public static readonly DiagnosticDescriptor InvalidObjectCreationExpression = new DiagnosticDescriptor( id: "CMPS0010", title: "Invalid object creation expression", messageFormat: "The type {0} cannot be created in a compute shader (only unmanaged types are supported)", @@ -158,7 +160,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for an anonymous object creation expression. /// - public static readonly DiagnosticDescriptor AnonymousObjectCreationExpression = new( + public static readonly DiagnosticDescriptor AnonymousObjectCreationExpression = new DiagnosticDescriptor( id: "CMPS0011", title: "Anonymous object creation expression", messageFormat: "An anonymous object cannot be created in a compute shader", @@ -171,7 +173,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for an async modifier on a method or function. /// - public static readonly DiagnosticDescriptor AsyncModifierOnMethodOrFunction = new( + public static readonly DiagnosticDescriptor AsyncModifierOnMethodOrFunction = new DiagnosticDescriptor( id: "CMPS0012", title: "Async modifier on method or function", messageFormat: "The async modifier cannot be used in methods or functions used in a compute shader", @@ -184,7 +186,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for an await expression. /// - public static readonly DiagnosticDescriptor AwaitExpression = new( + public static readonly DiagnosticDescriptor AwaitExpression = new DiagnosticDescriptor( id: "CMPS0013", title: "Await expression", messageFormat: "The await expression cannot be used in a compute shader", @@ -197,7 +199,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a checked expression. /// - public static readonly DiagnosticDescriptor CheckedExpression = new( + public static readonly DiagnosticDescriptor CheckedExpression = new DiagnosticDescriptor( id: "CMPS0014", title: "Checked expression", messageFormat: "A checked expression cannot be used in a compute shader", @@ -210,7 +212,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a checked statement. /// - public static readonly DiagnosticDescriptor CheckedStatement = new( + public static readonly DiagnosticDescriptor CheckedStatement = new DiagnosticDescriptor( id: "CMPS0015", title: "Checked statement", messageFormat: "A checked statement cannot be used in a compute shader", @@ -223,7 +225,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a fixed statement. /// - public static readonly DiagnosticDescriptor FixedStatement = new( + public static readonly DiagnosticDescriptor FixedStatement = new DiagnosticDescriptor( id: "CMPS0016", title: "Fixed statement", messageFormat: "A fixed statement cannot be used in a compute shader", @@ -236,7 +238,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a foreach statement. /// - public static readonly DiagnosticDescriptor ForEachStatement = new( + public static readonly DiagnosticDescriptor ForEachStatement = new DiagnosticDescriptor( id: "CMPS0017", title: "Foreach statement", messageFormat: "A foreach statement cannot be used in a compute shader", @@ -249,7 +251,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a lock statement. /// - public static readonly DiagnosticDescriptor LockStatement = new( + public static readonly DiagnosticDescriptor LockStatement = new DiagnosticDescriptor( id: "CMPS0018", title: "Foreach statement", messageFormat: "A lock statement cannot be used in a compute shader", @@ -262,7 +264,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a query statement. /// - public static readonly DiagnosticDescriptor QueryExpression = new( + public static readonly DiagnosticDescriptor QueryExpression = new DiagnosticDescriptor( id: "CMPS0019", title: "Foreach statement", messageFormat: "A LINQ query expression cannot be used in a compute shader", @@ -275,7 +277,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a range expression. /// - public static readonly DiagnosticDescriptor RangeExpression = new( + public static readonly DiagnosticDescriptor RangeExpression = new DiagnosticDescriptor( id: "CMPS0020", title: "Range expression", messageFormat: "A range expression cannot be used in a compute shader", @@ -288,7 +290,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a recursive pattern. /// - public static readonly DiagnosticDescriptor RecursivePattern = new( + public static readonly DiagnosticDescriptor RecursivePattern = new DiagnosticDescriptor( id: "CMPS0021", title: "Recursive pattern", messageFormat: "A recursive pattern cannot be used in a compute shader", @@ -301,7 +303,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a ref type. /// - public static readonly DiagnosticDescriptor RefType = new( + public static readonly DiagnosticDescriptor RefType = new DiagnosticDescriptor( id: "CMPS0022", title: "Ref type", messageFormat: "A compute shader cannot have a ref type declaration", @@ -314,7 +316,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a relational pattern. /// - public static readonly DiagnosticDescriptor RelationalPattern = new( + public static readonly DiagnosticDescriptor RelationalPattern = new DiagnosticDescriptor( id: "CMPS0023", title: "Relational pattern", messageFormat: "A relational pattern cannot be used in a compute shader", @@ -327,7 +329,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a sizeof expression. /// - public static readonly DiagnosticDescriptor SizeOfExpression = new( + public static readonly DiagnosticDescriptor SizeOfExpression = new DiagnosticDescriptor( id: "CMPS0024", title: "Sizeof expression", messageFormat: "A sizeof expression cannot be used in a compute shader", @@ -340,7 +342,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a stackalloc expression. /// - public static readonly DiagnosticDescriptor StackAllocArrayCreationExpression = new( + public static readonly DiagnosticDescriptor StackAllocArrayCreationExpression = new DiagnosticDescriptor( id: "CMPS0025", title: "Stackalloc expression", messageFormat: "A stackalloc expression cannot be used in a compute shader", @@ -353,7 +355,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a throw expression or statement. /// - public static readonly DiagnosticDescriptor ThrowExpressionOrStatement = new( + public static readonly DiagnosticDescriptor ThrowExpressionOrStatement = new DiagnosticDescriptor( id: "CMPS0026", title: "Throw expression or statement", messageFormat: "Throw expressions and statements cannot be used in a compute shader", @@ -366,7 +368,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a try statement. /// - public static readonly DiagnosticDescriptor TryStatement = new( + public static readonly DiagnosticDescriptor TryStatement = new DiagnosticDescriptor( id: "CMPS0027", title: "Try statement", messageFormat: "A try statement cannot be used in a compute shader", @@ -379,7 +381,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a tuple type. /// - public static readonly DiagnosticDescriptor TupleType = new( + public static readonly DiagnosticDescriptor TupleType = new DiagnosticDescriptor( id: "CMPS0028", title: "Tuple type", messageFormat: "A compute shader cannot have a tuple type declaration", @@ -392,7 +394,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a using statement or declaration. /// - public static readonly DiagnosticDescriptor UsingStatementOrDeclaration = new( + public static readonly DiagnosticDescriptor UsingStatementOrDeclaration = new DiagnosticDescriptor( id: "CMPS0029", title: "Using statement or declaration", messageFormat: "Using statements and declarations cannot be used in a compute shader", @@ -405,7 +407,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a yield statement. /// - public static readonly DiagnosticDescriptor YieldStatement = new( + public static readonly DiagnosticDescriptor YieldStatement = new DiagnosticDescriptor( id: "CMPS0030", title: "Yield statement", messageFormat: "A yield statement cannot be used in a compute shader", @@ -421,7 +423,7 @@ internal static class DiagnosticDescriptors /// Format: "A variable of type {0} cannot be declared in a compute shader". /// /// - public static readonly DiagnosticDescriptor InvalidObjectDeclaration = new( + public static readonly DiagnosticDescriptor InvalidObjectDeclaration = new DiagnosticDescriptor( id: "CMPS0031", title: "Invalid object declaration", messageFormat: "A variable of type {0} cannot be declared in a compute shader (only unmanaged types are supported)", @@ -434,7 +436,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a pointer type. /// - public static readonly DiagnosticDescriptor PointerType = new( + public static readonly DiagnosticDescriptor PointerType = new DiagnosticDescriptor( id: "CMPS0032", title: "Pointer type", messageFormat: "A compute shader cannot have a pointer type declaration", @@ -447,7 +449,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a function pointer type. /// - public static readonly DiagnosticDescriptor FunctionPointer = new( + public static readonly DiagnosticDescriptor FunctionPointer = new DiagnosticDescriptor( id: "CMPS0033", title: "Function pointer type", messageFormat: "A compute shader cannot have a function pointer type declaration", @@ -460,7 +462,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for an unsafe statement. /// - public static readonly DiagnosticDescriptor UnsafeStatement = new( + public static readonly DiagnosticDescriptor UnsafeStatement = new DiagnosticDescriptor( id: "CMPS0034", title: "Unsafe statement", messageFormat: "A compute shader cannot have an unsafe statement", @@ -473,7 +475,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for an unsafe modifier on a method or function. /// - public static readonly DiagnosticDescriptor UnsafeModifierOnMethodOrFunction = new( + public static readonly DiagnosticDescriptor UnsafeModifierOnMethodOrFunction = new DiagnosticDescriptor( id: "CMPS0035", title: "Unsafe modifier on method or function", messageFormat: "The unsafe modifier cannot be used in methods or functions used in a compute shader", @@ -486,7 +488,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a string literal. /// - public static readonly DiagnosticDescriptor StringLiteralExpression = new( + public static readonly DiagnosticDescriptor StringLiteralExpression = new DiagnosticDescriptor( id: "CMPS0036", title: "String literal expression", messageFormat: "String literal expressions cannot be used in a compute shader", @@ -499,7 +501,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for an incorrect matrix swizzling property argument. /// - public static readonly DiagnosticDescriptor NonConstantMatrixSwizzledIndex = new( + public static readonly DiagnosticDescriptor NonConstantMatrixSwizzledIndex = new DiagnosticDescriptor( id: "CMPS0037", title: "Non constant matrix swizzled property argument", messageFormat: "The arguments in a swizzled indexer for a matrix type must be compile-time constants", @@ -515,7 +517,7 @@ internal static class DiagnosticDescriptors /// Format: "The compute shader of type {0} contains a static field \"{1}\" of an invalid type {2} (only primitive, vector and matrix types are supported)". /// /// - public static readonly DiagnosticDescriptor InvalidShaderStaticFieldType = new( + public static readonly DiagnosticDescriptor InvalidShaderStaticFieldType = new DiagnosticDescriptor( id: "CMPS0038", title: "Invalid shader static field type", messageFormat: "The compute shader of type {0} contains a static field \"{1}\" of an invalid type {2} (only primitive, vector and matrix types are supported)", @@ -528,7 +530,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for an invalid usage. /// - public static readonly DiagnosticDescriptor InvalidDispatchSizeUsage = new( + public static readonly DiagnosticDescriptor InvalidDispatchSizeUsage = new DiagnosticDescriptor( id: "CMPS0039", title: "Invalid DispatchSize usage", messageFormat: "The DispatchSize type can only be used within the main body of a compute shader", @@ -541,7 +543,7 @@ internal static class DiagnosticDescriptors /// /// Gets a for a property declaration. /// - public static readonly DiagnosticDescriptor PropertyDeclaration = new( + public static readonly DiagnosticDescriptor PropertyDeclaration = new DiagnosticDescriptor( id: "CMPS0040", title: "Property declaration", messageFormat: "Property declarations cannot be used in a compute shader", @@ -557,7 +559,7 @@ internal static class DiagnosticDescriptors /// Format: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources". /// /// - public static readonly DiagnosticDescriptor ShaderDispatchDataSizeExceeded = new( + public static readonly DiagnosticDescriptor ShaderDispatchDataSizeExceeded = new DiagnosticDescriptor( id: "CMPS0041", title: "Shader dispatch data size exceeded", messageFormat: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources", @@ -573,7 +575,7 @@ internal static class DiagnosticDescriptors /// Format: "The shader of type {0} cannot implement more than one shader interface". /// /// - public static readonly DiagnosticDescriptor MultipleShaderTypesImplemented = new( + public static readonly DiagnosticDescriptor MultipleShaderTypesImplemented = new DiagnosticDescriptor( id: "CMPS0042", title: "Multiple shader implementations for type declaration", messageFormat: "The shader of type {0} cannot implement more than one shader interface", @@ -589,7 +591,7 @@ internal static class DiagnosticDescriptors /// Format: "The shader of type {0} cannot be precompiled, as it is dynamic (it captures delegate fields)". /// /// - public static readonly DiagnosticDescriptor EmbeddedBytecodeWithDynamicShader = new( + public static readonly DiagnosticDescriptor EmbeddedBytecodeWithDynamicShader = new DiagnosticDescriptor( id: "CMPS0043", title: "Embedded bytecode for dynamic shader", messageFormat: "The shader of type {0} cannot be precompiled, as it is dynamic (it captures delegate fields)", @@ -605,7 +607,7 @@ internal static class DiagnosticDescriptors /// Format: "The shader of type {0} is annotated with invalid thread ids values ({1}, {2}, {3})". /// /// - public static readonly DiagnosticDescriptor InvalidEmbeddedBytecodeThreadIds = new( + public static readonly DiagnosticDescriptor InvalidEmbeddedBytecodeThreadIds = new DiagnosticDescriptor( id: "CMPS0044", title: "Invalid thread ids for shader with embedded bytecode", messageFormat: "The shader of type {0} is annotated with invalid thread ids values ({1}, {2}, {3})", @@ -621,7 +623,7 @@ internal static class DiagnosticDescriptors /// Format: "The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: "{2}")". /// /// - public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithWin32Exception = new( + public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithWin32Exception = new DiagnosticDescriptor( id: "CMPS0045", title: "Embedded bytecode compilation failed due to Win32 exception", messageFormat: "The shader of type {0} failed to compile due to a Win32 exception (HRESULT: {1:X8}, Message: \"{2}\")", @@ -637,7 +639,7 @@ internal static class DiagnosticDescriptors /// Format: "The shader of type {{0}} failed to compile due to an HLSL compiler error (Message: "{1}")". /// /// - public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithHlslCompilationException = new( + public static readonly DiagnosticDescriptor EmbeddedBytecodeFailedWithHlslCompilationException = new DiagnosticDescriptor( id: "CMPS0046", title: "Embedded bytecode compilation failed due to an HLSL compiler error", messageFormat: "The shader of type {0} failed to compile due to an HLSL compiler error (Message: \"{1}\")", @@ -653,7 +655,7 @@ internal static class DiagnosticDescriptors /// Format: "The shader of type {0} needs to be annotated as having embedded bytecode (using the [EmbeddedBytecode] attribute), as dynamic shader compilation is not supported". /// /// - public static readonly DiagnosticDescriptor MissingEmbeddedBytecodeAttributeWhenDynamicShaderCompilationIsNotSupported = new( + public static readonly DiagnosticDescriptor MissingEmbeddedBytecodeAttributeWhenDynamicShaderCompilationIsNotSupported = new DiagnosticDescriptor( id: "CMPS0047", title: "Embedded bytecode compilation failed due to an HLSL compiler error", messageFormat: "The shader of type {0} needs to be annotated as having embedded bytecode (using the [EmbeddedBytecode] attribute), as dynamic shader compilation is not supported", @@ -669,7 +671,7 @@ internal static class DiagnosticDescriptors /// Format: "The shader of type {0} is annotated with an invalid dispatch axis value". /// /// - public static readonly DiagnosticDescriptor InvalidEmbeddedBytecodeDispatchAxis = new( + public static readonly DiagnosticDescriptor InvalidEmbeddedBytecodeDispatchAxis = new DiagnosticDescriptor( id: "CMPS0048", title: "Invalid dispatch axis for shader with embedded bytecode", messageFormat: "The shader of type {0} is annotated with with an invalid dispatch axis value",