Skip to content

Commit

Permalink
Merge pull request #525 from ElektroKill/fix-reference-compare-sigcom…
Browse files Browse the repository at this point in the history
…parer

Resolve `SigComparer` regression introduced in 4.0
  • Loading branch information
wtfsck authored Sep 2, 2023
2 parents aa9ac47 + 552d570 commit a5cce92
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions src/DotNet/SigComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public sealed class TypeEqualityComparer : IEqualityComparer<IType>, IEqualityCo
/// </summary>
public static readonly TypeEqualityComparer CaseInsensitive = new TypeEqualityComparer(SigComparerOptions.CaseInsensitiveAll);

/// <summary>
/// Compares definitions in same module using reference comparison instead of comparing them by name, signature, etc.
/// </summary>
public static readonly TypeEqualityComparer CompareReferenceInSameModule = new TypeEqualityComparer(SigComparerOptions.ReferenceCompareForMemberDefsInSameModule);

/// <summary>
/// Constructor
/// </summary>
Expand Down Expand Up @@ -96,6 +101,11 @@ public sealed class FieldEqualityComparer : IEqualityComparer<IField>, IEquality
/// </summary>
public static readonly FieldEqualityComparer CaseInsensitiveDontCompareDeclaringTypes = new FieldEqualityComparer(SigComparerOptions.CaseInsensitiveAll);

/// <summary>
/// Compares definitions in same module using reference comparison instead of comparing them by name, signature, etc.
/// </summary>
public static readonly FieldEqualityComparer CompareReferenceInSameModule = new FieldEqualityComparer(SigComparerOptions.ReferenceCompareForMemberDefsInSameModule);

/// <summary>
/// Constructor
/// </summary>
Expand Down Expand Up @@ -147,6 +157,11 @@ public sealed class MethodEqualityComparer : IEqualityComparer<IMethod>, IEquali
/// </summary>
public static readonly MethodEqualityComparer CaseInsensitiveDontCompareDeclaringTypes = new MethodEqualityComparer(SigComparerOptions.CaseInsensitiveAll);

/// <summary>
/// Compares definitions in same module using reference comparison instead of comparing them by name, signature, etc.
/// </summary>
public static readonly MethodEqualityComparer CompareReferenceInSameModule = new MethodEqualityComparer(SigComparerOptions.ReferenceCompareForMemberDefsInSameModule);

/// <summary>
/// Constructor
/// </summary>
Expand Down Expand Up @@ -210,6 +225,11 @@ public sealed class PropertyEqualityComparer : IEqualityComparer<PropertyDef> {
/// </summary>
public static readonly PropertyEqualityComparer CaseInsensitiveDontCompareDeclaringTypes = new PropertyEqualityComparer(SigComparerOptions.CaseInsensitiveAll);

/// <summary>
/// Compares definitions in same module using reference comparison instead of comparing them by name, signature, etc.
/// </summary>
public static readonly PropertyEqualityComparer CompareReferenceInSameModule = new PropertyEqualityComparer(SigComparerOptions.ReferenceCompareForMemberDefsInSameModule);

/// <summary>
/// Constructor
/// </summary>
Expand Down Expand Up @@ -249,6 +269,11 @@ public sealed class EventEqualityComparer : IEqualityComparer<EventDef> {
/// </summary>
public static readonly EventEqualityComparer CaseInsensitiveDontCompareDeclaringTypes = new EventEqualityComparer(SigComparerOptions.CaseInsensitiveAll);

/// <summary>
/// Compares definitions in same module using reference comparison instead of comparing them by name, signature, etc.
/// </summary>
public static readonly EventEqualityComparer CompareReferenceInSameModule = new EventEqualityComparer(SigComparerOptions.ReferenceCompareForMemberDefsInSameModule);

/// <summary>
/// Constructor
/// </summary>
Expand Down Expand Up @@ -487,10 +512,10 @@ public enum SigComparerOptions : uint {
IgnoreMultiDimensionalArrayLowerBoundsAndSizes = 0x800000,

/// <summary>
/// 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.
/// </summary>
DisableCompareReferenceOnlyForMemberDefsInSameModule = 0x1000000,
ReferenceCompareForMemberDefsInSameModule = 0x1000000,
}

/// <summary>
Expand Down Expand Up @@ -541,7 +566,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;

/// <summary>
/// Constructor
Expand Down Expand Up @@ -1482,7 +1507,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;
Expand Down Expand Up @@ -2614,7 +2639,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;
Expand Down Expand Up @@ -2944,7 +2969,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;
Expand Down Expand Up @@ -2991,7 +3016,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;
Expand Down Expand Up @@ -3039,7 +3064,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;
Expand Down

0 comments on commit a5cce92

Please sign in to comment.