-
Notifications
You must be signed in to change notification settings - Fork 214
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 8 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,8 @@ 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 | ||
| 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 +2449,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 +2469,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 @@ public override T[] Rent(int minimumLength) | |
| 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 @@ public override T[] Rent(int minimumLength) | |
| 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,8 @@ private SharedArrayPoolThreadLocalArray[] InitializeTlsBucketsAndTrimming() | |
| internal struct SharedArrayPoolThreadLocalArray | ||
| { | ||
| /// <summary>The stored array.</summary> | ||
| public Array? Array; | ||
| // Must be an array of T[] at runtime | ||
| 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,7 +398,8 @@ private sealed class Partition | |
| private int _millisecondsTimestamp; | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public bool TryPush(Array array) | ||
| // Array parameter must be a T[] | ||
| public unsafe bool TryPush(Array array) | ||
| { | ||
| bool enqueued = false; | ||
| Monitor.Enter(this); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2258,7 +2258,8 @@ | |
| 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> | ||
| 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 +2318,7 @@ | |
|
|
||
| /// <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 | ||
| { | ||
|
|
@@ -2384,7 +2386,7 @@ | |
| } | ||
|
|
||
| Tables tables = Dictionary._tables; | ||
| IAlternateEqualityComparer<TAlternateKey, TKey> comparer = GetAlternateComparer<TAlternateKey>(tables); | ||
|
Check failure on line 2389 in src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentDictionary.cs
|
||
|
|
||
| int hashcode = comparer.GetHashCode(key); | ||
|
|
||
|
|
@@ -2407,7 +2409,7 @@ | |
| tables = Dictionary._tables; | ||
| if (!ReferenceEquals(comparer, tables._comparer)) | ||
| { | ||
| comparer = GetAlternateComparer<TAlternateKey>(tables); | ||
|
Check failure on line 2412 in src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentDictionary.cs
|
||
| hashcode = comparer.GetHashCode(key); | ||
| } | ||
| continue; | ||
|
|
@@ -2543,7 +2545,7 @@ | |
| } | ||
|
|
||
| Tables tables = Dictionary._tables; | ||
| IAlternateEqualityComparer<TAlternateKey, TKey> comparer = GetAlternateComparer<TAlternateKey>(tables); | ||
|
Check failure on line 2548 in src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentDictionary.cs
|
||
|
|
||
| int hashcode = comparer.GetHashCode(key); | ||
| for (Node? n = GetBucket(tables, hashcode); n is not null; n = n._next) | ||
|
|
@@ -2589,7 +2591,7 @@ | |
| } | ||
|
|
||
| Tables tables = Dictionary._tables; | ||
| IAlternateEqualityComparer<TAlternateKey, TKey> comparer = GetAlternateComparer<TAlternateKey>(tables); | ||
|
Check failure on line 2594 in src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentDictionary.cs
|
||
| int hashcode = comparer.GetHashCode(key); | ||
|
|
||
| while (true) | ||
|
|
@@ -2610,7 +2612,7 @@ | |
| tables = Dictionary._tables; | ||
| if (!ReferenceEquals(comparer, tables._comparer)) | ||
| { | ||
| comparer = GetAlternateComparer<TAlternateKey>(tables); | ||
|
Check failure on line 2615 in src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentDictionary.cs
|
||
| hashcode = comparer.GetHashCode(key); | ||
| } | ||
| continue; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,8 @@ | |
| private int _freeList; | ||
| private int _freeCount; | ||
| private int _version; | ||
| private IEqualityComparer<TKey>? _comparer; | ||
| // Must be IAlternateEqualityComparer<TAlternateKey, TKey> | ||
| 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; | ||
|
|
@@ -716,7 +717,7 @@ | |
| ref TValue value = ref FindValue(key, out _); | ||
| if (Unsafe.IsNullRef(ref value)) | ||
| { | ||
| ThrowHelper.ThrowKeyNotFoundException(GetAlternateComparer(Dictionary).Create(key)); | ||
|
Check failure on line 720 in src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs
|
||
| } | ||
|
|
||
| return value; | ||
|
|
@@ -734,6 +735,7 @@ | |
|
|
||
| /// <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)); | ||
|
|
@@ -801,7 +803,7 @@ | |
| internal ref TValue FindValue(TAlternateKey key, [MaybeNullWhen(false)] out TKey actualKey) | ||
| { | ||
| Dictionary<TKey, TValue> dictionary = Dictionary; | ||
| IAlternateEqualityComparer<TAlternateKey, TKey> comparer = GetAlternateComparer(dictionary); | ||
|
Check failure on line 806 in src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs
|
||
|
|
||
| ref Entry entry = ref Unsafe.NullRef<Entry>(); | ||
| if (dictionary._buckets != null) | ||
|
|
@@ -872,7 +874,7 @@ | |
| public bool Remove(TAlternateKey key, [MaybeNullWhen(false)] out TKey actualKey, [MaybeNullWhen(false)] out TValue value) | ||
| { | ||
| Dictionary<TKey, TValue> dictionary = Dictionary; | ||
| IAlternateEqualityComparer<TAlternateKey, TKey> comparer = GetAlternateComparer(dictionary); | ||
|
Check failure on line 877 in src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs
|
||
|
|
||
| if (dictionary._buckets != null) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,8 @@ | |
| private int _freeList; | ||
| private int _freeCount; | ||
| private int _version; | ||
| private IEqualityComparer<T>? _comparer; | ||
| // Must be IAlternateEqualityComparer<TAlternate, T> | ||
| 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 +442,7 @@ | |
|
|
||
| /// <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)); | ||
|
|
@@ -453,7 +455,7 @@ | |
| public bool Add(TAlternate item) | ||
| { | ||
| HashSet<T> set = Set; | ||
| IAlternateEqualityComparer<TAlternate, T> comparer = GetAlternateComparer(set); | ||
|
Check failure on line 458 in src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs
|
||
|
|
||
| if (set._buckets == null) | ||
| { | ||
|
|
@@ -541,7 +543,7 @@ | |
| public bool Remove(TAlternate item) | ||
| { | ||
| HashSet<T> set = Set; | ||
| IAlternateEqualityComparer<TAlternate, T> comparer = GetAlternateComparer(set); | ||
|
Check failure on line 546 in src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs
|
||
|
|
||
| if (set._buckets != null) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.