From 15da94aba3d097aaafcbc1a9a524ed301fd6983e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 10 Oct 2023 23:03:48 +0200 Subject: [PATCH] Use string literal in global using directives generator --- .../ComputeSharp.Core.SourceGenerators.csproj | 49 -------- .../GlobalUsingDirectives.cs | 97 -------------- .../GlobalUsingDirectivesGenerator.cs | 119 ++++++++++++++++-- .../Helpers/DynamicCache{TKey,TValue}.cs | 2 +- 4 files changed, 107 insertions(+), 160 deletions(-) delete mode 100644 src/ComputeSharp.Core.SourceGenerators/EmbeddedResources/GlobalUsingDirectives.cs diff --git a/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj b/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj index cb00dfe3..6f9be687 100644 --- a/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj +++ b/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj @@ -1,7 +1,6 @@ netstandard2.0 - $(NoWarn);CS1591;CS0649;CS1574 @@ -15,48 +14,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -68,12 +25,6 @@ - - - - - - diff --git a/src/ComputeSharp.Core.SourceGenerators/EmbeddedResources/GlobalUsingDirectives.cs b/src/ComputeSharp.Core.SourceGenerators/EmbeddedResources/GlobalUsingDirectives.cs deleted file mode 100644 index 979d3122..00000000 --- a/src/ComputeSharp.Core.SourceGenerators/EmbeddedResources/GlobalUsingDirectives.cs +++ /dev/null @@ -1,97 +0,0 @@ -// -#pragma warning disable -global using bool2 = global::ComputeSharp.Bool2; -global using bool3 = global::ComputeSharp.Bool3; -global using bool4 = global::ComputeSharp.Bool4; -global using bool1x1 = global::ComputeSharp.Bool1x1; -global using bool1x2 = global::ComputeSharp.Bool1x2; -global using bool1x3 = global::ComputeSharp.Bool1x3; -global using bool1x4 = global::ComputeSharp.Bool1x4; -global using bool2x1 = global::ComputeSharp.Bool2x1; -global using bool2x2 = global::ComputeSharp.Bool2x2; -global using bool2x3 = global::ComputeSharp.Bool2x3; -global using bool2x4 = global::ComputeSharp.Bool2x4; -global using bool3x1 = global::ComputeSharp.Bool3x1; -global using bool3x2 = global::ComputeSharp.Bool3x2; -global using bool3x3 = global::ComputeSharp.Bool3x3; -global using bool3x4 = global::ComputeSharp.Bool3x4; -global using bool4x1 = global::ComputeSharp.Bool4x1; -global using bool4x2 = global::ComputeSharp.Bool4x2; -global using bool4x3 = global::ComputeSharp.Bool4x3; -global using bool4x4 = global::ComputeSharp.Bool4x4; -global using double2 = global::ComputeSharp.Double2; -global using double3 = global::ComputeSharp.Double3; -global using double4 = global::ComputeSharp.Double4; -global using double1x1 = global::ComputeSharp.Double1x1; -global using double1x2 = global::ComputeSharp.Double1x2; -global using double1x3 = global::ComputeSharp.Double1x3; -global using double1x4 = global::ComputeSharp.Double1x4; -global using double2x1 = global::ComputeSharp.Double2x1; -global using double2x2 = global::ComputeSharp.Double2x2; -global using double2x3 = global::ComputeSharp.Double2x3; -global using double2x4 = global::ComputeSharp.Double2x4; -global using double3x1 = global::ComputeSharp.Double3x1; -global using double3x2 = global::ComputeSharp.Double3x2; -global using double3x3 = global::ComputeSharp.Double3x3; -global using double3x4 = global::ComputeSharp.Double3x4; -global using double4x1 = global::ComputeSharp.Double4x1; -global using double4x2 = global::ComputeSharp.Double4x2; -global using double4x3 = global::ComputeSharp.Double4x3; -global using double4x4 = global::ComputeSharp.Double4x4; -global using float2 = global::ComputeSharp.Float2; -global using float3 = global::ComputeSharp.Float3; -global using float4 = global::ComputeSharp.Float4; -global using float1x1 = global::ComputeSharp.Float1x1; -global using float1x2 = global::ComputeSharp.Float1x2; -global using float1x3 = global::ComputeSharp.Float1x3; -global using float1x4 = global::ComputeSharp.Float1x4; -global using float2x1 = global::ComputeSharp.Float2x1; -global using float2x2 = global::ComputeSharp.Float2x2; -global using float2x3 = global::ComputeSharp.Float2x3; -global using float2x4 = global::ComputeSharp.Float2x4; -global using float3x1 = global::ComputeSharp.Float3x1; -global using float3x2 = global::ComputeSharp.Float3x2; -global using float3x3 = global::ComputeSharp.Float3x3; -global using float3x4 = global::ComputeSharp.Float3x4; -global using float4x1 = global::ComputeSharp.Float4x1; -global using float4x2 = global::ComputeSharp.Float4x2; -global using float4x3 = global::ComputeSharp.Float4x3; -global using float4x4 = global::ComputeSharp.Float4x4; -global using int2 = global::ComputeSharp.Int2; -global using int3 = global::ComputeSharp.Int3; -global using int4 = global::ComputeSharp.Int4; -global using int1x1 = global::ComputeSharp.Int1x1; -global using int1x2 = global::ComputeSharp.Int1x2; -global using int1x3 = global::ComputeSharp.Int1x3; -global using int1x4 = global::ComputeSharp.Int1x4; -global using int2x1 = global::ComputeSharp.Int2x1; -global using int2x2 = global::ComputeSharp.Int2x2; -global using int2x3 = global::ComputeSharp.Int2x3; -global using int2x4 = global::ComputeSharp.Int2x4; -global using int3x1 = global::ComputeSharp.Int3x1; -global using int3x2 = global::ComputeSharp.Int3x2; -global using int3x3 = global::ComputeSharp.Int3x3; -global using int3x4 = global::ComputeSharp.Int3x4; -global using int4x1 = global::ComputeSharp.Int4x1; -global using int4x2 = global::ComputeSharp.Int4x2; -global using int4x3 = global::ComputeSharp.Int4x3; -global using int4x4 = global::ComputeSharp.Int4x4; -global using uint2 = global::ComputeSharp.UInt2; -global using uint3 = global::ComputeSharp.UInt3; -global using uint4 = global::ComputeSharp.UInt4; -global using uint1x1 = global::ComputeSharp.UInt1x1; -global using uint1x2 = global::ComputeSharp.UInt1x2; -global using uint1x3 = global::ComputeSharp.UInt1x3; -global using uint1x4 = global::ComputeSharp.UInt1x4; -global using uint2x1 = global::ComputeSharp.UInt2x1; -global using uint2x2 = global::ComputeSharp.UInt2x2; -global using uint2x3 = global::ComputeSharp.UInt2x3; -global using uint2x4 = global::ComputeSharp.UInt2x4; -global using uint3x1 = global::ComputeSharp.UInt3x1; -global using uint3x2 = global::ComputeSharp.UInt3x2; -global using uint3x3 = global::ComputeSharp.UInt3x3; -global using uint3x4 = global::ComputeSharp.UInt3x4; -global using uint4x1 = global::ComputeSharp.UInt4x1; -global using uint4x2 = global::ComputeSharp.UInt4x2; -global using uint4x3 = global::ComputeSharp.UInt4x3; -global using uint4x4 = global::ComputeSharp.UInt4x4; diff --git a/src/ComputeSharp.Core.SourceGenerators/GlobalUsingDirectivesGenerator.cs b/src/ComputeSharp.Core.SourceGenerators/GlobalUsingDirectivesGenerator.cs index 1892174c..a97be0df 100644 --- a/src/ComputeSharp.Core.SourceGenerators/GlobalUsingDirectivesGenerator.cs +++ b/src/ComputeSharp.Core.SourceGenerators/GlobalUsingDirectivesGenerator.cs @@ -1,5 +1,3 @@ -using System.IO; -using System.Reflection; using Microsoft.CodeAnalysis; namespace ComputeSharp.Core.SourceGenerators; @@ -10,19 +8,114 @@ namespace ComputeSharp.Core.SourceGenerators; [Generator(LanguageNames.CSharp)] public sealed class GlobalUsingDirectivesGenerator : IIncrementalGenerator { + /// + /// The generated global using directives to emit. + /// + private const string GlobalUsingDirectives = + """ + // + #pragma warning disable + + global using bool2 = global::ComputeSharp.Bool2; + global using bool3 = global::ComputeSharp.Bool3; + global using bool4 = global::ComputeSharp.Bool4; + global using bool1x1 = global::ComputeSharp.Bool1x1; + global using bool1x2 = global::ComputeSharp.Bool1x2; + global using bool1x3 = global::ComputeSharp.Bool1x3; + global using bool1x4 = global::ComputeSharp.Bool1x4; + global using bool2x1 = global::ComputeSharp.Bool2x1; + global using bool2x2 = global::ComputeSharp.Bool2x2; + global using bool2x3 = global::ComputeSharp.Bool2x3; + global using bool2x4 = global::ComputeSharp.Bool2x4; + global using bool3x1 = global::ComputeSharp.Bool3x1; + global using bool3x2 = global::ComputeSharp.Bool3x2; + global using bool3x3 = global::ComputeSharp.Bool3x3; + global using bool3x4 = global::ComputeSharp.Bool3x4; + global using bool4x1 = global::ComputeSharp.Bool4x1; + global using bool4x2 = global::ComputeSharp.Bool4x2; + global using bool4x3 = global::ComputeSharp.Bool4x3; + global using bool4x4 = global::ComputeSharp.Bool4x4; + global using double2 = global::ComputeSharp.Double2; + global using double3 = global::ComputeSharp.Double3; + global using double4 = global::ComputeSharp.Double4; + global using double1x1 = global::ComputeSharp.Double1x1; + global using double1x2 = global::ComputeSharp.Double1x2; + global using double1x3 = global::ComputeSharp.Double1x3; + global using double1x4 = global::ComputeSharp.Double1x4; + global using double2x1 = global::ComputeSharp.Double2x1; + global using double2x2 = global::ComputeSharp.Double2x2; + global using double2x3 = global::ComputeSharp.Double2x3; + global using double2x4 = global::ComputeSharp.Double2x4; + global using double3x1 = global::ComputeSharp.Double3x1; + global using double3x2 = global::ComputeSharp.Double3x2; + global using double3x3 = global::ComputeSharp.Double3x3; + global using double3x4 = global::ComputeSharp.Double3x4; + global using double4x1 = global::ComputeSharp.Double4x1; + global using double4x2 = global::ComputeSharp.Double4x2; + global using double4x3 = global::ComputeSharp.Double4x3; + global using double4x4 = global::ComputeSharp.Double4x4; + global using float2 = global::ComputeSharp.Float2; + global using float3 = global::ComputeSharp.Float3; + global using float4 = global::ComputeSharp.Float4; + global using float1x1 = global::ComputeSharp.Float1x1; + global using float1x2 = global::ComputeSharp.Float1x2; + global using float1x3 = global::ComputeSharp.Float1x3; + global using float1x4 = global::ComputeSharp.Float1x4; + global using float2x1 = global::ComputeSharp.Float2x1; + global using float2x2 = global::ComputeSharp.Float2x2; + global using float2x3 = global::ComputeSharp.Float2x3; + global using float2x4 = global::ComputeSharp.Float2x4; + global using float3x1 = global::ComputeSharp.Float3x1; + global using float3x2 = global::ComputeSharp.Float3x2; + global using float3x3 = global::ComputeSharp.Float3x3; + global using float3x4 = global::ComputeSharp.Float3x4; + global using float4x1 = global::ComputeSharp.Float4x1; + global using float4x2 = global::ComputeSharp.Float4x2; + global using float4x3 = global::ComputeSharp.Float4x3; + global using float4x4 = global::ComputeSharp.Float4x4; + global using int2 = global::ComputeSharp.Int2; + global using int3 = global::ComputeSharp.Int3; + global using int4 = global::ComputeSharp.Int4; + global using int1x1 = global::ComputeSharp.Int1x1; + global using int1x2 = global::ComputeSharp.Int1x2; + global using int1x3 = global::ComputeSharp.Int1x3; + global using int1x4 = global::ComputeSharp.Int1x4; + global using int2x1 = global::ComputeSharp.Int2x1; + global using int2x2 = global::ComputeSharp.Int2x2; + global using int2x3 = global::ComputeSharp.Int2x3; + global using int2x4 = global::ComputeSharp.Int2x4; + global using int3x1 = global::ComputeSharp.Int3x1; + global using int3x2 = global::ComputeSharp.Int3x2; + global using int3x3 = global::ComputeSharp.Int3x3; + global using int3x4 = global::ComputeSharp.Int3x4; + global using int4x1 = global::ComputeSharp.Int4x1; + global using int4x2 = global::ComputeSharp.Int4x2; + global using int4x3 = global::ComputeSharp.Int4x3; + global using int4x4 = global::ComputeSharp.Int4x4; + global using uint2 = global::ComputeSharp.UInt2; + global using uint3 = global::ComputeSharp.UInt3; + global using uint4 = global::ComputeSharp.UInt4; + global using uint1x1 = global::ComputeSharp.UInt1x1; + global using uint1x2 = global::ComputeSharp.UInt1x2; + global using uint1x3 = global::ComputeSharp.UInt1x3; + global using uint1x4 = global::ComputeSharp.UInt1x4; + global using uint2x1 = global::ComputeSharp.UInt2x1; + global using uint2x2 = global::ComputeSharp.UInt2x2; + global using uint2x3 = global::ComputeSharp.UInt2x3; + global using uint2x4 = global::ComputeSharp.UInt2x4; + global using uint3x1 = global::ComputeSharp.UInt3x1; + global using uint3x2 = global::ComputeSharp.UInt3x2; + global using uint3x3 = global::ComputeSharp.UInt3x3; + global using uint3x4 = global::ComputeSharp.UInt3x4; + global using uint4x1 = global::ComputeSharp.UInt4x1; + global using uint4x2 = global::ComputeSharp.UInt4x2; + global using uint4x3 = global::ComputeSharp.UInt4x3; + global using uint4x4 = global::ComputeSharp.UInt4x4; + """; + /// public void Initialize(IncrementalGeneratorInitializationContext context) { - context.RegisterPostInitializationOutput(static context => - { - const string filename = "ComputeSharp.Core.SourceGenerators.EmbeddedResources.GlobalUsingDirectives.cs"; - - using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(filename); - using StreamReader reader = new(stream); - - string globalUsingDirectives = reader.ReadToEnd(); - - context.AddSource("GlobalUsingDirectives.g.cs", globalUsingDirectives); - }); + context.RegisterPostInitializationOutput(static context => context.AddSource($"{nameof(GlobalUsingDirectives)}.g.cs", GlobalUsingDirectives)); } } \ No newline at end of file diff --git a/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs b/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs index 78775089..8303c8a7 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/DynamicCache{TKey,TValue}.cs @@ -171,7 +171,7 @@ public sealed class DynamicCache private bool isPerformingLookup; /// - /// Creates a new instance with the specified parameters. + /// Creates a new instance with the specified parameters. /// /// The key to use for the entry. public Entry(TKey key)