From c5f7390d4317fe4f9599fda56c1d6d91a69fe29b Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Fri, 8 Sep 2017 22:18:50 -0700 Subject: [PATCH 1/4] Marking {ReadOnly}Span as readonly structs, fixing issue #23809 --- src/System.Memory/src/System/ReadOnlySpan.cs | 2 ++ src/System.Memory/src/System/Span.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/System.Memory/src/System/ReadOnlySpan.cs b/src/System.Memory/src/System/ReadOnlySpan.cs index cfd4f56d71cc..9871645fe22d 100644 --- a/src/System.Memory/src/System/ReadOnlySpan.cs +++ b/src/System.Memory/src/System/ReadOnlySpan.cs @@ -15,6 +15,8 @@ namespace System /// ReadOnlySpan represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed /// or native memory, or to memory allocated on the stack. It is type- and memory-safe. /// + [IsReadOnly] + [IsByRefLike] public struct ReadOnlySpan { /// diff --git a/src/System.Memory/src/System/Span.cs b/src/System.Memory/src/System/Span.cs index 02609491939f..b805d4515ddb 100644 --- a/src/System.Memory/src/System/Span.cs +++ b/src/System.Memory/src/System/Span.cs @@ -17,6 +17,8 @@ namespace System /// [DebuggerTypeProxy(typeof(SpanDebugView<>))] [DebuggerDisplay("Length = {Length}")] + [IsReadOnly] + [IsByRefLike] public struct Span { /// From 1197c3cf3259363d05e90dea7ba1d2d8edbdc485 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Mon, 11 Sep 2017 14:03:17 -0700 Subject: [PATCH 2/4] Adding readonly attributes to reference assemblies. --- src/System.Memory/ref/System.Memory.cs | 4 ++++ src/System.Runtime/ref/System.Runtime.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/System.Memory/ref/System.Memory.cs b/src/System.Memory/ref/System.Memory.cs index dd7ceb0b2c97..912d4b5db357 100644 --- a/src/System.Memory/ref/System.Memory.cs +++ b/src/System.Memory/ref/System.Memory.cs @@ -8,6 +8,8 @@ #pragma warning disable 0809 //warning CS0809: Obsolete member 'Span.Equals(object)' overrides non-obsolete member 'object.Equals(object)' namespace System { + [System.Runtime.CompilerServices.IsReadOnly] + [System.Runtime.CompilerServices.IsByRefLike] public struct ReadOnlySpan { public static ReadOnlySpan Empty { get { throw null; } } @@ -36,6 +38,8 @@ public void CopyTo(Span destination) { } public bool TryCopyTo(Span destination) { throw null; } } + [System.Runtime.CompilerServices.IsReadOnly] + [System.Runtime.CompilerServices.IsByRefLike] public struct Span { public static Span Empty { get { throw null; } } diff --git a/src/System.Runtime/ref/System.Runtime.cs b/src/System.Runtime/ref/System.Runtime.cs index 12f1f7873696..fa796df4d798 100644 --- a/src/System.Runtime/ref/System.Runtime.cs +++ b/src/System.Runtime/ref/System.Runtime.cs @@ -1832,6 +1832,8 @@ public RankException(string message, System.Exception innerException) { } protected RankException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + [System.Runtime.CompilerServices.IsReadOnly] + [System.Runtime.CompilerServices.IsByRefLike] public partial struct ReadOnlySpan { public static ReadOnlySpan Empty { get { throw null; } } @@ -2017,6 +2019,8 @@ public partial struct Single : System.IComparable, System.IComparable, Sy public static bool TryParse(ReadOnlySpan s, out float result, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, System.IFormatProvider provider = null) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + [System.Runtime.CompilerServices.IsReadOnly] + [System.Runtime.CompilerServices.IsByRefLike] public partial struct Span { public static Span Empty { get { throw null; } } From 14add503537edbc9e865d54ecd6abad938a1bbe7 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Mon, 11 Sep 2017 15:58:21 -0700 Subject: [PATCH 3/4] Using "readonly ref" keyword instead of attributes. --- src/System.Memory/ref/System.Memory.cs | 8 ++------ src/System.Memory/src/System/ReadOnlySpan.cs | 4 +--- src/System.Memory/src/System/Span.cs | 4 +--- src/System.Runtime/ref/System.Runtime.cs | 8 ++------ 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/System.Memory/ref/System.Memory.cs b/src/System.Memory/ref/System.Memory.cs index 912d4b5db357..d5430348c0c3 100644 --- a/src/System.Memory/ref/System.Memory.cs +++ b/src/System.Memory/ref/System.Memory.cs @@ -8,9 +8,7 @@ #pragma warning disable 0809 //warning CS0809: Obsolete member 'Span.Equals(object)' overrides non-obsolete member 'object.Equals(object)' namespace System { - [System.Runtime.CompilerServices.IsReadOnly] - [System.Runtime.CompilerServices.IsByRefLike] - public struct ReadOnlySpan + public readonly ref struct ReadOnlySpan { public static ReadOnlySpan Empty { get { throw null; } } public ReadOnlySpan(T[] array) { throw null;} @@ -38,9 +36,7 @@ public void CopyTo(Span destination) { } public bool TryCopyTo(Span destination) { throw null; } } - [System.Runtime.CompilerServices.IsReadOnly] - [System.Runtime.CompilerServices.IsByRefLike] - public struct Span + public readonly ref struct Span { public static Span Empty { get { throw null; } } public Span(T[] array) { throw null;} diff --git a/src/System.Memory/src/System/ReadOnlySpan.cs b/src/System.Memory/src/System/ReadOnlySpan.cs index 9871645fe22d..72346d490168 100644 --- a/src/System.Memory/src/System/ReadOnlySpan.cs +++ b/src/System.Memory/src/System/ReadOnlySpan.cs @@ -15,9 +15,7 @@ namespace System /// ReadOnlySpan represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed /// or native memory, or to memory allocated on the stack. It is type- and memory-safe. /// - [IsReadOnly] - [IsByRefLike] - public struct ReadOnlySpan + public readonly ref struct ReadOnlySpan { /// /// Creates a new read-only span over the entirety of the target array. diff --git a/src/System.Memory/src/System/Span.cs b/src/System.Memory/src/System/Span.cs index b805d4515ddb..65b313dd6c27 100644 --- a/src/System.Memory/src/System/Span.cs +++ b/src/System.Memory/src/System/Span.cs @@ -17,9 +17,7 @@ namespace System /// [DebuggerTypeProxy(typeof(SpanDebugView<>))] [DebuggerDisplay("Length = {Length}")] - [IsReadOnly] - [IsByRefLike] - public struct Span + public readonly ref struct Span { /// /// Creates a new span over the entirety of the target array. diff --git a/src/System.Runtime/ref/System.Runtime.cs b/src/System.Runtime/ref/System.Runtime.cs index fa796df4d798..0259c61049e1 100644 --- a/src/System.Runtime/ref/System.Runtime.cs +++ b/src/System.Runtime/ref/System.Runtime.cs @@ -1832,9 +1832,7 @@ public RankException(string message, System.Exception innerException) { } protected RankException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - [System.Runtime.CompilerServices.IsReadOnly] - [System.Runtime.CompilerServices.IsByRefLike] - public partial struct ReadOnlySpan + public readonly ref struct ReadOnlySpan { public static ReadOnlySpan Empty { get { throw null; } } public ReadOnlySpan(T[] array) { throw null; } @@ -2019,9 +2017,7 @@ public partial struct Single : System.IComparable, System.IComparable, Sy public static bool TryParse(ReadOnlySpan s, out float result, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, System.IFormatProvider provider = null) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - [System.Runtime.CompilerServices.IsReadOnly] - [System.Runtime.CompilerServices.IsByRefLike] - public partial struct Span + public readonly ref struct Span { public static Span Empty { get { throw null; } } public Span(T[] array) { throw null; } From cbbbe1d67d784620f24848dd243c93b0d80a4b71 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Mon, 18 Sep 2017 20:14:07 -0700 Subject: [PATCH 4/4] Adding a LangVersion 7.2 property --- src/System.Memory/ref/System.Memory.csproj | 1 + src/System.Memory/src/System.Memory.csproj | 1 + src/System.Runtime/ref/System.Runtime.csproj | 1 + 3 files changed, 3 insertions(+) diff --git a/src/System.Memory/ref/System.Memory.csproj b/src/System.Memory/ref/System.Memory.csproj index 0d0db9a2fd95..6226292ea1aa 100644 --- a/src/System.Memory/ref/System.Memory.csproj +++ b/src/System.Memory/ref/System.Memory.csproj @@ -6,6 +6,7 @@ false {E883935B-D8FD-4FC9-A189-9D9E7F7EF550} true + 7.2 diff --git a/src/System.Memory/src/System.Memory.csproj b/src/System.Memory/src/System.Memory.csproj index 1091463c00c4..04eaf96d323e 100644 --- a/src/System.Memory/src/System.Memory.csproj +++ b/src/System.Memory/src/System.Memory.csproj @@ -9,6 +9,7 @@ true $(DefineConstants);netcoreapp $(DefineConstants);netstandard11 + 7.2 diff --git a/src/System.Runtime/ref/System.Runtime.csproj b/src/System.Runtime/ref/System.Runtime.csproj index 349f7efa2045..7b13bb87fedf 100644 --- a/src/System.Runtime/ref/System.Runtime.csproj +++ b/src/System.Runtime/ref/System.Runtime.csproj @@ -5,6 +5,7 @@ true true {ADBCF120-3454-4A3C-9D1D-AC4293E795D6} + 7.2