Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4eaa32f
Provide signature help for collection initializers
CyrusNajmabadi Sep 25, 2019
9ee1bc5
simplify
CyrusNajmabadi Sep 25, 2019
90ad420
Update src/Features/CSharp/Portable/SignatureHelp/SignatureHelpUtilit…
CyrusNajmabadi Sep 25, 2019
23e86a6
Add tests
CyrusNajmabadi Sep 25, 2019
92e3b41
Merge branch 'initializeSigHelp' of https://github.com/CyrusNajmabadi…
CyrusNajmabadi Sep 25, 2019
6e3e3fc
simplify
CyrusNajmabadi Sep 25, 2019
c7d2be6
Simplify
CyrusNajmabadi Sep 25, 2019
913a0a3
Simplify
CyrusNajmabadi Sep 25, 2019
4d0c64b
Simplify
CyrusNajmabadi Sep 25, 2019
5ba947f
VB support
CyrusNajmabadi Sep 26, 2019
bb0750b
Rename
CyrusNajmabadi Sep 26, 2019
0155de3
Add VB tests
CyrusNajmabadi Sep 26, 2019
85f719b
Share code'
CyrusNajmabadi Sep 26, 2019
eb9bc01
Fixup spans
CyrusNajmabadi Sep 26, 2019
2298173
Enable nullable reference types for XmlFileResolver
sharwell Sep 24, 2019
73899ec
Enable nullable reference types for enumerations
sharwell Sep 24, 2019
b6a2e76
Enable nullable reference types for collection types
sharwell Sep 25, 2019
64045f6
Enable nullable reference types for SpecializedCollections
sharwell Sep 26, 2019
2a655cc
Enable nullable reference types for FailFast
sharwell Sep 26, 2019
c326d06
Enable nullable reference types for internal utilities without other …
sharwell Sep 26, 2019
1b528d9
Enable nullable reference types for FatalError
sharwell Sep 26, 2019
a625ecd
Define RoslynString
sharwell Sep 26, 2019
1170518
Enable nullable reference types for UnicodeCharacterUtilities
sharwell Sep 26, 2019
1b174d0
Enable nullable reference types for EnumerableExtensions
sharwell Sep 26, 2019
7733532
Enable nullable reference types in internal utilities without attributes
sharwell Sep 26, 2019
21c9c43
Enable nullable reference types for Hash
sharwell Sep 26, 2019
ed14ce8
Enable nullable reference types for EnumField
sharwell Sep 26, 2019
8ca19bd
Enable nullable reference types for StringExtensions
sharwell Sep 26, 2019
825d527
Enable nullable reference types for internal utilities
sharwell Sep 26, 2019
0315740
Merge remote-tracking branch 'upstream/master' into initializeSigHelp
CyrusNajmabadi Sep 30, 2019
8e72b7e
Address code review feedback
sharwell Sep 27, 2019
85efe5f
Additional annotations from code review
sharwell Oct 2, 2019
65ff530
Disable assert tracked by https://github.com/dotnet/roslyn/issues/35818
333fred Oct 3, 2019
cf5cc3a
Merge branch 'master' into initializeSigHelp
CyrusNajmabadi Oct 3, 2019
773c4d7
Keep all add methods. Prefer add method with 2 or more parameters.
CyrusNajmabadi Oct 3, 2019
8a0df8e
Spelling fixes (#38977)
nnpcYvIVl Oct 3, 2019
b368e00
Disable assert tracked by https://github.com/dotnet/roslyn/iss… (#39018)
333fred Oct 3, 2019
eb66f91
Merge pull request #38882 from sharwell/new-compiler-annotations
sharwell Oct 3, 2019
7bf4366
Merge pull request #38855 from CyrusNajmabadi/initializeSigHelp
ivanbasov Oct 3, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\Debug.cs" Link="Formatting\Debug.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\EnumerableExtensions.cs" Link="Formatting\EnumerableExtensions.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\ExceptionUtilities.cs" Link="InternalUtilities\ExceptionUtilities.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\IReadOnlySet.cs" Link="InternalUtilities\IReadOnlySet.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\KeyValuePairUtil.cs" Link="InternalUtilities\KeyValuePairUtil.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\NullableAttributes.cs" Link="Formatting\NullableAttributes.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\PerformanceSensitiveAttribute.cs" Link="PerformanceSensitiveAttribute.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\RoslynString.cs" Link="RoslynString.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\SpecializedCollections.cs" Link="InternalUtilities\SpecializedCollections.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\SpecializedCollections.Empty.Collection.cs" Link="InternalUtilities\SpecializedCollections.Empty.Collection.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\InternalUtilities\SpecializedCollections.Empty.cs" Link="InternalUtilities\SpecializedCollections.Empty.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
<Compile Include="..\Portable\InternalUtilities\CommandLineUtilities.cs" />
<Compile Include="..\Portable\InternalUtilities\CompilerOptionParseUtilities.cs" />
<Compile Include="..\Portable\InternalUtilities\IReadOnlySet.cs" />
<Compile Include="..\Portable\InternalUtilities\NullableAttributes.cs" />
<Compile Include="..\Portable\InternalUtilities\PlatformInformation.cs" />
<Compile Include="..\Portable\InternalUtilities\ReflectionUtilities.cs" />
<Compile Include="..\Portable\InternalUtilities\RoslynString.cs" />
<Compile Include="..\Portable\InternalUtilities\UnicodeCharacterUtilities.cs" />
<Compile Update="ErrorString.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.PooledObjects;
Expand Down Expand Up @@ -134,7 +136,7 @@ public static ImmutableArray<TResult> SelectAsArray<TItem, TArg, TResult>(this A
}
}

public static void AddOptional<T>(this ArrayBuilder<T> builder, T item)
public static void AddOptional<T>(this ArrayBuilder<T> builder, T? item)
where T : class
{
if (item != null)
Expand Down Expand Up @@ -163,9 +165,9 @@ public static T Peek<T>(this ArrayBuilder<T> builder)
return builder[builder.Count - 1];
}

public static ImmutableArray<T> ToImmutableOrEmptyAndFree<T>(this ArrayBuilder<T> builderOpt)
public static ImmutableArray<T> ToImmutableOrEmptyAndFree<T>(this ArrayBuilder<T>? builder)
{
return builderOpt?.ToImmutableAndFree() ?? ImmutableArray<T>.Empty;
return builder?.ToImmutableAndFree() ?? ImmutableArray<T>.Empty;
}

public static void AddIfNotNull<T>(this ArrayBuilder<T> builder, T? value)
Expand All @@ -177,7 +179,7 @@ public static void AddIfNotNull<T>(this ArrayBuilder<T> builder, T? value)
}
}

public static void AddIfNotNull<T>(this ArrayBuilder<T> builder, T value)
public static void AddIfNotNull<T>(this ArrayBuilder<T> builder, T? value)
where T : class
{
if (value != null)
Expand All @@ -186,6 +188,7 @@ public static void AddIfNotNull<T>(this ArrayBuilder<T> builder, T value)
}
}

#nullable disable
public static void FreeAll<T>(this ArrayBuilder<T> builder, Func<T, ArrayBuilder<T>> getNested)
{
foreach (var item in builder)
Expand All @@ -194,5 +197,6 @@ public static void FreeAll<T>(this ArrayBuilder<T> builder, Func<T, ArrayBuilder
}
builder.Free();
}
#nullable enable
}
}
9 changes: 7 additions & 2 deletions src/Compilers/Core/Portable/Collections/ArrayElement.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

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

public static ArrayElement<T>[] MakeElementArray(T[] items)
[return: NotNullIfNotNull(parameterName: "items")]
public static ArrayElement<T>[]? MakeElementArray(T[]? items)
{
if (items == null)
{
Expand All @@ -41,7 +45,8 @@ public static ArrayElement<T>[] MakeElementArray(T[] items)
return array;
}

public static T[] MakeArray(ArrayElement<T>[] items)
[return: NotNullIfNotNull(parameterName: "items")]
public static T[]? MakeArray(ArrayElement<T>[]? items)
{
if (items == null)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Compilers/Core/Portable/Collections/Boxes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;

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

private static readonly object[] s_boxedAsciiChars = new object[128];
private static readonly object?[] s_boxedAsciiChars = new object?[128];

public static object Box(bool b)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
Expand Down Expand Up @@ -41,7 +44,7 @@ internal static bool Equals(ImmutableArray<byte> x, ImmutableArray<byte> y)
return true;
}

internal static bool Equals(byte[] left, int leftStart, byte[] right, int rightStart, int length)
internal static bool Equals(byte[]? left, int leftStart, byte[]? right, int rightStart, int length)
{
if (left == null || right == null)
{
Expand All @@ -64,7 +67,7 @@ internal static bool Equals(byte[] left, int leftStart, byte[] right, int rightS
return true;
}

internal static bool Equals(byte[] left, byte[] right)
internal static bool Equals(byte[]? left, byte[]? right)
{
if (ReferenceEquals(left, right))
{
Expand All @@ -91,7 +94,7 @@ internal static bool Equals(byte[] left, byte[] right)

internal static int GetHashCode(byte[] x)
{
Debug.Assert(x != null);
RoslynDebug.Assert(x != null);
return Hash.GetFNVHashCode(x);
}

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

bool IEqualityComparer<byte[]>.Equals(byte[] x, byte[] y)
bool IEqualityComparer<byte[]>.Equals(byte[]? x, byte[]? y)
{
return Equals(x, y);
}
Expand Down
14 changes: 9 additions & 5 deletions src/Compilers/Core/Portable/Collections/CachingDictionary.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Microsoft.CodeAnalysis.PooledObjects;

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

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

// Check if we're fully populated before trying to retrieve the elements. If we are
// and we don't get any elements back, then we don't have to go any further.
Expand Down Expand Up @@ -197,7 +201,7 @@ private ImmutableArray<TElement> AddToConcurrentMap(ConcurrentDictionary<TKey, I
/// </summary>
/// <param name="existingMap">The map to test.</param>
/// <returns>true if the map is fully populated.</returns>
private static bool IsNotFullyPopulatedMap(IDictionary<TKey, ImmutableArray<TElement>> existingMap)
private static bool IsNotFullyPopulatedMap([NotNullWhen(returnValue: false)] IDictionary<TKey, ImmutableArray<TElement>>? existingMap)
{
return existingMap == null || existingMap is ConcurrentDictionary<TKey, ImmutableArray<TElement>>;
}
Expand All @@ -207,7 +211,7 @@ private static bool IsNotFullyPopulatedMap(IDictionary<TKey, ImmutableArray<TEle
/// </summary>
/// <param name="existingMap">The existing map which may be null or a ConcurrentDictionary.</param>
/// <returns></returns>
private IDictionary<TKey, ImmutableArray<TElement>> CreateFullyPopulatedMap(IDictionary<TKey, ImmutableArray<TElement>> existingMap)
private IDictionary<TKey, ImmutableArray<TElement>> CreateFullyPopulatedMap(IDictionary<TKey, ImmutableArray<TElement>>? existingMap)
{
Debug.Assert(IsNotFullyPopulatedMap(existingMap));

Expand Down Expand Up @@ -250,7 +254,7 @@ private IDictionary<TKey, ImmutableArray<TElement>> CreateFullyPopulatedMap(IDic
/// </summary>
private IDictionary<TKey, ImmutableArray<TElement>> EnsureFullyPopulated()
{
IDictionary<TKey, ImmutableArray<TElement>> fullyPopulatedMap = null;
IDictionary<TKey, ImmutableArray<TElement>>? fullyPopulatedMap = null;

var currentMap = _map;
while (IsNotFullyPopulatedMap(currentMap))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

Expand All @@ -10,7 +12,7 @@ namespace Microsoft.CodeAnalysis
/// </summary>
internal static class ConsListExtensions
{
public static ConsList<T> Prepend<T>(this ConsList<T> list, T head)
public static ConsList<T> Prepend<T>(this ConsList<T>? list, T head)
{
return new ConsList<T>(head, list ?? ConsList<T>.Empty);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.CodeAnalysis
{
internal static class HashSetExtensions
{
internal static bool IsNullOrEmpty<T>(this HashSet<T> hashSet)
internal static bool IsNullOrEmpty<T>([NotNullWhen(returnValue: false)] this HashSet<T>? hashSet)
{
return hashSet == null || hashSet.Count == 0;
}

internal static bool InitializeAndAdd<T>(ref HashSet<T> hashSet, T item) where T : class
internal static bool InitializeAndAdd<T>([NotNullIfNotNull(parameterName: "item"), NotNullWhen(returnValue: true)] ref HashSet<T>? hashSet, [NotNullWhen(returnValue: true)] T? item)
where T : class
{
if (item is null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System.Collections.Generic;
using Roslyn.Utilities;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand Down Expand Up @@ -36,7 +38,7 @@ public static ImmutableArray<T> AsImmutable<T>(this IEnumerable<T> items)
/// <param name="items">The sequence to convert.</param>
/// <returns>An immutable copy of the contents of the sequence.</returns>
/// <remarks>If the sequence is null, this will return an empty array.</remarks>
public static ImmutableArray<T> AsImmutableOrEmpty<T>(this IEnumerable<T> items)
public static ImmutableArray<T> AsImmutableOrEmpty<T>(this IEnumerable<T>? items)
{
if (items == null)
{
Expand All @@ -53,7 +55,7 @@ public static ImmutableArray<T> AsImmutableOrEmpty<T>(this IEnumerable<T> items)
/// <param name="items">The sequence to convert.</param>
/// <returns>An immutable copy of the contents of the sequence.</returns>
/// <remarks>If the sequence is null, this will return the default (null) array.</remarks>
public static ImmutableArray<T> AsImmutableOrNull<T>(this IEnumerable<T> items)
public static ImmutableArray<T> AsImmutableOrNull<T>(this IEnumerable<T>? items)
{
if (items == null)
{
Expand Down Expand Up @@ -82,7 +84,7 @@ public static ImmutableArray<T> AsImmutable<T>(this T[] items)
/// <param name="items">The sequence to convert</param>
/// <returns></returns>
/// <remarks>If the sequence is null, this will return the default (null) array.</remarks>
public static ImmutableArray<T> AsImmutableOrNull<T>(this T[] items)
public static ImmutableArray<T> AsImmutableOrNull<T>(this T[]? items)
{
if (items == null)
{
Expand All @@ -98,7 +100,7 @@ public static ImmutableArray<T> AsImmutableOrNull<T>(this T[] items)
/// <typeparam name="T"></typeparam>
/// <param name="items">The sequence to convert</param>
/// <returns>If the array is null, this will return an empty immutable array.</returns>
public static ImmutableArray<T> AsImmutableOrEmpty<T>(this T[] items)
public static ImmutableArray<T> AsImmutableOrEmpty<T>(this T[]? items)
{
if (items == null)
{
Expand Down Expand Up @@ -260,7 +262,7 @@ public static ImmutableArray<T> WhereAsArray<T>(this ImmutableArray<T> array, Fu
{
Debug.Assert(!array.IsDefault);

ArrayBuilder<T> builder = null;
ArrayBuilder<T>? builder = null;
bool none = true;
bool all = true;

Expand Down Expand Up @@ -391,7 +393,7 @@ public static ImmutableArray<T> NullToEmpty<T>(this ImmutableArray<T> array)
/// Returns an array of distinct elements, preserving the order in the original array.
/// If the array has no duplicates, the original array is returned. The original array must not be null.
/// </summary>
public static ImmutableArray<T> Distinct<T>(this ImmutableArray<T> array, IEqualityComparer<T> comparer = null)
public static ImmutableArray<T> Distinct<T>(this ImmutableArray<T> array, IEqualityComparer<T>? comparer = null)
{
Debug.Assert(!array.IsDefault);

Expand Down Expand Up @@ -448,7 +450,8 @@ internal static ImmutableArray<T> ConditionallyDeOrder<T>(this ImmutableArray<T>

internal static ImmutableArray<TValue> Flatten<TKey, TValue>(
this Dictionary<TKey, ImmutableArray<TValue>> dictionary,
IComparer<TValue> comparer = null)
IComparer<TValue>? comparer = null)
where TKey : notnull
{
if (dictionary.Count == 0)
{
Expand Down Expand Up @@ -525,7 +528,7 @@ public static int Count<T>(this ImmutableArray<T> items, Func<T, bool> predicate
return count;
}

internal static Dictionary<K, ImmutableArray<T>> ToDictionary<K, T>(this ImmutableArray<T> items, Func<T, K> keySelector, IEqualityComparer<K> comparer = null)
internal static Dictionary<K, ImmutableArray<T>> ToDictionary<K, T>(this ImmutableArray<T> items, Func<T, K> keySelector, IEqualityComparer<K>? comparer = null)
{
if (items.Length == 1)
{
Expand Down
Loading