Added [SkipLocalsInit] to generated methods, if possible

このコミットが含まれているのは:
Sergio Pedri committed 2021-07-22 23:34:57 +02:00
1 親 bbb42e5367
コミット 5c32501fd5
2ファイル変更
+8 -8

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

+8 -5
ファイルの表示
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComputeSharp.__Internals;
using ComputeSharp.SourceGenerators.Diagnostics;
using ComputeSharp.SourceGenerators.Extensions;
using Microsoft.CodeAnalysis;
@@ -12,8 +11,6 @@ using static ComputeSharp.SourceGenerators.Diagnostics.DiagnosticDescriptors;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
using static Microsoft.CodeAnalysis.SymbolDisplayTypeQualificationStyle;
#pragma warning disable CS0618
namespace ComputeSharp.SourceGenerators
{
/// <summary>
@@ -75,7 +72,7 @@ namespace ComputeSharp.SourceGenerators
};
// Method attributes
AttributeListSyntax[] attributes = new[]
List<AttributeListSyntax> attributes = new()
{
AttributeList(SingletonSeparatedList(
Attribute(IdentifierName("GeneratedCode")).AddArgumentListArguments(
@@ -93,6 +90,12 @@ namespace ComputeSharp.SourceGenerators
Literal("This method is not intended to be used directly by user code"))))))
};
// Add [SkipLocalsInit] if the target project allows it
if (context.Compilation.Options is CSharpCompilationOptions { AllowUnsafe: true })
{
attributes.Add(AttributeList(SingletonSeparatedList(Attribute(IdentifierName("SkipLocalsInit")))));
}
string namespaceName = structDeclarationSymbol.ContainingNamespace.ToDisplayString(new(typeQualificationStyle: NameAndContainingTypesAndNamespaces));
string structName = structDeclaration.Identifier.Text;
SyntaxTokenList structModifiers = structDeclaration.Modifiers;
@@ -107,7 +110,7 @@ namespace ComputeSharp.SourceGenerators
var structDeclarationSyntax =
StructDeclaration(structName)
.WithModifiers(structModifiers)
.AddMembers(methods.Select(m => m.AddAttributeLists(attributes)).ToArray());
.AddMembers(methods.Select(m => m.AddAttributeLists(attributes.ToArray())).ToArray());
TypeDeclarationSyntax typeDeclarationSyntax = structDeclarationSyntax;
-3
ファイルの表示
@@ -2,7 +2,6 @@ using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using ComputeSharp.__Internals;
using ComputeSharp.SwapChain.Shaders;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
@@ -11,8 +10,6 @@ using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
#pragma warning disable CS0618
namespace ComputeSharp.Tests
{
[TestClass]