Disable D2D1 generator if unsafe blocks are not allowed

このコミットが含まれているのは:
Sergio Pedri committed 2023-09-27 18:30:53 +02:00
1 親 33e0eb6f49
コミット 24ac70faa4
2ファイル変更
+17

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

+6
ファイルの表示
@@ -36,6 +36,12 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
static (node, _) => node.IsTypeDeclarationWithOrPotentiallyWithBaseTypes<StructDeclarationSyntax>(),
static (context, token) =>
{
// The source generator requires unsafe blocks to be enabled (eg. for pointers, [SkipLocalsInit], etc.)
if (!context.SemanticModel.Compilation.IsAllowUnsafeBlocksEnabled())
{
return default;
}
StructDeclarationSyntax typeDeclaration = (StructDeclarationSyntax)context.Node;
// If the type symbol doesn't have at least one interface, it can't possibly be a shader type
+11
ファイルの表示
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
namespace ComputeSharp.SourceGeneration.Extensions;
@@ -45,6 +46,16 @@ internal static class CompilationExtensions
return true;
}
/// <summary>
/// Checks whether the <c>AllowUnsafeBlocks</c> option is set for a given compilation.
/// </summary>
/// <param name="compilation">The <see cref="Compilation"/> object to check.</param>
/// <returns>Whether the <c>AllowUnsafeBlocks</c> option is set for <paramref name="compilation"/>.</returns>
public static bool IsAllowUnsafeBlocksEnabled(this Compilation compilation)
{
return compilation.Options is CSharpCompilationOptions { AllowUnsafe: true };
}
/// <summary>
/// <para>
/// Checks whether or not a type with a specified metadata name is accessible from a given <see cref="Compilation"/> instance.