From 532a392ecf96d4f7b3ec62c0dbdd35d91714d6b3 Mon Sep 17 00:00:00 2001 From: ElektroKill Date: Fri, 1 Sep 2023 18:14:19 +0200 Subject: [PATCH 1/2] Replace faulty flag with `ReferenceCompareForMemberDefsInSameModule` --- src/DotNet/SigComparer.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/DotNet/SigComparer.cs b/src/DotNet/SigComparer.cs index 754ca8a61..aab21ce8d 100644 --- a/src/DotNet/SigComparer.cs +++ b/src/DotNet/SigComparer.cs @@ -487,10 +487,10 @@ public enum SigComparerOptions : uint { IgnoreMultiDimensionalArrayLowerBoundsAndSizes = 0x800000, /// - /// When comparing MemberDefs in same module, comparing reference only can avoid conflict when members have same signature. - /// If this flag is set, these members are compared just like any other members. + /// When comparing MemberDefs in same module, use regular reference comparison instead + /// comparing the signature, name, and other properties. /// - DisableCompareReferenceOnlyForMemberDefsInSameModule = 0x1000000, + ReferenceCompareForMemberDefsInSameModule = 0x1000000, } /// @@ -541,7 +541,7 @@ public struct SigComparer { bool DontProjectWinMDRefs => (options & SigComparerOptions.DontProjectWinMDRefs) != 0; bool DontCheckTypeEquivalence => (options & SigComparerOptions.DontCheckTypeEquivalence) != 0; bool IgnoreMultiDimensionalArrayLowerBoundsAndSizes => (options & SigComparerOptions.IgnoreMultiDimensionalArrayLowerBoundsAndSizes) != 0; - bool CompareReferenceOnlyForMemberDefsInSameModule => (options & SigComparerOptions.DisableCompareReferenceOnlyForMemberDefsInSameModule) == 0; + bool ReferenceCompareForMemberDefsInSameModule => (options & SigComparerOptions.ReferenceCompareForMemberDefsInSameModule) != 0; /// /// Constructor @@ -1482,7 +1482,7 @@ public bool Equals(TypeDef a, TypeDef b) { return true; if (a is null || b is null) return false; - if (CompareReferenceOnlyForMemberDefsInSameModule && InSameModule(a, b)) + if (ReferenceCompareForMemberDefsInSameModule && InSameModule(a, b)) return false; if (!recursionCounter.Increment()) return false; @@ -2614,7 +2614,7 @@ public bool Equals(MethodDef a, MethodDef b) { return true; if (a is null || b is null) return false; - if (CompareReferenceOnlyForMemberDefsInSameModule && InSameModule(a, b)) + if (ReferenceCompareForMemberDefsInSameModule && InSameModule(a, b)) return false; if (!recursionCounter.Increment()) return false; @@ -2944,7 +2944,7 @@ public bool Equals(FieldDef a, FieldDef b) { return true; if (a is null || b is null) return false; - if (CompareReferenceOnlyForMemberDefsInSameModule && InSameModule(a, b)) + if (ReferenceCompareForMemberDefsInSameModule && InSameModule(a, b)) return false; if (!recursionCounter.Increment()) return false; @@ -2991,7 +2991,7 @@ public bool Equals(PropertyDef a, PropertyDef b) { return true; if (a is null || b is null) return false; - if (CompareReferenceOnlyForMemberDefsInSameModule && InSameModule(a, b)) + if (ReferenceCompareForMemberDefsInSameModule && InSameModule(a, b)) return false; if (!recursionCounter.Increment()) return false; @@ -3039,7 +3039,7 @@ public bool Equals(EventDef a, EventDef b) { return true; if (a is null || b is null) return false; - if (CompareReferenceOnlyForMemberDefsInSameModule && InSameModule(a, b)) + if (ReferenceCompareForMemberDefsInSameModule && InSameModule(a, b)) return false; if (!recursionCounter.Increment()) return false; From 552d57055f2be7fdfc2e615f8bce6b47d8cb7969 Mon Sep 17 00:00:00 2001 From: ElektroKill Date: Fri, 1 Sep 2023 18:18:37 +0200 Subject: [PATCH 2/2] Add `CompareReferenceInSameModule` convenience properties --- src/DotNet/SigComparer.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/DotNet/SigComparer.cs b/src/DotNet/SigComparer.cs index aab21ce8d..5fbfca772 100644 --- a/src/DotNet/SigComparer.cs +++ b/src/DotNet/SigComparer.cs @@ -21,6 +21,11 @@ public sealed class TypeEqualityComparer : IEqualityComparer, IEqualityCo /// public static readonly TypeEqualityComparer CaseInsensitive = new TypeEqualityComparer(SigComparerOptions.CaseInsensitiveAll); + /// + /// Compares definitions in same module using reference comparison instead of comparing them by name, signature, etc. + /// + public static readonly TypeEqualityComparer CompareReferenceInSameModule = new TypeEqualityComparer(SigComparerOptions.ReferenceCompareForMemberDefsInSameModule); + /// /// Constructor /// @@ -96,6 +101,11 @@ public sealed class FieldEqualityComparer : IEqualityComparer, IEquality /// public static readonly FieldEqualityComparer CaseInsensitiveDontCompareDeclaringTypes = new FieldEqualityComparer(SigComparerOptions.CaseInsensitiveAll); + /// + /// Compares definitions in same module using reference comparison instead of comparing them by name, signature, etc. + /// + public static readonly FieldEqualityComparer CompareReferenceInSameModule = new FieldEqualityComparer(SigComparerOptions.ReferenceCompareForMemberDefsInSameModule); + /// /// Constructor /// @@ -147,6 +157,11 @@ public sealed class MethodEqualityComparer : IEqualityComparer, IEquali /// public static readonly MethodEqualityComparer CaseInsensitiveDontCompareDeclaringTypes = new MethodEqualityComparer(SigComparerOptions.CaseInsensitiveAll); + /// + /// Compares definitions in same module using reference comparison instead of comparing them by name, signature, etc. + /// + public static readonly MethodEqualityComparer CompareReferenceInSameModule = new MethodEqualityComparer(SigComparerOptions.ReferenceCompareForMemberDefsInSameModule); + /// /// Constructor /// @@ -210,6 +225,11 @@ public sealed class PropertyEqualityComparer : IEqualityComparer { /// public static readonly PropertyEqualityComparer CaseInsensitiveDontCompareDeclaringTypes = new PropertyEqualityComparer(SigComparerOptions.CaseInsensitiveAll); + /// + /// Compares definitions in same module using reference comparison instead of comparing them by name, signature, etc. + /// + public static readonly PropertyEqualityComparer CompareReferenceInSameModule = new PropertyEqualityComparer(SigComparerOptions.ReferenceCompareForMemberDefsInSameModule); + /// /// Constructor /// @@ -249,6 +269,11 @@ public sealed class EventEqualityComparer : IEqualityComparer { /// public static readonly EventEqualityComparer CaseInsensitiveDontCompareDeclaringTypes = new EventEqualityComparer(SigComparerOptions.CaseInsensitiveAll); + /// + /// Compares definitions in same module using reference comparison instead of comparing them by name, signature, etc. + /// + public static readonly EventEqualityComparer CompareReferenceInSameModule = new EventEqualityComparer(SigComparerOptions.ReferenceCompareForMemberDefsInSameModule); + /// /// Constructor ///