Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Expose ConcurrentDictionary GetOrAdd/AddOrUpdate overloads in netcoreapp1.1#13828

Merged
ianhays merged 3 commits intodotnet:masterfrom
justinvp:concurrentdictionary
Dec 14, 2016
Merged

Expose ConcurrentDictionary GetOrAdd/AddOrUpdate overloads in netcoreapp1.1#13828
ianhays merged 3 commits intodotnet:masterfrom
justinvp:concurrentdictionary

Conversation

@justinvp
Copy link
Copy Markdown
Contributor

Port #1783 from future to master. Contributes to #2869.

I cherry-picked (and slightly tweaked) the two relevant commits from the future branch:

  • fffd49f (fixed the conflict due to moved test file)
  • ee5906f (updated to use current throw null; style)

I then added a third commit that cleaned some things up, extracted tests, and exposed the APIs in netcoreapp1.1.

cc: @stephentoub

Adds one overload to each of GetOrAdd and AddOrUpdate.  These overloads accept a generic argument that is passed through to any invocations of the supplied delegates, enabling developers to avoid delegate/closure allocations when more input is needed than just the key or existing value.  For AddOrUpdate, there are two existing overloads with delegates; this only provide a new overload for the one that accepts two delegates.
case 2:
if (s_getOrAddNetCoreApp11 != null)
{
s_getOrAddNetCoreApp11(dict, j);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kinda ugly... I wanted to move the tests for the new APIs out to separate test file (which seems to be the preferred way), but also wanted to keep this particular test intact. This is what I came up with to accomplish that. However, in this case, ifdefs in the tests might be cleaner, and there is some precedent with #13199, for example. @stephentoub, do you have a preference?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would be to implement the new method behavior as extension methods in the test that are compiled in only when testing the older version, and then leave this test itself clean.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@justinvp
Copy link
Copy Markdown
Contributor Author

@ericstj, is there anything you think I should change in this PR to bring it in-line with what you did in #13199?

@@ -5,6 +5,7 @@
<AssemblyVersion>4.0.10.0</AssemblyVersion>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the version not go up if public members are added?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bumped the version (though, I'm not confident I changed it in all the right places). Tests pass locally, but CI is now failing across the board (previously was green) and I'm not sure what the issue is. Hmm.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was as much asking because I'm not confident I bumped the right places on something I'm working on :(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I just followed your lead from your PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well since the last change I tried there was copying something here, that's like Pooh and Piglet hunting Woozles and following their own footprints around a tree.

@justinvp justinvp force-pushed the concurrentdictionary branch 3 times, most recently from d6c0a76 to 64e42cc Compare November 20, 2016 19:26
@justinvp
Copy link
Copy Markdown
Contributor Author

justinvp commented Nov 20, 2016

Since this is adding new APIs, the minor version should be incremented.

What files need to be updated to bump the version to 4.1.0.0?

I tried updating the following:

Tests passed for me locally, but CI was failing across the board and I couldn't find a reason for the failures. So I've reverted the version changes for now (CI is back to green).

@stephentoub
Copy link
Copy Markdown
Member

Thanks, Justin. The src/test changes LGTM. @weshaggard or @joperezr could probably help with the ref/version stuff.

@@ -5,6 +5,7 @@
<AssemblyVersion>4.0.10.0</AssemblyVersion>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do have to upgrade the version at least for the netcoreapp1.1 framework since you are adding API there. To do so, please update src/System.Collections.Concurrent/dir.props to have it's assembly version be 4.1.0.0. Also, you will need to keep this declaration in here, but you will need to add a Condition like:

<AssemblyVersion Condition="'$(TargetGroup)'=='netstandard1.3'">4.0.10.0</AssemblyVersion>

<ItemGroup>
<Project Include="System.Collections.Concurrent.csproj" />
<Project Include="System.Collections.Concurrent.csproj">
<TargetGroup>netcoreapp1.1</TargetGroup>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please make netcoreapp1.1 the default? that wold mean changing the .csproj to have netcoreapp1.1 as the nuget target moniker by default, and in here you will be cross compiling for netstandard1.3 instead. The reason to do this is because you want the default build of the .csproj to be the newest version of it.

<TestTFMs>netcoreapp1.0</TestTFMs>
</Project>
<Project Include="System.Collections.Concurrent.Tests.csproj">
<TargetGroup>netcoreapp1.1</TargetGroup>
Copy link
Copy Markdown
Member

@joperezr joperezr Nov 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<TestTFMs>netcoreapp1.1</TestTFMs>

This is already the default so you don't need it.

@joperezr
Copy link
Copy Markdown
Member

Looks like you are not crosscompiling the src for netcoreapp1.1 which is something that you have to fix. To do this, add a new configuration in your src/System.Collections.Concurrent.builds file for netcoreapp1.1, and then make sure that you are defining the <ContractProject> property for netstandard1.3, since you will need to pass in the targetGroup for that case.

@danmoseley
Copy link
Copy Markdown
Member

@justinvp have you had a chance to address feedback?

@danmoseley danmoseley closed this Nov 29, 2016
@danmoseley
Copy link
Copy Markdown
Member

oops

@justinvp
Copy link
Copy Markdown
Contributor Author

justinvp commented Dec 1, 2016

@danmosemsft, sorry, I haven't had time to work through getting the version incremented. Will try to get to it in the next week or so.

@justinvp
Copy link
Copy Markdown
Contributor Author

justinvp commented Dec 2, 2016

@joperezr, I made changes based on your feedback, but something still isn't right and I'm not familiar enough with the build/packaging to know what needs to be changed to address it.

Here's one of the errors at the end of msbuild.log from one of the CI builds:

D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should support API version 4.1.0.0 on .NETCoreApp,Version=v1.0/win7-x86 but D:\j\workspace\windows_nt_de---4526f5ff\packages\System.Collections.Concurrent\4.3.0\ref\netstandard1.3\System.Collections.Concurrent.dll was found to support 4.0.10.0. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]

Any ideas?

<ItemGroup>
<ProjectReference Include="..\ref\System.Collections.Concurrent.csproj">
<ProjectReference Include="..\ref\System.Collections.Concurrent.builds">
<SupportedFramework>net46;netcore50;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated to <SupportedFramework>netcoreapp1.1;net463;$(AllXamarinFrameworks)</SupportedFramework>

<ItemGroup>
<Project Include="System.Collections.Concurrent.csproj" />
<Project Include="System.Collections.Concurrent.csproj">
<TargetGroup>netstandard1.3</TargetGroup>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure but you many need to remove this netstandard1.3 build configuration as well. It will automatically be harvested from the last stable package.

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'net46_Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'net46_Release|AnyCPU'" />
<ItemGroup Condition="'$(TargetGroup)' == 'netstandard1.3'">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary as this project doesn't build a netstandard1.3 build configuration.

@justinvp
Copy link
Copy Markdown
Contributor Author

justinvp commented Dec 3, 2016

Thanks, Wes. I made changes per your suggestions, but now seeing new errors in msbuild.log:

         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should be supported on .NETFramework,Version=v4.6.3 but has no compile assets. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]
         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should be supported on .NETFramework,Version=v4.6.3 but has no runtime assets. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]
         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should be supported on .NETFramework,Version=v4.6.3/win-x86 but has no compile assets. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]
         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should be supported on .NETFramework,Version=v4.6.3/win-x86 but has no runtime assets. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]
         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should be supported on .NETFramework,Version=v4.6.3/win-x64 but has no compile assets. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]
         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should be supported on .NETFramework,Version=v4.6.3/win-x64 but has no runtime assets. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]
         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should be supported on .NETFramework,Version=v4.6.3/win7-x86 but has no compile assets. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]
         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should be supported on .NETFramework,Version=v4.6.3/win7-x86 but has no runtime assets. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]
         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should be supported on .NETFramework,Version=v4.6.3/win7-x64 but has no compile assets. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]
         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should be supported on .NETFramework,Version=v4.6.3/win7-x64 but has no runtime assets. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]
         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent should support API version 4.1.0.0 on .NETStandard,Version=v1.7 but D:\j\workspace\windows_nt_de---4526f5ff\packages\System.Collections.Concurrent\4.3.0\ref\netstandard1.3\System.Collections.Concurrent.dll was found to support 4.0.10.0. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]
         D:\j\workspace\windows_nt_de---4526f5ff\Tools\Packaging.targets(1096,5): error : System.Collections.Concurrent has mismatched compile (4.0.10.0) and runtime (4.1.0.0) versions on .NETStandard,Version=v1.7. [D:\j\workspace\windows_nt_de---4526f5ff\src\System.Collections.Concurrent\pkg\System.Collections.Concurrent.pkgproj]

Any ideas?

},
"frameworks": {
"netstandard1.3": {}
"netstandard1.3": {},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be netstandard1.7?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, there is no new API for netstandard so this is fine.

<OutputType>Library</OutputType>
<NuGetTargetMoniker>.NETStandard,Version=v1.3</NuGetTargetMoniker>
<NuGetTargetMoniker Condition="'$(TargetGroup)'==''">.NETCoreApp,Version=v1.1</NuGetTargetMoniker>
<DefineConstants Condition="'$(TargetGroup)'==''">$(DefineConstants);netcoreapp11</DefineConstants>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these ever false? The only entry in the builds file has a null TargetGroup.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if we x-compile for netstandard1.3


namespace System.Collections.Concurrent.Tests
{
// Allows the ConcurrentDictionary tests to run on targets that do not have the new GetOrAdd/AddOrUpdate overloads.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? What's the purpose in testing a function that doesn't actually exist in that version?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't as clean to separate out the tests into a separate file in this case. Steve suggested the extension methods. #13828 (comment)

<TargetGroup>netstandard1.3</TargetGroup>
<TestTFMs>netcoreapp1.0</TestTFMs>
</Project>
<Project Include="System.Collections.Concurrent.Tests.csproj">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to set TestTFMs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had that originally, but removed based on feedback from Jose as it's the default. #13828 (comment)

<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.0.14.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I talked with @ericstj and it looks like we intentionally keep AssemblyVersion as it was when we are adding API for core-only. So in this case, I guess that we have to revert this change, and that might solve your build issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case, should the version bump done in #13726 be reverted? cc: @JonHanna

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe so. cc: @ericstj @stephentoub Should we log an issue to track reverting that change and bring the assembly version down again given that api changes were only for netcoreapp1.1?

<ProjectReference Include="..\ref\System.Collections.Concurrent.csproj">
<SupportedFramework>net46;netcore50;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
<ProjectReference Include="..\ref\System.Collections.Concurrent.builds">
<SupportedFramework>netcoreapp1.1;net463;$(AllXamarinFrameworks)</SupportedFramework>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

net463 [](start = 40, length = 6)

Let's remove net463 from here since we are not exposing any new API for it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should also fix your current build issue.

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion Condition="'$(TargetGroup)'=='netstandard1.3'">4.0.10.0</AssemblyVersion>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said on my previous comment on the dir.props file, I misguided you to update this AssemblyVersion, since it looks like we only want to update the AssemblyVersion whenever we expose new API for netstandard and not when we only expose it for netcoreapp. That means that this should go back to being: <AssemblyVersion>4.0.10.0</AssemblyVersion> That should fix your build issue.

@karelz karelz modified the milestone: 1.2.0 Dec 6, 2016
@justinvp justinvp force-pushed the concurrentdictionary branch from 9d4fda1 to a5c20bc Compare December 10, 2016 17:54
@justinvp
Copy link
Copy Markdown
Contributor Author

I reverted the version bump per @joperezr's feedback (#13828 (comment)). CI all green now.

Copy link
Copy Markdown
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. thanks for fixing the version

@justinvp
Copy link
Copy Markdown
Contributor Author

Unless there's any other feedback, this should be good to merge.

@ianhays ianhays merged commit 7d64cf1 into dotnet:master Dec 14, 2016
@justinvp justinvp deleted the concurrentdictionary branch December 14, 2016 21:48
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…nary

Expose ConcurrentDictionary GetOrAdd/AddOrUpdate overloads in netcoreapp1.1

Commit migrated from dotnet/corefx@7d64cf1
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants