Skip to content

Commit

Permalink
Remove some stale nullable suppressions / TODOs (#37978)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Jun 17, 2020
1 parent fa7c99d commit dba8a3f
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ public override bool Equals(object? obj)
{
if (InnerList[i] != other.InnerList[i])
{
// TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
if (InnerList[i] == null || !InnerList[i]!.Equals(other.InnerList[i]))
if (InnerList[i] == null || !InnerList[i]!.Equals(other.InnerList[i])) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,12 +664,10 @@ internal static void GetPrintDialogInfo(string printer, ref string port, ref str
NameValueCollection options = LoadPrinterOptions(cups_dests.options, cups_dests.num_options);

if (options["printer-state"] != null)
// TODO-NULLABLE dotnet/roslyn#34644
state = int.Parse(options["printer-state"]!);
state = int.Parse(options["printer-state"]!); // TODO-NULLABLE dotnet/roslyn#34644

if (options["printer-comment"] != null)
// TODO-NULLABLE dotnet/roslyn#34644
comment = options["printer-state"]!;
comment = options["printer-state"]!; // TODO-NULLABLE dotnet/roslyn#34644

switch (state)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public bool Remove(TElement value)
int last = -1;
for (int i = _buckets[bucket] - 1; i >= 0; last = i, i = _slots[i].next)
{
if (_slots[i].hashCode == hashCode && _comparer.Equals(_slots[i].value!, value)) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872
if (_slots[i].hashCode == hashCode && _comparer.Equals(_slots[i].value, value))
{
if (last < 0)
{
Expand All @@ -92,7 +92,7 @@ private bool Find(TElement value, bool add)
int hashCode = InternalGetHashCode(value);
for (int i = _buckets[hashCode % _buckets.Length] - 1; i >= 0; i = _slots[i].next)
{
if (_slots[i].hashCode == hashCode && _comparer.Equals(_slots[i].value!, value)) return true; // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872
if (_slots[i].hashCode == hashCode && _comparer.Equals(_slots[i].value, value)) return true;
}
if (add)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal sealed class AsynchronousChannelMergeEnumerator<T> : MergeEnumerator<T>
private IntValueEvent? _consumerEvent; // The consumer event.
private readonly bool[] _done; // Tracks which channels are done.
private int _channelIndex; // The next channel from which we'll dequeue.
[MaybeNull, AllowNull] private T _currentElement = default; // The remembered element from the previous MoveNext. TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/37511
[MaybeNull, AllowNull] private T _currentElement = default; // The remembered element from the previous MoveNext.

//-----------------------------------------------------------------------------------
// Allocates a new enumerator over a set of one-to-one channels.
Expand Down Expand Up @@ -99,7 +99,7 @@ public override bool MoveNext()
}

// Else try the fast path.
if (!_done[index] && _channels[index].TryDequeue(ref _currentElement!)) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872
if (!_done[index] && _channels[index].TryDequeue(ref _currentElement))
{
_channelIndex = (index + 1) % _channels.Length;
return true;
Expand Down Expand Up @@ -127,7 +127,7 @@ private bool MoveNextSlowPath()
AsynchronousChannel<T> current = _channels[currChannelIndex];

bool isDone = _done[currChannelIndex];
if (!isDone && current.TryDequeue(ref _currentElement!)) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872
if (!isDone && current.TryDequeue(ref _currentElement))
{
// The channel has an item to be processed. We already remembered the current
// element (Dequeue stores it as an out-parameter), so we just return true
Expand All @@ -147,7 +147,7 @@ private bool MoveNextSlowPath()
// we still need to continue processing them.
if (!current.IsChunkBufferEmpty)
{
bool dequeueResult = current.TryDequeue(ref _currentElement!); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872
bool dequeueResult = current.TryDequeue(ref _currentElement);
Debug.Assert(dequeueResult, "channel isn't empty, yet the dequeue failed, hmm");
return true;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ private bool MoveNextSlowPath()
for (int i = 0; i < _channels.Length; i++)
{
bool channelIsDone = false;
if (!_done[i] && _channels[i].TryDequeue(ref _currentElement!, ref channelIsDone)) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2872
if (!_done[i] && _channels[i].TryDequeue(ref _currentElement, ref channelIsDone))
{
// The channel has received an item since the last time we checked.
// Just return and let the consumer process the element returned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public ReadOnlySequence(T[] array)
_startObject = array;
_endObject = array;
_startInteger = ReadOnlySequence.ArrayToSequenceStart(0);
_endInteger = ReadOnlySequence.ArrayToSequenceEnd(array!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
_endInteger = ReadOnlySequence.ArrayToSequenceEnd(array.Length);
}

/// <summary>
Expand All @@ -146,9 +146,7 @@ public ReadOnlySequence(T[] array, int start, int length)
/// </summary>
public ReadOnlySequence(ReadOnlyMemory<T> memory)
{
#pragma warning disable CS8631 // TODO-NULLABLE: ILLink rewriter removing some necessary metadata (https://github.com/dotnet/corefx/pull/38983#issuecomment-506757237)
if (MemoryMarshal.TryGetMemoryManager(memory, out MemoryManager<T>? manager, out int index, out int length))
#pragma warning restore CS8631
{
_startObject = manager;
_endObject = manager;
Expand Down
13 changes: 12 additions & 1 deletion src/libraries/System.Memory/src/System/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;
using System.Buffers;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace System
{
Expand All @@ -24,37 +25,45 @@ namespace System

internal static class ThrowHelper
{
[DoesNotReturn]
internal static void ThrowArgumentNullException(ExceptionArgument argument) { throw CreateArgumentNullException(argument); }
[MethodImpl(MethodImplOptions.NoInlining)]
private static Exception CreateArgumentNullException(ExceptionArgument argument) { return new ArgumentNullException(argument.ToString()); }

[DoesNotReturn]
internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument) { throw CreateArgumentOutOfRangeException(argument); }
[MethodImpl(MethodImplOptions.NoInlining)]
private static Exception CreateArgumentOutOfRangeException(ExceptionArgument argument) { return new ArgumentOutOfRangeException(argument.ToString()); }

[DoesNotReturn]
internal static void ThrowInvalidOperationException() { throw CreateInvalidOperationException(); }
[MethodImpl(MethodImplOptions.NoInlining)]
private static Exception CreateInvalidOperationException() { return new InvalidOperationException(); }

[DoesNotReturn]
internal static void ThrowInvalidOperationException_EndPositionNotReached() { throw CreateInvalidOperationException_EndPositionNotReached(); }
[MethodImpl(MethodImplOptions.NoInlining)]
private static Exception CreateInvalidOperationException_EndPositionNotReached() { return new InvalidOperationException(SR.EndPositionNotReached); }

[DoesNotReturn]
internal static void ThrowArgumentOutOfRangeException_PositionOutOfRange() { throw CreateArgumentOutOfRangeException_PositionOutOfRange(); }
[MethodImpl(MethodImplOptions.NoInlining)]
private static Exception CreateArgumentOutOfRangeException_PositionOutOfRange() { return new ArgumentOutOfRangeException("position"); }

[DoesNotReturn]
internal static void ThrowArgumentOutOfRangeException_OffsetOutOfRange() { throw CreateArgumentOutOfRangeException_OffsetOutOfRange(); }
[MethodImpl(MethodImplOptions.NoInlining)]
private static Exception CreateArgumentOutOfRangeException_OffsetOutOfRange() { return new ArgumentOutOfRangeException(nameof(ExceptionArgument.offset)); }

[DoesNotReturn]
internal static void ThrowObjectDisposedException_ArrayMemoryPoolBuffer() { throw CreateObjectDisposedException_ArrayMemoryPoolBuffer(); }
[MethodImpl(MethodImplOptions.NoInlining)]
private static Exception CreateObjectDisposedException_ArrayMemoryPoolBuffer() { return new ObjectDisposedException("ArrayMemoryPoolBuffer"); }

//
// ReadOnlySequence .ctor validation Throws coalesced to enable inlining of the .ctor
//
[DoesNotReturn]
public static void ThrowArgumentValidationException<T>(ReadOnlySequenceSegment<T>? startSegment, int startIndex, ReadOnlySequenceSegment<T>? endSegment)
=> throw CreateArgumentValidationException(startSegment, startIndex, endSegment);

Expand All @@ -72,6 +81,7 @@ private static Exception CreateArgumentValidationException<T>(ReadOnlySequenceSe
return CreateArgumentOutOfRangeException(ExceptionArgument.endIndex);
}

[DoesNotReturn]
public static void ThrowArgumentValidationException(Array? array, int start)
=> throw CreateArgumentValidationException(array, start);

Expand All @@ -88,6 +98,7 @@ private static Exception CreateArgumentValidationException(Array? array, int sta
//
// ReadOnlySequence Slice validation Throws coalesced to enable inlining of the Slice
//
[DoesNotReturn]
public static void ThrowStartOrEndArgumentValidationException(long start)
=> throw CreateStartOrEndArgumentValidationException(start);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ public override int AttributeCount
{
if (name == _nsAttributes![i].name)
{
// TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
return _nsAttributes[i].value;
}
}
Expand All @@ -284,7 +283,6 @@ public override int AttributeCount
{
if (name == _nsAttributes![i].localName && namespaceURI == _xmlnsUri)
{
// TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
return _nsAttributes[i].value;
}
}
Expand Down Expand Up @@ -1353,12 +1351,12 @@ private void RemoveNamespace(string prefix, string localName)
for (int i = 0; i < _nsAttrCount; i++)
{
if (Ref.Equal(prefix, _nsAttributes![i].prefix) &&
Ref.Equal(localName, _nsAttributes![i].localName)) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
Ref.Equal(localName, _nsAttributes[i].localName))
{
if (i < _nsAttrCount - 1)
{
// swap
NodeData tmpNodeData = _nsAttributes![i]; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
NodeData tmpNodeData = _nsAttributes[i];
_nsAttributes[i] = _nsAttributes[_nsAttrCount - 1];
_nsAttributes[_nsAttrCount - 1] = tmpNodeData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void NullableAttributesOnPublicApiOnly(Type type)
{
// When using BindingFlags.NonPublic protected members are included and those are expected
// to have Nullable attributes.
if (internalMember.IsProtected() || internalMember is PropertyInfo) // TODO-NULLABLE: validate properties (https://github.com/dotnet/roslyn/issues/37161)
if (internalMember.IsProtected() || internalMember is PropertyInfo)
continue;

Assert.Empty(internalMember.CustomAttributes.GetNullableAttributes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ internal sealed class SingleConsumerUnboundedChannel<T> : Channel<T>, IDebugEnum
/// <summary>non-null if the channel has been marked as complete for writing.</summary>
private volatile Exception? _doneWriting;

#pragma warning disable CA1823 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/38195
/// <summary>An <see cref="AsyncOperation{T}"/> if there's a blocked reader.</summary>
private AsyncOperation<T>? _blockedReader;

/// <summary>A waiting reader (e.g. WaitForReadAsync) if there is one.</summary>
private AsyncOperation<bool>? _waitingReader;
#pragma warning restore CA1823

/// <summary>Initialize the channel.</summary>
/// <param name="runContinuationsAsynchronously">Whether to force continuations to be executed asynchronously.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ public IDisposable LinkTo(ITargetBlock<T[]> target, DataflowLinkOptions linkOpti
}

/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="TryReceive"]/*' />
#pragma warning disable CS8614 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470
public bool TryReceive(Predicate<T[]>? filter, [NotNullWhen(true)] out T[]? item)
#pragma warning restore CS8614
{
return _source.TryReceive(filter, out item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ public IDisposable LinkTo(ITargetBlock<Tuple<IList<T1>, IList<T2>>> target, Data
}

/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="TryReceive"]/*' />
#pragma warning disable CS8614 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470
public bool TryReceive(Predicate<Tuple<IList<T1>, IList<T2>>>? filter, [NotNullWhen(true)] out Tuple<IList<T1>, IList<T2>>? item)
#pragma warning restore CS8614
{
return _source.TryReceive(filter, out item);
}
Expand Down Expand Up @@ -396,9 +394,7 @@ public IDisposable LinkTo(ITargetBlock<Tuple<IList<T1>, IList<T2>, IList<T3>>> t
}

/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="TryReceive"]/*' />
#pragma warning disable CS8614 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470
public bool TryReceive(Predicate<Tuple<IList<T1>, IList<T2>, IList<T3>>>? filter, [NotNullWhen(true)] out Tuple<IList<T1>, IList<T2>, IList<T3>>? item)
#pragma warning restore CS8614
{
return _source.TryReceive(filter, out item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ public IDisposable LinkTo(ITargetBlock<Tuple<T1, T2>> target, DataflowLinkOption
}

/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="TryReceive"]/*' />
#pragma warning disable CS8614 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470
public bool TryReceive(Predicate<Tuple<T1, T2>>? filter, [NotNullWhen(true)] out Tuple<T1, T2>? item)
#pragma warning restore CS8614
{
return _source.TryReceive(filter, out item);
}
Expand Down Expand Up @@ -166,9 +164,7 @@ void IDataflowBlock.Fault(Exception exception)
public ITargetBlock<T2> Target2 { get { return _target2; } }

/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
#pragma warning disable CS8616 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470
Tuple<T1, T2>? ISourceBlock<Tuple<T1, T2>>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<Tuple<T1, T2>> target, out bool messageConsumed)
#pragma warning restore CS8616
{
return _source.ConsumeMessage(messageHeader, target, out messageConsumed);
}
Expand Down Expand Up @@ -349,9 +345,7 @@ public IDisposable LinkTo(ITargetBlock<Tuple<T1, T2, T3>> target, DataflowLinkOp
}

/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="TryReceive"]/*' />
#pragma warning disable CS8614 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470
public bool TryReceive(Predicate<Tuple<T1, T2, T3>>? filter, [NotNullWhen(true)] out Tuple<T1, T2, T3>? item)
#pragma warning restore CS8614
{
return _source.TryReceive(filter, out item);
}
Expand Down Expand Up @@ -403,9 +397,7 @@ void IDataflowBlock.Fault(Exception exception)
public ITargetBlock<T3> Target3 { get { return _target3; } }

/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
#pragma warning disable CS8616 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/42470
Tuple<T1, T2, T3>? ISourceBlock<Tuple<T1, T2, T3>>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<Tuple<T1, T2, T3>> target, out bool messageConsumed)
#pragma warning restore CS8616
{
return _source.ConsumeMessage(messageHeader, target, out messageConsumed);
}
Expand Down

0 comments on commit dba8a3f

Please sign in to comment.