-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
#53285 switch to use MemberInfo.MetadataToken #55801
#53285 switch to use MemberInfo.MetadataToken #55801
Conversation
fix code style
remove whitespace to fix SA1028
return false; | ||
|
||
if (left.Name != right.Name) | ||
if (left.MetadataToken != right.MetadataToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that left is MethodRef and right is MethodDef? (not sure if those are always resolved) that could potentially produce false where it shouldn't.
Also if the token is equal should it just return true? Could arguments differ for same token?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, MetadataToken is unique in the same Module, so when MetadataToken is equal, it can return true. In addition, according to documentation, I am not sure whether it is necessary to judge the unexpected situation. Do you have any suggestions? I will change the code later.
delete redundant judgments, only use MetadataToken and Module for judgment
} | ||
|
||
return true; | ||
return left.Module.Name == right.Module.Name && left.MetadataToken == right.MetadataToken; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The modules can have same name, but different identity. This condition would not work correctly in that case.
Should the whole MethodInfoEqualityComparer type be deleted and the dictionary switched to use the default comparer? It is not clear what this implementation is trying to achieve that the default EqualityComparer would not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default comparator will compare the reference of the object. It cannot be judged correctly when used here, so need to use MethodInfoEqualityComparer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default EqualityComparer will call Equals method to compare the objects:
runtime/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs
Line 135 in 57bfe47
if (y != null) return x.Equals(y); |
MethodInfo.Equals should do exactly what the existing code is trying to achieve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not find information about MethodInfo.Equals
override from Object.Equals
Any feedback? |
It would be useful to understand why a simple |
You are right, |
use Methodinfo.Equals to judge equality use Methodinfo.Equals to judge equality and remove special comparator. Fix #453285
Are there automated tests that verify the original issue and\or that the Equals overload works as expected? |
I will check automated tests and add new tests if necessary. |
I have reviewed the existing automated test cases, and I don’t think there is a need to add new test cases for this change. |
I read the code again, |
The special equality comparer was added in dotnet/corefx#9546 dotnet/corefx#9546 (comment) has more discussion about. I do not think that the arguments in that discussion are valid. In particular, I do not agree that "The default Equality test for MethodInfo is reference equality, not "semantic equality" is true. |
@FatTigerWang Thank you! |
Switch to use MemberInfo.MetadataToken
With #53283, we won't build a netstandard1.x configuration of this library anymore and the code path can be optimized.
Fix #53285