-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Allow parameterized arrays to be differentiated using value comparison (Fixes #2838) #2886
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
Conversation
|
2 issues I have with this. Hashes should not be used to determine equality, as you mentioned they can collide. If we really want to go down this road, we should probably refactor the system to get it correct. Users may be surprised to see it work for arrays, but not lists and other collection types. I wonder if we should just leave it up to the user somehow (I'm not sure if the current system lets users override it already). |
|
I agree with the hashing equality thing and that we probably refactor to not use ValueText On the docs there is a snippet on wrapping things like arrays and other collections which don't have signatures built in to their ToString in a custom class that provides a unique ToString, so maybe this is a wontfix? |
|
On the other hand I could bring back my old ParameterComparer code that worked for arrays via StructuralComparer (so we could probably get it to work with most collections through LINQ conversions) and refactor the way logical groups are organized (to go for object comparison rather than ValueInfo comparsion) |
|
Well, looking at the OP again, it looks like the display value of the text is not being taken into account for the array comparisons, so that should be fixed at least (so it will at least take length into account). I also see that it shows multi dimensional arrays as single dimension, so that should also be fixed. But probably yeah we leave the true equality comparisons as won't fix, and the user can wrap it in a struct that implements |
I'm open to trying that out. |
I'll try this first and otherwise will just go for fixing #2838 Closing this PR for now since both changes would go in a different direction. |
Solves a larger problem dealing with array comparison that fixes #2838
Previous Behavior
In the following example,
the arguments
int[] { 1, 2, 3 }andint[] { 2, 3, 4 }would not be recognized as different because theirParameterInstances.ValueInfoproperty--whichDefaultOrdereruses to generate logical groups--depended onobject.ToString(), which for an array just provides the type and length of the array (in this case, they were equal, so the library interpreted them as the same argument). Because they were seen as the same, the cases wherearr = { 1, 2, 3 }andarr = { 2, 3, 4 }were not separated into different logical groups and the runtime ratio for all cases was calculated with respect to the first caseAcceptsArrays({ 1, 2, 3 }). The desired behavior would be for the cases with corresponding arguments to be grouped properly and have the baseline runtime calculated once forarr = { 1, 2, 3 }and another time forarr = { 2, 3, 4 }.Solution
Have
ParameterInstances.ValueInfodepend on a customizableToValueText(which eventually propagates down to a new propertyIParam.ValueText) rather thanToString(). For most param types,IParam.ValueTextwill point toIParam.ValueText, but for arrays, it will contain extra information likeArray.Rankas well as a hash computed based off of the array's elements to properly distinguish between different-valued arrays of the same size.Downsides of this approach
New Behavior
Benchmark cases accepting an array parameter or argument will be grouped by array values rather than just length.
The new test case ArrayArgumentsCanBeGrouped tests for this behavior.