Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply some code tweaks to make analysis happy #635

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
Enable the latest warning wave, which shows additional warnings for invalid language features that are disabled by default.
For additional info, see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/warning-waves.
-->
<AnalysisLevel>7</AnalysisLevel>
<AnalysisLevel>latest</AnalysisLevel>
Sergio0694 marked this conversation as resolved.
Show resolved Hide resolved

<!-- Import the global configs from the CodeStyle package (enables all IDExxxx warnings)-->
<AnalysisLevelStyle>7-all</AnalysisLevelStyle>
<AnalysisLevelStyle>latest-all</AnalysisLevelStyle>

<!-- Enforce all code style rules during build (this replaces referencing Microsoft.CodeAnalysis.CSharp.CodeStyle) -->
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Immutable;
using System.Globalization;
using ComputeSharp.D2D1.SourceGenerators.Models;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
Expand Down Expand Up @@ -48,7 +49,7 @@ public static void GetInfo(
if (HlslKnownTypes.IsResourceTextureType(metadataName))
{
// The type name will be ComputeSharp.D2D1.D2D1ResourceTexture1D`1 or the 2D/3D versions
int rank = int.Parse(metadataName.Substring(metadataName.Length - 4, 1));
int rank = int.Parse(metadataName.Substring(metadataName.Length - 4, 1), CultureInfo.InvariantCulture);
int? index = null;

// Get the index from the [D2DResourceTextureIndex] attribute over the field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ private static IReadOnlyDictionary<string, string> BuildKnownMethodsMap()
["System.MathF.Exp"] = "exp",
["System.MathF.Log"] = "log",
["System.MathF.Log10"] = "log10",
["System.MathF.Max"] = "max",
["System.MathF.Min"] = "min",
["System.MathF.Round"] = "round",
["System.MathF.Sqrt"] = "sqrt",
["System.MathF.Sign"] = "sign",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static IReadOnlyDictionary<string, string> BuildKnownOperatorsMap()
foreach ((Type Type, MethodInfo Operator, string IntrinsicName, bool RequiresParametersMatching) item in
from type in HlslKnownTypes.KnownVectorTypes.Concat(HlslKnownTypes.KnownMatrixTypes)
from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public)
where method.IsSpecialName && method.Name.StartsWith("op_")
where method.IsSpecialName && method.Name.StartsWith("op_", StringComparison.InvariantCulture)
let attribute = method.GetCustomAttribute<HlslIntrinsicNameAttribute>()
where attribute is not null
select (Type: type, Operator: method, IntrinsicName: attribute.Name, attribute.RequiresParametersMatching))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -140,8 +141,8 @@ public static bool IsNonLinearMatrixType(string typeName, out string? elementNam
if (match.Success)
{
elementName = match.Groups[1].Value;
rows = int.Parse(match.Groups[2].Value);
columns = int.Parse(match.Groups[3].Value);
rows = int.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture);
columns = int.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture);

return true;
}
Expand Down Expand Up @@ -247,7 +248,7 @@ static void ExploreTypes(INamedTypeSymbol type, HashSet<INamedTypeSymbol> custom
type.TypeKind is TypeKind.Enum ||
type.IsGenericType ||
type.IsRefLikeType ||
type.GetFullyQualifiedName().StartsWith("System."))
type.GetFullyQualifiedName().StartsWith("System.", StringComparison.InvariantCulture))
{
_ = invalidTypes.Add(type);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public override SyntaxNode VisitMemberAccessExpression(MemberAccessExpressionSyn
ArgumentSyntax coordinateSyntax = mapping switch
{
not null => Argument(InvocationExpression(IdentifierName(mapping!), ArgumentList(updatedNode.ArgumentList.Arguments))),
null => updatedNode.ArgumentList.Arguments[0]
_ => updatedNode.ArgumentList.Arguments[0]
};

// Rewrite texture resource sampled accesses, if needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public static void WriteGeneratedAttributes(this IndentedTextWriter writer, stri
public static void WriteSortedUsingDirectives(this IndentedTextWriter writer, IEnumerable<string> usingDirectives)
{
// Add the System directives first, in the correct order
foreach (string usingDirective in usingDirectives.Where(static name => name.StartsWith("global::System")).OrderBy(static name => name))
foreach (string usingDirective in usingDirectives.Where(static name => name.StartsWith("global::System", StringComparison.InvariantCulture)).OrderBy(static name => name))
{
writer.WriteLine($"using {usingDirective};");
}

// Add the other directives, also sorted in the correct order
foreach (string usingDirective in usingDirectives.Where(static name => !name.StartsWith("global::System")).OrderBy(static name => name))
foreach (string usingDirective in usingDirectives.Where(static name => !name.StartsWith("global::System", StringComparison.InvariantCulture)).OrderBy(static name => name))
{
writer.WriteLine($"using {usingDirective};");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ComputeSharp.SourceGeneration.Helpers;
/// </summary>
/// <typeparam name="TKey">The type of keys to use for the cache.</typeparam>
/// <typeparam name="TValue">The type of values to store in the cache.</typeparam>
public sealed class DynamicCache<TKey, TValue>
internal sealed class DynamicCache<TKey, TValue>
where TKey : class
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class DxcCompilationException : Exception
/// Creates a new <see cref="DxcCompilationException"/> instance.
/// </summary>
/// <param name="error">The error message produced by the DXC compiler.</param>
internal DxcCompilationException(string error)
public DxcCompilationException(string error)
: base(GetExceptionMessage(error))
{
}
Expand Down