From 86bc68e4dddf0441a8968f6534599dceb4cb950e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 29 Nov 2023 22:58:22 +0100 Subject: [PATCH] Move MultipleShaderTypesImplemented to analyzer --- ...uteShaderDescriptorGenerator.HlslSource.cs | 6 ----- .../DiagnosticsTests.cs | 20 ---------------- .../Test_Analyzers.cs | 23 +++++++++++++++++++ .../Test_D2DPixelShaderSourceGenerator.cs | 1 + 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs index c9a1fc0b..25ee4f1c 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs @@ -58,12 +58,6 @@ partial class ComputeShaderDescriptorGenerator Dictionary instanceMethods = new(SymbolEqualityComparer.Default); Dictionary constantDefinitions = new(SymbolEqualityComparer.Default); - // A given type can only represent a single shader type - if (structDeclarationSymbol.AllInterfaces.Count(static interfaceSymbol => interfaceSymbol is { Name: nameof(IComputeShader) } or { IsGenericType: true, Name: nameof(IComputeShader) }) > 1) - { - diagnostics.Add(MultipleShaderTypesImplemented, structDeclarationSymbol, structDeclarationSymbol); - } - // Explore the syntax tree and extract the processed info SemanticModelProvider semanticModelProvider = new(compilation); INamedTypeSymbol? pixelShaderSymbol = structDeclarationSymbol.AllInterfaces.FirstOrDefault(static interfaceSymbol => interfaceSymbol is { IsGenericType: true, Name: nameof(IComputeShader) }); diff --git a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs index b4d99408..e42ca2c2 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/DiagnosticsTests.cs @@ -1116,26 +1116,6 @@ public class DiagnosticsTests VerifyGeneratedDiagnostics(source, "CMPS0041", "CMPS0047"); } - [TestMethod] - public void MultipleShaderTypes() - { - const string source = """ - using ComputeSharp; - - namespace MyFancyApp.Sample; - - [GeneratedComputeShaderDescriptor] - public partial struct MyShader : IComputeShader, IComputeShader - { - public void Execute() - { - } - } - """; - - VerifyGeneratedDiagnostics(source, "CMPS0042", "CMPS0047"); - } - [TestMethod] [DataRow(-1, 1, 1)] [DataRow(1, -1, 1)] diff --git a/tests/ComputeSharp.Tests.SourceGenerators/Test_Analyzers.cs b/tests/ComputeSharp.Tests.SourceGenerators/Test_Analyzers.cs index 343c521b..a26475ab 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/Test_Analyzers.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/Test_Analyzers.cs @@ -391,4 +391,27 @@ public class Test_Analyzers await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); } + + [TestMethod] + public async Task MultipleComputeShaderInterfacesOnShader_TwoInterfaces() + { + const string source = """ + using ComputeSharp; + + [GeneratedComputeShaderDescriptor] + internal partial struct {|CMPS0042:MyType|} : IComputeShader, IComputeShader + { + public void Execute() + { + } + + Float4 IComputeShader.Execute() + { + return 0; + } + } + """; + + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + } } \ No newline at end of file diff --git a/tests/ComputeSharp.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs b/tests/ComputeSharp.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs index 5e4d6743..5446cee7 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/Test_D2DPixelShaderSourceGenerator.cs @@ -899,6 +899,7 @@ public class Test_D2DPixelShaderSourceGenerator await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); + await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source); await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);