From 2a58a227233ca71d2149205f7780165fc0873861 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Tue, 18 Jul 2023 09:36:29 +0530 Subject: [PATCH] Different approach for equality check ignoring indices --- .../Framework/DataFlow/AnalysisEntity.cs | 25 ++----------------- ...nalysisEntityBasedPredicateAnalysisData.cs | 2 +- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntity.cs b/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntity.cs index 596ba94b5b..1793798eb2 100644 --- a/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntity.cs +++ b/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntity.cs @@ -204,29 +204,8 @@ or PointsToAbstractValueKind.UnknownNull public bool IsLValueFlowCaptureEntity => CaptureId.HasValue && CaptureId.Value.IsLValueFlowCapture; - internal bool EqualsIgnoringIndices(AnalysisEntity? other) - { - // Perform fast equality checks first. - if (ReferenceEquals(this, other)) - { - return true; - } - - if (other == null || - EqualsIgnoringInstanceLocationId != other.EqualsIgnoringInstanceLocationId) - { - return false; - } - - // Now perform slow check that compares individual hash code parts sequences. - return Symbol.GetHashCodeOrDefault() == other.Symbol.GetHashCodeOrDefault() - && InstanceLocation.GetHashCode() == other.InstanceLocation.GetHashCode() - && InstanceReferenceOperationSyntax.GetHashCodeOrDefault() == other.InstanceReferenceOperationSyntax.GetHashCodeOrDefault() - && CaptureId.GetHashCodeOrDefault() == other.CaptureId.GetHashCodeOrDefault() - && Type.GetHashCodeOrDefault() == other.Type.GetHashCodeOrDefault() - && Parent.GetHashCodeOrDefault() == other.Parent.GetHashCodeOrDefault() - && IsThisOrMeInstance.GetHashCode() == other.IsThisOrMeInstance.GetHashCode(); - } + internal AnalysisEntity WithIndices(ImmutableArray indices) + => new(Symbol, indices, InstanceReferenceOperationSyntax, CaptureId, InstanceLocation, Type, Parent, IsThisOrMeInstance); public bool EqualsIgnoringInstanceLocation(AnalysisEntity? other) { diff --git a/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntityBasedPredicateAnalysisData.cs b/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntityBasedPredicateAnalysisData.cs index 128e988df9..5061463415 100644 --- a/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntityBasedPredicateAnalysisData.cs +++ b/src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntityBasedPredicateAnalysisData.cs @@ -191,7 +191,7 @@ private void ClearOverlappingAnalysisDataForIndexedEntity(AnalysisEntity analysi } if (canOverlap && - entity.EqualsIgnoringIndices(analysisEntity) && + entity.WithIndices(analysisEntity.Indices).Equals(analysisEntity) && CoreAnalysisData.TryGetValue(entity, out var existingValue)) { var mergedValue = ValueDomain.Merge(value, existingValue);