Issue #15622 New overload Dictionary.Remove#18109
Conversation
|
Yes it will need the BaselineCompat file for uapaot. Still you will need to port the implementation to dotnet/corert and once that merges and gets consumed in corefx we can remove that baseline, but before that it is needed. |
| dictionary.Add(missingKey, CreateTValue(34251)); | ||
| Assert.True(dictionary.Remove(missingKey, out value)); | ||
| Assert.Equal(count, dictionary.Count); | ||
| Assert.Equal(CreateTValue(34251), value); |
There was a problem hiding this comment.
Instead of calling CreateTValue twice you could create a TValue variable to store it and add it and then compare against that. Also... instead of using a random seed could we use count as a seed or something like that?
There was a problem hiding this comment.
We should also verify that TryGetValue returns false for the key after removal.
There was a problem hiding this comment.
- Used CreateTValue once.
- Actually this was to create and check the value consistency... Changed random seed to
countthat is passed to the test method. - Added TryGetValue
| public void Dictionary_Generic_RemoveKey_DefaultKeyNotContainedInDictionary(int count) | ||
| { | ||
| Dictionary<TKey, TValue> dictionary = (Dictionary<TKey, TValue>)GenericIDictionaryFactory(count); | ||
| TValue value = CreateTValue(12345); |
There was a problem hiding this comment.
Fixed using count passed to the method.
| else | ||
| { | ||
| Assert.Throws<ArgumentNullException>(() => dictionary.Remove(default(TKey))); | ||
| Assert.Equal(CreateTValue(12345), value); |
There was a problem hiding this comment.
Oops... The lines 204 and 205 were supposed to be like this...
Assert.Throws<ArgumentNullException>(() => dictionary.Remove(default(TKey), out outValue));
Assert.Equal(refValue, outValue);Where outValue was supposed to be assigned with refValue and after the exception the assert was to ensure that the outValue hasn't changed from refValue. This is based on the knowledge that the Remove(K, V) method (just like existing Remove(K) method) doesn't assign default(TValue) to output parameter in the Null Key case.
Changed the code...
Edited:
Sorry, I have struck out the factually incorrect information that I quoted above. I think I need to change the Remove(K, V) API implementation to set the output parameter value to default(TValue) in case it is about to throw exception due to Null key. Not assigning default to output parameter had broken the convention that callee always sets output parameter on all paths, either to expected value or to default. [I am not able to recollect why I didn't set it to default(TValue) in first place, but I do remember that I had done it consciously based on something that I had observed at that time...] Keeping @jkotas @danmosemsft in loop for the change that I will be doing at this place.
| TValue value = default(TValue); | ||
|
|
||
| if (!dictionary.ContainsKey(missingKey)) | ||
| dictionary.Add(missingKey, CreateTValue(5341)); |
There was a problem hiding this comment.
Instead of checking if the key exists before adding, we could probably use dictionary.TryAdd
| if (!dictionary.ContainsKey(missingKey)) | ||
| dictionary.Add(missingKey, CreateTValue(5341)); | ||
| Assert.True(dictionary.Remove(missingKey, out value)); | ||
| Assert.Equal(CreateTValue(5341), value); |
|
@safern could you please help me with the path for BaselineCompat file... couldn't locate file with this name in CoreFx / CoreClr repos... Thank you! |
You will need to run |
|
@safern hmmm to clarify a bit more. I'm not having local compilation issues. I was referring to any ApiCompatBaseline.uapaot.txt file that needs to be manually edited ( @stephentoub ) had pointed me to one as mentioned in previous comment (the LazyInitializer task that I had done) ... Between, I ran the above command but it created following two files which are not checked in into the repo. So it seems that in this particular case there is no ApiCompatBaseline.uapaot.txt or equivalent file to be edited and checked in for the new overload that I added into CoreClr...? Thanks. |
|
@safern for your q. |
|
@WinCPP you don't need the baseline anymore since the corert changes should be now ingested as your PR on that side was merged 2 days ago. So you will just need to do 2 things to fix CI checks.
The second has to be done because the new API that you added is not available in desktop so when building the netfx tests we get a failure saying it can't find that API. So we should only include your tests when testing for netcoreapp. |
|
@safern Thanks for the steps. I will do them. Between, a bit unrelated question. Whenever I get latest changes from dotnet/master for CoreFx using "Update from dotnet/master" button on GitHub client, it creates a merge commit on my branch and adds up the files on changed file list on PR even thought they are just branch updates. Hence @stephentoub had suggested me to squash everything on branch. Are there some special steps that you all follow to not get a Merge commit on the branch... but still have genuine code changes as valid commits? |
|
Thanks @safern. The checks are passing. Please review. |
I don't know about GitHub client, what all (?) of us do is use git.exe, something like if you have changes you would either commit them to mybranch first or stash them temporarily out the way. For your own changes, you can usually just commit as you please and we (almost always) merge your PR to master with squash so it doesn't matter. Also typically people just code review the whole thing not commit by commit. That's what most people do most times. Sometimes it's worth having clean logical separate commits though
|
|
Dunno if @stephentoub has anythign else to say about that. |
|
BTW @WinCPP are you planning to pick up another work item? Need any help selecting? As you know our focus is on Milestone=2.0 right now. |
Sounds about right. I don't use the GitHub standalone client tool, instead using either the GitHub integration with VS or the command-line. For rebasing, I use the command-line, similar to what @safern outlined. And I basically always rebase rather merge when working on a change. |
|
Personally I use a combination of git.exe and SourceTree because then I know what's actually going on. I generally don't use VS for this either as it abstracts a bit high for me also. Each to their own. |
|
I like having different upstreams (one my fork and one dotnet/corefx repo) and I never pull from my master fork branch. I always do:
That will place the commits on MyIssueBranch on top of dotnet/master changes one by one and will merge changes or will ask to solve merge conflicts. Whenever I want to solve conflicts I first squash everything to one commit (to solve conflicts once) and I use VS tool to solve merge conflicts and the command line for everything else. |
|
@safern @danmosemsft @stephentoub thank you for the inputs on Git usage. I will go by pure git.exe instead of GitHub windows client and try as the latter is a bit confusing, especially while working with forks. @danmosemsft I am working on #17118 which should be done in a day (I have left one comment there about optimization) and then will get back to XPath test cases that we previously discussed. Is there something that you would want me to pick up that might help you guys with 2.0...? Aah... I have inputs on #8578 now which is Milestone 2.0 task. I will finish it off as well... |
|
@WinCPP anything 2.0 is great really depends on your interests. if you need help scoping how how complex something might be just ping on the issue. |
* Issue #15622 New overload Dictionary.Remove
|
Some 2.0 tasks where help is appreciated: |
* Issue #15622 New overload Dictionary.Remove
|
@ViktorHofer @karelz I can take up #16640 (2.0 issue) mentioned above before I go back to the performance data collection for PR #18435 (non-2.0 issue)... Please note that #16510 is already closed... |
|
@WinCPP I assigned you to #16640 |
New overload Dictionary<TKey, TValue>.Remove(TKey, out TValue) that
ouputs value associated with the key that is being removed.
Fixes #15622.
Depends on dotnet/coreclr PR #10203
@karelz @danmosemsft @safern @jkotas Please review.