Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Merge SpanOfT branch into master #7886

Merged
merged 17 commits into from
Oct 31, 2016
Merged

Merge SpanOfT branch into master #7886

merged 17 commits into from
Oct 31, 2016

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Oct 29, 2016

@jkotas
Copy link
Member Author

jkotas commented Oct 29, 2016

@atsushikan PTLA

FYI @adamsitnik We are getting closer to make Span real. Thank you for your work on it!

@jkotas
Copy link
Member Author

jkotas commented Oct 29, 2016

cc @joshfree

@jkotas
Copy link
Member Author

jkotas commented Oct 29, 2016

The tests are not enabled in automation because of the Span is not exposed in the contracts yet.

}
}

public static class ReadOnlySpanExtensions
Copy link
Member

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?

Copy link
Member Author

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.)

Copy link
Member

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.

Copy link
Member Author

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.

@jkotas jkotas force-pushed the SpanOfT branch 2 times, most recently from b4fe60d to d0ebbd4 Compare October 29, 2016 16:57
Copy link

@MartinJohns MartinJohns left a 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);

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.

@jkotas
Copy link
Member Author

jkotas commented Oct 30, 2016

@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;

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?

Copy link
Member Author

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.
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Copy link

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
Copy link
Member

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

Copy link
Member Author

@jkotas jkotas Oct 30, 2016

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();
}
Copy link
Member

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?

Copy link
Member Author

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()).

Copy link
Member

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.

@jkotas jkotas force-pushed the SpanOfT branch 2 times, most recently from 1adfa90 to f31afb2 Compare October 31, 2016 03:55
/// Thrown when the specified <paramref name="length"/> is negative.
/// </exception>
[CLSCompliant(false)]
public unsafe ReadOnlySpan(void* ptr, int length)
Copy link
Member

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 .

Copy link
Member Author

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;
Copy link
Member

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))
Copy link

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@ghost
Copy link

ghost commented Oct 31, 2016

Also, ReadOnlySpan.Slice(this String text, ...) has the too strict range check.

@jkotas
Copy link
Member Author

jkotas commented Oct 31, 2016

ReadOnlySpan.Slice(this String text, ...) has the too strict range check

Fixed.

@jkotas jkotas merged commit f429841 into dotnet:master Oct 31, 2016
@jkotas jkotas deleted the SpanOfT branch November 2, 2016 16:57
@karelz karelz modified the milestone: 2.0.0 Aug 28, 2017
@jkotas jkotas mentioned this pull request Jan 31, 2020
28 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants