Skip to content

Conversation

@agocke
Copy link
Member

@agocke agocke commented Oct 29, 2025

No description provided.

unsafe
{
return false;
unsafe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is really, really unsafe I guess :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol not sure what happened there

/// code from an application.
/// </remarks>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)]
internal sealed class RequiresUnsafeAttribute : Attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we know some version of this attribute is going to be required, should we go ahead and take it to API review so we can land on the name (even if the exact constructors it contains may change over time)?

There's been a few names that have been floated around such as RequiresUnsafe (closest prior is RequiresUnreferencedCode) or UnsafeCallersOnly (closest prior is UnmanagedCallersOnly). There may be other ideas/opinions that more correctly conveys "this member is unsafe" as well.

buffer = Unsafe.As<T[]>(tlsBuckets[bucketIndex].Array);
unsafe
{
buffer = Unsafe.As<T[]>(tlsBuckets[bucketIndex].Array);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could remove the unsafe here and just cast to T[] here, right?

The only reason this isn't already T[] and that it's using System.Array instead is to avoid the generic code size increase for the SharedArrayPoolThreadLocalArray struct, but maybe that's something we could track addressing as well if the cast is too expensive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this has perf fine-tuned using unsafe code. Number of other cases in this PR are in the same category.

buffer = Unsafe.As<T[]>(tlsBuckets[bucketIndex].Array);
unsafe
{
buffer = Unsafe.As<T[]>(tlsBuckets[bucketIndex].Array);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good case-study for the annotation guidelines. This is safe because we manually ensure that we only assign T[] into Array field. Should the Array field and all places that assign to it be marked unsafe as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants