From b74ea28646e547149b7d6150e6f24b4d9bd9feff Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 30 Nov 2019 16:20:55 -0800 Subject: [PATCH] Update dependencies --- dependencies.props | 6 +- src/Framework/Framework.depproj | 4 +- .../src/JitInterface/CorInfoImpl.RyuJit.cs | 2 +- src/JitInterface/src/CorInfoTypes.cs | 6 +- src/JitInterface/src/ThunkGenerator/corinfo.h | 6 +- .../shared/Internal/IO/File.Windows.cs | 1 - .../Runtime/CompilerServices/Unsafe.cs | 22 +++-- .../shared/Interop/Unix/Interop.IOErrors.cs | 1 - .../Unix/System.Native/Interop.Unlink.cs | 1 - .../Crypt32/Interop.CryptProtectMemory.cs | 1 - .../OleAut32/Interop.SysAllocStringLen.cs | 1 - src/System.Private.CoreLib/shared/README.md | 18 +--- .../System.Private.CoreLib.Shared.projitems | 35 +++----- .../shared/System/Buffer.cs | 1 - .../Collections/Concurrent/ConcurrentQueue.cs | 2 +- .../Concurrent/ConcurrentQueueSegment.cs | 4 +- .../shared/System/Decimal.DecCalc.cs | 2 + .../System/Diagnostics/Contracts/Contracts.cs | 2 +- .../Diagnostics/Tracing/EventProvider.cs | 6 ++ .../Tracing/IncrementingPollingCounter.cs | 1 + .../Diagnostics/Tracing/PollingCounter.cs | 1 + .../System/Globalization/DateTimeParse.cs | 71 +++++++-------- .../shared/System/IO/FileStream.Unix.cs | 2 + .../shared/System/IO/FileStream.Win32.cs | 2 +- .../shared/System/IO/FileStream.Windows.cs | 15 ++-- .../IO/FileStreamCompletionSource.Win32.cs | 1 - .../shared/System/IO/PathInternal.cs | 8 +- .../System/IO/StreamHelpers.CopyValidation.cs | 4 - .../shared/System/IO/TextWriter.cs | 2 + .../shared/System/IntPtr.cs | 17 ---- .../shared/System/Lazy.cs | 1 + .../CustomAttributeNamedArgument.cs | 5 +- .../shared/System/Resources/ResourceSet.cs | 4 +- .../AsyncTaskMethodBuilderT.cs | 10 ++- .../InteropServices/DispatchWrapper.cs | 2 +- .../SuppressGCTransitionAttribute.cs | 4 +- .../Runtime/Loader/AssemblyLoadContext.cs | 2 +- .../System/Security/SecureString.Windows.cs | 1 - .../shared/System/SpanHelpers.Char.cs | 18 ++-- .../shared/System/SpanHelpers.cs | 1 - .../shared/System/String.Manipulation.cs | 87 +++++++++---------- .../shared/System/Text/Rune.cs | 4 +- .../shared/System/Threading/AsyncLocal.cs | 4 +- .../System/Threading/CancellationToken.cs | 1 + .../System/Threading/ExecutionContext.cs | 4 +- .../System/Threading/LazyInitializer.cs | 8 +- .../shared/System/Threading/Tasks/Future.cs | 8 +- .../shared/System/Threading/Tasks/Task.cs | 1 + .../System/Threading/Tasks/TplEventSource.cs | 8 +- .../System/Threading/Tasks/ValueTask.cs | 2 +- .../shared/System/Threading/ThreadLocal.cs | 1 + .../shared/System/Threading/ThreadPool.cs | 1 - .../shared/System/Threading/Timer.cs | 1 - .../shared/System/TimeZoneInfo.cs | 1 - .../shared/System/UIntPtr.cs | 17 ---- .../shared/System/WeakReference.T.cs | 2 +- 56 files changed, 186 insertions(+), 257 deletions(-) diff --git a/dependencies.props b/dependencies.props index 92b667ce9f5..158ab1ba6d5 100644 --- a/dependencies.props +++ b/dependencies.props @@ -1,10 +1,10 @@ - 5.0.0-alpha1.19559.4 + 5.0.0-alpha1.19563.3 1.0.0-alpha-28204-03 - 5.0.0-alpha.1.19555.8 + 5.0.0-alpha.1.19563.6 4.7.0-preview6.19265.2 - 5.0.0-alpha1.19559.4 + 5.0.0-alpha1.19563.3 2.1.11 15.8.0 2.4.1-pre.build.4059 diff --git a/src/Framework/Framework.depproj b/src/Framework/Framework.depproj index 935715cc513..7bfb067d81b 100644 --- a/src/Framework/Framework.depproj +++ b/src/Framework/Framework.depproj @@ -5,8 +5,8 @@ - .NETCoreApp,Version=v3.0 - netcoreapp3.0 + .NETCoreApp,Version=v5.0 + netcoreapp5.0 $(NuPkgRid) true diff --git a/src/ILCompiler.RyuJit/src/JitInterface/CorInfoImpl.RyuJit.cs b/src/ILCompiler.RyuJit/src/JitInterface/CorInfoImpl.RyuJit.cs index 5bde6ca0d04..8bcdf97d697 100644 --- a/src/ILCompiler.RyuJit/src/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/ILCompiler.RyuJit/src/JitInterface/CorInfoImpl.RyuJit.cs @@ -1365,7 +1365,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO } } - pResult->_secureDelegateInvoke = 0; + pResult->_wrapperDelegateInvoke = 0; } private void embedGenericHandle(ref CORINFO_RESOLVED_TOKEN pResolvedToken, bool fEmbedParent, ref CORINFO_GENERICHANDLE_RESULT pResult) diff --git a/src/JitInterface/src/CorInfoTypes.cs b/src/JitInterface/src/CorInfoTypes.cs index 9bbc747a5e7..cadc6e4b914 100644 --- a/src/JitInterface/src/CorInfoTypes.cs +++ b/src/JitInterface/src/CorInfoTypes.cs @@ -926,7 +926,7 @@ public struct InlinedCallFrameInfo public uint offsetOfDelegateFirstTarget; // Secure delegate offsets - public uint offsetOfSecureDelegateIndirectCell; + public uint offsetOfWrapperDelegateIndirectCell; // Remoting offsets public uint offsetOfTransparentProxyRP; @@ -1103,8 +1103,8 @@ public unsafe struct CORINFO_CALL_INFO // Used by Ready-to-Run public CORINFO_CONST_LOOKUP instParamLookup; - public uint _secureDelegateInvoke; - public bool secureDelegateInvoke { get { return _secureDelegateInvoke != 0; } set { _secureDelegateInvoke = value ? (byte)1 : (byte)0; } } + public uint _wrapperDelegateInvoke; + public bool wrapperDelegateInvoke { get { return _wrapperDelegateInvoke != 0; } set { _wrapperDelegateInvoke = value ? (byte)1 : (byte)0; } } } diff --git a/src/JitInterface/src/ThunkGenerator/corinfo.h b/src/JitInterface/src/ThunkGenerator/corinfo.h index 0fcdac29920..822ca2bbb0b 100644 --- a/src/JitInterface/src/ThunkGenerator/corinfo.h +++ b/src/JitInterface/src/ThunkGenerator/corinfo.h @@ -1703,7 +1703,7 @@ struct CORINFO_CALL_INFO CORINFO_CONST_LOOKUP instParamLookup; // Used by Ready-to-Run - BOOL secureDelegateInvoke; + BOOL wrapperDelegateInvoke; }; //---------------------------------------------------------------------------- @@ -1830,8 +1830,8 @@ struct CORINFO_EE_INFO unsigned offsetOfDelegateInstance; unsigned offsetOfDelegateFirstTarget; - // Secure delegate offsets - unsigned offsetOfSecureDelegateIndirectCell; + // Wrapper delegate offsets + unsigned offsetOfWrapperDelegateIndirectCell; // Remoting offsets unsigned offsetOfTransparentProxyRP; diff --git a/src/System.Private.CoreLib/shared/Internal/IO/File.Windows.cs b/src/System.Private.CoreLib/shared/Internal/IO/File.Windows.cs index c19279d5514..879ac61b20e 100644 --- a/src/System.Private.CoreLib/shared/Internal/IO/File.Windows.cs +++ b/src/System.Private.CoreLib/shared/Internal/IO/File.Windows.cs @@ -23,7 +23,6 @@ internal static bool InternalExists(string fullPath) /// Returns 0 on success, otherwise a Win32 error code. Note that /// classes should use -1 as the uninitialized state for dataInitialized. /// - /// Return the error code for not found errors? internal static int FillAttributeInfo(string path, ref Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data, bool returnErrorOnNotFound) { int errorCode = Interop.Errors.ERROR_SUCCESS; diff --git a/src/System.Private.CoreLib/shared/Internal/Runtime/CompilerServices/Unsafe.cs b/src/System.Private.CoreLib/shared/Internal/Runtime/CompilerServices/Unsafe.cs index 7c5f9f70b92..32ceaf8b62b 100644 --- a/src/System.Private.CoreLib/shared/Internal/Runtime/CompilerServices/Unsafe.cs +++ b/src/System.Private.CoreLib/shared/Internal/Runtime/CompilerServices/Unsafe.cs @@ -11,16 +11,11 @@ #pragma warning disable SA1121 // explicitly using type aliases instead of built-in types #if BIT64 using nuint = System.UInt64; -#else -using nuint = System.UInt32; -#endif -#if !CORECLR -#if BIT64 using nint = System.Int64; #else +using nuint = System.UInt32; using nint = System.Int32; #endif -#endif // // The implementations of most the methods in this file are provided as intrinsics. @@ -150,12 +145,25 @@ public static int SizeOf() #endif } +#if BIT64 /// /// Adds an element offset to the given reference. /// [Intrinsic] [NonVersionable] [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static ref T Add(ref T source, nint elementOffset) + { + return ref Unsafe.Add(ref source, (IntPtr)(void*)elementOffset); + } +#endif + + /// + /// Adds an byte offset to the given reference. + /// + [Intrinsic] + [NonVersionable] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static ref T AddByteOffset(ref T source, nuint byteOffset) { return ref AddByteOffset(ref source, (IntPtr)(void*)byteOffset); @@ -295,7 +303,7 @@ public static void WriteUnaligned(ref byte destination, T value) } /// - /// Adds an element offset to the given reference. + /// Adds an byte offset to the given reference. /// [Intrinsic] [NonVersionable] diff --git a/src/System.Private.CoreLib/shared/Interop/Unix/Interop.IOErrors.cs b/src/System.Private.CoreLib/shared/Interop/Unix/Interop.IOErrors.cs index 666220ea194..fe3c34a3407 100644 --- a/src/System.Private.CoreLib/shared/Interop/Unix/Interop.IOErrors.cs +++ b/src/System.Private.CoreLib/shared/Interop/Unix/Interop.IOErrors.cs @@ -7,7 +7,6 @@ using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; internal static partial class Interop { diff --git a/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Unlink.cs b/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Unlink.cs index 829210fa7e0..9395428de02 100644 --- a/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Unlink.cs +++ b/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Unlink.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Runtime.InteropServices; internal static partial class Interop diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs index cce01906ff6..54fdd425e31 100644 --- a/src/System.Private.CoreLib/shared/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs +++ b/src/System.Private.CoreLib/shared/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Runtime.InteropServices; -using System.Security; internal static partial class Interop { diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringLen.cs b/src/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringLen.cs index ac9459907bf..d33ecfe3e89 100644 --- a/src/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringLen.cs +++ b/src/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringLen.cs @@ -4,7 +4,6 @@ using System; using System.Runtime.InteropServices; -using System.Security; internal static partial class Interop { diff --git a/src/System.Private.CoreLib/shared/README.md b/src/System.Private.CoreLib/shared/README.md index 28c9e733a38..3a563329ebb 100644 --- a/src/System.Private.CoreLib/shared/README.md +++ b/src/System.Private.CoreLib/shared/README.md @@ -1,19 +1,3 @@ # System.Private.CoreLib Shared Sources -This directory contains the shared sources for System.Private.CoreLib. These are shared between [mono/mono](https://github.com/mono/mono/tree/master/netcore/System.Private.CoreLib/shared), [dotnet/coreclr](https://github.com/dotnet/coreclr/tree/master/src/System.Private.CoreLib/shared) and [dotnet/corefx](https://github.com/dotnet/corefx/tree/master/src/Common/src/CoreLib). - -The sources are synchronized with a mirroring tool that watches for new commits on either side and creates new pull requests (as @dotnet-bot) in the other repository. - -## Conventions - -Code in the shared directory should have no code specific to CoreCLR, CoreRT or CoreFX. Parts of classes that need to have different implementations on different runtimes should use partial classes and *.CoreCLR.cs/*.CoreFX.cs files in the non shared portion. Code that is different based on platform (Windows/Unix) is fine to leave in the shared portion. Remember to follow the [style guidelines](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md). - -## Getting clean CI and merging the mirror PRs - -Once the mirror PR is created there is a chance that the new code will require changes to get a clean CI. Any changes can be added to the PR by checking out the PR branch and adding new commits. Please follow the following guidelines for modifying these PRs. - - - **DO NOT** modify the commits made by @dotnet-bot in any way. - - **TRY** to only make changes outside of shared. - - Changes made in the shared folder in additional commits will get mirrored properly if the mirror PR is merged with a **REBASE** - - **ALWAYS** Merge the mirror PR with the **REBASE** option. - - Using one of the other options will cause the mirror to miss commits +This directory contains the shared sources for System.Private.CoreLib. It represents the majority of the CoreLib implementation. Each flavor of the runtime (e.g. coreclr, mono) provides a few additional files as part of its build of CoreLib to complement this directory's contents. diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems index ac793c38fc2..613fb87f2e6 100644 --- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems @@ -1,6 +1,5 @@  - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) true c5ed3c1d-b572-46f1-8f96-522a85ce1179 @@ -10,16 +9,6 @@ enable - - false - false - false - - - - true - - @@ -1029,7 +1018,7 @@ - + @@ -1075,7 +1064,7 @@ - + @@ -1158,7 +1147,7 @@ - + @@ -1193,7 +1182,7 @@ - + @@ -1221,7 +1210,7 @@ - + @@ -1306,7 +1295,7 @@ - + @@ -1323,7 +1312,7 @@ - + @@ -1340,7 +1329,7 @@ - + @@ -1348,7 +1337,7 @@ - + @@ -1369,11 +1358,11 @@ - + - + - + diff --git a/src/System.Private.CoreLib/shared/System/Buffer.cs b/src/System.Private.CoreLib/shared/System/Buffer.cs index 18064bca07a..637398fde2b 100644 --- a/src/System.Private.CoreLib/shared/System/Buffer.cs +++ b/src/System.Private.CoreLib/shared/System/Buffer.cs @@ -7,7 +7,6 @@ #endif using System.Diagnostics; -using System.Runtime; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs b/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs index 7ba4c09440c..ae86c6f960c 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs @@ -544,7 +544,7 @@ private static T GetItemWhenAvailable(ConcurrentQueueSegment segment, int i) } // Return the value from the slot. - return segment._slots[i].Item; + return segment._slots[i].Item!; } private IEnumerator Enumerate(ConcurrentQueueSegment head, int headHead, ConcurrentQueueSegment tail, int tailTail) diff --git a/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueueSegment.cs b/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueueSegment.cs index 621d8163813..e9525b47b82 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueueSegment.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueueSegment.cs @@ -160,7 +160,7 @@ public bool TryDequeue([MaybeNullWhen(false)] out T item) { // Successfully reserved the slot. Note that after the above CompareExchange, other threads // trying to dequeue from this slot will end up spinning until we do the subsequent Write. - item = slots[slotsIndex].Item; + item = slots[slotsIndex].Item!; if (!Volatile.Read(ref _preservedForObservation)) { // If we're preserving, though, we don't zero out the slot, as we need it for @@ -230,7 +230,7 @@ public bool TryPeek([MaybeNullWhen(false)] out T result, bool resultUsed) int diff = sequenceNumber - (currentHead + 1); if (diff == 0) { - result = resultUsed ? slots[slotsIndex].Item : default!; + result = resultUsed ? slots[slotsIndex].Item! : default!; return true; } else if (diff < 0) diff --git a/src/System.Private.CoreLib/shared/System/Decimal.DecCalc.cs b/src/System.Private.CoreLib/shared/System/Decimal.DecCalc.cs index eb5deb9cc98..d5380c1694d 100644 --- a/src/System.Private.CoreLib/shared/System/Decimal.DecCalc.cs +++ b/src/System.Private.CoreLib/shared/System/Decimal.DecCalc.cs @@ -874,6 +874,8 @@ private static bool Add32To96(ref Buf12 bufNum, uint value) /// Adds or subtracts two decimal values. /// On return, d1 contains the result of the operation and d2 is trashed. /// + /// First decimal to add or subtract. + /// Second decimal to add or subtract. /// True means subtract and false means add. internal static unsafe void DecAddSub(ref DecCalc d1, ref DecCalc d2, bool sign) { diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs index 507c63499e0..8ce59d0d1c5 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs @@ -617,7 +617,7 @@ public static bool Exists(IEnumerable collection, Predicate predicate) #region Private Methods /// - /// This method is used internally to trigger a failure indicating to the "programmer" that he is using the interface incorrectly. + /// This method is used internally to trigger a failure indicating to the "programmer" that they are using the interface incorrectly. /// It is NEVER used to indicate failure of actual contracts at runtime. /// private static void AssertMustUseRewriter(ContractFailureKind kind, string contractKind) diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs index b1787019a16..f61366dcfa3 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs @@ -930,6 +930,9 @@ private static void SetLastError(WriteEventErrorCode error) /// /// Event Descriptor for this event. /// + /// + /// Event handle for this event. + /// /// /// A pointer to the activity ID GUID to log /// @@ -1132,6 +1135,9 @@ internal unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, IntPtr even /// /// Event Descriptor for this event. /// + /// + /// Event handle for this event. + /// /// /// A pointer to the activity ID to log /// diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingPollingCounter.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingPollingCounter.cs index 0cdbac7e6a0..52def27eb25 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingPollingCounter.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/IncrementingPollingCounter.cs @@ -29,6 +29,7 @@ public partial class IncrementingPollingCounter : DiagnosticCounter /// /// The name. /// The event source. + /// The delegate to invoke to get the total value for this counter. public IncrementingPollingCounter(string name, EventSource eventSource, Func totalValueProvider) : base(name, eventSource) { if (totalValueProvider == null) diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/PollingCounter.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/PollingCounter.cs index 3dd3d832ea9..d6c6a568e27 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/PollingCounter.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/PollingCounter.cs @@ -27,6 +27,7 @@ public partial class PollingCounter : DiagnosticCounter /// /// The name. /// The event source. + /// The delegate to invoke to get the current metric value. public PollingCounter(string name, EventSource eventSource, Func metricProvider) : base(name, eventSource) { if (metricProvider == null) diff --git a/src/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs b/src/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs index 50002e6e04e..3de87ec65d5 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/DateTimeParse.cs @@ -15,7 +15,7 @@ internal static class DateTimeParse internal delegate bool MatchNumberDelegate(ref __DTString str, int digitLen, out int result); - internal static MatchNumberDelegate m_hebrewNumberParser = new MatchNumberDelegate(DateTimeParse.MatchHebrewDigits); + private static readonly MatchNumberDelegate s_hebrewNumberParser = new MatchNumberDelegate(MatchHebrewDigits); internal static DateTime ParseExact(ReadOnlySpan s, ReadOnlySpan format, DateTimeFormatInfo dtfi, DateTimeStyles style) { @@ -334,7 +334,7 @@ internal enum DS //////////////////////////////////////////////////////////////////////////// // End NumEnd NumAmPm NumSpace NumDaySep NumTimesep MonthEnd MonthSpace MonthDSep NumDateSuff NumTimeSuff DayOfWeek YearSpace YearDateSep YearEnd TimeZone Era UTCTimeMark - private static readonly DS[][] dateParsingStates = { + private static readonly DS[][] s_dateParsingStates = { // DS.BEGIN // DS.BEGIN new DS[] { DS.BEGIN, DS.ERROR, DS.TX_N, DS.N, DS.D_Nd, DS.T_Nt, DS.ERROR, DS.D_M, DS.D_M, DS.D_S, DS.T_S, DS.BEGIN, DS.D_Y, DS.D_Y, DS.ERROR, DS.BEGIN, DS.BEGIN, DS.ERROR }, @@ -615,7 +615,7 @@ private static bool Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref str.GetRegularToken(out tokenType, out tokenValue, dtfi); #if _LOGGING - if (_tracingEnabled) + if (s_tracingEnabled) { Trace($"Lex({Hex(str.Value)})\tpos:{str.Index}({Hex(str.m_current)}), {tokenType}, DS.{dps}"); } @@ -720,8 +720,8 @@ private static bool Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref case TokenType.SEP_DateOrOffset: // The separator is either a date separator or the start of a time zone offset. If the token will complete the date then // process just the number and roll back the index so that the outer loop can attempt to parse the time zone offset. - if ((dateParsingStates[(int)dps][(int)DTT.YearDateSep] == DS.ERROR) - && (dateParsingStates[(int)dps][(int)DTT.YearSpace] > DS.ERROR)) + if ((s_dateParsingStates[(int)dps][(int)DTT.YearDateSep] == DS.ERROR) + && (s_dateParsingStates[(int)dps][(int)DTT.YearSpace] > DS.ERROR)) { str.Index = indexBeforeSeparator; str.m_current = charBeforeSeparator; @@ -779,7 +779,7 @@ private static bool Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref // Fix AM/PM parsing case, e.g. "1/10 5 AM" if (dps == DS.D_NN) { - if (!ProcessTerminalState(DS.DX_NN, ref str, ref result, ref styles, ref raw, dtfi)) + if (!ProcessTerminalState(DS.DX_NN, ref result, ref styles, ref raw, dtfi)) { return false; } @@ -812,8 +812,8 @@ private static bool Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref case TokenType.SEP_DateOrOffset: // The separator is either a date separator or the start of a time zone offset. If the token will complete the date then // process just the number and roll back the index so that the outer loop can attempt to parse the time zone offset. - if ((dateParsingStates[(int)dps][(int)DTT.NumDatesep] == DS.ERROR) - && (dateParsingStates[(int)dps][(int)DTT.NumSpace] > DS.ERROR)) + if ((s_dateParsingStates[(int)dps][(int)DTT.NumDatesep] == DS.ERROR) + && (s_dateParsingStates[(int)dps][(int)DTT.NumSpace] > DS.ERROR)) { str.Index = indexBeforeSeparator; str.m_current = charBeforeSeparator; @@ -896,7 +896,7 @@ private static bool Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref case TokenType.SEP_DateOrOffset: // The separator is either a date separator or the start of a time zone offset. If the token will complete the date then // process just the number and roll back the index so that the outer loop can attempt to parse the time zone offset. - if (dateParsingStates[(int)dps][(int)DTT.YearSpace] > DS.ERROR) + if (s_dateParsingStates[(int)dps][(int)DTT.YearSpace] > DS.ERROR) { str.Index = indexBeforeSeparator; str.m_current = charBeforeSeparator; @@ -941,8 +941,8 @@ private static bool Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref case TokenType.SEP_DateOrOffset: // The separator is either a date separator or the start of a time zone offset. If the token will complete the date then // process just the number and roll back the index so that the outer loop can attempt to parse the time zone offset. - if ((dateParsingStates[(int)dps][(int)DTT.NumDatesep] == DS.ERROR) - && (dateParsingStates[(int)dps][(int)DTT.NumSpace] > DS.ERROR)) + if ((s_dateParsingStates[(int)dps][(int)DTT.NumDatesep] == DS.ERROR) + && (s_dateParsingStates[(int)dps][(int)DTT.NumSpace] > DS.ERROR)) { str.Index = indexBeforeSeparator; str.m_current = charBeforeSeparator; @@ -1009,8 +1009,8 @@ private static bool Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref case TokenType.SEP_DateOrOffset: // The separator is either a date separator or the start of a time zone offset. If the token will complete the date then // process just the number and roll back the index so that the outer loop can attempt to parse the time zone offset. - if ((dateParsingStates[(int)dps][(int)DTT.MonthDatesep] == DS.ERROR) - && (dateParsingStates[(int)dps][(int)DTT.MonthSpace] > DS.ERROR)) + if ((s_dateParsingStates[(int)dps][(int)DTT.MonthDatesep] == DS.ERROR) + && (s_dateParsingStates[(int)dps][(int)DTT.MonthSpace] > DS.ERROR)) { str.Index = indexBeforeSeparator; str.m_current = charBeforeSeparator; @@ -1676,8 +1676,7 @@ private static bool GetDayOfMN(ref DateTimeResult result, ref DateTimeStyles sty } if (yearMonthOrder == ORDER_MY) { - int year; - if (!TryAdjustYear(ref result, raw.GetNumber(0), out year) || !SetDateYMD(ref result, year, raw.month, 1)) + if (!TryAdjustYear(ref result, raw.GetNumber(0), out int year) || !SetDateYMD(ref result, year, raw.month, 1)) { result.SetBadDateTimeFailure(); return false; @@ -1759,8 +1758,7 @@ private static bool GetDayOfNM(ref DateTimeResult result, ref DateTimeStyles sty } if (yearMonthOrder == ORDER_YM) { - int year; - if (!TryAdjustYear(ref result, raw.GetNumber(0), out year) || !SetDateYMD(ref result, year, raw.month, 1)) + if (!TryAdjustYear(ref result, raw.GetNumber(0), out int year) || !SetDateYMD(ref result, year, raw.month, 1)) { result.SetBadDateTimeFailure(); return false; @@ -2345,7 +2343,7 @@ internal static bool ProcessHebrewTerminalState(DS dps, ref DateTimeResult resul // A terminal state has been reached, call the appropriate function to fill in the parsing result. // Return true if the state is a terminal state. // - internal static bool ProcessTerminalState(DS dps, ref __DTString str, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + internal static bool ProcessTerminalState(DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) { bool passed = true; switch (dps) @@ -2504,7 +2502,6 @@ internal static bool TryParse(ReadOnlySpan s, DateTimeFormatInfo dtfi, Dat DTFITrace(dtfi); #endif - DateTime time; // // First try the predefined format. // @@ -2605,7 +2602,7 @@ internal static bool TryParse(ReadOnlySpan s, DateTimeFormatInfo dtfi, Dat } bool atEnd = str.AtEnd(); - if (dateParsingStates[(int)dps][(int)dtok.dtt] == DS.ERROR || atEnd) + if (s_dateParsingStates[(int)dps][(int)dtok.dtt] == DS.ERROR || atEnd) { switch (dtok.dtt) { @@ -2623,7 +2620,7 @@ internal static bool TryParse(ReadOnlySpan s, DateTimeFormatInfo dtfi, Dat // // Advance to the next state, and continue // - dps = dateParsingStates[(int)dps][(int)dtok.dtt]; + dps = s_dateParsingStates[(int)dps][(int)dtok.dtt]; if (dps == DS.ERROR) { @@ -2643,7 +2640,7 @@ internal static bool TryParse(ReadOnlySpan s, DateTimeFormatInfo dtfi, Dat } else { - if (!ProcessTerminalState(dps, ref str, ref result, ref styles, ref raw, dtfi)) + if (!ProcessTerminalState(dps, ref result, ref styles, ref raw, dtfi)) { TPTraceExit("0060 (ProcessTerminalState)", dps); return false; @@ -2689,6 +2686,7 @@ internal static bool TryParse(ReadOnlySpan s, DateTimeFormatInfo dtfi, Dat return false; } + DateTime time; if (!result.calendar.TryToDateTime(result.Year, result.Month, result.Day, result.Hour, result.Minute, result.Second, 0, result.era, out time)) { @@ -2941,8 +2939,7 @@ private static bool AdjustTimeZoneToLocal(ref DateTimeResult result, bool bTimeO { // Convert the GMT time to local time. DateTime utcDt = new DateTime(resultTicks, DateTimeKind.Utc); - bool isDaylightSavings = false; - resultTicks += TimeZoneInfo.GetUtcOffsetFromUtc(utcDt, TimeZoneInfo.Local, out isDaylightSavings, out isAmbiguousLocalDst).Ticks; + resultTicks += TimeZoneInfo.GetUtcOffsetFromUtc(utcDt, TimeZoneInfo.Local, out _, out isAmbiguousLocalDst).Ticks; } } if (resultTicks < DateTime.MinTicks || resultTicks > DateTime.MaxTicks) @@ -3879,7 +3876,7 @@ private static void ConfigureFormatOS(ref DateTimeFormatInfo dtfi, ref ParsingIn DateTimeFormatInfo dtfi, ref DateTimeResult result) { - int tokenLen = 0; + int tokenLen; int tempYear = 0, tempMonth = 0, tempDay = 0, tempDayOfWeek = 0, tempHour = 0, tempMinute = 0, tempSecond = 0; double tempFraction = 0; TM tempTimeMark = 0; @@ -4009,7 +4006,7 @@ private static void ConfigureFormatOS(ref DateTimeFormatInfo dtfi, ref ParsingIn } break; case 'g': - tokenLen = format.GetRepeatCount(); + _ = format.GetRepeatCount(); // Put the era value in result.era. if (!MatchEraName(ref str, dtfi, ref result.era)) { @@ -4507,12 +4504,11 @@ internal static bool TryParseQuoteString(ReadOnlySpan format, int pos, Str formatParam = ExpandPredefinedFormat(formatParam, ref dtfi, ref parseInfo, ref result); } - bool bTimeOnly = false; result.calendar = parseInfo.calendar; if (parseInfo.calendar.ID == CalendarId.HEBREW) { - parseInfo.parseNumberDelegate = m_hebrewNumberParser; + parseInfo.parseNumberDelegate = s_hebrewNumberParser; parseInfo.fCustomNumberParser = true; } @@ -4625,7 +4621,7 @@ internal static bool TryParseQuoteString(ReadOnlySpan format, int pos, Str } // Check if the parsed string only contains hour/minute/second values. - bTimeOnly = (result.Year == -1 && result.Month == -1 && result.Day == -1); + bool bTimeOnly = (result.Year == -1 && result.Month == -1 && result.Day == -1); if (!CheckDefaultDateTime(ref result, ref parseInfo.calendar, styles)) { return false; @@ -5111,7 +5107,7 @@ private static Exception GetDateTimeParseException(ref DateTimeResult result) private static void LexTraceExit(string message, DS dps) { #if _LOGGING - if (!_tracingEnabled) + if (!s_tracingEnabled) return; Trace($"Lex return {message}, DS.{dps}"); #endif // _LOGGING @@ -5120,7 +5116,7 @@ private static void LexTraceExit(string message, DS dps) private static void PTSTraceExit(DS dps, bool passed) { #if _LOGGING - if (!_tracingEnabled) + if (!s_tracingEnabled) return; Trace($"ProcessTerminalState {(passed ? "passed" : "failed")} @ DS.{dps}"); #endif // _LOGGING @@ -5129,7 +5125,7 @@ private static void PTSTraceExit(DS dps, bool passed) private static void TPTraceExit(string message, DS dps) { #if _LOGGING - if (!_tracingEnabled) + if (!s_tracingEnabled) return; Trace($"TryParse return {message}, DS.{dps}"); #endif // _LOGGING @@ -5138,7 +5134,7 @@ private static void TPTraceExit(string message, DS dps) private static void DTFITrace(DateTimeFormatInfo dtfi) { #if _LOGGING - if (!_tracingEnabled) + if (!s_tracingEnabled) return; Trace("DateTimeFormatInfo Properties"); @@ -5164,14 +5160,13 @@ private static string Hex(string[] strs) if (strs.Length == 1) return Hex(strs[0]); - int curLineLength = 0; const int MaxLineLength = 55; const int NewLinePadding = 20; // invariant: strs.Length >= 2 StringBuilder buffer = new StringBuilder(); buffer.Append(Hex(strs[0])); - curLineLength = buffer.Length; + int curLineLength = buffer.Length; string s; for (int i = 1; i < strs.Length - 1; i++) @@ -5239,7 +5234,7 @@ private static void Trace(string s) } // for testing; do not make this readonly - private static bool _tracingEnabled = false; + private static bool s_tracingEnabled = false; #endif // _LOGGING } @@ -5382,11 +5377,9 @@ internal void GetRegularToken(out TokenType tokenType, out int tokenValue, DateT // Re-scan using the staring Index to see if this is a token. Index = start; // To include the first digit. m_current = Value[Index]; - TokenType tempType; - int tempValue; // This DTFI has tokens starting with digits. // E.g. mn-MN has month name like "\x0031\x00a0\x0434\x04af\x0433\x044d\x044d\x0440\x00a0\x0441\x0430\x0440" - if (dtfi.Tokenize(TokenType.RegularTokenMask, out tempType, out tempValue, ref this)) + if (dtfi.Tokenize(TokenType.RegularTokenMask, out TokenType tempType, out int tempValue, ref this)) { tokenType = tempType; tokenValue = tempValue; diff --git a/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs b/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs index c1f0fcfb57f..2a8e277c35e 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs @@ -66,6 +66,7 @@ private SafeFileHandle OpenHandle(FileMode mode, FileShare share, FileOptions op /// Initializes a stream for reading or writing a Unix file. /// How the file should be opened. /// What other access to the file should be allowed. This is currently ignored. + /// The original path specified for the FileStream. private void Init(FileMode mode, FileShare share, string originalPath) { _fileHandle.IsAsync = _useAsyncIO; @@ -802,6 +803,7 @@ public override long Seek(long offset, SeekOrigin origin) } /// Sets the current position of this stream to the given value. + /// The file handle on which to seek. /// The point relative to origin from which to begin seeking. /// /// Specifies the beginning, the end, or the current position as a reference diff --git a/src/System.Private.CoreLib/shared/System/IO/FileStream.Win32.cs b/src/System.Private.CoreLib/shared/System/IO/FileStream.Win32.cs index 310d5d2d1fb..626635918f5 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileStream.Win32.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileStream.Win32.cs @@ -90,7 +90,7 @@ private static bool GetDefaultIsAsync(SafeFileHandle handle) return (fileMode & (Interop.NtDll.FILE_SYNCHRONOUS_IO_ALERT | Interop.NtDll.FILE_SYNCHRONOUS_IO_NONALERT)) > 0; } - private static void VerifyHandleIsSync(SafeFileHandle handle, int fileType, FileAccess access) + private static void VerifyHandleIsSync(SafeFileHandle handle) { // As we can accurately check the handle type when we have access to NtQueryInformationFile we don't need to skip for // any particular file handle type. diff --git a/src/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs b/src/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs index cc6da307f6a..03900a1b9c7 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs @@ -127,7 +127,7 @@ private void InitFromHandle(SafeFileHandle handle, FileAccess access, bool useAs try { #endif - InitFromHandleImpl(handle, access, useAsyncIO); + InitFromHandleImpl(handle, useAsyncIO); #if DEBUG } catch @@ -138,7 +138,7 @@ private void InitFromHandle(SafeFileHandle handle, FileAccess access, bool useAs #endif } - private void InitFromHandleImpl(SafeFileHandle handle, FileAccess access, bool useAsyncIO) + private void InitFromHandleImpl(SafeFileHandle handle, bool useAsyncIO) { int handleType = Interop.Kernel32.GetFileType(handle); Debug.Assert(handleType == Interop.Kernel32.FileTypes.FILE_TYPE_DISK || handleType == Interop.Kernel32.FileTypes.FILE_TYPE_PIPE || handleType == Interop.Kernel32.FileTypes.FILE_TYPE_CHAR, "FileStream was passed an unknown file type!"); @@ -173,7 +173,7 @@ private void InitFromHandleImpl(SafeFileHandle handle, FileAccess access, bool u } else if (!useAsyncIO) { - VerifyHandleIsSync(handle, handleType, access); + VerifyHandleIsSync(handle); } if (_canSeek) @@ -709,8 +709,7 @@ private unsafe void WriteCore(ReadOnlySpan source) // Make sure we are writing to the position that we think we are VerifyOSHandlePosition(); - int errorCode = 0; - int r = WriteFileNative(_fileHandle, source, null, out errorCode); + int r = WriteFileNative(_fileHandle, source, null, out int errorCode); if (r == -1) { @@ -884,8 +883,7 @@ private unsafe Task ReadNativeAsync(Memory destination, int numBuffer } // queue an async ReadFile operation and pass in a packed overlapped - int errorCode = 0; - int r = ReadFileNative(_fileHandle, destination.Span, intOverlapped, out errorCode); + int r = ReadFileNative(_fileHandle, destination.Span, intOverlapped, out int errorCode); // ReadFile, the OS version, will return 0 on failure. But // my ReadFileNative wrapper returns -1. My wrapper will return @@ -1089,9 +1087,8 @@ private unsafe Task WriteAsyncInternalCore(ReadOnlyMemory source, Cancella SeekCore(_fileHandle, source.Length, SeekOrigin.Current); } - int errorCode = 0; // queue an async WriteFile operation and pass in a packed overlapped - int r = WriteFileNative(_fileHandle, source.Span, intOverlapped, out errorCode); + int r = WriteFileNative(_fileHandle, source.Span, intOverlapped, out int errorCode); // WriteFile, the OS version, will return 0 on failure. But // my WriteFileNative wrapper returns -1. My wrapper will return diff --git a/src/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs b/src/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs index 7345afec3f1..419670582ee 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs @@ -4,7 +4,6 @@ using System.Buffers; using System.Diagnostics; -using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; diff --git a/src/System.Private.CoreLib/shared/System/IO/PathInternal.cs b/src/System.Private.CoreLib/shared/System/IO/PathInternal.cs index 47839718227..ba1570536b6 100644 --- a/src/System.Private.CoreLib/shared/System/IO/PathInternal.cs +++ b/src/System.Private.CoreLib/shared/System/IO/PathInternal.cs @@ -228,8 +228,8 @@ internal static bool RemoveRelativeSegments(ReadOnlySpan path, int rootLen /// /// Returns true if the path ends in a directory separator. /// - internal static bool EndsInDirectorySeparator(string path) - => !string.IsNullOrEmpty(path) && IsDirectorySeparator(path[path.Length - 1]); + internal static bool EndsInDirectorySeparator(string path) => + !string.IsNullOrEmpty(path) && IsDirectorySeparator(path[path.Length - 1]); /// /// Trims one trailing directory separator beyond the root of the path. @@ -242,7 +242,7 @@ internal static bool EndsInDirectorySeparator(string path) /// /// Returns true if the path ends in a directory separator. /// - internal static bool EndsInDirectorySeparator(ReadOnlySpan path) - => path.Length > 0 && IsDirectorySeparator(path[path.Length - 1]); + internal static bool EndsInDirectorySeparator(ReadOnlySpan path) => + path.Length > 0 && IsDirectorySeparator(path[path.Length - 1]); } } diff --git a/src/System.Private.CoreLib/shared/System/IO/StreamHelpers.CopyValidation.cs b/src/System.Private.CoreLib/shared/System/IO/StreamHelpers.CopyValidation.cs index 1d120e5a077..7dca7eba48d 100644 --- a/src/System.Private.CoreLib/shared/System/IO/StreamHelpers.CopyValidation.cs +++ b/src/System.Private.CoreLib/shared/System/IO/StreamHelpers.CopyValidation.cs @@ -2,10 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Buffers; -using System.Threading; -using System.Threading.Tasks; - namespace System.IO { /// Provides methods to help in the implementation of Stream-derived types. diff --git a/src/System.Private.CoreLib/shared/System/IO/TextWriter.cs b/src/System.Private.CoreLib/shared/System/IO/TextWriter.cs index 8263072b14e..8188fd878d4 100644 --- a/src/System.Private.CoreLib/shared/System/IO/TextWriter.cs +++ b/src/System.Private.CoreLib/shared/System/IO/TextWriter.cs @@ -567,6 +567,7 @@ public virtual Task WriteAsync(string? value) /// StringBuilder.GetChunks() method to avoid creating the intermediate string /// /// The string (as a StringBuilder) to write to the stream + /// The token to monitor for cancellation requests. public virtual Task WriteAsync(StringBuilder? value, CancellationToken cancellationToken = default) { return @@ -641,6 +642,7 @@ public virtual Task WriteLineAsync(string? value) /// StringBuilder.GetChunks() method to avoid creating the intermediate string /// /// The string (as a StringBuilder) to write to the stream + /// The token to monitor for cancellation requests. public virtual Task WriteLineAsync(StringBuilder? value, CancellationToken cancellationToken = default) { return diff --git a/src/System.Private.CoreLib/shared/System/IntPtr.cs b/src/System.Private.CoreLib/shared/System/IntPtr.cs index 1d93be7fb15..b67d1fde245 100644 --- a/src/System.Private.CoreLib/shared/System/IntPtr.cs +++ b/src/System.Private.CoreLib/shared/System/IntPtr.cs @@ -29,14 +29,12 @@ namespace System [Intrinsic] public static readonly IntPtr Zero; - [Intrinsic] [NonVersionable] public unsafe IntPtr(int value) { _value = (void*)value; } - [Intrinsic] [NonVersionable] public unsafe IntPtr(long value) { @@ -48,7 +46,6 @@ public unsafe IntPtr(long value) } [CLSCompliant(false)] - [Intrinsic] [NonVersionable] public unsafe IntPtr(void* value) { @@ -90,7 +87,6 @@ public override unsafe int GetHashCode() #endif } - [Intrinsic] [NonVersionable] public unsafe int ToInt32() { @@ -102,34 +98,28 @@ public unsafe int ToInt32() #endif } - [Intrinsic] [NonVersionable] public unsafe long ToInt64() => (nint)_value; - [Intrinsic] [NonVersionable] public static unsafe explicit operator IntPtr(int value) => new IntPtr(value); - [Intrinsic] [NonVersionable] public static unsafe explicit operator IntPtr(long value) => new IntPtr(value); [CLSCompliant(false)] - [Intrinsic] [NonVersionable] public static unsafe explicit operator IntPtr(void* value) => new IntPtr(value); [CLSCompliant(false)] - [Intrinsic] [NonVersionable] public static unsafe explicit operator void*(IntPtr value) => value._value; - [Intrinsic] [NonVersionable] public static unsafe explicit operator int(IntPtr value) { @@ -141,17 +131,14 @@ public unsafe int ToInt32() #endif } - [Intrinsic] [NonVersionable] public static unsafe explicit operator long(IntPtr value) => (nint)value._value; - [Intrinsic] [NonVersionable] public static unsafe bool operator ==(IntPtr value1, IntPtr value2) => value1._value == value2._value; - [Intrinsic] [NonVersionable] public static unsafe bool operator !=(IntPtr value1, IntPtr value2) => value1._value != value2._value; @@ -160,7 +147,6 @@ public unsafe int ToInt32() public static IntPtr Add(IntPtr pointer, int offset) => pointer + offset; - [Intrinsic] [NonVersionable] public static unsafe IntPtr operator +(IntPtr pointer, int offset) => new IntPtr((nint)pointer._value + offset); @@ -169,20 +155,17 @@ public unsafe int ToInt32() public static IntPtr Subtract(IntPtr pointer, int offset) => pointer - offset; - [Intrinsic] [NonVersionable] public static unsafe IntPtr operator -(IntPtr pointer, int offset) => new IntPtr((nint)pointer._value - offset); public static int Size { - [Intrinsic] [NonVersionable] get => sizeof(nint); } [CLSCompliant(false)] - [Intrinsic] [NonVersionable] public unsafe void* ToPointer() => _value; diff --git a/src/System.Private.CoreLib/shared/System/Lazy.cs b/src/System.Private.CoreLib/shared/System/Lazy.cs index a88b0a9f228..e071b16cc7c 100644 --- a/src/System.Private.CoreLib/shared/System/Lazy.cs +++ b/src/System.Private.CoreLib/shared/System/Lazy.cs @@ -525,6 +525,7 @@ public LazyDebugView(Lazy lazy) public bool IsValueCreated => _lazy.IsValueCreated; /// Returns the value of the Lazy object. + [MaybeNull] public T Value => _lazy.ValueForDebugDisplay; /// Returns the execution mode of the Lazy object diff --git a/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs b/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs index 8aa4d8fa72d..7ecd391f5a9 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/CustomAttributeNamedArgument.cs @@ -37,10 +37,7 @@ public CustomAttributeNamedArgument(MemberInfo memberInfo, object? value) public CustomAttributeNamedArgument(MemberInfo memberInfo, CustomAttributeTypedArgument typedArgument) { - if (memberInfo == null) - throw new ArgumentNullException(nameof(memberInfo)); - - m_memberInfo = memberInfo; + m_memberInfo = memberInfo ?? throw new ArgumentNullException(nameof(memberInfo)); m_value = typedArgument; } diff --git a/src/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs b/src/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs index 12cde70d0e6..12dcc379563 100644 --- a/src/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs +++ b/src/System.Private.CoreLib/shared/System/Resources/ResourceSet.cs @@ -71,9 +71,7 @@ public ResourceSet(Stream stream) public ResourceSet(IResourceReader reader) : this() { - if (reader == null) - throw new ArgumentNullException(nameof(reader)); - Reader = reader; + Reader = reader ?? throw new ArgumentNullException(nameof(reader)); ReadResources(); } diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs index 043a133ab13..0cea7389bbf 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @@ -151,6 +151,7 @@ public struct AsyncTaskMethodBuilder /// Gets the "boxed" state machine object. /// Specifies the type of the async state machine. /// The state machine. + /// The reference to the Task field storing the Task instance. /// The "boxed" state machine. private static IAsyncStateMachineBox GetStateMachineBox( ref TStateMachine stateMachine, @@ -427,16 +428,17 @@ public void SetResult(TResult result) /// Completes the already initialized task with the specified result. /// The result to use to complete the task. - internal static void SetExistingTaskResult(Task taskField, [AllowNull] TResult result) + /// The task to complete. + internal static void SetExistingTaskResult(Task task, [AllowNull] TResult result) { - Debug.Assert(taskField != null, "Expected non-null task"); + Debug.Assert(task != null, "Expected non-null task"); if (AsyncCausalityTracer.LoggingOn) { - AsyncCausalityTracer.TraceOperationCompletion(taskField, AsyncCausalityStatus.Completed); + AsyncCausalityTracer.TraceOperationCompletion(task, AsyncCausalityStatus.Completed); } - if (!taskField.TrySetResult(result)) + if (!task.TrySetResult(result)) { ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted); } diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs index 3bb1507203c..b59e293bfb7 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/DispatchWrapper.cs @@ -11,7 +11,7 @@ public DispatchWrapper(object? obj) { if (obj != null) { - // Make sure this guy has an IDispatch + // Make sure this object has an IDispatch IntPtr pdisp = Marshal.GetIDispatchForObject(obj); // If we got here without throwing an exception, the QI for IDispatch succeeded. diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs index 21f1695192c..14a42b7235a 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/SuppressGCTransitionAttribute.cs @@ -33,7 +33,7 @@ namespace System.Runtime.InteropServices /// of the unmanaged function. However, avoiding this transition removes some of the guarantees the runtime /// provides through a normal P/Invoke. When exiting the managed runtime to enter an unmanaged function the /// GC must transition from Cooperative mode into Preemptive mode. Full details on these modes can be found at - /// https://github.com/dotnet/coreclr/blob/master/Documentation/coding-guidelines/clr-code-guide.md#2.1.8. + /// https://github.com/dotnet/runtime/blob/master/docs/coreclr/coding-guidelines/clr-code-guide.md#2.1.8. /// Suppressing the GC transition is an advanced scenario and should not be done without fully understanding /// potential consequences. /// @@ -62,4 +62,4 @@ public SuppressGCTransitionAttribute() { } } -} \ No newline at end of file +} diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs b/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs index 5ae3f8d06f3..740239e3f1a 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs @@ -466,7 +466,7 @@ private void VerifyIsAlive() /// /// The property is stored in an AsyncLocal<AssemblyLoadContext>. This means the setting can be unique for every async or thread in the process. /// - /// For more details see https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/AssemblyLoadContext.ContextualReflection.md + /// For more details see https://github.com/dotnet/runtime/blob/master/docs/coreclr/design-docs/AssemblyLoadContext.ContextualReflection.md /// public static AssemblyLoadContext? CurrentContextualReflectionContext => s_asyncLocalCurrent?.Value; diff --git a/src/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs b/src/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs index 9e226ec7a8a..b2ff3196ef6 100644 --- a/src/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; -using System.Runtime; using System.Runtime.InteropServices; using System.Security.Cryptography; diff --git a/src/System.Private.CoreLib/shared/System/SpanHelpers.Char.cs b/src/System.Private.CoreLib/shared/System/SpanHelpers.Char.cs index 7d4d27aded2..25dc8f6fae4 100644 --- a/src/System.Private.CoreLib/shared/System/SpanHelpers.Char.cs +++ b/src/System.Private.CoreLib/shared/System/SpanHelpers.Char.cs @@ -107,7 +107,8 @@ public static unsafe int SequenceCompareTo(ref char first, int firstLength, ref } } - if (sizeof(UIntPtr) > sizeof(int) && (byte*)minLength >= (byte*)(i + sizeof(int) / sizeof(char))) +#if BIT64 + if ((byte*)minLength >= (byte*)(i + sizeof(int) / sizeof(char))) { if (Unsafe.ReadUnaligned(ref Unsafe.As(ref Unsafe.Add(ref first, i))) == Unsafe.ReadUnaligned(ref Unsafe.As(ref Unsafe.Add(ref second, i)))) @@ -115,6 +116,7 @@ public static unsafe int SequenceCompareTo(ref char first, int firstLength, ref i += sizeof(int) / sizeof(char); } } +#endif while ((byte*)i < (byte*)minLength) { @@ -254,15 +256,15 @@ public static unsafe int IndexOf(ref char searchSpace, char value, int length) // remaining data that is shorter than a Vector length. while (lengthToExamine >= 4) { - ref char current = ref Add(ref searchSpace, offset); + ref char current = ref Unsafe.Add(ref searchSpace, offset); if (value == current) goto Found; - if (value == Add(ref current, 1)) + if (value == Unsafe.Add(ref current, 1)) goto Found1; - if (value == Add(ref current, 2)) + if (value == Unsafe.Add(ref current, 2)) goto Found2; - if (value == Add(ref current, 3)) + if (value == Unsafe.Add(ref current, 3)) goto Found3; offset += 4; @@ -271,7 +273,7 @@ public static unsafe int IndexOf(ref char searchSpace, char value, int length) while (lengthToExamine > 0) { - if (value == Add(ref searchSpace, offset)) + if (value == Unsafe.Add(ref searchSpace, offset)) goto Found; offset++; @@ -1031,10 +1033,6 @@ private static int LocateLastFoundChar(ulong match) return 3 - (BitOperations.LeadingZeroCount(match) >> 4); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ref char Add(ref char source, nint elementOffset) - => ref Unsafe.Add(ref source, (IntPtr)elementOffset); - [MethodImpl(MethodImplOptions.AggressiveInlining)] private static unsafe Vector LoadVector(ref char start, nint offset) => Unsafe.ReadUnaligned>(ref Unsafe.As(ref Unsafe.Add(ref start, (IntPtr)offset))); diff --git a/src/System.Private.CoreLib/shared/System/SpanHelpers.cs b/src/System.Private.CoreLib/shared/System/SpanHelpers.cs index d558758f634..c07c7ef5e9c 100644 --- a/src/System.Private.CoreLib/shared/System/SpanHelpers.cs +++ b/src/System.Private.CoreLib/shared/System/SpanHelpers.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; -using System.Runtime; using Internal.Runtime.CompilerServices; diff --git a/src/System.Private.CoreLib/shared/System/String.Manipulation.cs b/src/System.Private.CoreLib/shared/System/String.Manipulation.cs index 4d703da082e..8e51249f5e5 100644 --- a/src/System.Private.CoreLib/shared/System/String.Manipulation.cs +++ b/src/System.Private.CoreLib/shared/System/String.Manipulation.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; +using System.Numerics; using System.Text; using Internal.Runtime.CompilerServices; @@ -1055,63 +1056,55 @@ public string Replace(char oldChar, char newChar) if (oldChar == newChar) return this; - unsafe - { - int remainingLength = Length; - - fixed (char* pChars = &_firstChar) - { - char* pSrc = pChars; + int firstIndex = IndexOf(oldChar); - while (remainingLength > 0) - { - if (*pSrc == oldChar) - { - break; - } + if (firstIndex < 0) + return this; - remainingLength--; - pSrc++; - } - } + int remainingLength = Length - firstIndex; + string result = FastAllocateString(Length); - if (remainingLength == 0) - return this; + int copyLength = firstIndex; - string result = FastAllocateString(Length); - - fixed (char* pChars = &_firstChar) - { - fixed (char* pResult = &result._firstChar) - { - int copyLength = Length - remainingLength; + // Copy the characters already proven not to match. + if (copyLength > 0) + { + Buffer.Memmove(ref result._firstChar, ref _firstChar, (uint)copyLength); + } - // Copy the characters already proven not to match. - if (copyLength > 0) - { - wstrcpy(pResult, pChars, copyLength); - } + // Copy the remaining characters, doing the replacement as we go. + ref ushort pSrc = ref Unsafe.Add(ref Unsafe.As(ref _firstChar), copyLength); + ref ushort pDst = ref Unsafe.Add(ref Unsafe.As(ref result._firstChar), copyLength); - // Copy the remaining characters, doing the replacement as we go. - char* pSrc = pChars + copyLength; - char* pDst = pResult + copyLength; + if (Vector.IsHardwareAccelerated && remainingLength >= Vector.Count) + { + Vector oldChars = new Vector(oldChar); + Vector newChars = new Vector(newChar); - do - { - char currentChar = *pSrc; - if (currentChar == oldChar) - currentChar = newChar; - *pDst = currentChar; - - remainingLength--; - pSrc++; - pDst++; - } while (remainingLength > 0); - } + do + { + Vector original = Unsafe.ReadUnaligned>(ref Unsafe.As(ref pSrc)); + Vector equals = Vector.Equals(original, oldChars); + Vector results = Vector.ConditionalSelect(equals, newChars, original); + Unsafe.WriteUnaligned(ref Unsafe.As(ref pDst), results); + + pSrc = ref Unsafe.Add(ref pSrc, Vector.Count); + pDst = ref Unsafe.Add(ref pDst, Vector.Count); + remainingLength -= Vector.Count; } + while (remainingLength >= Vector.Count); + } - return result; + for (; remainingLength > 0; remainingLength--) + { + ushort currentChar = pSrc; + pDst = currentChar == oldChar ? newChar : currentChar; + + pSrc = ref Unsafe.Add(ref pSrc, 1); + pDst = ref Unsafe.Add(ref pDst, 1); } + + return result; } public string Replace(string oldValue, string? newValue) diff --git a/src/System.Private.CoreLib/shared/System/Text/Rune.cs b/src/System.Private.CoreLib/shared/System/Text/Rune.cs index b704f8440b6..ff3f4d00535 100644 --- a/src/System.Private.CoreLib/shared/System/Text/Rune.cs +++ b/src/System.Private.CoreLib/shared/System/Text/Rune.cs @@ -210,7 +210,7 @@ private static Rune ChangeCaseCultureAware(Rune rune, TextInfo textInfo, bool to } } - public int CompareTo(Rune other) => this._value.CompareTo(other._value); + public int CompareTo(Rune other) => _value.CompareTo(other._value); /// /// Decodes the at the beginning of the provided UTF-16 source buffer. @@ -699,7 +699,7 @@ public int EncodeToUtf8(Span destination) return bytesWritten; } - public override bool Equals(object? obj) => (obj is Rune other) && this.Equals(other); + public override bool Equals(object? obj) => (obj is Rune other) && Equals(other); public bool Equals(Rune other) => this == other; diff --git a/src/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs b/src/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs index e80fb97e249..ee048e88f2f 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs @@ -98,8 +98,8 @@ internal interface IAsyncLocal internal AsyncLocalValueChangedArgs([AllowNull] T previousValue, [AllowNull] T currentValue, bool contextChanged) { - PreviousValue = previousValue; - CurrentValue = currentValue; + PreviousValue = previousValue!; + CurrentValue = currentValue!; ThreadContextChanged = contextChanged; } } diff --git a/src/System.Private.CoreLib/shared/System/Threading/CancellationToken.cs b/src/System.Private.CoreLib/shared/System/Threading/CancellationToken.cs index 498ccd4f2ca..d751bb41b6c 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/CancellationToken.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/CancellationToken.cs @@ -262,6 +262,7 @@ public CancellationToken(bool canceled) : this(canceled ? CancellationTokenSourc /// A Boolean value that indicates whether to capture /// the current SynchronizationContext and use it /// when invoking the . + /// true to capture the current ExecutionContext; otherwise, false. /// The instance that can /// be used to unregister the callback. /// is null. diff --git a/src/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs b/src/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs index aa2ec5456f9..9b64000cdb2 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs @@ -135,7 +135,7 @@ internal static void RunInternal(ExecutionContext? executionContext, ContextCall { // Note: ExecutionContext.RunInternal is an extremely hot function and used by every await, ThreadPool execution, etc. // Note: Manual enregistering may be addressed by "Exception Handling Write Through Optimization" - // https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/eh-writethru.md + // https://github.com/dotnet/runtime/blob/master/docs/coreclr/design-docs/eh-writethru.md // Enregister variables with 0 post-fix so they can be used in registers without EH forcing them to stack // Capture references to Thread Contexts @@ -205,7 +205,7 @@ internal static void RunInternal(ExecutionContext? executionContext, Con { // Note: ExecutionContext.RunInternal is an extremely hot function and used by every await, ThreadPool execution, etc. // Note: Manual enregistering may be addressed by "Exception Handling Write Through Optimization" - // https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/eh-writethru.md + // https://github.com/dotnet/runtime/blob/master/docs/coreclr/design-docs/eh-writethru.md // Enregister variables with 0 post-fix so they can be used in registers without EH forcing them to stack // Capture references to Thread Contexts diff --git a/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs b/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs index b8b05a77473..0e9ecac5877 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs @@ -140,7 +140,7 @@ public static T EnsureInitialized([AllowNull] ref T target, ref bool initiali // Fast path. if (Volatile.Read(ref initialized)) { - return target; + return target!; } return EnsureInitializedCore(ref target, ref initialized, ref syncLock); @@ -177,7 +177,7 @@ private static T EnsureInitializedCore([AllowNull] ref T target, ref bool ini } } - return target; + return target!; } /// @@ -199,7 +199,7 @@ public static T EnsureInitialized([AllowNull] ref T target, ref bool initiali // Fast path. if (Volatile.Read(ref initialized)) { - return target; + return target!; } return EnsureInitializedCore(ref target, ref initialized, ref syncLock, valueFactory); @@ -230,7 +230,7 @@ private static T EnsureInitializedCore([AllowNull] ref T target, ref bool ini } } - return target; + return target!; } /// diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs index 71181d7502f..ad362be2d7f 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs @@ -60,7 +60,7 @@ namespace System.Threading.Tasks public class Task : Task { // The value itself, if set. - [MaybeNull] internal TResult m_result = default!; + [MaybeNull, AllowNull] internal TResult m_result = default!; private static readonly TaskFactory s_Factory = new TaskFactory(); @@ -439,7 +439,7 @@ internal void DangerousSetResult(TResult result) public TResult Result => IsWaitNotificationEnabledOrNotRanToCompletion ? GetResultCore(waitCompletionNotification: true) : - m_result; + m_result!; /// /// Gets the result value of this once the task has completed successfully. @@ -454,7 +454,7 @@ internal TResult ResultOnSuccess { Debug.Assert(!IsWaitNotificationEnabledOrNotRanToCompletion, "Should only be used when the task completed successfully and there's no wait notification enabled"); - return m_result; + return m_result!; } } @@ -473,7 +473,7 @@ internal TResult GetResultCore(bool waitCompletionNotification) // We shouldn't be here if the result has not been set. Debug.Assert(IsCompletedSuccessfully, "Task.Result getter: Expected result to have been set."); - return m_result; + return m_result!; } /// diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs index 05cd310369b..8ce80046baf 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs @@ -4229,6 +4229,7 @@ public Task ContinueWith(Func continua /// The continuation task itself. /// TaskScheduler with which to associate continuation task. /// Restrictions on when the continuation becomes active. + /// The token to monitor for cancellation requests. internal void ContinueWithCore(Task continuationTask, TaskScheduler scheduler, CancellationToken cancellationToken, diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TplEventSource.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TplEventSource.cs index 359d3363c54..f244f31383c 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TplEventSource.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TplEventSource.cs @@ -194,6 +194,7 @@ public static class Keywords // this name is important for EventSource /// The task ID. /// The task ID /// The options used to create the task. + /// The ID for the current AppDomain. [Event(TASKSCHEDULED_ID, Task = Tasks.TaskScheduled, Version = 1, Opcode = EventOpcode.Send, Level = EventLevel.Informational, Keywords = Keywords.TaskTransfer | Keywords.Tasks)] public void TaskScheduled( @@ -392,11 +393,12 @@ public void TaskWaitContinuationStarted(int TaskID) /// /// The scheduler ID. /// The task ID. + /// The ID of the continuation object. [Event(AWAITTASKCONTINUATIONSCHEDULED_ID, Task = Tasks.AwaitTaskContinuationScheduled, Opcode = EventOpcode.Send, Level = EventLevel.Informational, Keywords = Keywords.TaskTransfer | Keywords.Tasks)] public void AwaitTaskContinuationScheduled( int OriginatingTaskSchedulerID, int OriginatingTaskID, // PFX_COMMON_EVENT_HEADER - int ContinuwWithTaskId) + int ContinueWithTaskId) { if (IsEnabled() && IsEnabled(EventLevel.Informational, Keywords.TaskTransfer | Keywords.Tasks)) { @@ -410,11 +412,11 @@ public void TaskWaitContinuationStarted(int TaskID) eventPayload[1].DataPointer = ((IntPtr)(&OriginatingTaskID)); eventPayload[1].Reserved = 0; eventPayload[2].Size = sizeof(int); - eventPayload[2].DataPointer = ((IntPtr)(&ContinuwWithTaskId)); + eventPayload[2].DataPointer = ((IntPtr)(&ContinueWithTaskId)); eventPayload[2].Reserved = 0; if (TasksSetActivityIds) { - Guid continuationActivityId = CreateGuidForTaskID(ContinuwWithTaskId); + Guid continuationActivityId = CreateGuidForTaskID(ContinueWithTaskId); WriteEventWithRelatedActivityIdCore(AWAITTASKCONTINUATIONSCHEDULED_ID, &continuationActivityId, 3, eventPayload); } else diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs index d945938bb0e..77a8b95b41e 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs @@ -67,7 +67,7 @@ namespace System.Threading.Tasks internal readonly object? _obj; /// Opaque value passed through to the . internal readonly short _token; - /// true to continue on the capture context; otherwise, true. + /// true to continue on the captured context; otherwise, false. /// Stored in the rather than in the configured awaiter to utilize otherwise padding space. internal readonly bool _continueOnCapturedContext; diff --git a/src/System.Private.CoreLib/shared/System/Threading/ThreadLocal.cs b/src/System.Private.CoreLib/shared/System/Threading/ThreadLocal.cs index dbaf1627c7d..592db0b3a68 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/ThreadLocal.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/ThreadLocal.cs @@ -805,6 +805,7 @@ public SystemThreading_ThreadLocalDebugView(ThreadLocal tlocal) public bool IsValueCreated => _tlocal.IsValueCreated; /// Returns the value of the ThreadLocal object. + [MaybeNull] public T Value => _tlocal.ValueForDebugDisplay; /// Return all values for all threads that have accessed this instance. diff --git a/src/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs b/src/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs index 98ca59c2db9..14755e59159 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/ThreadPool.cs @@ -14,7 +14,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/src/System.Private.CoreLib/shared/System/Threading/Timer.cs b/src/System.Private.CoreLib/shared/System/Threading/Timer.cs index d7c0537f559..3b590ae7382 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Timer.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Timer.cs @@ -4,7 +4,6 @@ using System.Diagnostics; using System.Diagnostics.Tracing; -using System.Runtime.ExceptionServices; using System.Threading.Tasks; namespace System.Threading diff --git a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.cs b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.cs index 8e04fd2d27e..53711f0bcbf 100644 --- a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.cs +++ b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.Serialization; using System.Threading; diff --git a/src/System.Private.CoreLib/shared/System/UIntPtr.cs b/src/System.Private.CoreLib/shared/System/UIntPtr.cs index 754fc5e412d..8b9868881ad 100644 --- a/src/System.Private.CoreLib/shared/System/UIntPtr.cs +++ b/src/System.Private.CoreLib/shared/System/UIntPtr.cs @@ -26,14 +26,12 @@ namespace System [Intrinsic] public static readonly UIntPtr Zero; - [Intrinsic] [NonVersionable] public unsafe UIntPtr(uint value) { _value = (void*)value; } - [Intrinsic] [NonVersionable] public unsafe UIntPtr(ulong value) { @@ -44,7 +42,6 @@ public unsafe UIntPtr(ulong value) #endif } - [Intrinsic] [NonVersionable] public unsafe UIntPtr(void* value) { @@ -91,7 +88,6 @@ public override unsafe int GetHashCode() #endif } - [Intrinsic] [NonVersionable] public unsafe uint ToUInt32() { @@ -102,31 +98,25 @@ public unsafe uint ToUInt32() #endif } - [Intrinsic] [NonVersionable] public unsafe ulong ToUInt64() => (ulong)_value; - [Intrinsic] [NonVersionable] public static explicit operator UIntPtr(uint value) => new UIntPtr(value); - [Intrinsic] [NonVersionable] public static explicit operator UIntPtr(ulong value) => new UIntPtr(value); - [Intrinsic] [NonVersionable] public static unsafe explicit operator UIntPtr(void* value) => new UIntPtr(value); - [Intrinsic] [NonVersionable] public static unsafe explicit operator void*(UIntPtr value) => value._value; - [Intrinsic] [NonVersionable] public static unsafe explicit operator uint(UIntPtr value) => #if BIT64 @@ -135,17 +125,14 @@ public unsafe uint ToUInt32() (uint)value._value; #endif - [Intrinsic] [NonVersionable] public static unsafe explicit operator ulong(UIntPtr value) => (ulong)value._value; - [Intrinsic] [NonVersionable] public static unsafe bool operator ==(UIntPtr value1, UIntPtr value2) => value1._value == value2._value; - [Intrinsic] [NonVersionable] public static unsafe bool operator !=(UIntPtr value1, UIntPtr value2) => value1._value != value2._value; @@ -154,7 +141,6 @@ public unsafe uint ToUInt32() public static UIntPtr Add(UIntPtr pointer, int offset) => pointer + offset; - [Intrinsic] [NonVersionable] public static unsafe UIntPtr operator +(UIntPtr pointer, int offset) => new UIntPtr((nuint)pointer._value + (nuint)offset); @@ -163,19 +149,16 @@ public unsafe uint ToUInt32() public static UIntPtr Subtract(UIntPtr pointer, int offset) => pointer - offset; - [Intrinsic] [NonVersionable] public static unsafe UIntPtr operator -(UIntPtr pointer, int offset) => new UIntPtr((nuint)pointer._value - (nuint)offset); public static int Size { - [Intrinsic] [NonVersionable] get => sizeof(nuint); } - [Intrinsic] [NonVersionable] public unsafe void* ToPointer() => _value; diff --git a/src/System.Private.CoreLib/shared/System/WeakReference.T.cs b/src/System.Private.CoreLib/shared/System/WeakReference.T.cs index 864ad5b7916..bedc90feb6f 100644 --- a/src/System.Private.CoreLib/shared/System/WeakReference.T.cs +++ b/src/System.Private.CoreLib/shared/System/WeakReference.T.cs @@ -56,7 +56,7 @@ public bool TryGetTarget([MaybeNullWhen(false), NotNullWhen(true)] out T target) { // Call the worker method that has more performant but less user friendly signature. T o = this.Target; - target = o; + target = o!; return o != null; }