From 502baaca03d75b90cf0d9c75051dea189850b99a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 May 2022 01:46:11 +0200 Subject: [PATCH 1/6] Use raw multiline string literals for generated HLSL source This is optionally enabled when C# preview is used --- .../ComputeSharp.D2D1.SourceGenerators.csproj | 2 +- ...ator.CreateBuildHlslSourceMethod.Syntax.cs | 23 +++++++++++++++++-- .../ID2D1ShaderGenerator.cs | 17 +++++++++----- .../ComputeSharp.D2D1.Tests.csproj | 1 + 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj index e53c3b74..84a806b7 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj @@ -91,7 +91,7 @@ - + diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs index df18aab4..0e0e3986 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs @@ -1,4 +1,5 @@ using ComputeSharp.D2D1.__Internals; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; @@ -17,9 +18,27 @@ partial class ID2D1ShaderGenerator /// Creates a instance for the BuildHlslSource method. /// /// The input HLSL source. + /// The depth of the hierarchy for this type (used to calculate the right indentation). + /// Whether to use a raw multiline string literal expression /// The resulting instance for the BuildHlslSource method. - public static MethodDeclarationSyntax GetSyntax(string hlslSource) + public static MethodDeclarationSyntax GetSyntax(string hlslSource, int hierarchyDepth, bool useRawMultiLineStringLiteralExpression) { + // If raw multiline string literal expressions are used, create a token to represent it. Here some spaces are + // also added to properly align the resulting text with one indentation below the declaring string constant. + // The spaces are: 4 for each containing type, 4 for the containing method, and 4 for the one additional indentation. + string indentation = new(' ', 4 * hierarchyDepth + 4 + 4); + SyntaxToken hlslSourceLiteralToken = useRawMultiLineStringLiteralExpression switch + { + true => + Token( + TriviaList(), + SyntaxKind.MultiLineRawStringLiteralToken, + $"\"\"\"\n{indentation}{hlslSource.Replace("\n", $"\n{indentation}")}\"\"\"", + hlslSource, + TriviaList()), + false => Literal(hlslSource) + }; + // This code produces a method declaration as follows: // // readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.BuildHlslSource(out string hlslSource) @@ -36,7 +55,7 @@ partial class ID2D1ShaderGenerator AssignmentExpression( SyntaxKind.SimpleAssignmentExpression, IdentifierName("hlslSource"), - LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(hlslSource)))))); + LiteralExpression(SyntaxKind.StringLiteralExpression, hlslSourceLiteralToken))))); } } } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index a301af50..625b10d6 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -193,13 +193,18 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator .Select(static (item, token) => (item.Hierarchy, item.Source.HlslSource)) .WithComparers(HierarchyInfo.Comparer.Default, EqualityComparer.Default); - // Generate the BuildHlslSource() methods - context.RegisterSourceOutput(hlslSourceInfo, static (context, item) => - { - MethodDeclarationSyntax buildHlslStringMethod = BuildHlslSource.GetSyntax(item.HlslSource); - CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, buildHlslStringMethod, canUseSkipLocalsInit: false); + // Check whether raw multiline string literals can be used (C# preview) + IncrementalValueProvider canUseRawMultiLineStringLiterals = + context.ParseOptionsProvider + .Select((item, _) => item is CSharpParseOptions options && options.LanguageVersion >= LanguageVersion.Preview); - context.AddSource($"{item.Hierarchy.FilenameHint}.{nameof(BuildHlslSource)}", compilationUnit.GetText(Encoding.UTF8)); + // Generate the BuildHlslSource() methods + context.RegisterSourceOutput(hlslSourceInfo.Combine(canUseRawMultiLineStringLiterals), static (context, item) => + { + MethodDeclarationSyntax buildHlslStringMethod = BuildHlslSource.GetSyntax(item.Left.HlslSource, item.Left.Hierarchy.Hierarchy.Length, item.Right); + CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, buildHlslStringMethod, canUseSkipLocalsInit: false); + + context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(BuildHlslSource)}", compilationUnit.GetText(Encoding.UTF8)); }); // Get a filtered sequence to enable caching diff --git a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj index 8c49cd29..126ec9db 100644 --- a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj +++ b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj @@ -4,6 +4,7 @@ net6.0 false $(NoWarn);CS0419;CA1416 + preview From 989f34655587eb488eace4a4e9768348ea39a3aa Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 May 2022 01:53:52 +0200 Subject: [PATCH 2/6] Add missing LF between include and defined constants --- .../ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs index 350e30f0..54c6eac6 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -469,9 +469,14 @@ partial class ID2D1ShaderGenerator AppendLineAndLF("#include \"d2d1effecthelpers.hlsli\""); // Define declarations - foreach (var (name, value) in definedConstants) + if (definedConstants.Any()) { - AppendLineAndLF($"#define {name} {value}"); + AppendLF(); + + foreach (var (name, value) in definedConstants) + { + AppendLineAndLF($"#define {name} {value}"); + } } // Static fields From f2e4dac552bbcb1932c128ee09e80d90ea6bfd2a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 May 2022 02:00:08 +0200 Subject: [PATCH 3/6] Add extra LF in shaders with no captured values --- ...2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs index 54c6eac6..af38826c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -505,12 +505,14 @@ partial class ID2D1ShaderGenerator } // Captured variables - AppendLF(); - - // User-defined values - foreach (var (fieldName, fieldType) in valueFields) + if (valueFields.Any()) { - AppendLineAndLF($"{fieldType} {fieldName};"); + AppendLF(); + + foreach (var (fieldName, fieldType) in valueFields) + { + AppendLineAndLF($"{fieldType} {fieldName};"); + } } // Forward declarations From 398ec17fb3d1834922cdc83fc0d022eea5dc925e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 May 2022 02:53:44 +0200 Subject: [PATCH 4/6] Use raw multiline string literals in DX12 generator as well --- .../ComputeSharp.SourceGenerators.csproj | 2 +- ...ator.CreateBuildHlslSourceMethod.Syntax.cs | 32 ++++++++++++++++--- .../IShaderGenerator.cs | 17 ++++++---- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index 24881627..3167bf64 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -83,7 +83,7 @@ - + diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs index 9140019e..364da166 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs @@ -3,6 +3,7 @@ using System.Collections.Immutable; using System.Text; using ComputeSharp.__Internals; using ComputeSharp.SourceGenerators.Models; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; @@ -22,12 +23,14 @@ partial class IShaderGenerator /// /// The input instance to use. /// Indicates whether or not dynamic shaders are supported. + /// The depth of the hierarchy for this type (used to calculate the right indentation). + /// Whether to use a raw multiline string literal expression /// The resulting instance for the BuildHlslSource method. - public static MethodDeclarationSyntax GetSyntax(HlslShaderSourceInfo hlslSourceInfo, bool supportsDynamicShaders) + public static MethodDeclarationSyntax GetSyntax(HlslShaderSourceInfo hlslSourceInfo, bool supportsDynamicShaders, int hierarchyDepth, bool useRawMultiLineStringLiteralExpression) { // Generate the necessary body statements depending on whether dynamic shaders are supported ImmutableArray bodyStatements = supportsDynamicShaders - ? GenerateRenderMethodBody(hlslSourceInfo) + ? GenerateRenderMethodBody(hlslSourceInfo, hierarchyDepth, useRawMultiLineStringLiteralExpression) : GenerateEmptyMethodBody(); // This code produces a method declaration as follows: @@ -78,8 +81,10 @@ partial class IShaderGenerator /// Produces the series of statements to build the current HLSL source. /// /// The input instance to use. + /// The depth of the hierarchy for this type (used to calculate the right indentation). + /// Whether to use a raw multiline string literal expression /// The series of statements to build the HLSL source to compile to execute the current shader. - private static ImmutableArray GenerateRenderMethodBody(HlslShaderSourceInfo hlslSourceInfo) + private static ImmutableArray GenerateRenderMethodBody(HlslShaderSourceInfo hlslSourceInfo, int hierarchyDepth, bool useRawMultiLineStringLiteralExpression) { ImmutableArray.Builder statements = ImmutableArray.CreateBuilder(); StringBuilder textBuilder = new(); @@ -114,11 +119,30 @@ partial class IShaderGenerator sizeHint += textBuilder.Length; + // If raw multiline string literal expressions are used, create a token to represent it. Here some spaces are + // also added to properly align the resulting text with one indentation below the declaring string constant. + // The spaces are: 4 for each containing type, 4 for the containing method, and 4 for the one additional indentation. + // An extra newline and indentation has to be added to the raw text when there is no trailing newline, as not doing + // so would otherwise case the terminating """ token to fall on the same line, which is invalid syntax. This is only + // needed to make the code valid, as the actual literal context of the string is not affected and remains the same. + string indentation = new(' ', 4 * hierarchyDepth + 4 + 4); + SyntaxToken textToken = useRawMultiLineStringLiteralExpression switch + { + true => + Token( + TriviaList(), + SyntaxKind.MultiLineRawStringLiteralToken, + $"\"\"\"\n{indentation}{text.Replace("\n", $"\n{indentation}")}{(text.EndsWith("\n") ? "" : $"\n{indentation}")}\"\"\"", + text, + TriviaList()), + false => Literal(text) + }; + statements.Add( ExpressionStatement( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("builder"), IdentifierName("Append"))) - .AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(text)))))); + .AddArgumentListArguments(Argument(LiteralExpression(SyntaxKind.StringLiteralExpression, textToken))))); textBuilder.Clear(); } diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index 2eb5473a..8786be8b 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -171,13 +171,18 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator .Select(static (item, token) => (item.Left.Dispatch.Hierarchy, item.Left.Hlsl, item.Right)) .WithComparers(HierarchyInfo.Comparer.Default, HlslShaderSourceInfo.Comparer.Default, EqualityComparer.Default); - // Generate the BuildHlslSource() methods - context.RegisterSourceOutput(hlslSourceInfo.Combine(canUseSkipLocalsInit), static (context, item) => - { - MethodDeclarationSyntax buildHlslStringMethod = BuildHlslSource.GetSyntax(item.Left.SourceInfo, item.Left.SupportsDynamicShaders); - CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, buildHlslStringMethod, item.Right); + // Check whether raw multiline string literals can be used (C# preview) + IncrementalValueProvider canUseRawMultiLineStringLiterals = + context.ParseOptionsProvider + .Select((item, _) => item is CSharpParseOptions options && options.LanguageVersion >= LanguageVersion.Preview); - context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(BuildHlslSource)}", compilationUnit.GetText(Encoding.UTF8)); + // Generate the BuildHlslSource() methods + context.RegisterSourceOutput(hlslSourceInfo.Combine(canUseSkipLocalsInit).Combine(canUseRawMultiLineStringLiterals), static (context, item) => + { + MethodDeclarationSyntax buildHlslStringMethod = BuildHlslSource.GetSyntax(item.Left.Left.SourceInfo, item.Left.Left.SupportsDynamicShaders, item.Left.Left.Hierarchy.Hierarchy.Length, item.Right); + CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Left.Hierarchy, buildHlslStringMethod, item.Right); + + context.AddSource($"{item.Left.Left.Hierarchy.FilenameHint}.{nameof(BuildHlslSource)}", compilationUnit.GetText(Encoding.UTF8)); }); // Get the dispatch metadata info From ae00acc2701fe3c211f0da1507260add9be557d8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 26 May 2022 00:14:51 +0200 Subject: [PATCH 5/6] Update all Roslyn-related NuGet packages This also fixes some build errors in test projects --- .../ComputeSharp.Core.SourceGenerators.csproj | 2 +- ...ComputeSharp.D2D1.Tests.AssemblyLevelAttributes.csproj | 6 +++--- .../ComputeSharp.D2D1.Tests.csproj | 6 +++--- .../ComputeSharp.Tests.DisableDynamicCompilation.csproj | 6 +++--- .../ComputeSharp.Tests.Internals.csproj | 6 +++--- .../ComputeSharp.Tests.NativeLibrariesResolver.csproj | 6 +++--- .../ComputeSharp.Tests.SourceGenerators.csproj | 8 ++++---- tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj | 6 +++--- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj b/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj index 4a9583fa..17c0c1bd 100644 --- a/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj +++ b/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj @@ -60,7 +60,7 @@ - + diff --git a/tests/ComputeSharp.D2D1.Tests.AssemblyLevelAttributes/ComputeSharp.D2D1.Tests.AssemblyLevelAttributes.csproj b/tests/ComputeSharp.D2D1.Tests.AssemblyLevelAttributes/ComputeSharp.D2D1.Tests.AssemblyLevelAttributes.csproj index a7349e55..a4fa0dc0 100644 --- a/tests/ComputeSharp.D2D1.Tests.AssemblyLevelAttributes/ComputeSharp.D2D1.Tests.AssemblyLevelAttributes.csproj +++ b/tests/ComputeSharp.D2D1.Tests.AssemblyLevelAttributes/ComputeSharp.D2D1.Tests.AssemblyLevelAttributes.csproj @@ -6,9 +6,9 @@ - - - + + + diff --git a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj index 126ec9db..16fd9b98 100644 --- a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj +++ b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj @@ -12,9 +12,9 @@ - - - + + + diff --git a/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj b/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj index 58e1ee6b..ea6ed60b 100644 --- a/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj +++ b/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj @@ -7,10 +7,10 @@ - + - - + + diff --git a/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj b/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj index 69f6b126..5b59ef16 100644 --- a/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj +++ b/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj @@ -7,9 +7,9 @@ - - - + + + diff --git a/tests/ComputeSharp.Tests.NativeLibrariesResolver/ComputeSharp.Tests.NativeLibrariesResolver.csproj b/tests/ComputeSharp.Tests.NativeLibrariesResolver/ComputeSharp.Tests.NativeLibrariesResolver.csproj index 1ffb39a8..cb3020de 100644 --- a/tests/ComputeSharp.Tests.NativeLibrariesResolver/ComputeSharp.Tests.NativeLibrariesResolver.csproj +++ b/tests/ComputeSharp.Tests.NativeLibrariesResolver/ComputeSharp.Tests.NativeLibrariesResolver.csproj @@ -6,9 +6,9 @@ - - - + + + diff --git a/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj b/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj index 9346fcef..57df5646 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj +++ b/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj @@ -6,10 +6,10 @@ - - - - + + + + diff --git a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj index 328d4f56..fb26bd84 100644 --- a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj +++ b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj @@ -8,9 +8,9 @@ - - - + + + From 772553852cf3fd08c85e031b07d316975c5199af Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 28 May 2022 03:15:51 +0200 Subject: [PATCH 6/6] Use pattern matching to check parse options Co-authored-by: Ashley --- src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs | 2 +- src/ComputeSharp.SourceGenerators/IShaderGenerator.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index 625b10d6..3802d0c4 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -196,7 +196,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator // Check whether raw multiline string literals can be used (C# preview) IncrementalValueProvider canUseRawMultiLineStringLiterals = context.ParseOptionsProvider - .Select((item, _) => item is CSharpParseOptions options && options.LanguageVersion >= LanguageVersion.Preview); + .Select((item, _) => item is CSharpParseOptions { LanguageVersion: >= LanguageVersion.Preview }); // Generate the BuildHlslSource() methods context.RegisterSourceOutput(hlslSourceInfo.Combine(canUseRawMultiLineStringLiterals), static (context, item) => diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs index 8786be8b..f53deffe 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs @@ -174,7 +174,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator // Check whether raw multiline string literals can be used (C# preview) IncrementalValueProvider canUseRawMultiLineStringLiterals = context.ParseOptionsProvider - .Select((item, _) => item is CSharpParseOptions options && options.LanguageVersion >= LanguageVersion.Preview); + .Select((item, _) => item is CSharpParseOptions { LanguageVersion: >= LanguageVersion.Preview }); // Generate the BuildHlslSource() methods context.RegisterSourceOutput(hlslSourceInfo.Combine(canUseSkipLocalsInit).Combine(canUseRawMultiLineStringLiterals), static (context, item) =>