Merge pull request #528 from Sergio0694/dev/remove-null-suppressions

Remove some null suppressions, add [NotNullWhen]
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2023-06-15 01:52:31 +02:00
コミット 5ce2d4da30
10ファイル変更
+17 -17

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

+1 -2
ファイルの表示
@@ -79,8 +79,7 @@ public sealed class AutoConstructorGenerator : IIncrementalGenerator
// Check whether the field is annotated to have a special behavior
if (fieldSymbol.Type.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.AutoConstructorBehaviorAttribute", out AttributeData? usageData) &&
usageData!.ConstructorArguments is { Length: 1 } arguments &&
arguments[0].Value is (int)AutoConstructorBehavior.IgnoreAndSetToDefault)
usageData.ConstructorArguments is [{ Value: (int)AutoConstructorBehavior.IgnoreAndSetToDefault }])
{
defaulted.Add(fieldSymbol.Name);
}
+4 -4
ファイルの表示
@@ -85,12 +85,12 @@ partial class D2DPixelShaderSourceGenerator
{
if (methodSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out AttributeData? attributeData))
{
return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!;
return (D2D1ShaderProfile)attributeData.ConstructorArguments[0].Value!;
}
if (methodSymbol.ContainingAssembly.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out attributeData))
{
return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!;
return (D2D1ShaderProfile)attributeData.ConstructorArguments[0].Value!;
}
diagnostics.Add(
@@ -112,12 +112,12 @@ partial class D2DPixelShaderSourceGenerator
{
if (methodSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData))
{
return (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value!;
return (D2D1CompileOptions)attributeData.ConstructorArguments[0].Value!;
}
if (methodSymbol.ContainingAssembly.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out attributeData))
{
return (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value!;
return (D2D1CompileOptions)attributeData.ConstructorArguments[0].Value!;
}
diagnostics.Add(
@@ -31,7 +31,7 @@ public sealed class InvalidAssemblyLevelCompileOptionsAnalyzer : DiagnosticAnaly
// - The input D2D1CompileOptions value, which can be retrieved from the constructor arguments of the AttributeData object.
if (assemblySymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData))
{
D2D1CompileOptions options = (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value!;
D2D1CompileOptions options = (D2D1CompileOptions)attributeData.ConstructorArguments[0].Value!;
if ((options & D2D1CompileOptions.PackMatrixColumnMajor) != 0)
{
@@ -155,7 +155,7 @@ partial class ID2D1ShaderGenerator
// by the logic handling the info gathering for LoadResourceTextureDescriptions.
if (fieldSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DResourceTextureIndexAttribute", out AttributeData? attributeData))
{
_ = attributeData!.TryGetConstructorArgument(0, out index);
_ = attributeData.TryGetConstructorArgument(0, out index);
}
resourceTextures.Add((mapping ?? fieldSymbol.Name, typeName, index));
@@ -32,7 +32,7 @@ partial class ID2D1ShaderGenerator
}
// Extract the buffer precision and channel depth, if available
if (attributeData!.ConstructorArguments.Length == 1)
if (attributeData.ConstructorArguments.Length == 1)
{
if (attributeData.AttributeConstructor is IMethodSymbol { Parameters.Length: 1 } constructorSymbol &&
constructorSymbol.Parameters[0].Type.HasFullyQualifiedMetadataName("ComputeSharp.D2D1.D2D1BufferPrecision"))
@@ -20,7 +20,7 @@ partial class ID2D1ShaderGenerator
{
if (structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DPixelOptionsAttribute", out AttributeData? attributeData))
{
pixelOptions = (D2D1PixelOptions)attributeData!.ConstructorArguments[0].Value!;
pixelOptions = (D2D1PixelOptions)attributeData.ConstructorArguments[0].Value!;
}
else
{
@@ -35,12 +35,12 @@ partial class ID2D1ShaderGenerator
{
if (structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out AttributeData? attributeData))
{
return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!;
return (D2D1ShaderProfile)attributeData.ConstructorArguments[0].Value!;
}
if (structDeclarationSymbol.ContainingAssembly.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out attributeData))
{
return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!;
return (D2D1ShaderProfile)attributeData.ConstructorArguments[0].Value!;
}
return null;
@@ -56,7 +56,7 @@ partial class ID2D1ShaderGenerator
{
if (structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData))
{
D2D1CompileOptions options = (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value!;
D2D1CompileOptions options = (D2D1CompileOptions)attributeData.ConstructorArguments[0].Value!;
if ((options & D2D1CompileOptions.PackMatrixColumnMajor) != 0)
{
@@ -73,7 +73,7 @@ partial class ID2D1ShaderGenerator
if (structDeclarationSymbol.ContainingAssembly.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out attributeData))
{
// No need to validate against PackMatrixColumnMajor as that's checked separately
return (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value! | D2D1CompileOptions.PackMatrixRowMajor;
return (D2D1CompileOptions)attributeData.ConstructorArguments[0].Value! | D2D1CompileOptions.PackMatrixRowMajor;
}
return null;
@@ -56,7 +56,7 @@ partial class ID2D1ShaderGenerator
{
// If the constructor argument isn't available, it means the code is invalid. Just do nothing then, as the
// user will have to fix that to get the code to compile anyway. This way the generator won't crash too.
if (attributeData!.TryGetConstructorArgument(0, out int resourceIndex))
if (attributeData.TryGetConstructorArgument(0, out int resourceIndex))
{
index = resourceIndex;
}
+2 -1
ファイルの表示
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.SourceGeneration.Extensions;
@@ -33,7 +34,7 @@ internal static class ISymbolExtensions
/// <param name="name">The attribute name to look for.</param>
/// <param name="attributeData">The resulting attribute data, if found.</param>
/// <returns>Whether or not <paramref name="symbol"/> has an attribute with the specified name.</returns>
public static bool TryGetAttributeWithFullyQualifiedMetadataName(this ISymbol symbol, string name, out AttributeData? attributeData)
public static bool TryGetAttributeWithFullyQualifiedMetadataName(this ISymbol symbol, string name, [NotNullWhen(true)] out AttributeData? attributeData)
{
foreach (AttributeData attribute in symbol.GetAttributes())
{
+1 -1
ファイルの表示
@@ -63,7 +63,7 @@ partial class IShaderGenerator
int threadsZ;
// Check for a dispatch axis argument first
if (attribute!.ConstructorArguments.Length == 1)
if (attribute.ConstructorArguments.Length == 1)
{
int dispatchAxis = (int)attribute.ConstructorArguments[0].Value!;