Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an assert in PoolingAsyncValueTaskMethodBuilder #56468

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -356,14 +356,18 @@ private static ref StateMachineBox<TStateMachine>? PerCoreCacheSlot
// Get the current processor ID. We need to ensure it fits within s_perCoreCache, so we
// could % by its length, but we can do so instead by Environment.ProcessorCount, which will be a const
// in tier 1, allowing better code gen, and then further use uints for even better code gen.
Debug.Assert(s_perCoreCache.Length == Environment.ProcessorCount);
Debug.Assert(s_perCoreCache.Length == Environment.ProcessorCount, $"{s_perCoreCache.Length} != {Environment.ProcessorCount}");
int i = (int)((uint)Thread.GetCurrentProcessorId() % (uint)Environment.ProcessorCount);

// We want an array of StateMachineBox<> objects, each consuming its own cache line so that
// elements don't cause false sharing with each other. But we can't use StructLayout.Explicit
// with generics. So we use object fields, but always reinterpret them (for all reads and writes
// to avoid any safety issues) as StateMachineBox<> instances.
Debug.Assert(s_perCoreCache[i].Object is null || s_perCoreCache[i].Object is StateMachineBox<TStateMachine>);
#if DEBUG
object? transientValue = s_perCoreCache[i].Object;
Debug.Assert(transientValue is null || transientValue is StateMachineBox<TStateMachine>,
$"Expected null or {nameof(StateMachineBox<TStateMachine>)}, got '{transientValue}'");
#endif
return ref Unsafe.As<object?, StateMachineBox<TStateMachine>?>(ref s_perCoreCache[i].Object);
}
}
Expand All @@ -385,7 +389,7 @@ public void ClearStateUponCompletion()
private static void ExecutionContextCallback(object? s)
{
// Only used privately to pass directly to EC.Run
Debug.Assert(s is StateMachineBox<TStateMachine>);
Debug.Assert(s is StateMachineBox<TStateMachine>, $"Expected {nameof(StateMachineBox<TStateMachine>)}, got '{s}'");
Unsafe.As<StateMachineBox<TStateMachine>>(s).StateMachine!.MoveNext();
}

Expand All @@ -402,7 +406,7 @@ public void MoveNext()

if (context is null)
{
Debug.Assert(StateMachine is not null);
Debug.Assert(StateMachine is not null, $"Null {nameof(StateMachine)}");
StateMachine.MoveNext();
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void ThrowForFailedGetResult(short token)
}

_error?.Throw();
Debug.Fail("Should not get here");
Debug.Fail($"{nameof(ThrowForFailedGetResult)} should never get here");
}

/// <summary>Schedules the continuation action for this operation.</summary>
Expand Down Expand Up @@ -250,8 +250,8 @@ private void InvokeContinuationWithContext()
// for the surrounding code to become less efficent (stack spills etc)
// and it is an uncommon path.

Debug.Assert(_continuation != null);
Debug.Assert(_executionContext != null);
Debug.Assert(_continuation != null, $"Null {nameof(_continuation)}");
Debug.Assert(_executionContext != null, $"Null {nameof(_executionContext)}");

ExecutionContext? currentContext = ExecutionContext.CaptureForRestore();
// Restore the captured ExecutionContext before executing anything.
Expand Down Expand Up @@ -321,8 +321,8 @@ private void InvokeContinuationWithContext()
/// </summary>
private void InvokeSchedulerContinuation()
{
Debug.Assert(_capturedContext != null);
Debug.Assert(_continuation != null);
Debug.Assert(_capturedContext != null, $"Null {nameof(_capturedContext)}");
Debug.Assert(_continuation != null, $"Null {nameof(_continuation)}");

switch (_capturedContext)
{
Expand Down