From 7fce98f048a6ff97264aab85bcb0da16ae0faff5 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 16 May 2024 20:11:48 -0700 Subject: [PATCH 1/2] Cleanup CoreLib CompatibilitySuppressions --- .../CompatibilitySuppressions.xml | 32 ----------------- .../Collections/Generic/LowLevelDictionary.cs | 9 ----- .../Collections/Generic/LowLevelList.cs | 3 -- .../src/CompatibilitySuppressions.xml | 32 ----------------- .../src/ILLink/ILLink.LinkAttributes.xml | 3 -- .../src/System.Private.CoreLib.csproj | 5 ++- .../ForceDictionaryLookupsAttribute.cs | 12 ------- .../System.Private.CoreLib.Shared.projitems | 1 - .../TraceLogging/TraceLoggingEventSource.cs | 2 +- .../CompatibilitySuppressions.xml | 35 ------------------- .../CompilerServices/RuntimeHelpers.Mono.cs | 1 + 11 files changed, 6 insertions(+), 129 deletions(-) delete mode 100644 src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml delete mode 100644 src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ForceDictionaryLookupsAttribute.cs delete mode 100644 src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml diff --git a/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml b/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml deleted file mode 100644 index 97b65a2748409e..00000000000000 --- a/src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,``0):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,System.Guid@,System.Guid@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEvent(System.Int32,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEventCore(System.Int32,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityId(System.Int32,System.Guid,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - \ No newline at end of file diff --git a/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelDictionary.cs b/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelDictionary.cs index cd98bef0d7d8bc..5e8c8a073f1453 100644 --- a/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelDictionary.cs +++ b/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelDictionary.cs @@ -20,9 +20,6 @@ namespace System.Collections.Generic ** behavior.) ** ===========================================================*/ -#if TYPE_LOADER_IMPLEMENTATION - [System.Runtime.CompilerServices.ForceDictionaryLookups] -#endif internal class LowLevelDictionary where TKey : IEquatable { private const int DefaultSize = 17; @@ -209,9 +206,6 @@ private int GetBucket(TKey key, int numBuckets = 0) } -#if TYPE_LOADER_IMPLEMENTATION - [System.Runtime.CompilerServices.ForceDictionaryLookups] -#endif private sealed class Entry { public TKey m_key; @@ -223,9 +217,6 @@ private sealed class Entry private int _numEntries; private int _version; -#if TYPE_LOADER_IMPLEMENTATION - [System.Runtime.CompilerServices.ForceDictionaryLookups] -#endif protected sealed class LowLevelDictEnumerator : IEnumerator> { public LowLevelDictEnumerator(LowLevelDictionary dict) diff --git a/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelList.cs b/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelList.cs index a6e5e3a3fe9752..e9338d6cc7c300 100644 --- a/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelList.cs +++ b/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelList.cs @@ -33,9 +33,6 @@ namespace System.Collections.Generic // Code size is smaller because only functions called will be in the binary. // Use LowLevelListWithIList for IList support [DebuggerDisplay("Count = {Count}")] -#if TYPE_LOADER_IMPLEMENTATION - [System.Runtime.CompilerServices.ForceDictionaryLookups] -#endif internal class LowLevelList { private const int _defaultCapacity = 4; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml index 770514a671adfc..0fe341e7bc5917 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml @@ -821,10 +821,6 @@ CP0001 T:System.Reflection.RuntimeAssemblyName - - CP0001 - T:System.Runtime.CompilerServices.ForceDictionaryLookupsAttribute - CP0001 T:System.Runtime.CompilerServices.StaticClassConstructionContext @@ -837,32 +833,4 @@ CP0002 M:System.Threading.Lock.#ctor(System.Boolean) - - CP0015 - M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,``0):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,System.Guid@,System.Guid@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEvent(System.Int32,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEventCore(System.Int32,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityId(System.Int32,System.Guid,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.xml b/src/coreclr/nativeaot/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.xml index d2691fa8803934..b8cee37fb2cc5d 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.xml +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.xml @@ -5,9 +5,6 @@ - - - diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj index faf1eb8fc3de11..1d5eb6e7ec7c87 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -3,6 +3,10 @@ true + + + + @@ -185,7 +189,6 @@ - diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ForceDictionaryLookupsAttribute.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ForceDictionaryLookupsAttribute.cs deleted file mode 100644 index 104bd032bd6592..00000000000000 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ForceDictionaryLookupsAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace System.Runtime.CompilerServices -{ - // When applied to a type this custom attribute will force use of statically precompiled dictionary looks that - // do not depend on lazy resolution by the template type loader - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - public class ForceDictionaryLookupsAttribute : Attribute - { - } -} diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 0729a1434d2c01..3ec13eb3791f86 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -48,7 +48,6 @@ $(DefineConstants);TARGET_HAIKU - diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs index b978caaeaebabb..20c6c8516d9f40 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs @@ -19,7 +19,7 @@ public partial class EventSource { private byte[]? m_providerMetadata; private protected virtual ReadOnlySpan ProviderMetadata => m_providerMetadata; - private const string EventSourceRequiresUnreferenceMessage = "EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed."; + private const string EventSourceRequiresUnreferenceMessage = "EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type"; private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; #if FEATURE_PERFTRACING diff --git a/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml b/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml deleted file mode 100644 index 8e96fb8cbaa781..00000000000000 --- a/src/mono/System.Private.CoreLib/CompatibilitySuppressions.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - CP0014 - M:System.Runtime.CompilerServices.RuntimeHelpers.GetObjectValue(System.Object)->object?:[T:System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,``0):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.Write``1(System.String,System.Diagnostics.Tracing.EventSourceOptions@,System.Guid@,System.Guid@,``0@):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEvent(System.Int32,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEventCore(System.Int32,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityId(System.Int32,System.Guid,System.Object[]):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - - CP0015 - M:System.Diagnostics.Tracing.EventSource.WriteEventWithRelatedActivityIdCore(System.Int32,System.Guid*,System.Int32,System.Diagnostics.Tracing.EventSource.EventData*):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute] - - diff --git a/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs index 37a655841d652a..9be5b3d817dced 100644 --- a/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs @@ -77,6 +77,7 @@ internal static int TryGetHashCode(object? o) } [MethodImplAttribute(MethodImplOptions.InternalCall)] + [return: NotNullIfNotNull(nameof(obj))] public static extern object? GetObjectValue(object? obj); [RequiresUnreferencedCode("Trimmer can't guarantee existence of class constructor")] From d104deb4edc0900b5df2e227944fe292b54facdf Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 20 May 2024 07:28:39 -0700 Subject: [PATCH 2/2] Revert ForceDictionaryLookupsAttribute change --- .../System/Collections/Generic/LowLevelDictionary.cs | 9 +++++++++ .../src/System/Collections/Generic/LowLevelList.cs | 3 +++ .../src/CompatibilitySuppressions.xml | 4 ++++ .../src/ILLink/ILLink.LinkAttributes.xml | 3 +++ .../src/System.Private.CoreLib.csproj | 1 + .../ForceDictionaryLookupsAttribute.cs | 12 ++++++++++++ 6 files changed, 32 insertions(+) create mode 100644 src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ForceDictionaryLookupsAttribute.cs diff --git a/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelDictionary.cs b/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelDictionary.cs index 5e8c8a073f1453..cd98bef0d7d8bc 100644 --- a/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelDictionary.cs +++ b/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelDictionary.cs @@ -20,6 +20,9 @@ namespace System.Collections.Generic ** behavior.) ** ===========================================================*/ +#if TYPE_LOADER_IMPLEMENTATION + [System.Runtime.CompilerServices.ForceDictionaryLookups] +#endif internal class LowLevelDictionary where TKey : IEquatable { private const int DefaultSize = 17; @@ -206,6 +209,9 @@ private int GetBucket(TKey key, int numBuckets = 0) } +#if TYPE_LOADER_IMPLEMENTATION + [System.Runtime.CompilerServices.ForceDictionaryLookups] +#endif private sealed class Entry { public TKey m_key; @@ -217,6 +223,9 @@ private sealed class Entry private int _numEntries; private int _version; +#if TYPE_LOADER_IMPLEMENTATION + [System.Runtime.CompilerServices.ForceDictionaryLookups] +#endif protected sealed class LowLevelDictEnumerator : IEnumerator> { public LowLevelDictEnumerator(LowLevelDictionary dict) diff --git a/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelList.cs b/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelList.cs index e9338d6cc7c300..a6e5e3a3fe9752 100644 --- a/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelList.cs +++ b/src/coreclr/nativeaot/Common/src/System/Collections/Generic/LowLevelList.cs @@ -33,6 +33,9 @@ namespace System.Collections.Generic // Code size is smaller because only functions called will be in the binary. // Use LowLevelListWithIList for IList support [DebuggerDisplay("Count = {Count}")] +#if TYPE_LOADER_IMPLEMENTATION + [System.Runtime.CompilerServices.ForceDictionaryLookups] +#endif internal class LowLevelList { private const int _defaultCapacity = 4; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml index 0fe341e7bc5917..69d5d5a83a40de 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/CompatibilitySuppressions.xml @@ -821,6 +821,10 @@ CP0001 T:System.Reflection.RuntimeAssemblyName + + CP0001 + T:System.Runtime.CompilerServices.ForceDictionaryLookupsAttribute + CP0001 T:System.Runtime.CompilerServices.StaticClassConstructionContext diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.xml b/src/coreclr/nativeaot/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.xml index b8cee37fb2cc5d..d2691fa8803934 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.xml +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.xml @@ -5,6 +5,9 @@ + + + diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj index 1d5eb6e7ec7c87..a0326ea96f737d 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -189,6 +189,7 @@ + diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ForceDictionaryLookupsAttribute.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ForceDictionaryLookupsAttribute.cs new file mode 100644 index 00000000000000..104bd032bd6592 --- /dev/null +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ForceDictionaryLookupsAttribute.cs @@ -0,0 +1,12 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Runtime.CompilerServices +{ + // When applied to a type this custom attribute will force use of statically precompiled dictionary looks that + // do not depend on lazy resolution by the template type loader + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + public class ForceDictionaryLookupsAttribute : Attribute + { + } +}