From 9f789d1bb3ffc8e84b872dc5a01c1483c1d8b807 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 3 Jun 2024 02:23:45 +0200 Subject: [PATCH] Remove micro-optimization for old field values --- .../CanvasEffectPropertyGenerator.Execute.cs | 31 ------------------- .../CanvasEffectPropertyGenerator.cs | 5 --- .../Models/CanvasEffectPropertyInfo.cs | 2 -- 3 files changed, 38 deletions(-) diff --git a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs index 1ac2abf1..878468cf 100644 --- a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs +++ b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs @@ -58,37 +58,6 @@ partial class CanvasEffectPropertyGenerator return CanvasEffectInvalidationType.Update; } - /// - /// Checks whether the generated code has to directly reference the old property value. - /// - /// The input instance to process. - /// Whether the generated code needs direct access to the old property value. - public static bool IsOldPropertyValueDirectlyReferenced(IPropertySymbol propertySymbol) - { - // Check OnChanging( oldValue, newValue) first - foreach (ISymbol symbol in propertySymbol.ContainingType.GetMembers($"On{propertySymbol.Name}Changing")) - { - // No need to be too specific as we're not expecting false positives (which also wouldn't really - // cause any problems anyway, just produce slightly worse codegen). Just checking the number of - // parameters is good enough, and keeps the code very simple and cheap to run. - if (symbol is IMethodSymbol { Parameters.Length: 2 }) - { - return true; - } - } - - // Do the same for OnChanged( oldValue, newValue) - foreach (ISymbol symbol in propertySymbol.ContainingType.GetMembers($"On{propertySymbol.Name}Changed")) - { - if (symbol is IMethodSymbol { Parameters.Length: 2 }) - { - return true; - } - } - - return false; - } - public static void WritePropertyDeclarations(EquatableArray properties, IndentedTextWriter writer) { // First, generate all partial property implementations at the top of the partial type declaration diff --git a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.cs b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.cs index 0430b410..2ebcfa07 100644 --- a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.cs +++ b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.cs @@ -45,10 +45,6 @@ public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerato token.ThrowIfCancellationRequested(); - bool isOldPropertyValueDirectlyReferenced = Execute.IsOldPropertyValueDirectlyReferenced(propertySymbol); - - token.ThrowIfCancellationRequested(); - CanvasEffectInvalidationType invalidationType = Execute.GetCanvasEffectInvalidationType(context.Attributes[0]); token.ThrowIfCancellationRequested(); @@ -67,7 +63,6 @@ public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerato Hierarchy: hierarchyInfo, PropertyName: propertySymbol.Name, TypeNameWithNullabilityAnnotations: typeNameWithNullabilityAnnotations, - IsOldPropertyValueDirectlyReferenced: isOldPropertyValueDirectlyReferenced, IsReferenceTypeOrUnconstraindTypeParameter: isReferenceTypeOrUnconstraindTypeParameter, InvalidationType: invalidationType); }) diff --git a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/Models/CanvasEffectPropertyInfo.cs b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/Models/CanvasEffectPropertyInfo.cs index 7deb91a6..e4aed430 100644 --- a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/Models/CanvasEffectPropertyInfo.cs +++ b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/Models/CanvasEffectPropertyInfo.cs @@ -8,13 +8,11 @@ namespace ComputeSharp.D2D1.WinUI.SourceGenerators.Models; /// The hierarchy info for the shader type. /// The type name for the generated property, including nullability annotations. /// The generated property name. -/// Whether the old property value is being directly referenced. /// Indicates whether the property is of a reference type or an unconstrained type parameter. /// The invalidation type to request. internal sealed record CanvasEffectPropertyInfo( HierarchyInfo Hierarchy, string PropertyName, string TypeNameWithNullabilityAnnotations, - bool IsOldPropertyValueDirectlyReferenced, bool IsReferenceTypeOrUnconstraindTypeParameter, CanvasEffectInvalidationType InvalidationType);