Remove several uses of VoidTaskResult (dotnet/coreclr#22238)
authorStephen Toub <stoub@microsoft.com>
Sun, 27 Jan 2019 19:15:08 +0000 (14:15 -0500)
committerJan Kotas <jkotas@microsoft.com>
Sun, 27 Jan 2019 19:15:08 +0000 (11:15 -0800)
commit157d32ae707b44d4a729d14cc4d59b6595aeae65
tree115c42980c8ab91498d45a00cfe4d44a73b398d3
parent70c64d71ea1df4da048830dbd890edd0fc6d54e7
Remove several uses of VoidTaskResult  (dotnet/coreclr#22238)

* Remove defunct netstandard code from ValueTask

* Remove several uses of VoidTaskResult

Currently TrySetResult/Canceled/Exception live on `Task<T>`.  There's no reason `TrySetCanceled` and `TrySetException` need to live there, as they only access state from the base `Task`, and so can be moved down.  `TrySetResult` needs the `TResult`, however in a variety of cases `Task<T>` is used with a `VoidTaskResult`, and for such cases we can just have a parameterless `TrySetResult()` on the base class as well, which can be used any time there is no `TResult` or when `default(TResult)` is the desired result.  This lets us switch several cases where we were using `Task<VoidTaskResult>` to just be `Task`, which saves 8 bytes on the task instance on 64-bit.  It also avoids an Interlocked.Exchange as part of the TrySetResult call.

This primarily affects Task.Delay and the non-generic variants of Task.WhenAll, ValueTask.AsTask(), Task.FromCanceled, and Task.FromException.

Commit migrated from https://github.com/dotnet/coreclr/commit/5d5d680e64769f4807d2e114b74e1304a58822d5
src/libraries/System.Private.CoreLib/src/System/IO/MemoryStream.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs