Skip to content

Commit

Permalink
React to new compiler nullability warnings
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/coreclr@b5ccdc3
  • Loading branch information
safern committed Jun 27, 2019
1 parent a275c99 commit e8f7e35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,13 @@ private static void ExecutionContextCallback(object? s)
{
Debug.Assert(s is AsyncStateMachineBox<TStateMachine>);
// Only used privately to pass directly to EC.Run
Unsafe.As<AsyncStateMachineBox<TStateMachine>>(s).StateMachine.MoveNext();
Unsafe.As<AsyncStateMachineBox<TStateMachine>>(s).StateMachine!.MoveNext();
}

/// <summary>A delegate to the <see cref="MoveNext()"/> method.</summary>
private Action? _moveNextAction;
/// <summary>The state machine itself.</summary>
[AllowNull, MaybeNull] public TStateMachine StateMachine = default!; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name. // TODO-NULLABLE: Remove ! when nullable attributes are respected
[AllowNull, MaybeNull] public TStateMachine StateMachine = default; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name.
/// <summary>Captured ExecutionContext with which to invoke <see cref="MoveNextAction"/>; may be null.</summary>
public ExecutionContext? Context;

Expand All @@ -601,7 +601,8 @@ private void MoveNext(Thread? threadPoolThread)
ExecutionContext? context = Context;
if (context == null)
{
StateMachine.MoveNext();
Debug.Assert(StateMachine != null);
StateMachine!.MoveNext(); // TODO-NULLABLE: remove ! when Debug.Assert on fields is respected (https://github.com/dotnet/roslyn/issues/36830)
}
else
{
Expand All @@ -620,7 +621,7 @@ private void MoveNext(Thread? threadPoolThread)
// Clear out state now that the async method has completed.
// This avoids keeping arbitrary state referenced by lifted locals
// if this Task / state machine box is held onto.
StateMachine = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
StateMachine = default;
Context = default;

#if !CORERT
Expand All @@ -641,7 +642,7 @@ private void MoveNext(Thread? threadPoolThread)
}

/// <summary>Gets the state machine as a boxed object. This should only be used for debugging purposes.</summary>
IAsyncStateMachine IAsyncStateMachineBox.GetStateMachineObject() => StateMachine; // likely boxes, only use for debugging
IAsyncStateMachine IAsyncStateMachineBox.GetStateMachineObject() => StateMachine!; // likely boxes, only use for debugging
}

/// <summary>Gets the <see cref="System.Threading.Tasks.Task{TResult}"/> for this builder.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1260,14 +1260,15 @@ internal static void CompleteFromAsyncResult(IAsyncResult asyncResult)
// Grab the relevant state and then null it out so that the task doesn't hold onto the state unnecessarily
var thisRef = promise!.m_thisRef; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
var endMethod = promise.m_endMethod;
promise.m_thisRef = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
promise.m_thisRef = default;
promise.m_endMethod = null;
if (endMethod == null) ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple, ExceptionArgument.asyncResult);

// Complete the promise. If the IAsyncResult completed synchronously,
// we'll instead complete the promise at the call site.
if (!asyncResult.CompletedSynchronously)
{
Debug.Assert(thisRef != null);
promise.Complete(thisRef, endMethod!, asyncResult, requiresSynchronization: true); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
}
}
Expand Down

0 comments on commit e8f7e35

Please sign in to comment.