Mechanical/automated change. The only manual changes were a) removing the two rules from the CodeAnalysis.ruleset file, b) removing spaces from one line of a .targets file that is used to generate a .cs file, and c) reverting the changes in a few test files where the naive replacement happened in the middle of a verbatim string where the whitespace actually mattered.
Commit migrated from https://github.com/dotnet/corefx/commit/09a6e66b0c2b31bd0f6e7e3170537d14027aeed0
* Fix ordering of keywords in member signatures
* Add StyeCop.Analyzers
Most rules are disabled. Many of them we'll want to leave disabled, however there are a handful it'll be good to enable over time.
* Use built-in type alias
* Fix straggling stylecop warnings in all configurations
* Replace tabs with spaces
Commit migrated from https://github.com/dotnet/corefx/commit/a12c557a72988070b8624cc7ecc46899629895c4
* Enable xUnit2000 analyzer
This commit enables xUnit2000 (Constants and literals should be the expected argument) and apply fixes for the existing violating codes.
* a Massive commit fixing xUnit2000
* fixing some 2003 errors
* Fix mistakes
* Fix missed errors for unix
Commit migrated from https://github.com/dotnet/corefx/commit/93d7aa1c1737b6da29d04b78557215e18eb786d4
CancellationToken.Register captures the current ExecutionContext and uses it to invoke the callback if/when it's invoked. That's generally desirable and is the right default, but in cases where we know for certain the callback doesn't care about EC (e.g. we're not invoking any 3rd-party code), we can use UnsafeRegister instead (newly added in 3.0), which skips capturing the ExecutionContext, as if Capture returned null. This helps few a couple of small costs:
- Avoids thread local lookups to capture the current EC.
- Avoids additional delegate invocations and thread local gets/sets to invoke the callback with the captured EC.
- Avoids holding on to the EC in case it's needed, which can potentially keep alive an unbounded amount of state due to AsyncLocals.
Commit migrated from https://github.com/dotnet/corefx/commit/b1a1bfa0997ce35e8540fbbe74276858e315807e
* Auto-generate the reference assemblies
* Add back type forwards.
* Revert "Add back type forwards."
This reverts commit dotnet/corefx@3acf74aabb.
* Add back TypeForwardedTo in .Forward.cs files
* Add new type forward files to the csproj files
* Add back if-defs and move TestUtilities comment from ref to source
* Remove duplicate definitions, delete unnecessary manual files,
* Fix build breaks
* Add back missing AsyncMethodBuilderAttr to S.Runtime ref
* Fix typo between XmlDocument and XPath.XDocument
* Add type forward fild missed from previous commit
* Fix ECDiffieHellmanCngPublicKey internal ctor for netfx 4.6.1
* Remove "this type was moved to comments" from the type forwards.
* Add back the Xml and Debugger* attributes to Xml.ReaderWriter
* Add back struct layout attributes
* Add back attributes missing (highlighted from api compat)
* Add missing toolbox item attribute in s.data.common.
* Add missing struct layout attributes and remove unnecessary additions
* Add back InterfaceTypeAttribute
Commit migrated from https://github.com/dotnet/corefx/commit/16689aa0a933517dc45465fc6edb6223222414a6
It used to be that the CS0420 warning ("a reference to a volatile field will not be treated as volatile") would fire when a volatile was used with an Interlocked.* operation. That warning was unnecessary, as Interlocked.* would itself provide the relevant barriers, and these functions were special cased in Roslyn a long time ago. But there are still lots of places where pragmas disabling the warning have stuck around. I'm deleting them.
Commit migrated from https://github.com/dotnet/corefx/commit/8b3446f4e8ad1a7b19c7298e20396629c6e0092e
Various test projects validate that EventSource data is being appropriately generated. Since these tests can run concurrently with others in the process, they should be done as out-of-process such that they don't interfere with each other, but some test projects aren't doing that. This fixes that, ensuring we're using RemoteInvoke everywhere we should be.
Commit migrated from https://github.com/dotnet/corefx/commit/827f91c666c2b40e078c3f1df7a7e5ab13781eaa
* Moving PlatformDetection to Corefx.Private.TestUtilities assembly
The purpose of this change is to clean up all test projects instead of including the PlatformDetection code inside every test project, we’ll have it in the Corefx.Private.TestUtilities.
I have refactored the PlatformDetection to split the different implementation of Windows and Linux. If we need to do more refactoring there we can do it later as needed.
* Fix Linux BB
* Update the xunit package reference
* Fix wrong condition on one of the tests
* Update the ConditionalFact/Theory to use Type as a parameter
Commit migrated from https://github.com/dotnet/corefx/commit/878e2fcf5a9f1068015e5fada9231088663e3490
Fix Parallel.For* to consistently throw exception upon cancellation
Fix for dotnet/corefx#20093 in master:
- Write the exception to be thrown upon cancellation before setting the canceled state so that the exception will be visible upon cancellation
- Dispose the cancellation token registration before checking the exception so that a late cancellation would never yield an incomplete return status with no exception
Commit migrated from https://github.com/dotnet/corefx/commit/62bfba654acf00e4b0fc0811be057c637b135bba
Parallel.For uses the same code paths to handle its int and long-based overloads, using longs internally for both. Interlocked operations are used to move within the ranges created to partition the input space, and those interlocked operations happen on longs. In 32-bit processes, these long values may end up aligned on 4-byte but not 8-byte boundaries, in which case they can end up spanning two cache lines, which makes Interlocked.Add very slow, and can cause very measurable slow downs when using Parallel.For in a 32-bit process based on where the range objects are allocated and moved by the GC.
This commit fixes this by checking whether the current process is 32-bit and whether each partitioned range can fit in an int. If both are true, we use Interlocked.Add(int, ...) instead of Interlocked.Add(long, ...), only falling back to using Interlocked.Add(long, ...) in a 32-bit process if you actually have enough input to warrant it (e.g. ranges of at least 2B items), which is very rare.
Commit migrated from https://github.com/dotnet/corefx/commit/38b4d99fbe630359a6cc4a1b77badf1dcc204dd5
Now instead of Use*Key a project can instead define the assembly key
in the project (genreally the common dir.pops for a project) using
the AssemblyKey property. The accepted values are Open, ECMA, MSFT,
Test.
This change allows for a repo to set the default key they want to use
for projects. In corefx we have switched the default to use the Open
key instead of the old BuildTools default of MSFT key.
As part of this update we are explicitly setting the AssemblyKey in
all the library projects (although it is really only necessary for
projects that aren't the default).
Also with this change we are updating all the new libraries that have
not yet shipped stable (compared to our 1.1 release) and making them
use the Open key. Which means that for prerelease dependencies there
might be some binary breaking changes to consume.
The following libraries ahven't shipped so there key is being
changed from MSFT to Open:
Microsoft.XmlSerializer.Generator
System.CodeDom
System.Configuration.ConfigurationManager
System.Data.Odbc
System.DirectoryServices
System.DirectoryServices.AccountManagement
System.DirectoryServices.Protocols
System.IO.Ports
System.Json
System.Memory
System.Net.HttpListener
System.Net.Mail
System.Net.ServicePoint
System.Net.WebClient
System.Net.WebProxy
System.Private.Xml
System.Private.Xml.Linq
System.Security.Cryptography.Xml
System.Security.Permissions
System.Transactions.Local
System.Web.HttpUtility
Commit migrated from https://github.com/dotnet/corefx/commit/ac09a797d09502ebab61f7167bb856846602e1e6
The Parallel.For/ForEach/Invoke implementation in desktop uses a task-replicating functionality built into Task. This mechanism was a hold-over from pre-release TPL and was never exposed, nor was it particularly desirable for a situation other than Parallel, and has since been removed. To implement Parallel for corefx, then, a separate replication mechanism was implemented on top of Tasks rather than as part of its implementation, and in doing so it seems a small bug snuck in.
Parallel loops expand across the target scheduler by having creating a single task that participates in the body of the loop; when that task is executed, it creates a "replica" of itself that's scheduled before invoking the actual body of the task. If another thread becomes available to help, it'll pick up that replica and execute it, which will in turn create a replica of itself. And so on.
The problem is that the corefx version is creating that replica with TaskCreationOptions.PreferFairness. The goal of these replicas is that they're only handled when there are threads available to participate in the loop, and other available work should be preferred. So, for example, if a parallel loop is used in the processing of a web request, we want the server/pool to prioritize handling of new incoming requests over having all threads participate in the loop for a single request, and only have threads help out the loop if they're not busy doing anything else. By specifying PreferFairness, Parallel in corefx is putting its tasks into the global thread pool queue, prioritized in a FIFO manner with all other tasks coming into the global queue, and prioritized ahead of other tasks created by the body of the loop itself. Note that the desktop implementation doesn't use PreferFairness.
The fix is simply to change PreferFairness to None when creating the replicas.
Commit migrated from https://github.com/dotnet/corefx/commit/476a12f91ca21bf44762f58946fd3614c1f16f19