-
Notifications
You must be signed in to change notification settings - Fork 215
Merge requiresunsafe-corelib2 into feature/requires-unsafe #3209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/requires-unsafe
Are you sure you want to change the base?
Changes from all commits
f831e85
41893f5
73b3389
8aec308
f2e66af
9a8c31b
bc538f8
c0df804
b73ffce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2407,7 +2407,9 @@ private static bool FilterApplyMethodBase( | |
| private readonly object m_keepalive; // This will be filled with a LoaderAllocator reference when this RuntimeType represents a collectible type | ||
| #pragma warning restore CS0169 | ||
| #pragma warning restore CA1823 | ||
| private IntPtr m_cache; | ||
| // Must be a handle to a RuntimeTypeCache type | ||
| [RequiresUnsafe] | ||
| private unsafe IntPtr m_cache; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add [RequiresUnsafe] as well
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit b73ffce. Added |
||
| internal IntPtr m_handle; | ||
|
|
||
| internal static readonly RuntimeType ValueType = (RuntimeType)typeof(ValueType); | ||
|
|
@@ -2448,7 +2450,10 @@ private RuntimeTypeCache? CacheIfExists | |
| { | ||
| object? cache = GCHandle.InternalGet(m_cache); | ||
agocke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Debug.Assert(cache == null || cache is RuntimeTypeCache); | ||
| return Unsafe.As<RuntimeTypeCache>(cache); | ||
| unsafe | ||
| { | ||
| return Unsafe.As<RuntimeTypeCache>(cache); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
@@ -2465,7 +2470,10 @@ private RuntimeTypeCache Cache | |
| if (cache != null) | ||
| { | ||
| Debug.Assert(cache is RuntimeTypeCache); | ||
| return Unsafe.As<RuntimeTypeCache>(cache); | ||
| unsafe | ||
| { | ||
| return Unsafe.As<RuntimeTypeCache>(cache); | ||
| } | ||
| } | ||
| } | ||
| return InitializeCache(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,11 @@ | |
| SharedArrayPoolThreadLocalArray[]? tlsBuckets = t_tlsBuckets; | ||
| if (tlsBuckets is not null && (uint)bucketIndex < (uint)tlsBuckets.Length) | ||
| { | ||
| buffer = Unsafe.As<T[]>(tlsBuckets[bucketIndex].Array); | ||
agocke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| unsafe | ||
| { | ||
| // Array should always be an array of T[] | ||
| buffer = Unsafe.As<T[]>(tlsBuckets[bucketIndex].Array); | ||
agocke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| if (buffer is not null) | ||
| { | ||
| tlsBuckets[bucketIndex].Array = null; | ||
|
|
@@ -79,7 +83,10 @@ | |
| SharedArrayPoolPartitions? b = perCoreBuckets[bucketIndex]; | ||
| if (b is not null) | ||
| { | ||
| buffer = Unsafe.As<T[]>(b.TryPop()); | ||
| unsafe | ||
| { | ||
| buffer = Unsafe.As<T[]>(b.TryPop()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TryPop must always be a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit c0df804. Made TryPush method unsafe with comment "Array parameter must be a T[]".
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mark the TryPush method RequiresUnsafe instead.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit b73ffce. Changed TryPush method from |
||
| } | ||
| if (buffer is not null) | ||
| { | ||
| if (log.IsEnabled()) | ||
|
|
@@ -302,7 +309,9 @@ | |
| internal struct SharedArrayPoolThreadLocalArray | ||
| { | ||
| /// <summary>The stored array.</summary> | ||
| public Array? Array; | ||
| // Must be an array of T[] at runtime | ||
| [RequiresUnsafe] | ||
|
Check failure on line 313 in src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs
|
||
| public unsafe Array? Array; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add [RequiresUnsafe]
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit b73ffce. Added |
||
| /// <summary>Environment.TickCount timestamp for when this array was observed by Trim.</summary> | ||
| public int MillisecondsTimeStamp; | ||
|
|
||
|
|
@@ -390,6 +399,8 @@ | |
| private int _millisecondsTimestamp; | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| // Array parameter must be a T[] | ||
| [RequiresUnsafe] | ||
|
Check failure on line 403 in src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs
|
||
| public bool TryPush(Array array) | ||
| { | ||
| bool enqueued = false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2258,7 +2258,9 @@ internal Node(TKey key, TValue value, int hashcode, Node? next) | |
| private sealed class Tables | ||
| { | ||
| /// <summary>The comparer to use for lookups in the tables.</summary> | ||
| internal readonly IEqualityComparer<TKey>? _comparer; | ||
| // Must be IAlternateEqualityComparer<TAlternateKey, TKey> | ||
| [RequiresUnsafe] | ||
| internal readonly unsafe IEqualityComparer<TKey>? _comparer; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add [RequiresUnsafe]
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit b73ffce. Added |
||
| /// <summary>A singly-linked list for each bucket.</summary> | ||
| internal readonly VolatileNode[] _buckets; | ||
| /// <summary>Pre-computed multiplier for use on 64-bit performing faster modulo operations.</summary> | ||
|
|
@@ -2317,6 +2319,7 @@ private static bool IsCompatibleKey<TAlternateKey>(ConcurrentDictionary<TKey, TV | |
|
|
||
| /// <summary>Gets the dictionary's alternate comparer. The dictionary must have already been verified as compatible.</summary> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| [RequiresUnsafe] | ||
| private static IAlternateEqualityComparer<TAlternateKey, TKey> GetAlternateComparer<TAlternateKey>(ConcurrentDictionary<TKey, TValue>.Tables tables) | ||
| where TAlternateKey : notnull, allows ref struct | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,9 @@ public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, | |
| private int _freeList; | ||
| private int _freeCount; | ||
| private int _version; | ||
| private IEqualityComparer<TKey>? _comparer; | ||
| // Must be IAlternateEqualityComparer<TAlternateKey, TKey> | ||
| [RequiresUnsafe] | ||
| private unsafe IEqualityComparer<TKey>? _comparer; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add [RequiresUnsafe]
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit b73ffce. Added |
||
| private KeyCollection? _keys; | ||
| private ValueCollection? _values; | ||
| private const int StartOfFreeList = -3; | ||
|
|
@@ -734,6 +736,7 @@ internal static bool IsCompatibleKey(Dictionary<TKey, TValue> dictionary) | |
|
|
||
| /// <summary>Gets the dictionary's alternate comparer. The dictionary must have already been verified as compatible.</summary> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| [RequiresUnsafe] | ||
| internal static IAlternateEqualityComparer<TAlternateKey, TKey> GetAlternateComparer(Dictionary<TKey, TValue> dictionary) | ||
| { | ||
| Debug.Assert(IsCompatibleKey(dictionary)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,9 @@ public class HashSet<T> : ICollection<T>, ISet<T>, IReadOnlyCollection<T>, IRead | |
| private int _freeList; | ||
| private int _freeCount; | ||
| private int _version; | ||
| private IEqualityComparer<T>? _comparer; | ||
| // Must be IAlternateEqualityComparer<TAlternate, T> | ||
| [RequiresUnsafe] | ||
| private unsafe IEqualityComparer<T>? _comparer; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add [RequiresUnsafe]
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit b73ffce. Added |
||
|
|
||
| #region Constructors | ||
|
|
||
|
|
@@ -441,6 +443,7 @@ internal static bool IsCompatibleItem(HashSet<T> set) | |
|
|
||
| /// <summary>Gets the set's alternate comparer. The set must have already been verified as compatible.</summary> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| [RequiresUnsafe] | ||
| internal static IAlternateEqualityComparer<TAlternate, T> GetAlternateComparer(HashSet<T> set) | ||
| { | ||
| Debug.Assert(IsCompatibleItem(set)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.