Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
Do not check object references for equality after hot reload#73009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
560e4cb
Equality check of type members after hot reload
buyaa-n bfe943b
Apply comments
buyaa-n 76e2b02
Apply feedback
buyaa-n 71e176d
Renamed the propertyName in test
buyaa-n 1b0d414
Compare type instead of module, check MetadataUpdater.IsSupported in …
buyaa-n 621d6f7
Update and use CacheEquals
buyaa-n 97bde09
Apply feedbacks
buyaa-n 11355a4
Use ReferenceEquals
buyaa-n dffe2ab
Merge conflicts
buyaa-n 9d30a95
apply more feedback
buyaa-n 74c8563
Exclude RuntimeParameterInfo
buyaa-n 8ee9566
Update assert methods in test
buyaa-n d4d961c
Update RMethodInfo RConstructorInfo Equals override to fix CI test fa…
buyaa-n b9dc388
Revert "Update RMethodInfo RConstructorInfo Equals override to fix CI…
jkotas ea07c6f
Fix tests
jkotas 06681a8
Update RuntimeConstructorInfo Equals, HashCode similarly
buyaa-n eb9d197
Add reflected type into Equals, check MetadataUpdater.IsSupported in …
buyaa-n 72d21c6
Perf tweaks for Equals and GetHashCode
jkotas cbeb099
Apply suggestions from code review
buyaa-n 4730c9f
Apply feedback
buyaa-n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
11 changes: 9 additions & 2 deletions
11 src/coreclr/System.Private.CoreLib/src/System/Reflection/MdFieldInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8 src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11 src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeConstructorInfo.CoreCLR.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,6 +5,7 @@ | ||
| using System.Diagnostics; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Globalization; | ||
| using System.Reflection.Metadata; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Text; | ||
| using System.Threading; | ||
| @@ -72,7 +73,8 @@ internal RuntimeConstructorInfo( | ||
| RuntimeMethodHandleInternal IRuntimeMethodInfo.Value => new RuntimeMethodHandleInternal(m_handle); | ||
| internal override bool CacheEquals(object? o) => | ||
| o is RuntimeConstructorInfo m && m.m_handle == m_handle; | ||
| o is RuntimeConstructorInfo m && m.m_handle == m_handle && | ||
| ReferenceEquals(m_declaringType, m.m_declaringType); | ||
| internal Signature Signature | ||
| { | ||
| @@ -118,6 +120,13 @@ public override string ToString() | ||
| return m_toString; | ||
| } | ||
| public override bool Equals(object? obj) => | ||
| ReferenceEquals(this, obj) || | ||
| (MetadataUpdater.IsSupported && CacheEquals(obj)); | ||
buyaa-n marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| public override int GetHashCode() => | ||
| HashCode.Combine(m_handle.GetHashCode(), m_declaringType.GetUnderlyingNativeHandle().GetHashCode()); | ||
| #endregion | ||
| #region ICustomAttributeProvider | ||
11 changes: 9 additions & 2 deletions
11 src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1 src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 9 additions & 47 deletions
56 src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.CoreCLR.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -157,56 +157,18 @@ public override string ToString() | ||
| return m_toString; | ||
| } | ||
| public override int GetHashCode() | ||
| { | ||
| // See RuntimeMethodInfo.Equals() below. | ||
| if (IsGenericMethod) | ||
| return RuntimeHelpers.GetHashCodeOfPtr(m_handle); | ||
| else | ||
| return base.GetHashCode(); | ||
| } | ||
| public override bool Equals(object? obj) | ||
| { | ||
| if (!IsGenericMethod) | ||
| return obj == (object)this; | ||
| // We cannot do simple object identity comparisons for generic methods. | ||
| // Equals will be called in CerHashTable when RuntimeType+RuntimeTypeCache.GetGenericMethodInfo() | ||
| // retrieve items from and insert items into s_methodInstantiations which is a CerHashtable. | ||
| RuntimeMethodInfo? mi = obj as RuntimeMethodInfo; | ||
| if (mi == null || !mi.IsGenericMethod) | ||
| return false; | ||
| // now we know that both operands are generic methods | ||
| IRuntimeMethodInfo handle1 = RuntimeMethodHandle.StripMethodInstantiation(this); | ||
| IRuntimeMethodInfo handle2 = RuntimeMethodHandle.StripMethodInstantiation(mi); | ||
| if (handle1.Value.Value != handle2.Value.Value) | ||
| return false; | ||
| Type[] lhs = GetGenericArguments(); | ||
| Type[] rhs = mi.GetGenericArguments(); | ||
| // We cannot do simple object identity comparisons due to generic methods. | ||
| // Equals and GetHashCode will be called in CerHashTable when RuntimeType+RuntimeTypeCache.GetGenericMethodInfo() | ||
| // retrieve items from and insert items into s_methodInstantiations. | ||
| if (lhs.Length != rhs.Length) | ||
| return false; | ||
| public override int GetHashCode() => | ||
| HashCode.Combine(m_handle.GetHashCode(), m_declaringType.GetUnderlyingNativeHandle().GetHashCode()); | ||
| for (int i = 0; i < lhs.Length; i++) | ||
| { | ||
| if (lhs[i] != rhs[i]) | ||
| return false; | ||
| } | ||
| public override bool Equals(object? obj) => | ||
jkotas marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| obj is RuntimeMethodInfo m && m_handle == m.m_handle && | ||
| ReferenceEquals(m_declaringType, m.m_declaringType) && | ||
| ReferenceEquals(m_reflectedTypeCache.GetRuntimeType(), m.m_reflectedTypeCache.GetRuntimeType()); | ||
| if (DeclaringType != mi.DeclaringType) | ||
| return false; | ||
| if (ReflectedType != mi.ReflectedType) | ||
| return false; | ||
| return true; | ||
| } | ||
| #endregion | ||
| #region ICustomAttributeProvider | ||
11 changes: 9 additions & 2 deletions
11 src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.