diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 8b6c585721754..a8d12e09723e5 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -1500,7 +1500,7 @@ public unsafe struct CORINFO_TYPE_LAYOUT_NODE public bool hasSignificantPadding { get => _hasSignificantPadding != 0; set => _hasSignificantPadding = value ? (byte)1 : (byte)0; } } - public struct CORINFO_SWIFT_LOWERING + public struct CORINFO_SWIFT_LOWERING : IEquatable { private byte _byReference; public bool byReference { get => _byReference != 0; set => _byReference = value ? (byte)1 : (byte)0; } @@ -1529,6 +1529,47 @@ private struct LoweredOffsets public nint numLoweredElements; + public override bool Equals(object obj) + { + return obj is CORINFO_SWIFT_LOWERING other && Equals(other); + } + + public bool Equals(CORINFO_SWIFT_LOWERING other) + { + if (byReference != other.byReference) + { + return false; + } + + // If both are by-ref, the rest of the bits mean nothing. + if (byReference) + { + return true; + } + + return LoweredElements.Slice(0, (int)numLoweredElements).SequenceEqual(other.LoweredElements.Slice(0, (int)other.numLoweredElements)) + && Offsets.Slice(0, (int)numLoweredElements).SequenceEqual(other.Offsets.Slice(0, (int)other.numLoweredElements)); + } + + public override int GetHashCode() + { + HashCode code = default; + code.Add(byReference); + + if (byReference) + { + return code.ToHashCode(); + } + + for (int i = 0; i < numLoweredElements; i++) + { + code.Add(LoweredElements[i]); + code.Add(Offsets[i]); + } + + return code.ToHashCode(); + } + // Override for a better unit test experience public override string ToString() { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler.Tests/SwiftLoweringTests.cs b/src/coreclr/tools/aot/ILCompiler.Compiler.Tests/SwiftLoweringTests.cs index 1487f1b5e3880..21122fec7ffd2 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler.Tests/SwiftLoweringTests.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler.Tests/SwiftLoweringTests.cs @@ -88,6 +88,10 @@ public static IEnumerable DiscoverSwiftTypes() { expected.Offsets[i] = (uint)naturalOffset.AlignUp(size); } + else + { + expected.Offsets[i] = (uint)naturalOffset; + } naturalOffset += size; } }