From 0356a104a3bd0bca7979ddee3ddd663d4d529fef Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Wed, 7 Jun 2023 09:40:22 -0700 Subject: [PATCH 1/2] wip --- .../gen/ComInterfaceGenerator/ComInterfaceInfo.cs | 2 +- .../ContainingSyntaxContext.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs index 31db875d638d48..36edf93f8e51d8 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs @@ -190,7 +190,7 @@ private static bool TryGetGuid(INamedTypeSymbol interfaceSymbol, InterfaceDeclar public override int GetHashCode() { - // ContainingSyntax and ContainingSyntaxContext do not implement GetHashCode + // ContainingSyntax does not implement GetHashCode return HashCode.Combine(Type, TypeDefinitionContext, InterfaceId); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContainingSyntaxContext.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContainingSyntaxContext.cs index 69b2e1c02b58c5..59028310e6ff32 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContainingSyntaxContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContainingSyntaxContext.cs @@ -79,7 +79,7 @@ public override int GetHashCode() int code = ContainingNamespace?.GetHashCode() ?? 0; foreach (ContainingSyntax containingSyntax in ContainingSyntax) { - code ^= containingSyntax.Identifier.Value.GetHashCode(); + code = HashCode.Combine(code, containingSyntax.Identifier.Value); } return code; } From 40147b38a5e6462f93e8c9a172f76534ac134603 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Wed, 7 Jun 2023 09:54:10 -0700 Subject: [PATCH 2/2] Use HashCode.Combine instead of xor-ing hashes --- .../gen/ComInterfaceGenerator/ComInterfaceInfo.cs | 2 +- .../gen/Microsoft.Interop.SourceGeneration/ManagedTypeInfo.cs | 2 +- .../ManualTypeMarshallingHelper.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs index d858214b25d3d3..ccc947c65f9298 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs @@ -193,7 +193,7 @@ private static bool TryGetGuid(INamedTypeSymbol interfaceSymbol, InterfaceDeclar public override int GetHashCode() { // ContainingSyntax does not implement GetHashCode - return HashCode.Combine(Type, TypeDefinitionContext, InterfaceId); + return HashCode.Combine(Type, ThisInterfaceKey, BaseInterfaceKey, TypeDefinitionContext, InterfaceId); } public bool Equals(ComInterfaceInfo other) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManagedTypeInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManagedTypeInfo.cs index 193dab83f8f764..366e13f61c5247 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManagedTypeInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManagedTypeInfo.cs @@ -25,7 +25,7 @@ public virtual bool Equals(ManagedTypeInfo? other) public override int GetHashCode() { - return FullTypeName.GetHashCode() ^ DiagnosticFormattedName.GetHashCode(); + return HashCode.Combine(FullTypeName, DiagnosticFormattedName); } protected ManagedTypeInfo(ManagedTypeInfo original) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManualTypeMarshallingHelper.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManualTypeMarshallingHelper.cs index a714ff4c43ede8..439c2b3e46d106 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManualTypeMarshallingHelper.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManualTypeMarshallingHelper.cs @@ -37,7 +37,7 @@ public override int GetHashCode() int hash = 0; foreach (KeyValuePair mode in Modes) { - hash ^= mode.Key.GetHashCode() ^ mode.Value.GetHashCode(); + hash = HashCode.Combine(hash, mode.Key, mode.Value); } return hash; }