Merge pull request #706 from Sergio0694/dev/always-flow-cancellation-token

Flow cancellation token to all semantics operations
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2023-12-06 23:58:47 +01:00
コミット 2dca94343b
6ファイル変更
+128 -121

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

@@ -30,6 +30,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Models\Interfaces\IConstantBufferInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SyntaxProcessors\ConstantBufferSyntaxProcessor.Generation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SyntaxProcessors\HlslDefinitionsSyntaxProcessor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SyntaxRewriters\HlslSourceRewriter.Tracking.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SyntaxRewriters\HlslSourceRewriter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SyntaxRewriters\HlslSourceRewriter.Diagnostics.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SyntaxRewriters\ShaderSourceRewriter.cs" />
-87
ファイルの表示
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using ComputeSharp.SourceGeneration.Mappings;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -39,91 +37,6 @@ internal static class SyntaxNodeExtensions
return typeDeclaration.Modifiers.Any(SyntaxKind.PartialKeyword);
}
/// <summary>
/// Checks a <see cref="SyntaxNode"/> value and replaces the value type to be HLSL compatible, if needed.
/// </summary>
/// <typeparam name="TRoot">The type of the input <see cref="TypeSyntax"/> instance.</typeparam>
/// <param name="node">The input <see cref="SyntaxNode"/> to check and modify if needed.</param>
/// <param name="sourceType">The source <see cref="SyntaxNode"/> to use to get type into from <paramref name="semanticModel"/>.</param>
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance with info on the input tree.</param>
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
public static TRoot ReplaceAndTrackType<TRoot>(this TRoot node, SyntaxNode sourceType, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
where TRoot : TypeSyntax
{
return node.ReplaceAndTrackType(node, sourceType, semanticModel, discoveredTypes);
}
/// <summary>
/// Checks a <see cref="SyntaxNode"/> value and replaces the value type to be HLSL compatible, if needed.
/// </summary>
/// <typeparam name="TRoot">The type of the input <see cref="SyntaxNode"/> instance.</typeparam>
/// <param name="node">The input <see cref="SyntaxNode"/> to check and modify if needed.</param>
/// <param name="targetType">The target <see cref="TypeSyntax"/> node to replace.</param>
/// <param name="sourceType">The source <see cref="SyntaxNode"/> to use to get type into from <paramref name="semanticModel"/>.</param>
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance with info on the input tree.</param>
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
public static TRoot ReplaceAndTrackType<TRoot>(this TRoot node, TypeSyntax targetType, SyntaxNode sourceType, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
where TRoot : SyntaxNode
{
// Skip immediately for function pointers
if (sourceType is FunctionPointerTypeSyntax)
{
return node.ReplaceNode(targetType, ParseTypeName("void*"));
}
// Handle the various possible type kinds
ITypeSymbol typeSymbol = sourceType switch
{
RefTypeSyntax refType => semanticModel.GetTypeInfo(refType.Type).Type!,
PointerTypeSyntax pointerType => semanticModel.GetTypeInfo(pointerType.ElementType).Type!,
ArrayTypeSyntax arrayType => semanticModel.GetTypeInfo(arrayType.ElementType).Type!,
_ => semanticModel.GetTypeInfo(sourceType).Type!
};
// Do nothing if the type is just void
if (typeSymbol.SpecialType == SpecialType.System_Void)
{
return node;
}
string typeName = typeSymbol.GetFullyQualifiedName();
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
{
TypeSyntax newType = ParseTypeName(mappedName!);
return node.ReplaceNode(targetType, newType);
}
return node.ReplaceNode(targetType, ParseTypeName(typeName.ToHlslIdentifierName()));
}
/// <summary>
/// Tracks the associated type for a <see cref="SyntaxNode"/> value and returns the HLSL compatible <see cref="TypeSyntax"/>.
/// </summary>
/// <param name="node">The input <see cref="SyntaxNode"/> to check.</param>
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance with info on the input tree.</param>
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
public static TypeSyntax TrackType(this SyntaxNode node, SemanticModel semanticModel, ICollection<INamedTypeSymbol> discoveredTypes)
{
ITypeSymbol typeSymbol = semanticModel.GetTypeInfo(node).Type!;
string typeName = typeSymbol.GetFullyQualifiedName();
discoveredTypes.Add((INamedTypeSymbol)typeSymbol);
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
{
return ParseTypeName(mappedName!);
}
return ParseTypeName(typeName.ToHlslIdentifierName());
}
/// <summary>
/// Returns a <see cref="MethodDeclarationSyntax"/> with a block body.
/// </summary>
@@ -0,0 +1,93 @@
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Mappings;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace ComputeSharp.SourceGeneration.SyntaxRewriters;
/// <inheritdoc cref="HlslSourceRewriter"/>
partial class HlslSourceRewriter
{
/// <summary>
/// Tracks the associated type for a <see cref="SyntaxNode"/> value and returns the HLSL compatible <see cref="TypeSyntax"/>.
/// </summary>
/// <param name="node">The input <see cref="SyntaxNode"/> to check.</param>
/// <param name="semanticModel">The <see cref="Microsoft.CodeAnalysis.SemanticModel"/> instance with info on the input tree.</param>
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
protected TypeSyntax TrackType(SyntaxNode node, SemanticModel semanticModel)
{
ITypeSymbol typeSymbol = semanticModel.GetTypeInfo(node, CancellationToken).Type!;
string typeName = typeSymbol.GetFullyQualifiedName();
DiscoveredTypes.Add((INamedTypeSymbol)typeSymbol);
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
{
return ParseTypeName(mappedName!);
}
return ParseTypeName(typeName.ToHlslIdentifierName());
}
/// <summary>
/// Checks a <see cref="SyntaxNode"/> value and replaces the value type to be HLSL compatible, if needed.
/// </summary>
/// <typeparam name="TRoot">The type of the input <see cref="TypeSyntax"/> instance.</typeparam>
/// <param name="node">The input <see cref="SyntaxNode"/> to check and modify if needed.</param>
/// <param name="sourceType">The source <see cref="SyntaxNode"/> to use to get type into from <paramref name="semanticModel"/>.</param>
/// <param name="semanticModel">The <see cref="Microsoft.CodeAnalysis.SemanticModel"/> instance with info on the input tree.</param>
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
protected TRoot ReplaceAndTrackType<TRoot>(TRoot node, SyntaxNode sourceType, SemanticModel semanticModel)
where TRoot : TypeSyntax
{
return ReplaceAndTrackType(node, node, sourceType, semanticModel);
}
/// <summary>
/// Checks a <see cref="SyntaxNode"/> value and replaces the value type to be HLSL compatible, if needed.
/// </summary>
/// <typeparam name="TRoot">The type of the input <see cref="SyntaxNode"/> instance.</typeparam>
/// <param name="node">The input <see cref="SyntaxNode"/> to check and modify if needed.</param>
/// <param name="targetType">The target <see cref="TypeSyntax"/> node to replace.</param>
/// <param name="sourceType">The source <see cref="SyntaxNode"/> to use to get type into from <paramref name="semanticModel"/>.</param>
/// <param name="semanticModel">The <see cref="Microsoft.CodeAnalysis.SemanticModel"/> instance with info on the input tree.</param>
/// <returns>A <see cref="SyntaxNode"/> instance that represents a type compatible with HLSL.</returns>
protected TRoot ReplaceAndTrackType<TRoot>(TRoot node, TypeSyntax targetType, SyntaxNode sourceType, SemanticModel semanticModel)
where TRoot : SyntaxNode
{
// Skip immediately for function pointers
if (sourceType is FunctionPointerTypeSyntax)
{
return node.ReplaceNode(targetType, ParseTypeName("void*"));
}
// Handle the various possible type kinds
ITypeSymbol typeSymbol = sourceType switch
{
RefTypeSyntax refType => semanticModel.GetTypeInfo(refType.Type, CancellationToken).Type!,
PointerTypeSyntax pointerType => semanticModel.GetTypeInfo(pointerType.ElementType, CancellationToken).Type!,
ArrayTypeSyntax arrayType => semanticModel.GetTypeInfo(arrayType.ElementType, CancellationToken).Type!,
_ => semanticModel.GetTypeInfo(sourceType, CancellationToken).Type!
};
// Do nothing if the type is just void
if (typeSymbol.SpecialType == SpecialType.System_Void)
{
return node;
}
string typeName = typeSymbol.GetFullyQualifiedName();
DiscoveredTypes.Add((INamedTypeSymbol)typeSymbol);
if (HlslKnownTypes.TryGetMappedName(typeName, out string? mappedName))
{
TypeSyntax newType = ParseTypeName(mappedName!);
return node.ReplaceNode(targetType, newType);
}
return node.ReplaceNode(targetType, ParseTypeName(typeName.ToHlslIdentifierName()));
}
}
+15 -15
ファイルの表示
@@ -87,7 +87,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
{
CastExpressionSyntax updatedNode = (CastExpressionSyntax)base.VisitCastExpression(node)!;
return updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, SemanticModel.For(node), DiscoveredTypes);
return ReplaceAndTrackType(updatedNode, updatedNode.Type, node.Type, SemanticModel.For(node));
}
/// <inheritdoc/>
@@ -95,7 +95,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
{
VariableDeclarationSyntax updatedNode = (VariableDeclarationSyntax)base.VisitVariableDeclaration(node)!;
if (SemanticModel.For(node).GetTypeInfo(node.Type).Type is ITypeSymbol { IsUnmanagedType: false } type)
if (SemanticModel.For(node).GetTypeInfo(node.Type, CancellationToken).Type is ITypeSymbol { IsUnmanagedType: false } type)
{
Diagnostics.Add(InvalidObjectDeclaration, node, type);
}
@@ -103,7 +103,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
// If var is used, replace it with the explicit type
if (updatedNode.Type is IdentifierNameSyntax { IsVar: true })
{
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, SemanticModel.For(node), DiscoveredTypes);
updatedNode = ReplaceAndTrackType(updatedNode, updatedNode.Type, node.Type, SemanticModel.For(node));
}
return updatedNode;
@@ -114,7 +114,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
{
ObjectCreationExpressionSyntax updatedNode = (ObjectCreationExpressionSyntax)base.VisitObjectCreationExpression(node)!;
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node, SemanticModel.For(node), DiscoveredTypes);
updatedNode = ReplaceAndTrackType(updatedNode, updatedNode.Type, node, SemanticModel.For(node));
return VisitObjectCreationExpression(node, updatedNode, updatedNode.Type);
}
@@ -123,7 +123,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
public sealed override SyntaxNode VisitImplicitObjectCreationExpression(ImplicitObjectCreationExpressionSyntax node)
{
ImplicitObjectCreationExpressionSyntax updatedNode = (ImplicitObjectCreationExpressionSyntax)base.VisitImplicitObjectCreationExpression(node)!;
TypeSyntax explicitType = IdentifierName("").ReplaceAndTrackType(node, SemanticModel.For(node), DiscoveredTypes);
TypeSyntax explicitType = ReplaceAndTrackType(IdentifierName(""), node, SemanticModel.For(node));
return VisitObjectCreationExpression(node, updatedNode, explicitType);
}
@@ -137,7 +137,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
{
CancellationToken.ThrowIfCancellationRequested();
ITypeSymbol? typeSymbol = SemanticModel.For(node).GetTypeInfo(node).Type;
ITypeSymbol? typeSymbol = SemanticModel.For(node).GetTypeInfo(node, CancellationToken).Type;
// Handle the edge case of the type being null (shouldn't really happen)
if (typeSymbol is null)
@@ -180,7 +180,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
{
for (int i = 0; i < node.ArgumentList!.Arguments.Count; i++)
{
IArgumentOperation argumentOperation = (IArgumentOperation)SemanticModel.For(node).GetOperation(node.ArgumentList.Arguments[i])!;
IArgumentOperation argumentOperation = (IArgumentOperation)SemanticModel.For(node).GetOperation(node.ArgumentList.Arguments[i], CancellationToken)!;
INamedTypeSymbol elementType = (INamedTypeSymbol)argumentOperation.Parameter!.Type;
updatedNode = updatedNode.ReplaceNode(
@@ -202,7 +202,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
{
DefaultExpressionSyntax updatedNode = (DefaultExpressionSyntax)base.VisitDefaultExpression(node)!;
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, SemanticModel.For(node), DiscoveredTypes);
updatedNode = ReplaceAndTrackType(updatedNode, updatedNode.Type, node.Type, SemanticModel.For(node));
// A default expression becomes (T)0 in HLSL
return CastExpression(updatedNode.Type, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
@@ -217,13 +217,13 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
if (updatedNode.IsKind(SyntaxKind.DefaultLiteralExpression))
{
TypeSyntax type = node.TrackType(SemanticModel.For(node), DiscoveredTypes);
TypeSyntax type = TrackType(node, SemanticModel.For(node));
// Same HLSL-style expression in the form (T)0
return CastExpression(type, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
}
else if (updatedNode.IsKind(SyntaxKind.NumericLiteralExpression) &&
SemanticModel.For(node).GetOperation(node) is ILiteralOperation operation &&
SemanticModel.For(node).GetOperation(node, CancellationToken) is ILiteralOperation operation &&
operation.Type is INamedTypeSymbol type)
{
// If the expression is a literal floating point value, we need to ensure the proper suffixes are
@@ -275,7 +275,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
ElementAccessExpressionSyntax updatedNode = (ElementAccessExpressionSyntax)base.VisitElementAccessExpression(node)!;
if (SemanticModel.For(node).GetOperation(node) is IPropertyReferenceOperation operation)
if (SemanticModel.For(node).GetOperation(node, CancellationToken) is IPropertyReferenceOperation operation)
{
string propertyName = operation.Property.GetFullyQualifiedMetadataName();
@@ -298,7 +298,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
// This prepares all the individual parts to combine into the HLSL property name when rewriting.
foreach (ArgumentSyntax argument in node.ArgumentList.Arguments)
{
if (SemanticModel.For(node).GetOperation(argument.Expression) is not IFieldReferenceOperation fieldReference ||
if (SemanticModel.For(node).GetOperation(argument.Expression, CancellationToken) is not IFieldReferenceOperation fieldReference ||
!HlslKnownProperties.IsKnownMatrixIndex(fieldReference.Field.GetFullyQualifiedMetadataName()))
{
Diagnostics.Add(NonConstantMatrixSwizzledIndex, argument);
@@ -340,7 +340,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
AssignmentExpressionSyntax updatedNode = (AssignmentExpressionSyntax)base.VisitAssignmentExpression(node)!;
if (SemanticModel.For(node).GetOperation(node) is ICompoundAssignmentOperation { OperatorMethod: { ContainingType.ContainingNamespace.Name: "ComputeSharp" } method })
if (SemanticModel.For(node).GetOperation(node, CancellationToken) is ICompoundAssignmentOperation { OperatorMethod: { ContainingType.ContainingNamespace.Name: "ComputeSharp" } method })
{
// If the compound assignment is using an HLSL operator, replace the expression with an invocation and assignment.
// That is, do the following transformation:
@@ -370,7 +370,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
BinaryExpressionSyntax updatedNode = (BinaryExpressionSyntax)base.VisitBinaryExpression(node)!;
// Process binary operations to see if the target operator method is an intrinsic
if (SemanticModel.For(node).GetOperation(node) is IBinaryOperation { OperatorMethod: { ContainingType.ContainingNamespace.Name: "ComputeSharp" } method })
if (SemanticModel.For(node).GetOperation(node, CancellationToken) is IBinaryOperation { OperatorMethod: { ContainingType.ContainingNamespace.Name: "ComputeSharp" } method })
{
// If the operator is indeed an HLSL overload, replace the expression with an invocation.
// That is, do the following transformation:
@@ -398,7 +398,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
// and member access expressions, as those will be handled separately. Doing so avoids unnecessarily
// retrieving semantic information for every identifier, which would otherwise be fairly expensive.
if (node.Parent is not (InvocationExpressionSyntax or MemberAccessExpressionSyntax) &&
SemanticModel.For(node).GetOperation(node) is IFieldReferenceOperation operation &&
SemanticModel.For(node).GetOperation(node, CancellationToken) is IFieldReferenceOperation operation &&
operation.Field.IsConst &&
operation.Type!.TypeKind != TypeKind.Enum)
{
+17 -17
ファイルの表示
@@ -140,7 +140,7 @@ internal sealed partial class ShaderSourceRewriter(
MethodDeclarationSyntax? updatedNode = (MethodDeclarationSyntax?)base.Visit(node)!;
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node), DiscoveredTypes);
updatedNode = ReplaceAndTrackType(updatedNode, updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node));
if (node!.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword)))
{
@@ -175,7 +175,7 @@ internal sealed partial class ShaderSourceRewriter(
LocalFunctionStatementSyntax? updatedNode = (LocalFunctionStatementSyntax?)base.Visit(node)!;
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node), DiscoveredTypes);
updatedNode = ReplaceAndTrackType(updatedNode, updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node));
if (node!.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword)))
{
@@ -229,10 +229,10 @@ internal sealed partial class ShaderSourceRewriter(
ExitLoop:
return updatedNode
.WithAttributeLists(default)
.ReplaceAndTrackType(updatedNode.Type!, node.Type!, SemanticModel.For(node), DiscoveredTypes)
.WithModifiers(TokenList(modifier));
updatedNode = updatedNode.WithAttributeLists(default);
updatedNode = ReplaceAndTrackType(updatedNode, updatedNode.Type!, node.Type!, SemanticModel.For(node));
return updatedNode.WithModifiers(TokenList(modifier));
}
/// <inheritdoc/>
@@ -240,12 +240,12 @@ internal sealed partial class ShaderSourceRewriter(
{
LocalDeclarationStatementSyntax updatedNode = (LocalDeclarationStatementSyntax)base.VisitLocalDeclarationStatement(node)!;
if (SemanticModel.For(node).GetOperation(node) is IOperation { Kind: OperationKind.UsingDeclaration })
if (SemanticModel.For(node).GetOperation(node, CancellationToken) is IOperation { Kind: OperationKind.UsingDeclaration })
{
Diagnostics.Add(UsingStatementOrDeclaration, node);
}
return updatedNode.ReplaceAndTrackType(updatedNode.Declaration.Type, node.Declaration.Type, SemanticModel.For(node), DiscoveredTypes);
return ReplaceAndTrackType(updatedNode, updatedNode.Declaration.Type, node.Declaration.Type, SemanticModel.For(node));
}
/// <inheritdoc/>
@@ -253,7 +253,7 @@ internal sealed partial class ShaderSourceRewriter(
{
DeclarationExpressionSyntax updatedNode = (DeclarationExpressionSyntax)base.VisitDeclarationExpression(node)!;
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.Type, node.Type, SemanticModel.For(node), DiscoveredTypes);
updatedNode = ReplaceAndTrackType(updatedNode, updatedNode.Type, node.Type, SemanticModel.For(node));
// Add the variable to the list of implicit declarations
this.implicitVariables.Add(VariableDeclaration(updatedNode.Type).AddVariables(VariableDeclarator(updatedNode.Designation.ToString())));
@@ -286,7 +286,7 @@ internal sealed partial class ShaderSourceRewriter(
.WithBlockBody()
.WithAttributeLists(List<AttributeListSyntax>());
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node), DiscoveredTypes);
updatedNode = ReplaceAndTrackType(updatedNode, updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node));
if (node.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword)))
{
@@ -310,7 +310,7 @@ internal sealed partial class ShaderSourceRewriter(
.WithAttributeLists(List<AttributeListSyntax>())
.WithIdentifier(Identifier($"__{this.currentMethodIdentifier.Text}__{node.Identifier.Text}"));
updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node), DiscoveredTypes);
updatedNode = ReplaceAndTrackType(updatedNode, updatedNode.ReturnType, node!.ReturnType, SemanticModel.For(node));
if (node.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword)))
{
@@ -345,7 +345,7 @@ internal sealed partial class ShaderSourceRewriter(
// We also only process fields from external types, as those in shader types don't need handling here.
// This is because they're lowered to the same identifier name, without fully qualified names to rewrite.
if (node.Parent is not (InvocationExpressionSyntax or MemberAccessExpressionSyntax) &&
SemanticModel.For(node).GetOperation(node) is IFieldReferenceOperation { Field.IsStatic: true } operation &&
SemanticModel.For(node).GetOperation(node, CancellationToken) is IFieldReferenceOperation { Field.IsStatic: true } operation &&
!SymbolEqualityComparer.Default.Equals(operation.Field.ContainingType, this.shaderType))
{
return VisitExternalStaticFieldAccess(null, operation.Field) ?? base.VisitIdentifierName(node);
@@ -362,7 +362,7 @@ internal sealed partial class ShaderSourceRewriter(
MemberAccessExpressionSyntax updatedNode = (MemberAccessExpressionSyntax)base.VisitMemberAccessExpression(node)!;
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression) &&
SemanticModel.For(node).GetOperation(node) is IMemberReferenceOperation operation)
SemanticModel.For(node).GetOperation(node, CancellationToken) is IMemberReferenceOperation operation)
{
if (operation is IFieldReferenceOperation fieldOperation)
{
@@ -438,7 +438,7 @@ internal sealed partial class ShaderSourceRewriter(
if (!this.staticMethods.TryGetValue(key, out MethodDeclarationSyntax? methodSyntax))
{
INamedTypeSymbol resourceType = (INamedTypeSymbol)SemanticModel.For(node).GetTypeInfo(node.Expression).Type!;
INamedTypeSymbol resourceType = (INamedTypeSymbol)SemanticModel.For(node).GetTypeInfo(node.Expression, CancellationToken).Type!;
string resourceName = HlslKnownTypes.GetMappedName(resourceType);
// Create a static method to get a specified dimension for a target resource type.
@@ -488,7 +488,7 @@ internal sealed partial class ShaderSourceRewriter(
InvocationExpressionSyntax updatedNode = (InvocationExpressionSyntax)base.VisitInvocationExpression(node)!;
if (SemanticModel.For(node).GetOperation(node) is IInvocationOperation { TargetMethod: IMethodSymbol method } operation)
if (SemanticModel.For(node).GetOperation(node, CancellationToken) is IInvocationOperation { TargetMethod: IMethodSymbol method } operation)
{
if (method.IsStatic)
{
@@ -625,7 +625,7 @@ internal sealed partial class ShaderSourceRewriter(
updatedNode = updatedNode.WithRefKindKeyword(Token(SyntaxKind.None));
// Track and rewrite the discarded declaration
if (SemanticModel.For(node).GetOperation(node.Expression) is IDiscardOperation operation)
if (SemanticModel.For(node).GetOperation(node.Expression, CancellationToken) is IDiscardOperation operation)
{
TypeSyntax typeSyntax = ParseTypeName(HlslKnownTypes.TrackType(operation.Type!, DiscoveredTypes));
string identifier = $"__implicit{this.implicitVariables.Count}";
@@ -645,7 +645,7 @@ internal sealed partial class ShaderSourceRewriter(
BaseObjectCreationExpressionSyntax updatedNode,
TypeSyntax targetType)
{
if (SemanticModel.For(node).GetOperation(node) is IObjectCreationOperation { Constructor: IMethodSymbol constructor, Type: INamedTypeSymbol { TypeKind: TypeKind.Struct } typeSymbol })
if (SemanticModel.For(node).GetOperation(node, CancellationToken) is IObjectCreationOperation { Constructor: IMethodSymbol constructor, Type: INamedTypeSymbol { TypeKind: TypeKind.Struct } typeSymbol })
{
DiscoveredTypes.Add(typeSymbol);
+2 -2
ファイルの表示
@@ -54,7 +54,7 @@ internal sealed partial class StaticFieldRewriter(
MemberAccessExpressionSyntax updatedNode = (MemberAccessExpressionSyntax)base.VisitMemberAccessExpression(node)!;
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression) &&
SemanticModel.For(node).GetOperation(node) is IMemberReferenceOperation operation)
SemanticModel.For(node).GetOperation(node, CancellationToken) is IMemberReferenceOperation operation)
{
// Track and replace constants
if (operation is IFieldReferenceOperation fieldOperation &&
@@ -96,7 +96,7 @@ internal sealed partial class StaticFieldRewriter(
{
InvocationExpressionSyntax updatedNode = (InvocationExpressionSyntax)base.VisitInvocationExpression(node)!;
if (SemanticModel.For(node).GetOperation(node) is IInvocationOperation operation &&
if (SemanticModel.For(node).GetOperation(node, CancellationToken) is IInvocationOperation operation &&
operation.TargetMethod is IMethodSymbol method &&
method.IsStatic)
{