-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Conversation
@atsushikan PTLA FYI @adamsitnik We are getting closer to make Span real. Thank you for your work on it! |
cc @joshfree |
The tests are not enabled in automation because of the Span is not exposed in the contracts yet. |
} | ||
} | ||
|
||
public static class ReadOnlySpanExtensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we kill these extension methods until we get more clarity on Span/Memory sting interactions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is work to do to come up with the final version of the Span APIs, and then fix up both Span implementations to it. I do not think that it is productive to do speculative tweaks until then.
(And these extensions are not affected by Span/Memory interactions. They may be affected by slicing language syntax though.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing we could do is leave the extension methods in corfxlab. I will be easier/faster to tweak them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can, but we would be losing some perf - number of the current extension methods are implemented using constructs that are not in the public surface.
b4fe60d
to
d0ebbd4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not document all public APIs?
public T[] ToArray() | ||
{ | ||
var destination = new T[_length]; | ||
TryCopyTo(destination); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if it fails? A Try
pattern implies it can fail and a success value is returned, which is not used here. I'd expect it to be either used or have an inline comment if it's sure that it can't fail.
@MartinJohns Thanks for taking a look - I have incorporated your feedback. |
public struct ReadOnlySpan<T> | ||
{ | ||
/// <summary>A byref or a native ptr. Do not access directly</summary> | ||
internal /* readonly */ IntPtr _rawPointer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the readonly
commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was necessary for the JitHelpers that fetch the field as ref
. These JitHelpers are not 100% correct anyway wrt GC and we need work in the JIT to fix it - I have removed them and switched the fields to private readonly
.
@@ -631,6 +631,10 @@ Argument_UnmanagedMemAccessorWrapAround = The UnmanagedMemoryAccessor capacity a | |||
Argument_UnrecognizedLoaderOptimization = Unrecognized LOADER_OPTIMIZATION property value. Supported values may include "SingleDomain", "MultiDomain", "MultiDomainHost", and "NotSpecified". | |||
ArgumentException_NotAllCustomSortingFuncsDefined = Implementations of all the NLS functions must be provided. | |||
ArgumentException_MinSortingVersion = The runtime does not support a version of "{0}" less than {1}. | |||
#if FEATURE_SPAN_OF_T | |||
Argument_InvalidTypeWithPointersNotSupported = Cannot use type '{0}'. Only value types without pointers are supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: We should probably clarify the error message to call out that only value types without pointers or references are supported, since they show up differently in the language.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the doc comments also contain the text "type may not contain pointers."
And how does runtime enforcement of this (JitHelpers.ContainsGcReferences) happen on the OOB version?
namespace System | ||
{ | ||
/// <summary> | ||
/// Span is a uniform API for dealing with arrays and subarrays, strings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: in its current form, it's not really for strings and substrings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am replacing this description with the one in @KrzysztofCwalina spec.
else if (strcmp(name, g_ReadOnlySpanName) == 0) | ||
{ | ||
pMT->SetIsByRefLike(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this going to cause any problems if someone has their own System.Span<T>
or System.ReadOnlySpan<T>
defined in their own library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only runs for types in corelib. The callsite of this method is under if (GetModule()->IsSystem())
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let's leave them here as-is. We want to get quickly to a point where we understand where we are with perf. We can tweak the APIs in both places and sync them periodically.
- Generic ArrayPinningHelper resulted into incorrect array data offset for reference types. Use non-generic one instead. - Add array covariance checks to guarantee type safety.
…otnet#7220) * added AsBytes() and NonPortableCast() to Span and ReadOnlySpan API, fixes #7211 * throw when casted types contain pointers
Fix missing pinning in CopyTo<T> Move and rename some JitHelpers to S.R.CS.Unsafe to make different implementations more similar
1adfa90
to
f31afb2
Compare
/// Thrown when the specified <paramref name="length"/> is negative. | ||
/// </exception> | ||
[CLSCompliant(false)] | ||
public unsafe ReadOnlySpan(void* ptr, int length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could the parameter be called "pointer"? It's more aligned with out naming conventions and I use Pointer for the same concept in in Memory APIs .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -0,0 +1,672 @@ | |||
using System; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atsushikan, it would be great if fast and slow span tests were equivalent to ensure the same semantics.
{ | ||
if (array == null) | ||
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); | ||
if ((uint)start >= (uint)array.Length || (uint)length > (uint)(array.Length - start)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check makes this illegal:
int[] a = new int[5];
ReadOnlySpan<int> span = new ReadOnlySpan<int>(a, 5, 0);
It should be valid (and consistent with other api's that work on a segment of an array) to take an empty span starting from "one past" the end of the array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Also, ReadOnlySpan.Slice(this String text, ...) has the too strict range check. |
Fixed. |
Part of https://github.com/dotnet/coreclr/issues/5851