Skip to content

Commit 9a7601c

Browse files
authored
Merge pull request #39050 from dotnet/merges/master-to-features/local-function-attributes
Merge master to features/local-function-attributes
2 parents 1c81543 + 7bf4366 commit 9a7601c

File tree

138 files changed

+1522
-532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+1522
-532
lines changed

src/CodeStyle/Core/Analyzers/Microsoft.CodeAnalysis.CodeStyle.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests" />
2828
</ItemGroup>
2929
<ItemGroup>
30+
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\Debug.cs" Link="Formatting\Debug.cs" />
3031
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\EnumerableExtensions.cs" Link="Formatting\EnumerableExtensions.cs" />
3132
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\ExceptionUtilities.cs" Link="InternalUtilities\ExceptionUtilities.cs" />
3233
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\IReadOnlySet.cs" Link="InternalUtilities\IReadOnlySet.cs" />
3334
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\KeyValuePairUtil.cs" Link="InternalUtilities\KeyValuePairUtil.cs" />
3435
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\NullableAttributes.cs" Link="Formatting\NullableAttributes.cs" />
3536
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\PerformanceSensitiveAttribute.cs" Link="PerformanceSensitiveAttribute.cs" />
37+
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\RoslynString.cs" Link="RoslynString.cs" />
3638
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\SpecializedCollections.cs" Link="InternalUtilities\SpecializedCollections.cs" />
3739
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\SpecializedCollections.Empty.Collection.cs" Link="InternalUtilities\SpecializedCollections.Empty.Collection.cs" />
3840
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\SpecializedCollections.Empty.cs" Link="InternalUtilities\SpecializedCollections.Empty.cs" />

src/Compilers/Core/MSBuildTask/Microsoft.Build.Tasks.CodeAnalysis.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
<Compile Include="..\Portable\InternalUtilities\CommandLineUtilities.cs" />
4040
<Compile Include="..\Portable\InternalUtilities\CompilerOptionParseUtilities.cs" />
4141
<Compile Include="..\Portable\InternalUtilities\IReadOnlySet.cs" />
42+
<Compile Include="..\Portable\InternalUtilities\NullableAttributes.cs" />
4243
<Compile Include="..\Portable\InternalUtilities\PlatformInformation.cs" />
4344
<Compile Include="..\Portable\InternalUtilities\ReflectionUtilities.cs" />
45+
<Compile Include="..\Portable\InternalUtilities\RoslynString.cs" />
4446
<Compile Include="..\Portable\InternalUtilities\UnicodeCharacterUtilities.cs" />
4547
<Compile Update="ErrorString.Designer.cs">
4648
<AutoGen>True</AutoGen>

src/Compilers/Core/Portable/Collections/ArrayBuilderExtensions.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
#nullable enable
4+
35
using System;
46
using System.Collections.Immutable;
57
using Microsoft.CodeAnalysis.PooledObjects;
@@ -134,7 +136,7 @@ public static ImmutableArray<TResult> SelectAsArray<TItem, TArg, TResult>(this A
134136
}
135137
}
136138

137-
public static void AddOptional<T>(this ArrayBuilder<T> builder, T item)
139+
public static void AddOptional<T>(this ArrayBuilder<T> builder, T? item)
138140
where T : class
139141
{
140142
if (item != null)
@@ -163,9 +165,9 @@ public static T Peek<T>(this ArrayBuilder<T> builder)
163165
return builder[builder.Count - 1];
164166
}
165167

166-
public static ImmutableArray<T> ToImmutableOrEmptyAndFree<T>(this ArrayBuilder<T> builderOpt)
168+
public static ImmutableArray<T> ToImmutableOrEmptyAndFree<T>(this ArrayBuilder<T>? builder)
167169
{
168-
return builderOpt?.ToImmutableAndFree() ?? ImmutableArray<T>.Empty;
170+
return builder?.ToImmutableAndFree() ?? ImmutableArray<T>.Empty;
169171
}
170172

171173
public static void AddIfNotNull<T>(this ArrayBuilder<T> builder, T? value)
@@ -177,7 +179,7 @@ public static void AddIfNotNull<T>(this ArrayBuilder<T> builder, T? value)
177179
}
178180
}
179181

180-
public static void AddIfNotNull<T>(this ArrayBuilder<T> builder, T value)
182+
public static void AddIfNotNull<T>(this ArrayBuilder<T> builder, T? value)
181183
where T : class
182184
{
183185
if (value != null)
@@ -186,6 +188,7 @@ public static void AddIfNotNull<T>(this ArrayBuilder<T> builder, T value)
186188
}
187189
}
188190

191+
#nullable disable
189192
public static void FreeAll<T>(this ArrayBuilder<T> builder, Func<T, ArrayBuilder<T>> getNested)
190193
{
191194
foreach (var item in builder)
@@ -194,5 +197,6 @@ public static void FreeAll<T>(this ArrayBuilder<T> builder, Func<T, ArrayBuilder
194197
}
195198
builder.Free();
196199
}
200+
#nullable enable
197201
}
198202
}

src/Compilers/Core/Portable/Collections/ArrayElement.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
#nullable enable
4+
35
using System.Diagnostics;
6+
using System.Diagnostics.CodeAnalysis;
47

58
namespace Microsoft.CodeAnalysis
69
{
@@ -25,7 +28,8 @@ public static implicit operator T(ArrayElement<T> element)
2528
// as JIT does not know if the write goes to a stack or a heap location.
2629
// Assigning to Value directly easily avoids all this redundancy.
2730

28-
public static ArrayElement<T>[] MakeElementArray(T[] items)
31+
[return: NotNullIfNotNull(parameterName: "items")]
32+
public static ArrayElement<T>[]? MakeElementArray(T[]? items)
2933
{
3034
if (items == null)
3135
{
@@ -41,7 +45,8 @@ public static ArrayElement<T>[] MakeElementArray(T[] items)
4145
return array;
4246
}
4347

44-
public static T[] MakeArray(ArrayElement<T>[] items)
48+
[return: NotNullIfNotNull(parameterName: "items")]
49+
public static T[]? MakeArray(ArrayElement<T>[]? items)
4550
{
4651
if (items == null)
4752
{

src/Compilers/Core/Portable/Collections/Boxes.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
#nullable enable
4+
35
using System;
46

57
namespace Microsoft.CodeAnalysis
@@ -21,7 +23,7 @@ internal static class Boxes
2123
public static readonly object BoxedDoubleZero = 0.0;
2224
public static readonly object BoxedDecimalZero = 0m;
2325

24-
private static readonly object[] s_boxedAsciiChars = new object[128];
26+
private static readonly object?[] s_boxedAsciiChars = new object?[128];
2527

2628
public static object Box(bool b)
2729
{

src/Compilers/Core/Portable/Collections/ByteSequenceComparer.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
#nullable enable
4+
35
using System;
46
using System.Collections.Generic;
57
using System.Collections.Immutable;
68
using System.Diagnostics;
9+
using System.Diagnostics.CodeAnalysis;
710
using System.Linq;
811
using Microsoft.CodeAnalysis.Text;
912
using Roslyn.Utilities;
@@ -41,7 +44,7 @@ internal static bool Equals(ImmutableArray<byte> x, ImmutableArray<byte> y)
4144
return true;
4245
}
4346

44-
internal static bool Equals(byte[] left, int leftStart, byte[] right, int rightStart, int length)
47+
internal static bool Equals(byte[]? left, int leftStart, byte[]? right, int rightStart, int length)
4548
{
4649
if (left == null || right == null)
4750
{
@@ -64,7 +67,7 @@ internal static bool Equals(byte[] left, int leftStart, byte[] right, int rightS
6467
return true;
6568
}
6669

67-
internal static bool Equals(byte[] left, byte[] right)
70+
internal static bool Equals(byte[]? left, byte[]? right)
6871
{
6972
if (ReferenceEquals(left, right))
7073
{
@@ -91,7 +94,7 @@ internal static bool Equals(byte[] left, byte[] right)
9194

9295
internal static int GetHashCode(byte[] x)
9396
{
94-
Debug.Assert(x != null);
97+
RoslynDebug.Assert(x != null);
9598
return Hash.GetFNVHashCode(x);
9699
}
97100

@@ -101,7 +104,7 @@ internal static int GetHashCode(ImmutableArray<byte> x)
101104
return Hash.GetFNVHashCode(x);
102105
}
103106

104-
bool IEqualityComparer<byte[]>.Equals(byte[] x, byte[] y)
107+
bool IEqualityComparer<byte[]>.Equals(byte[]? x, byte[]? y)
105108
{
106109
return Equals(x, y);
107110
}

src/Compilers/Core/Portable/Collections/CachingDictionary.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
#nullable enable
4+
35
using System;
46
using System.Collections.Concurrent;
57
using System.Collections.Generic;
68
using System.Collections.Immutable;
79
using System.Diagnostics;
10+
using System.Diagnostics.CodeAnalysis;
811
using System.Threading;
912
using Microsoft.CodeAnalysis.PooledObjects;
1013

@@ -25,6 +28,7 @@ namespace Microsoft.CodeAnalysis.Collections
2528
/// Thread safe.
2629
/// </summary>
2730
internal class CachingDictionary<TKey, TElement>
31+
where TKey : notnull
2832
{
2933
private readonly Func<TKey, ImmutableArray<TElement>> _getElementsOfKey;
3034
private readonly Func<IEqualityComparer<TKey>, HashSet<TKey>> _getKeys;
@@ -34,7 +38,7 @@ internal class CachingDictionary<TKey, TElement>
3438
// or something frozen (usually a regular Dictionary). The frozen Dictionary is used only once the collection
3539
// is fully populated. This is a memory optimization so that we don't hold onto relatively ConcurrentDictionary
3640
// instances once the cache is fully populated.
37-
private IDictionary<TKey, ImmutableArray<TElement>> _map;
41+
private IDictionary<TKey, ImmutableArray<TElement>>? _map;
3842

3943
// This is a special sentinel value that is placed inside the map to indicate that a key was looked
4044
// up, but not found.
@@ -142,7 +146,7 @@ private IDictionary<TKey, ImmutableArray<TElement>> CreateDictionaryForFullyPopu
142146
private ImmutableArray<TElement> GetOrCreateValue(TKey key)
143147
{
144148
ImmutableArray<TElement> elements;
145-
ConcurrentDictionary<TKey, ImmutableArray<TElement>> concurrentMap;
149+
ConcurrentDictionary<TKey, ImmutableArray<TElement>>? concurrentMap;
146150

147151
// Check if we're fully populated before trying to retrieve the elements. If we are
148152
// and we don't get any elements back, then we don't have to go any further.
@@ -197,7 +201,7 @@ private ImmutableArray<TElement> AddToConcurrentMap(ConcurrentDictionary<TKey, I
197201
/// </summary>
198202
/// <param name="existingMap">The map to test.</param>
199203
/// <returns>true if the map is fully populated.</returns>
200-
private static bool IsNotFullyPopulatedMap(IDictionary<TKey, ImmutableArray<TElement>> existingMap)
204+
private static bool IsNotFullyPopulatedMap([NotNullWhen(returnValue: false)] IDictionary<TKey, ImmutableArray<TElement>>? existingMap)
201205
{
202206
return existingMap == null || existingMap is ConcurrentDictionary<TKey, ImmutableArray<TElement>>;
203207
}
@@ -207,7 +211,7 @@ private static bool IsNotFullyPopulatedMap(IDictionary<TKey, ImmutableArray<TEle
207211
/// </summary>
208212
/// <param name="existingMap">The existing map which may be null or a ConcurrentDictionary.</param>
209213
/// <returns></returns>
210-
private IDictionary<TKey, ImmutableArray<TElement>> CreateFullyPopulatedMap(IDictionary<TKey, ImmutableArray<TElement>> existingMap)
214+
private IDictionary<TKey, ImmutableArray<TElement>> CreateFullyPopulatedMap(IDictionary<TKey, ImmutableArray<TElement>>? existingMap)
211215
{
212216
Debug.Assert(IsNotFullyPopulatedMap(existingMap));
213217

@@ -250,7 +254,7 @@ private IDictionary<TKey, ImmutableArray<TElement>> CreateFullyPopulatedMap(IDic
250254
/// </summary>
251255
private IDictionary<TKey, ImmutableArray<TElement>> EnsureFullyPopulated()
252256
{
253-
IDictionary<TKey, ImmutableArray<TElement>> fullyPopulatedMap = null;
257+
IDictionary<TKey, ImmutableArray<TElement>>? fullyPopulatedMap = null;
254258

255259
var currentMap = _map;
256260
while (IsNotFullyPopulatedMap(currentMap))

src/Compilers/Core/Portable/Collections/ConsListExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
#nullable enable
4+
35
using Microsoft.CodeAnalysis.Text;
46
using Roslyn.Utilities;
57

@@ -10,7 +12,7 @@ namespace Microsoft.CodeAnalysis
1012
/// </summary>
1113
internal static class ConsListExtensions
1214
{
13-
public static ConsList<T> Prepend<T>(this ConsList<T> list, T head)
15+
public static ConsList<T> Prepend<T>(this ConsList<T>? list, T head)
1416
{
1517
return new ConsList<T>(head, list ?? ConsList<T>.Empty);
1618
}

src/Compilers/Core/Portable/Collections/HashSetExtensions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
#nullable enable
4+
35
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
47

58
namespace Microsoft.CodeAnalysis
69
{
710
internal static class HashSetExtensions
811
{
9-
internal static bool IsNullOrEmpty<T>(this HashSet<T> hashSet)
12+
internal static bool IsNullOrEmpty<T>([NotNullWhen(returnValue: false)] this HashSet<T>? hashSet)
1013
{
1114
return hashSet == null || hashSet.Count == 0;
1215
}
1316

14-
internal static bool InitializeAndAdd<T>(ref HashSet<T> hashSet, T item) where T : class
17+
internal static bool InitializeAndAdd<T>([NotNullIfNotNull(parameterName: "item"), NotNullWhen(returnValue: true)] ref HashSet<T>? hashSet, [NotNullWhen(returnValue: true)] T? item)
18+
where T : class
1519
{
1620
if (item is null)
1721
{

src/Compilers/Core/Portable/Collections/IOrderedReadOnlySet.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
#nullable enable
4+
35
using System.Collections.Generic;
46
using Roslyn.Utilities;
57

0 commit comments

Comments
 (0)