Skip warnings for shader types with no fields
このコミットが含まれているのは:
1 親
709197ee43
コミット
43b79bdf4b
9ファイル変更
+46
-16
検索条件に一致するファイルはありません
+3
-3
@@ -8,12 +8,12 @@ namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class NotReadonlyPixelShaderTypeAnalyzer : NotReadonlyShaderTypeAnalyzerBase
|
||||
public sealed class NotReadOnlyPixelShaderTypeWithFieldsAnalyzer : NotReadOnlyShaderTypeWithFieldsAnalyzerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="NotReadonlyPixelShaderTypeAnalyzer"/> instance.
|
||||
/// Creates a new <see cref="NotReadOnlyPixelShaderTypeWithFieldsAnalyzer"/> instance.
|
||||
/// </summary>
|
||||
public NotReadonlyPixelShaderTypeAnalyzer()
|
||||
public NotReadOnlyPixelShaderTypeWithFieldsAnalyzer()
|
||||
: base(NotReadOnlyShaderType, ImmutableArray.Create("ComputeSharp.D2D1.ID2D1PixelShader"))
|
||||
{
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Analyzers\NotAccessibleFieldTypeInGeneratedShaderDescriptorAttributeTargetAnalyzerBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Analyzers\NotReadonlyShaderTypeAnalyzerBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Analyzers\NotReadOnlyShaderTypeWithFieldsAnalyzerBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Analyzers\NotAccessibleGeneratedShaderDescriptorAttributeTargetAnalyzerBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Analyzers\MissingAllowUnsafeBlocksCompilationOptionAnalyzerBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\DiagnosticDescriptors.cs" />
|
||||
|
||||
+8
-1
@@ -11,7 +11,7 @@ namespace ComputeSharp.SourceGeneration.Diagnostics;
|
||||
/// </summary>
|
||||
/// <param name="diagnosticDescriptor">The <see cref="DiagnosticDescriptor"/> instance to use.</param>
|
||||
/// <param name="shaderInterfaceTypeFullyQualifiedMetadataNames">The fully qualified metadata names of all candidate shader interface types.</param>
|
||||
public abstract class NotReadonlyShaderTypeAnalyzerBase(
|
||||
public abstract class NotReadOnlyShaderTypeWithFieldsAnalyzerBase(
|
||||
DiagnosticDescriptor diagnosticDescriptor,
|
||||
ImmutableArray<string> shaderInterfaceTypeFullyQualifiedMetadataNames) : DiagnosticAnalyzer
|
||||
{
|
||||
@@ -40,6 +40,13 @@ public abstract class NotReadonlyShaderTypeAnalyzerBase(
|
||||
return;
|
||||
}
|
||||
|
||||
// In order to trigger the analyzer, we must have at least one field.
|
||||
// If not (eg. shaders that just return a constant color), no need.
|
||||
if (!typeSymbol.GetMembers().Any(static m => m is IFieldSymbol { IsStatic: false, IsConst: false, IsFixedSizeBuffer: false }))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Emit a diagnostic if the type is a shader type
|
||||
if (IsShaderType(typeSymbol, typeSymbols))
|
||||
{
|
||||
+4
-4
@@ -8,13 +8,13 @@ namespace ComputeSharp.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class NotReadonlyComputeShaderTypeAnalyzer : NotReadonlyShaderTypeAnalyzerBase
|
||||
public sealed class NotReadOnlyComputeShaderTypeWithFieldsAnalyzer : NotReadOnlyShaderTypeWithFieldsAnalyzerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="NotReadonlyComputeShaderTypeAnalyzer"/> instance.
|
||||
/// Creates a new <see cref="NotReadOnlyComputeShaderTypeWithFieldsAnalyzer"/> instance.
|
||||
/// </summary>
|
||||
public NotReadonlyComputeShaderTypeAnalyzer()
|
||||
: base(NotReadonlyShaderType, ImmutableArray.Create("ComputeSharp.IComputeShader", "ComputeSharp.IComputeShader`1"))
|
||||
public NotReadOnlyComputeShaderTypeWithFieldsAnalyzer()
|
||||
: base(NotReadOnlyShaderType, ImmutableArray.Create("ComputeSharp.IComputeShader", "ComputeSharp.IComputeShader`1"))
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -805,7 +805,7 @@ partial class DiagnosticDescriptors
|
||||
/// Format: <c>"The shader of type {0} is not readonly (shaders cannot mutate their instance state while running, so shader types not being readonly makes them error prone)"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor NotReadonlyShaderType = new(
|
||||
public static readonly DiagnosticDescriptor NotReadOnlyShaderType = new(
|
||||
id: "CMPS0057",
|
||||
title: "Not readonly shader type (using IComputeShader or IComputeShader<T>)",
|
||||
messageFormat: "The shader of type {0} is not readonly (shaders cannot mutate their instance state while running, so shader types not being readonly makes them error prone)",
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace ComputeSharp.D2D1.Tests.SourceGenerators;
|
||||
public class Test_Analyzers
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task NotReadonlyShaderType()
|
||||
public async Task NotReadOnlyShaderType_WithFields_Warns()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
@@ -18,6 +18,29 @@ public class Test_Analyzers
|
||||
namespace MyFancyApp.Sample;
|
||||
|
||||
internal partial struct {|CMPSD2D0070:MyShader|} : ID2D1PixelShader
|
||||
{
|
||||
public float number;
|
||||
|
||||
public Float4 Execute()
|
||||
{
|
||||
return this.number;
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotReadOnlyPixelShaderTypeWithFieldsAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task NotReadOnlyShaderType_WithNoFields_DoesNotWarn()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
using ComputeSharp.D2D1;
|
||||
|
||||
namespace MyFancyApp.Sample;
|
||||
|
||||
internal partial struct MyShader : ID2D1PixelShader
|
||||
{
|
||||
public Float4 Execute()
|
||||
{
|
||||
@@ -26,6 +49,6 @@ public class Test_Analyzers
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotReadonlyPixelShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotReadOnlyPixelShaderTypeWithFieldsAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
}
|
||||
@@ -1812,7 +1812,7 @@ public class Test_D2DPixelShaderSourceGenerator
|
||||
await CSharpAnalyzerWithLanguageVersionTest<MissingPixelShaderDescriptorOnPixelShaderAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotAccessibleD2DGeneratedPixelShaderDescriptorAttributeTargetAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotAccessibleFieldTypeInD2DGeneratedShaderDescriptorAttributeTargetAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotReadonlyPixelShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotReadOnlyPixelShaderTypeWithFieldsAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
|
||||
// Get all assembly references for the .NET TFM and ComputeSharp
|
||||
IEnumerable<MetadataReference> metadataReferences =
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Test_Analyzers
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task NotReadonlyShaderType()
|
||||
public async Task NotReadOnlyShaderType()
|
||||
{
|
||||
const string source = """
|
||||
using ComputeSharp;
|
||||
@@ -83,6 +83,6 @@ public class Test_Analyzers
|
||||
}
|
||||
""";
|
||||
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotReadonlyComputeShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotReadOnlyComputeShaderTypeWithFieldsAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
}
|
||||
}
|
||||
@@ -899,7 +899,7 @@ public class Test_D2DPixelShaderSourceGenerator
|
||||
await CSharpAnalyzerWithLanguageVersionTest<MissingComputeShaderDescriptorOnComputeShaderAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotAccessibleFieldTypeInGeneratedShaderDescriptorAttributeTargetAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotAccessibleGeneratedComputeShaderDescriptorAttributeTargetAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotReadonlyComputeShaderTypeAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
await CSharpAnalyzerWithLanguageVersionTest<NotReadOnlyComputeShaderTypeWithFieldsAnalyzer>.VerifyAnalyzerAsync(source);
|
||||
|
||||
// Get all assembly references for the .NET TFM and ComputeSharp
|
||||
IEnumerable<MetadataReference> metadataReferences =
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする