-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Conversation
@jamesqo, would you have to add it in coreclr as well? Or maybe just add an ApiCompatBaseline.txt (example: https://github.com/dotnet/corefx/blob/master/src/System.IO/src/ApiCompatBaseline.txt). From CI: |
@ahsonkhan I already made such a PR at dotnet/coreclr#9923; @danmosemsft wanted me to submit the matching tests in corefx before the coreclr implementation was merged. This PR will fail CI until that is merged. |
Got it. Thanks for clarifying :) |
@jamesqo I added "Fixes #1942" to top post to enable auto-closing upon merge. Please shout out if it is wrong. |
Just curious, where does the XML documentation go for this new method? |
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.
LGTM. When we ingest the new coreclr with your changes you'll need to update the uapaot baseline file so that you don't get any failures in CI in the Build for all configurations.
You can do that by running:
msbuild src\System.Collections\src\System.Collections.csproj /p:BaselineAllApiCompatError=true /p:TargetGroup=uapaot
Thanks @jamesqo
@@ -33,5 +65,4 @@ public void Dictionary_Generic_Constructor_IEnumerable_IEqualityComparer(int cou | |||
Assert.Equal(collection, copied); | |||
} | |||
} | |||
|
|||
} |
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.
nit: end of line
I'm not sure because I don't work at Microsoft. @karelz Would you know? |
@TylerBrinkley do you mean /// comments docs? |
@karelz yes. |
I poked at the topic in December. The story is not 100% clear yet (or rather I didn't quite like the story I heard and I plan to poke at it more ;-)). So, that's where we are. Does it help? Do you have any immediate concerns or questions? |
@karelz, does that mean new APIs provided in .NET Core implemented in CoreCLR repo will not have XML comments documentation for the time being as those APIs are not in Net FX or Net Standard? |
@TylerBrinkley I assume that at certain point (before shipping) we will create the documentation and also add it into IntelliSense. |
I merged the implementation so we should be able to merge this in a day or so if it gets okayed |
TKey key = CreateTKey(seed: count); | ||
TValue value = dictionary.ContainsKey(key) ? dictionary[key] : default(TValue); | ||
int originalCount = dictionary.Count; | ||
bool alreadyContainsKey = dictionary.ContainsKey(key); |
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.
Why call ContainsKey(key) twice?
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.
Now that GetValueOrDefault
is in I no longer have to 😄
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.
What does it have to do with GetValueOrDefault? Why did you ever need to call it twice?
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.
You could do:
bool alreadyContainsKey = dictionary.ContainsKey(key);
TValue value = alreadyContainsKey ? dictionary[key] : default(TValue);
...
Assert.Equal(!alreadyContainsKey, dictionary.TryAdd(key, default(TValue)));
I'm with @stephentoub that there is no need in calling ContainsKey(key)
twice.
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.
What does it have to do with GetValueOrDefault?
TValue value = dictionary.GetValueOrDefault(key)
Why did you ever need to call it twice?
I didn't think it mattered because this is test code. Are you concerned about code duplication in calling the method twice?
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.
Are you concerned about code duplication in calling the method twice?
That it's confusing seeing it called twice when it's not necessary.
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.
@stephentoub Ok. Will try to keep in mind for later PRs
Assert.Equal(alreadyContainsKey ? originalCount : originalCount + 1, dictionary.Count); | ||
Assert.Equal(dictionary[key], value); | ||
|
||
if (!dictionary.Any()) |
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.
In what situation will Any here return false?
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.
Was a logical mistake on my part. Updated
return; | ||
} | ||
|
||
// It's unlikely that randomly generated data will already be in the dictionary, |
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 don't understand this comment... we already added key to the dictionary, so don't we know it's in there?
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.
Good idea, I should have thought of simply using the key that was added instead of finding a new key.
As an aside @jamesqo if you want you could follow up with issue(s) for places you believe it would be worthwhile for us to start using this API. |
Coreclr should now be updated to have your changes. So you can move forward on updating this one @jamesqo |
@safern I am busy as of late, so I might not have time to respond to @stephentoub's feedback and fix the conflicts for a day or so. |
@jamesqo the failures in CI are because the new API is not implemented in uap yet but it is in the contract. To fix that you need to do a baseline by running: and update the PR with the changes to the ApiCompatBaseline.uapaot.txt file. |
@safern Will the failures be fixed if I submit a PR to the corert Dictionary? |
I think the answer is yes please do, but meantime update the baseline to unblock this PR. |
+1. @jamesqo please update the baseline so that we can unblock this PR and not wait to another PR in other repo and when you do the PR in CoreRT and it is ingested then we can update the baseline. |
@danmosemsft I have already submitted a corert PR, actually: dotnet/corert#2926 How long does it take for the corert build to get updated? (/cc @jkotas) It'd be preferable to avoid adding more changes and submitting another PR to delete them later. |
@jamesqo after commit to CoreRT I believe they have to get ported to our internal "Project N" repo (where we do UWP runtime work) after which a bot puts up a PR like #16866 The baselines don't trigger an error if they have unnecessary lines, so there'll be no need to remove the excess entries later -- it will happen sooner or later -- and that's why we don't generally wait for such codeflow. |
Seems like it has been answered already, but you do want to update the baseline as part of this PR since even if you have the corert change merged, it will take some time (usually around a day) for ProjectN to produce a new Targeting pack and then for us to ingest it. Once we do that, we can update the baseline that you will change here. |
TKey key = CreateTKey(seed: count); | ||
TValue value = dictionary.GetValueOrDefault(key); | ||
int originalCount = dictionary.Count; | ||
bool alreadyContainsKey = dictionary.ContainsKey(key); |
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.
In what situation will this already contain the key? And isn't / shouldn't this be deterministic? Seems like the test should either assert that it contains the key or assert that it doesn't, based on the test's construction, rather than having to account for the possibility that it may or may not.
Even if you can't predict whether GenericIDictionaryFactory(count) will include the relevant key, we can still set up the test to ensure the key isn't there, e.g.
var dictionary = (Dictionary<TKey, TValue>)GenericIDictionaryFactory(count);
TKey key = CreateTKey(seed: count);
dictionary.Remove(key);
int originalCount = dictionary.Count;
TValue value = CreateTValue(seed: count);
Assert.True(dictionary.TryAdd(key, value));
Assert.Equal(originalCount + 1, dictionary.Count);
Assert.Equal(dictionary[key], value);
Assert.False(dictionary.TryAdd(key, default(TValue)));
Assert.Equal(originalCount + 1, dictionary.Count);
Assert.Equal(dictionary[key], value);
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.
You're right, it's probably not wise to have code that we're unsure will run floating around. Updated.
LGTM. Thanks, @jamesqo. |
* Exposure/implementation of Dictionary.TryAdd Commit migrated from dotnet/corefx@fa66c2e
This is the matching PR for dotnet/coreclr#9923.
Fixes #1942
/cc @stephentoub, @ianhays, @safern, @danmosemsft