Refactor diagnostic models to be properly equatable

このコミットが含まれているのは:
Sergio Pedri committed 2022-09-17 17:58:44 +02:00
1 親 bdaf402a4c
コミット 9eac3c779d
26ファイル変更
+247 -134

検索条件に一致するファイルはありません

+15 -14
ファイルの表示
@@ -6,6 +6,7 @@ using System.Text;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Mappings;
using ComputeSharp.SourceGeneration.Models;
using ComputeSharp.SourceGeneration.SyntaxRewriters;
using ComputeSharp.SourceGenerators.Models;
using ComputeSharp.SourceGenerators.SyntaxRewriters;
@@ -39,9 +40,9 @@ partial class IShaderGenerator
Compilation compilation,
StructDeclarationSyntax structDeclaration,
INamedTypeSymbol structDeclarationSymbol,
out ImmutableArray<Diagnostic> diagnostics)
out ImmutableArray<DiagnosticInfo> diagnostics)
{
ImmutableArray<Diagnostic>.Builder builder = ImmutableArray.CreateBuilder<Diagnostic>();
ImmutableArray<DiagnosticInfo>.Builder builder = ImmutableArray.CreateBuilder<DiagnosticInfo>();
// Detect invalid properties
DetectAndReportInvalidPropertyDeclarations(builder, structDeclarationSymbol);
@@ -94,7 +95,7 @@ partial class IShaderGenerator
/// <summary>
/// Gets a sequence of captured fields and their mapped names.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
/// <param name="types">The collection of currently discovered types.</param>
/// <param name="isComputeShader">Indicates whether or not <paramref name="structDeclarationSymbol"/> represents a compute shader.</param>
@@ -103,7 +104,7 @@ partial class IShaderGenerator
ImmutableArray<(string MetadataName, string Name, string HlslType)>,
ImmutableArray<(string Name, string HlslType)>)
GetInstanceFields(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
ICollection<INamedTypeSymbol> types,
bool isComputeShader)
@@ -186,7 +187,7 @@ partial class IShaderGenerator
/// <summary>
/// Gets a sequence of shader static fields and their mapped names.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the type to process.</param>
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> instance for the current type.</param>
/// <param name="structDeclarationSymbol">The type symbol for the shader type.</param>
@@ -194,7 +195,7 @@ partial class IShaderGenerator
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
/// <returns>A sequence of static constant fields in <paramref name="structDeclarationSymbol"/>.</returns>
private static ImmutableArray<(string Name, string TypeDeclaration, string? Assignment)> GetStaticFields(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
SemanticModelProvider semanticModel,
StructDeclarationSyntax structDeclaration,
INamedTypeSymbol structDeclarationSymbol,
@@ -256,12 +257,12 @@ partial class IShaderGenerator
/// <summary>
/// Gets a sequence of captured members and their mapped names.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
/// <param name="types">The collection of currently discovered types.</param>
/// <returns>A sequence of captured members in <paramref name="structDeclarationSymbol"/>.</returns>
private static ImmutableArray<(string Name, string Type, int? Count)> GetSharedBuffers(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
ICollection<INamedTypeSymbol> types)
{
@@ -312,7 +313,7 @@ partial class IShaderGenerator
/// <summary>
/// Gets a sequence of processed methods declared within a given type.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The type symbol for the shader type.</param>
/// <param name="structDeclaration">The <see cref="StructDeclarationSyntax"/> instance for the current type.</param>
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the type to process.</param>
@@ -322,7 +323,7 @@ partial class IShaderGenerator
/// <param name="isComputeShader">Indicates whether or not <paramref name="structDeclarationSymbol"/> represents a compute shader.</param>
/// <returns>A sequence of processed methods in <paramref name="structDeclaration"/>, and the entry point.</returns>
private static (string EntryPoint, ImmutableArray<(string Signature, string Definition)> Methods, bool IsSamplerUser) GetProcessedMethods(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
StructDeclarationSyntax structDeclaration,
INamedTypeSymbol structDeclarationSymbol,
SemanticModelProvider semanticModel,
@@ -441,10 +442,10 @@ partial class IShaderGenerator
/// </summary>
/// <param name="types">The sequence of discovered custom types.</param>
/// <param name="sourceSymbol">The symbol for the current object being processed.</param>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <returns>A sequence of custom type definitions to add to the shader source.</returns>
internal static ImmutableArray<(string Name, string Definition)> GetDeclaredTypes(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
ISymbol sourceSymbol,
IEnumerable<INamedTypeSymbol> types)
{
@@ -503,9 +504,9 @@ partial class IShaderGenerator
/// <summary>
/// Finds and reports all invalid declared properties in a shader.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
private static void DetectAndReportInvalidPropertyDeclarations(ImmutableArray<Diagnostic>.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol)
private static void DetectAndReportInvalidPropertyDeclarations(ImmutableArray<DiagnosticInfo>.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol)
{
foreach (var memberSymbol in structDeclarationSymbol.GetMembers())
{
+5 -5
ファイルの表示
@@ -42,9 +42,9 @@ partial class IShaderGenerator
INamedTypeSymbol structDeclarationSymbol,
bool isDynamicShader,
bool supportsDynamicShaders,
out ImmutableArray<Diagnostic> diagnostics)
out ImmutableArray<DiagnosticInfo> diagnostics)
{
ImmutableArray<Diagnostic>.Builder builder = ImmutableArray.CreateBuilder<Diagnostic>();
ImmutableArray<DiagnosticInfo>.Builder builder = ImmutableArray.CreateBuilder<DiagnosticInfo>();
AttributeData? attribute = structDeclarationSymbol
.GetAttributes()
@@ -149,7 +149,7 @@ partial class IShaderGenerator
ThreadIdsInfo threadIds,
string hlslSource,
CancellationToken token,
out DiagnosticInfo? diagnostic)
out DeferredDiagnosticInfo? diagnostic)
{
ImmutableArray<byte> bytecode = ImmutableArray<byte>.Empty;
@@ -189,11 +189,11 @@ partial class IShaderGenerator
}
catch (Win32Exception e)
{
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithWin32Exception, e.HResult, FixupExceptionMessage(e.Message));
diagnostic = DeferredDiagnosticInfo.Create(EmbeddedBytecodeFailedWithWin32Exception, e.HResult, FixupExceptionMessage(e.Message));
}
catch (DxcCompilationException e)
{
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithDxcCompilationException, FixupExceptionMessage(e.Message));
diagnostic = DeferredDiagnosticInfo.Create(EmbeddedBytecodeFailedWithDxcCompilationException, FixupExceptionMessage(e.Message));
}
End:
+3 -2
ファイルの表示
@@ -6,6 +6,7 @@ using System.Runtime.CompilerServices;
using ComputeSharp.Core.Helpers;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Mappings;
using ComputeSharp.SourceGeneration.Models;
using ComputeSharp.SourceGenerators.Models;
using Microsoft.CodeAnalysis;
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
@@ -34,7 +35,7 @@ partial class IShaderGenerator
Type shaderInterfaceType,
out int resourceCount,
out int root32BitConstantCount,
out ImmutableArray<Diagnostic> diagnostics)
out ImmutableArray<DiagnosticInfo> diagnostics)
{
// Helper method that uses boxes instead of ref-s (illegal in enumerators)
static IEnumerable<FieldInfo> GetCapturedFieldInfos(
@@ -87,7 +88,7 @@ partial class IShaderGenerator
}
}
ImmutableArray<Diagnostic>.Builder builder = ImmutableArray.CreateBuilder<Diagnostic>();
ImmutableArray<DiagnosticInfo>.Builder builder = ImmutableArray.CreateBuilder<DiagnosticInfo>();
// Setup the resource and byte offsets for tracking. Pixel shaders have only two
// implicitly captured int values, as they're always dispatched over a 2D texture.
+8 -11
ファイルの表示
@@ -88,7 +88,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
item.Left.Left.Type,
out int resourceCount,
out int root32BitConstantCount,
out ImmutableArray<Diagnostic> dispatchDataDiagnostics);
out ImmutableArray<DiagnosticInfo> dispatchDataDiagnostics);
token.ThrowIfCancellationRequested();
@@ -106,7 +106,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
item.Right,
item.Left.Left.Syntax,
item.Left.Left.Symbol,
out ImmutableArray<Diagnostic> hlslSourceDiagnostics);
out ImmutableArray<DiagnosticInfo> hlslSourceDiagnostics);
token.ThrowIfCancellationRequested();
@@ -115,7 +115,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
item.Left.Left.Symbol,
!hlslSourceInfo.Delegates.IsEmpty,
item.Left.Right,
out ImmutableArray<Diagnostic> threadIdsDiagnostics);
out ImmutableArray<DiagnosticInfo> threadIdsDiagnostics);
token.ThrowIfCancellationRequested();
@@ -206,11 +206,11 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
.Select(static (item, token) => (item.Dispatch.Hierarchy, BuildHlslSource.GetNonDynamicHlslSource(item.Hlsl), item.ThreadIds));
// Compile the requested shader bytecodes
IncrementalValuesProvider<(HierarchyInfo Hierarchy, EmbeddedBytecodeInfo BytecodeInfo, DiagnosticInfo? Diagnostic)> embeddedBytecodeWithErrors =
IncrementalValuesProvider<(HierarchyInfo Hierarchy, EmbeddedBytecodeInfo BytecodeInfo, DeferredDiagnosticInfo? Diagnostic)> embeddedBytecodeWithErrors =
shaderBytecodeInfo
.Select(static (item, token) =>
{
ImmutableArray<byte> bytecode = LoadBytecode.GetBytecode(item.ThreadIds, item.Hlsl, token, out DiagnosticInfo? diagnostic);
ImmutableArray<byte> bytecode = LoadBytecode.GetBytecode(item.ThreadIds, item.Hlsl, token, out DeferredDiagnosticInfo? diagnostic);
token.ThrowIfCancellationRequested();
@@ -224,7 +224,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
});
// Gather the diagnostics
IncrementalValuesProvider<Diagnostic> embeddedBytecodeDiagnostics =
IncrementalValuesProvider<DiagnosticInfo> embeddedBytecodeDiagnostics =
embeddedBytecodeWithErrors
.Select(static (item, token) => (item.Hierarchy.FullyQualifiedMetadataName, item.Diagnostic))
.Where(static item => item.Diagnostic is not null)
@@ -232,11 +232,8 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
.Select(static (item, token) =>
{
INamedTypeSymbol typeSymbol = item.Right.GetTypeByMetadataName(item.Left.FullyQualifiedMetadataName)!;
return Diagnostic.Create(
item.Left.Diagnostic!.Descriptor,
typeSymbol.Locations.FirstOrDefault(),
new object[] { typeSymbol }.Concat(item.Left.Diagnostic.Args).ToArray());
return DiagnosticInfo.Create(item.Left.Diagnostic!.Descriptor, typeSymbol, new object[] { typeSymbol }.Concat(item.Left.Diagnostic.Arguments).ToArray());
});
// Output the diagnostics
+5 -5
ファイルの表示
@@ -46,7 +46,7 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
item.Right,
item.Left.Syntax,
item.Left.Symbol,
out ImmutableArray<Diagnostic> diagnostics);
out ImmutableArray<DiagnosticInfo> diagnostics);
return new Result<HlslMethodSourceInfo>(sourceInfo, diagnostics);
});
@@ -85,9 +85,9 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
Compilation compilation,
CSharpSyntaxNode methodDeclaration,
IMethodSymbol methodSymbol,
out ImmutableArray<Diagnostic> diagnostics)
out ImmutableArray<DiagnosticInfo> diagnostics)
{
ImmutableArray<Diagnostic>.Builder builder = ImmutableArray.CreateBuilder<Diagnostic>();
ImmutableArray<DiagnosticInfo>.Builder builder = ImmutableArray.CreateBuilder<DiagnosticInfo>();
// We need to sets to track all discovered custom types and static methods
HashSet<INamedTypeSymbol> discoveredTypes = new(SymbolEqualityComparer.Default);
@@ -112,14 +112,14 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
/// <summary>
/// Gets a sequence of processed methods from a target method declaration.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
/// <param name="methodDeclaration">The <see cref="MethodDeclarationSyntax"/> or <see cref="LocalFunctionStatementSyntax"/> instance for the current method.</param>
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the method to process.</param>
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
/// <returns>A sequence of processed methods in <paramref name="methodDeclaration"/> (main method and all captured methods).</returns>
private static (string TargetMethod, ImmutableArray<(string Signature, string Definition)> DependentMethods) GetProcessedMethods(
ImmutableArray<Diagnostic>.Builder diagnostics,
ImmutableArray<DiagnosticInfo>.Builder diagnostics,
CSharpSyntaxNode methodDeclaration,
SemanticModelProvider semanticModel,
ICollection<INamedTypeSymbol> discoveredTypes,