Commit Graph
806 Commits
Author SHA1 Message Date
Stephen Toub d84115f52f Enable IDE0029 (Use coalesce expression) (#70506)
* Enable IDE0029 (Use coalesce expression)

* Address PR feedback and a few missed cases
2022-06-10 09:33:19 -04:00
Stephen Toub 9dfbc5bd7c Remove unnecessary CA1052 suppressions (#70512)
The analyzer bug was fixed.
2022-06-10 06:07:54 -04:00
Buyaa Namnan 61ca87cb48 Update analyzer version and fix new findings (#70157) 2022-06-09 15:25:37 -07:00
Stephen Toub 76b5b76ceb Enable IDE0074 (Use compound assignment) (#70402) 2022-06-08 21:23:35 -07:00
Shay Rojansky be4d292eaf Implement DbDataSource (#70006)
Closes #64812
2022-06-06 16:10:15 +02:00
Eric Erhardt 37a0d9fd6b Fix Stream.ReadAtLeast perf regression in DataContractSerializer (#69879)
* Fix Stream.ReadAtLeast perf regression in DataContractSerializer

#69272 changed DCS to no longer call Stream.Read inside a loop, but instead call the new ReadAtLeast method. ReadAtLeast only takes a Span<byte>, and not a byte[]. This caused a regression because the internal encoding stream wrapper classes don't override Read(Span<byte>), so the base implementation is used. The base implementation is slower because it needs to rent a byte[] from the pool, and do 2 copies.

Overriding Read(Span<byte>) on the internal encoding stream wrapper classes allows ReadAtLeast to be just as fast.

Fix #69730

* Add Span overloads for Stream Read and Write implementations that don't currently override the Span overloads.
2022-05-27 19:16:45 -05:00
55e2378d86 Fix typos (#69537)
* Fix typos

* Fix typo: seperate -> separate

* Rename ApplicationNameSetFromArgument

* Update src/coreclr/vm/methodtablebuilder.cpp

* Update docs/coding-guidelines/clr-code-guide.md

Co-authored-by: Dan Moseley <[email protected]>

* Update src/mono/mono/tests/verifier/make_tests.sh

Co-authored-by: Dan Moseley <[email protected]>
Co-authored-by: Jan Kotas <[email protected]>
2022-05-23 10:14:58 -07:00
Stephen Toub 9260c24914 Add more char.Is* helpers for common ASCII sets (#69318)
* Add more char.Is helpers for common ASCII sets

* Fix hex tests
2022-05-18 11:04:39 -04:00
Stephen Toub 20120e0d1c Improve some use of Regex (#68961)
- Use IsMatch instead of Match(...).Success
- Use EnumerateMatches when Index/Length are needed but not captures
- Remove Regex that could just be IndexOf
2022-05-14 17:55:38 -04:00
Levi Broderick 52fd1a576e Call simpler overloads of Substring and Slice (#68937) 2022-05-10 23:23:22 -07:00
Adeel Mujahid 4141913109 Fix typos (#69011) 2022-05-07 11:55:53 -07:00
Stephen Toub aeb79b40dc Remove some unnecessary StringBuilder use (#68768)
* Remove some unnecessary StringBuilder use

* Fix missing using and typos
2022-05-03 22:51:28 -04:00
Viktor Hofer 24cabc6eb0 Update solution files to include missing deps (#68668) 2022-05-02 20:14:05 +02:00
Eric StJohn 0e84780fd2 Fixing API compat issues between ref/src for attributes on properties (#68432)
* Fixing API compat issues between ref/src for attributes on properties

* Fix some build breaks due to obsoleted API

* Fix remaining attribute inconsistencies

* Update API compat baselines for the shared framework.

* Temporarily suppress ApiCompat baseline validation

This will allow us to ensure the codebase is ready to ingest the arcade
fix to ApiCompat.

* Fix usage of obsolete API in Data.Common tests
2022-04-30 07:29:14 -07:00
Viktor HoferandJeremy Barton ba055bd94e Minimize the build graph by deleting unnecessary references (#68603)
* Minimize the build graph by deleting references

Minimizing projects' dependency graph. There are tons of unnecessary
Reference and ProjectReference items which aren't required anymore as
the referenced projects became full facade assemblies. Removing those
from a leaf's graph makes the graph smaller and therefore the project's
evaluation and build faster.

* Update src/libraries/System.Net.Quic/ref/System.Net.Quic.csproj

Co-authored-by: Jeremy Barton <[email protected]>

* Update Versions.props

Co-authored-by: Jeremy Barton <[email protected]>
2022-04-28 15:04:26 +02:00
Eric Erhardt 18be907176 Change Nullable to default to enable in libraries src and ref projects (#68102)
* Change the default Nullable to enabled for src projects

* Set Nullable=enable as the default for ref projects

* Fixup merge conflicts

* Disable nullable on shim projects and EventLog.Messages

* Set Nullable to blank on EventLog.Messages

This way no CodeAnalysis attributes are emitted into the assembly.
2022-04-25 11:15:37 -05:00
Stephen Toub 5d47558f70 Delete some dead code (#68333) 2022-04-21 18:47:21 -04:00
Stephen Toub 46871b8541 Enable new CA1311 (ToLower/Upper culture) and CA1852 (seal internal/private types) rules (#68268)
* Enable new CA1311 (ToLower/Upper culture) and CA1852 (seal internal/private types)

CA1311 flagged a few issues, all addressed by using ToLowerInvariant/ToUpperInvariant.

CA1852 flagged a bunch that previous cleanups around sealing types missed or that are new since.  Sealing types then highlighted places where protected or virtual members were being exposed unnecessarily, so those were fixed, too.  Adding sealed to things also highlighted some discrepancies in the order of "unsafe sealed" keywords, where the vast majority in the repo were "sealed unsafe", so I fixed the few that weren't.

* Address PR feedback and fix more CI failures

* Fix unit test build error
2022-04-21 16:22:53 -04:00
Stephen Toub 215b39abf9 Remove usage of !! from dotnet/runtime (#68178)
* Remove usage of !! from dotnet/runtime

- Use ArgumentNullException.ThrowIfNull instead where possible.  It's only usable for projects that only target .NET 6+, and it can't be used in places like this(...) or base(...).
- In other cases, if the project already has a ThrowHelper, augment it for null as needed and use that.
- For most of the extensions projects, add a ThrowHelper.ThrowIfNull that replicates ArgumentNullException.ThrowIfNull.
- For everything else, just use "throw new".

* Address PR feedback

* Address PR feedback

* Remove false positives from searches

* Address PR feedback
2022-04-21 13:25:52 -04:00
Viktor Hofer f4931fe0e5 Delete dead code (#67648) 2022-04-10 15:48:47 -07:00
Stephen Toub b2e494c6ba Enable recently added analyzers (and fix some violations) (#67292) 2022-03-30 06:55:28 -04:00
Theodore Tsirpanis a56b1066be Use generic Enum methods in more places. (#67147) 2022-03-26 12:34:21 -07:00
Marek Safar 6a889d2342 Enable CA1822 (Mark members as static) analyzer (#66333) 2022-03-25 12:06:33 +01:00
Elinor Fung a0635832f1 Rename DllImportGenerator project to LibraryImportGenerator (#66029) 2022-03-03 22:17:23 -08:00
Sven Boemer 6246f84506 Run trim analyzer (#65870)
* Use SDK logic for IsTrimmable

* Address some analyzer warnings

* Disable analyzer when baseline suppressions exist

* Don't mark unannotated test project as trimmable

* Add nativeaot annotations

* Add suppression in windows-only code

* Import illink.targets only when trimming mobile tests

* Don't run analyzer on unannotated windows OOBs

* PR feedback

Use pragma instead of UnconditionalSuppressMessage
2022-03-03 14:22:30 -08:00
Theodore TsirpanisandGünther Foidl d579527765 Use generic Enum methods when possible. (#64850)
* Use generic `Enum` methods when possible.

* Update src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ToolboxItemFilterAttribute.cs

Co-authored-by: Günther Foidl <[email protected]>

Co-authored-by: Günther Foidl <[email protected]>
2022-03-02 11:27:18 -05:00
Michael Ketting ac246b17f3 Improve nullability for TypeConverter.CanConvertTo (#63874)
The nullability of parameter 'destinationType' in
TypeConverter.CanConvertTo(...) was changed from
not-nullable to nullable during the development of .NET 6.

Since a destination type supported by this TypeConverter
can never be null, a NotNullWhenAttribute is added to the
'destinationType' parameter when the result value of
TypeConverter.CanConvertTo(...) is 'true'.

Fix #63186
2022-03-01 12:43:17 -06:00
Viktor Hofer 7671b5084a Use TargetFramework singular for tests
Use TargetFramework instead of TargetFrameworks property whenever a
test project targets a single target framework only.
This avoid unnecessary outer builds and evaluations and makes the build
faster.
2022-02-24 12:32:04 +01:00
Viktor Hofer febaf76743 Fix slngen.proj and update solution files (#65711)
* Fix slngen.proj

The SolutionName property is defined by the SDK and hence the condition was always true. Also the star (*) didn't expand when using the ValurOrDefault msbuild function. Fixing this by using a different name `SolutionNameOverride` and avoiding the ValueOrDefault msbuild function.

* Update solution files

Updating the solution files as those changed because of
microsoft/slngen@cb57e28 and apparently the solution files never were
updated.
2022-02-22 17:18:54 +01:00
WraithandVlad Brezae ddb22ef2ac Remove S.R.CS.Unsafe and Intrinsify Unsafe (#64861)
* private assemblies moved from Internal to System Runtime.CompilerServices

* reformat existing unsafe vm intrinsics

* implement Copy, CopyBlock, CopyBlockUnaligned, InitBlock, InitBlockUnaligned, Unbox, Add, Subtract, SubtractByteOffset

* remove System.Runtime.CompilerServices.Unsafe il project and replace with forward only cs project

* change all ilproj references to csproj

* remove nativeaot Unsafe

* add conditional package reference for S.R.CS.Unsafe on netcoreapp 6.0

* regenerate solutions

* mono interp

* [mono][interp] Implement Copy and Unbox intrinsics

* [mono][jit] Implement Copy and Unbox intrinsics

Co-authored-by: Vlad Brezae <[email protected]>
2022-02-19 21:50:14 -08:00
Shay Rojansky bda8c9163a Obsolete and put SerializationFormat.Binary behind an appcontext switch (#65139)
Part of #39289
2022-02-12 14:03:18 +01:00
Viktor Hofer 20e8f905d0 Don't use Targets* helper properties in libs (#64500)
* Don't use Targets* helper properties in libs projs

This change makes it possible to migrate 200+ (ref+src) projects to use
TargetFramework instead of TargetFrameworks which avoids the additional
outer build evaluation and invocation which ultimately makes the overall
build faster.

Targets* properties (i.e. TargetsWindows, TargetsAnyOS, TargetsUnix,
etc.) rely on the TargetFramework property which usually are set
inside a project. The TargetFramework property is only
available before a project specifies it if it's explicitly set in a props
file or if the project is cross-targeting and the outer-build dispatches
into the inner-build. During the dispatch, the TargetFramework property
is passed in as a global property.

Until now that behavior wasn't a problem because every libraries project
cross-targeted (by setting the TargetFrameworks property) even though
many only include a single TargetFramework (i.e. NetCoreAppCurrent).

To allow projects to use the TargetFramework property instead of
TargetFrameworks, the Targets* helper properties can't be calculated
anymore early in a props file as the TargetFramework property isn't set
at that time.

In general, the guidance by the SDK/msbuild team is to not read from the
TargetFramework property before the project sets it
(in a property group). That effectively means that the TargetFramework
property shouldn't be used in props files at all.

Therefore these helper properties can't be used anymore for property
conditions and I'm replacing their usage with TargetPlatformIdentifier
comparisons for both properties and items.
In nearly all cases, the Targets* helper properties can be replaced with
TargetPlatformIdentifier checks on items and in the few cases where
TargetsUnix or TargetsLinux marks multiple tfms as compatible, the exact
tfms must be used instead for the TargetPlatformIdentifier comparison.

Whenever a project needs to condition properties on the platform, I'm
first setting the TargetPlatformIdentifier the same way the SDK sets it
so that the SDK later doesn't need to set it again to avoid the
additional expensive msbuild function call.

* Use TargetFramework singular to avoid outer builds

Use TargetFramework instead of TargetFrameworks property whenever a
projects only targets a single target framework. This avoid unnecessary
outer builds and evaluations and makes the build faster.
2022-02-12 13:07:16 +01:00
Stephen Toub 3ae87395f6 Initial roll out of !! (#64720)
* Bump version of C# compiler

This should be reverted when arcade brings in a new enough compiler.

* Fix a few new warnings from updating compiler

* Enable IDE0190 to employ parameter null checking

* Initial roll out of !!

* Fix more compiler warnings from upgrade, plus some test fixes / reverts

* Fix a few more tests

* Disable profiling test
2022-02-08 16:06:59 -05:00
Viktor Hofer 64f3bae738 Consume renamed TargetFramework package (#64670)
* Consume renamed TargetFramework package

* Rename CoreLibs generator parent dir

Projects under src/libraries/ which are located under a "gen" directory
are automatically treated as source generator projects. Because the
CoreLib generator was placed under a different directory "generators",
it was treated as a RuntimeAssembly which gets binplaced into the
runtime path. The runtime tests then take the assemblies from there and
copy them into their CORE_ROOT directory.

Renaming the CoreLib source generators parent directory fixes that so
that it is treated as source generator and it brings consistency into
src/libraries.
2022-02-03 15:32:50 +01:00
Adam Sitnik 2074477643 Remove some of the unused resource strings (#64379) 2022-01-27 19:21:12 +01:00
Bar Arnon d34c0ff7c1 Add UnreachableException (#63922) 2022-01-26 02:58:21 -07:00
Stephen Toub 0ac0071e45 Implement IEquatable<T> on value types overriding Equals (and enable CA1066/1077) (#63690) 2022-01-24 09:43:25 -05:00
Eric StJohn 1d751ba856 Update XUnit to 2.4.2-pre.22 (#63948)
* Update to Xunit build 2.4.2-pre.13

Also pick up latest pre-release of analyzers

* Disambiguate calls to Assert.Equals(double,double,int)

Xunit added a new Assert overload that caused a lot of ambiguous calls.
https://github.com/xunit/xunit/issues/2393

Workaround by casting to double.

* Fix new instances of xUnit2000 diagnostic

* Workaround xUnit2002 issue with implicit cast

Works around https://github.com/xunit/xunit/issues/2395

* Disable xUnit2014 diagnostic

This diagnostic forces the use of Assert.ThrowsAsync for any async method,
however in our case we may want to test that a method will throw
synchronously to avoid regressing that behavior by moving to the async
portion of the method.

* Use AssertExtensions to test for null ArgumentException.ParamName

Workaround https://github.com/xunit/xunit/issues/2396

* Update to Xunit 2.4.2-pre.22

* Fix another ArugmentException.ParamName == null assert
2022-01-20 10:35:50 -08:00
Marek Safar 6de7147b92 Enable IDE0059 analyzer: Unnecessary assignment of a value (#63340) 2022-01-12 18:10:45 +01:00
Marek Fišera b9d8d846e7 Make test System.Data.Tests.AppDomainsAndFormatInfo.Bug55978 more robust (#63028)
Add explicit 1 minute difference to all datetimes in rows.
2022-01-12 09:39:53 +01:00
Stephen Toub 60012a1092 Remove some unnecessary duplicated checks (#63341)
* Remove unnecessary duplicate check in DeflateManagedStream ctor

* Remove duplicate null check in JsonSerializer.Deserialize

* Delete duplicate check in XmlSerializationWriterILGen.WriteQualifiedNameElement

* Delete duplicate rule check in XmlTreeGen.AutoGenerated
2022-01-05 06:42:27 -05:00
Pavel Savara a73d44f100 [wasm] Testing with NodeJs on CI (#62779)
* enable testing with NodeJS on CI
* Fix task marshal tests.
Co-authored-by: Marek Fišera <[email protected]>
2021-12-18 10:14:01 +01:00
Badre BSAILA ae20c2e149 Remove #ifs in System.ComponentModel.TypeConverter (#62364)
Make 2 scenarios work like they did on .NET Framework:

1. Skipping GuidAttribute and InterfaceTypeAttribute on interfaces.
2. GetExtenderProviders checks `component.Site.Container` for extenders

* Remove #ifs in System.ComponentModel.TypeConverter

* use reflection instead of making internals visible to test assembly

* make pass broken trimming test

* drop reflection
2021-12-07 11:27:54 -06:00
Gérald Barré 42224c6978 Avoid closure for GetOrAdd (#62317) 2021-12-03 00:27:38 -07:00
Adeel Mujahid 03e0187a1a Fix miscellaneous typos (#62062)
* Fix miscellaneous typos

* Cleanup trailing whitespaces
```sh
# git remote add dotnet https://github.com/dotnet/runtime && git pull --rebase dotnet main

if uname 2>/devnull | grep -q Darwin; then
    space=" "
fi

git show --name-only --pretty="" HEAD...dotnet/main |\
    xargs -I{} sh -c "test -f {} && sed -i$space'' 's/[[:space:]]*$//' {}"
```
2021-11-26 16:32:13 -08:00
Viktor Hofer 0964be0ae9 Update slngen and solution files (#60871)
Update slngen tooling to latest stable version and solution files since
a lot changed since the last time they were updated:
- NET7 (removal of older TFMs)
- Source Generators
2021-10-26 21:23:54 +02:00
Andrii Kurdiumov 5588f94924 Remove usused rd.xml files (#59201)
Closes #51112
2021-09-16 16:53:54 -06:00
Viktor Hofer 36b6247cc7 Update solution files for correct ordering of elements (#58655)
With the newest udpate of slngen, the order of elements (configuration, folders, etc.) is in sync with how Visual Studio arranges them.
Also the order is now deterministic.

Based on that, updating all solution files to have the correct ordering of elements. This change also unblocks adding CI protection for
making sure that solution files are up-to-date in regards to their dependencies as slngen is now generating the files deterministically.
2021-09-04 00:16:15 +02:00
Ankit Jain f11c8ff5f5 [wasm] System.Data.Tests - add debug info, to help with the test failure (#56838)
`System.Data.Tests.AppDomainsAndFormatInfo.Bug55978` fails sometimes for
wasm:

```
Assert.Equal() Failure
Expected: 2
Actual:   3

Stack trace
   at System.Data.Tests.AppDomainsAndFormatInfo.Bug55978()
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
```

To debug the issue, this dumps some state when the test fails.

Issue: https://github.com/dotnet/runtime/issues/47968
2021-08-04 20:52:42 -04:00
Jeff Handley 895c99cc50 Remove old fwlink from Obsolete messages and make message improvements (#56690)
* Remove old fwlink from Obsolete messages and make message improvements

* Thorough review and update of Obsolete messages

* Cleanup

* Make messages about unsupported APIs more consistent

* Update RequiresUnreferencedCodeAttribute messages to be consistent between ref and src

* Cleanup

* Cleanup

* Use 'not supported' instead of 'no longer supported'

* Omit unnecessary error:false from Obsolete attributes. Fix message typo.

* Remove old comment

* PR feedback
2021-08-04 14:58:10 -04:00