ObjectIdForDebugger

pull/73/head
neuecc 2020-05-05 21:34:11 +09:00
parent b9b2925e8d
commit 51f4003bc5
4 changed files with 115 additions and 3 deletions

View File

@ -9,11 +9,17 @@ namespace NetCoreSandbox
static async Task Main(string[] args) static async Task Main(string[] args)
{ {
Console.WriteLine("Foo"); Console.WriteLine("Foo");
var v = await DoAsync().AsTask(); var v = await outer().AsTask();
Console.WriteLine("Bar:" + v); Console.WriteLine("Bar:" + v);
} }
static async UniTask<int> outer()
{
var v = await DoAsync();
return v;
}
static async UniTask<int> DoAsync() static async UniTask<int> DoAsync()
{ {

View File

@ -135,6 +135,20 @@ namespace Cysharp.Threading.Tasks.CompilerServices
{ {
// don't use boxed stateMachine. // don't use boxed stateMachine.
} }
// 9. For Debugger Attach
[DebuggerHidden]
public object ObjectIdForDebugger
{
get
{
if (promise == null)
{
promise = AutoResetUniTaskCompletionSource.Create();
}
return promise;
}
}
} }
[StructLayout(LayoutKind.Auto)] [StructLayout(LayoutKind.Auto)]
@ -266,6 +280,19 @@ namespace Cysharp.Threading.Tasks.CompilerServices
{ {
// don't use boxed stateMachine. // don't use boxed stateMachine.
} }
// 9. For Debugger Attach
[DebuggerHidden]
public object ObjectIdForDebugger
{
get
{
if (promise == null)
{
promise = AutoResetUniTaskCompletionSource<T>.Create();
}
return promise;
}
}
} }
} }

View File

@ -100,6 +100,26 @@ namespace Cysharp.Threading.Tasks.CompilerServices
{ {
// don't use boxed stateMachine. // don't use boxed stateMachine.
} }
#if DEBUG || !UNITY_2018_3_OR_NEWER
object id;
// 9. For Debugger Attach
[DebuggerHidden]
public object ObjectIdForDebugger
{
get
{
if (id == null)
{
id = new object();
}
return id;
}
}
#endif
} }
} }

View File

@ -51,6 +51,7 @@ namespace Cysharp.Threading.Tasks
Action<object> continuation; Action<object> continuation;
object continuationState; object continuationState;
[DebuggerHidden]
public void Reset() public void Reset()
{ {
ReportUnhandledError(); ReportUnhandledError();
@ -90,6 +91,7 @@ namespace Cysharp.Threading.Tasks
/// <summary>Completes with a successful result.</summary> /// <summary>Completes with a successful result.</summary>
/// <param name="result">The result.</param> /// <param name="result">The result.</param>
[DebuggerHidden]
public bool TrySetResult(TResult result) public bool TrySetResult(TResult result)
{ {
if (Interlocked.Increment(ref completedCount) == 1) if (Interlocked.Increment(ref completedCount) == 1)
@ -109,6 +111,7 @@ namespace Cysharp.Threading.Tasks
/// <summary>Completes with an error.</summary> /// <summary>Completes with an error.</summary>
/// <param name="error">The exception.</param> /// <param name="error">The exception.</param>
[DebuggerHidden]
public bool TrySetException(Exception error) public bool TrySetException(Exception error)
{ {
if (Interlocked.Increment(ref completedCount) == 1) if (Interlocked.Increment(ref completedCount) == 1)
@ -127,6 +130,7 @@ namespace Cysharp.Threading.Tasks
return false; return false;
} }
[DebuggerHidden]
public bool TrySetCanceled(CancellationToken cancellationToken = default) public bool TrySetCanceled(CancellationToken cancellationToken = default)
{ {
if (Interlocked.Increment(ref completedCount) == 1) if (Interlocked.Increment(ref completedCount) == 1)
@ -146,10 +150,12 @@ namespace Cysharp.Threading.Tasks
} }
/// <summary>Gets the operation version.</summary> /// <summary>Gets the operation version.</summary>
[DebuggerHidden]
public short Version => version; public short Version => version;
/// <summary>Gets the status of the operation.</summary> /// <summary>Gets the status of the operation.</summary>
/// <param name="token">Opaque value that was provided to the <see cref="UniTask"/>'s constructor.</param> /// <param name="token">Opaque value that was provided to the <see cref="UniTask"/>'s constructor.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public UniTaskStatus GetStatus(short token) public UniTaskStatus GetStatus(short token)
{ {
@ -161,6 +167,7 @@ namespace Cysharp.Threading.Tasks
} }
/// <summary>Gets the status of the operation without token validation.</summary> /// <summary>Gets the status of the operation without token validation.</summary>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public UniTaskStatus UnsafeGetStatus() public UniTaskStatus UnsafeGetStatus()
{ {
@ -173,6 +180,7 @@ namespace Cysharp.Threading.Tasks
/// <summary>Gets the result of the operation.</summary> /// <summary>Gets the result of the operation.</summary>
/// <param name="token">Opaque value that was provided to the <see cref="UniTask"/>'s constructor.</param> /// <param name="token">Opaque value that was provided to the <see cref="UniTask"/>'s constructor.</param>
// [StackTraceHidden] // [StackTraceHidden]
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public TResult GetResult(short token) public TResult GetResult(short token)
{ {
@ -204,6 +212,7 @@ namespace Cysharp.Threading.Tasks
/// <param name="continuation">The continuation to invoke when the operation has completed.</param> /// <param name="continuation">The continuation to invoke when the operation has completed.</param>
/// <param name="state">The state object to pass to <paramref name="continuation"/> when it's invoked.</param> /// <param name="state">The state object to pass to <paramref name="continuation"/> when it's invoked.</param>
/// <param name="token">Opaque value that was provided to the <see cref="UniTask"/>'s constructor.</param> /// <param name="token">Opaque value that was provided to the <see cref="UniTask"/>'s constructor.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void OnCompleted(Action<object> continuation, object state, short token /*, ValueTaskSourceOnCompletedFlags flags */) public void OnCompleted(Action<object> continuation, object state, short token /*, ValueTaskSourceOnCompletedFlags flags */)
{ {
@ -244,6 +253,7 @@ namespace Cysharp.Threading.Tasks
} }
} }
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ValidateToken(short token) private void ValidateToken(short token)
{ {
@ -274,6 +284,7 @@ namespace Cysharp.Threading.Tasks
TaskTracker.TrackActiveTask(this, 2); TaskTracker.TrackActiveTask(this, 2);
} }
[DebuggerHidden]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
internal void MarkHandled() internal void MarkHandled()
{ {
@ -286,12 +297,14 @@ namespace Cysharp.Threading.Tasks
public UniTask Task public UniTask Task
{ {
[DebuggerHidden]
get get
{ {
return new UniTask(this, core.Version); return new UniTask(this, core.Version);
} }
} }
[DebuggerHidden]
public void Reset() public void Reset()
{ {
// Reset, re-active tracker // Reset, re-active tracker
@ -300,37 +313,44 @@ namespace Cysharp.Threading.Tasks
core.Reset(); core.Reset();
} }
[DebuggerHidden]
public bool TrySetResult() public bool TrySetResult()
{ {
return core.TrySetResult(AsyncUnit.Default); return core.TrySetResult(AsyncUnit.Default);
} }
[DebuggerHidden]
public bool TrySetCanceled(CancellationToken cancellationToken = default) public bool TrySetCanceled(CancellationToken cancellationToken = default)
{ {
return core.TrySetCanceled(cancellationToken); return core.TrySetCanceled(cancellationToken);
} }
[DebuggerHidden]
public bool TrySetException(Exception exception) public bool TrySetException(Exception exception)
{ {
return core.TrySetException(exception); return core.TrySetException(exception);
} }
[DebuggerHidden]
public void GetResult(short token) public void GetResult(short token)
{ {
MarkHandled(); MarkHandled();
core.GetResult(token); core.GetResult(token);
} }
[DebuggerHidden]
public UniTaskStatus GetStatus(short token) public UniTaskStatus GetStatus(short token)
{ {
return core.GetStatus(token); return core.GetStatus(token);
} }
[DebuggerHidden]
public UniTaskStatus UnsafeGetStatus() public UniTaskStatus UnsafeGetStatus()
{ {
return core.UnsafeGetStatus(); return core.UnsafeGetStatus();
} }
[DebuggerHidden]
public void OnCompleted(Action<object> continuation, object state, short token) public void OnCompleted(Action<object> continuation, object state, short token)
{ {
core.OnCompleted(continuation, state, token); core.OnCompleted(continuation, state, token);
@ -353,6 +373,7 @@ namespace Cysharp.Threading.Tasks
{ {
} }
[DebuggerHidden]
public static AutoResetUniTaskCompletionSource Create() public static AutoResetUniTaskCompletionSource Create()
{ {
var value = pool.TryRent() ?? new AutoResetUniTaskCompletionSource(); var value = pool.TryRent() ?? new AutoResetUniTaskCompletionSource();
@ -360,6 +381,7 @@ namespace Cysharp.Threading.Tasks
return value; return value;
} }
[DebuggerHidden]
public static AutoResetUniTaskCompletionSource CreateFromCanceled(CancellationToken cancellationToken, out short token) public static AutoResetUniTaskCompletionSource CreateFromCanceled(CancellationToken cancellationToken, out short token)
{ {
var source = Create(); var source = Create();
@ -368,6 +390,7 @@ namespace Cysharp.Threading.Tasks
return source; return source;
} }
[DebuggerHidden]
public static AutoResetUniTaskCompletionSource CreateFromException(Exception exception, out short token) public static AutoResetUniTaskCompletionSource CreateFromException(Exception exception, out short token)
{ {
var source = Create(); var source = Create();
@ -376,6 +399,7 @@ namespace Cysharp.Threading.Tasks
return source; return source;
} }
[DebuggerHidden]
public static AutoResetUniTaskCompletionSource CreateCompleted(out short token) public static AutoResetUniTaskCompletionSource CreateCompleted(out short token)
{ {
var source = Create(); var source = Create();
@ -386,27 +410,32 @@ namespace Cysharp.Threading.Tasks
public UniTask Task public UniTask Task
{ {
[DebuggerHidden]
get get
{ {
return new UniTask(this, core.Version); return new UniTask(this, core.Version);
} }
} }
[DebuggerHidden]
public bool TrySetResult() public bool TrySetResult()
{ {
return core.TrySetResult(AsyncUnit.Default); return core.TrySetResult(AsyncUnit.Default);
} }
[DebuggerHidden]
public bool TrySetCanceled(CancellationToken cancellationToken = default) public bool TrySetCanceled(CancellationToken cancellationToken = default)
{ {
return core.TrySetCanceled(cancellationToken); return core.TrySetCanceled(cancellationToken);
} }
[DebuggerHidden]
public bool TrySetException(Exception exception) public bool TrySetException(Exception exception)
{ {
return core.TrySetException(exception); return core.TrySetException(exception);
} }
[DebuggerHidden]
public void GetResult(short token) public void GetResult(short token)
{ {
try try
@ -421,21 +450,25 @@ namespace Cysharp.Threading.Tasks
} }
[DebuggerHidden]
public UniTaskStatus GetStatus(short token) public UniTaskStatus GetStatus(short token)
{ {
return core.GetStatus(token); return core.GetStatus(token);
} }
[DebuggerHidden]
public UniTaskStatus UnsafeGetStatus() public UniTaskStatus UnsafeGetStatus()
{ {
return core.UnsafeGetStatus(); return core.UnsafeGetStatus();
} }
[DebuggerHidden]
public void OnCompleted(Action<object> continuation, object state, short token) public void OnCompleted(Action<object> continuation, object state, short token)
{ {
core.OnCompleted(continuation, state, token); core.OnCompleted(continuation, state, token);
} }
[DebuggerHidden]
void IPromisePoolItem.Reset() void IPromisePoolItem.Reset()
{ {
core.Reset(); core.Reset();
@ -456,11 +489,13 @@ namespace Cysharp.Threading.Tasks
UniTaskCompletionSourceCore<T> core; UniTaskCompletionSourceCore<T> core;
bool handled = false; bool handled = false;
[DebuggerHidden]
public UniTaskCompletionSource() public UniTaskCompletionSource()
{ {
TaskTracker.TrackActiveTask(this, 2); TaskTracker.TrackActiveTask(this, 2);
} }
[DebuggerHidden]
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
internal void MarkHandled() internal void MarkHandled()
{ {
@ -471,6 +506,7 @@ namespace Cysharp.Threading.Tasks
} }
} }
[DebuggerHidden]
public UniTask<T> Task public UniTask<T> Task
{ {
get get
@ -479,6 +515,7 @@ namespace Cysharp.Threading.Tasks
} }
} }
[DebuggerHidden]
public void Reset() public void Reset()
{ {
handled = false; handled = false;
@ -486,42 +523,50 @@ namespace Cysharp.Threading.Tasks
TaskTracker.TrackActiveTask(this, 2); TaskTracker.TrackActiveTask(this, 2);
} }
[DebuggerHidden]
public bool TrySetResult(T result) public bool TrySetResult(T result)
{ {
return core.TrySetResult(result); return core.TrySetResult(result);
} }
[DebuggerHidden]
public bool TrySetCanceled(CancellationToken cancellationToken = default) public bool TrySetCanceled(CancellationToken cancellationToken = default)
{ {
return core.TrySetCanceled(cancellationToken); return core.TrySetCanceled(cancellationToken);
} }
[DebuggerHidden]
public bool TrySetException(Exception exception) public bool TrySetException(Exception exception)
{ {
return core.TrySetException(exception); return core.TrySetException(exception);
} }
[DebuggerHidden]
public T GetResult(short token) public T GetResult(short token)
{ {
MarkHandled(); MarkHandled();
return core.GetResult(token); return core.GetResult(token);
} }
[DebuggerHidden]
void IUniTaskSource.GetResult(short token) void IUniTaskSource.GetResult(short token)
{ {
GetResult(token); GetResult(token);
} }
[DebuggerHidden]
public UniTaskStatus GetStatus(short token) public UniTaskStatus GetStatus(short token)
{ {
return core.GetStatus(token); return core.GetStatus(token);
} }
[DebuggerHidden]
public UniTaskStatus UnsafeGetStatus() public UniTaskStatus UnsafeGetStatus()
{ {
return core.UnsafeGetStatus(); return core.UnsafeGetStatus();
} }
[DebuggerHidden]
public void OnCompleted(Action<object> continuation, object state, short token) public void OnCompleted(Action<object> continuation, object state, short token)
{ {
core.OnCompleted(continuation, state, token); core.OnCompleted(continuation, state, token);
@ -544,6 +589,7 @@ namespace Cysharp.Threading.Tasks
{ {
} }
[DebuggerHidden]
public static AutoResetUniTaskCompletionSource<T> Create() public static AutoResetUniTaskCompletionSource<T> Create()
{ {
var result = pool.TryRent() ?? new AutoResetUniTaskCompletionSource<T>(); var result = pool.TryRent() ?? new AutoResetUniTaskCompletionSource<T>();
@ -551,6 +597,7 @@ namespace Cysharp.Threading.Tasks
return result; return result;
} }
[DebuggerHidden]
public static AutoResetUniTaskCompletionSource<T> CreateFromCanceled(CancellationToken cancellationToken, out short token) public static AutoResetUniTaskCompletionSource<T> CreateFromCanceled(CancellationToken cancellationToken, out short token)
{ {
var source = Create(); var source = Create();
@ -559,6 +606,7 @@ namespace Cysharp.Threading.Tasks
return source; return source;
} }
[DebuggerHidden]
public static AutoResetUniTaskCompletionSource<T> CreateFromException(Exception exception, out short token) public static AutoResetUniTaskCompletionSource<T> CreateFromException(Exception exception, out short token)
{ {
var source = Create(); var source = Create();
@ -567,6 +615,7 @@ namespace Cysharp.Threading.Tasks
return source; return source;
} }
[DebuggerHidden]
public static AutoResetUniTaskCompletionSource<T> CreateFromResult(T result, out short token) public static AutoResetUniTaskCompletionSource<T> CreateFromResult(T result, out short token)
{ {
var source = Create(); var source = Create();
@ -577,27 +626,32 @@ namespace Cysharp.Threading.Tasks
public UniTask<T> Task public UniTask<T> Task
{ {
[DebuggerHidden]
get get
{ {
return new UniTask<T>(this, core.Version); return new UniTask<T>(this, core.Version);
} }
} }
[DebuggerHidden]
public bool TrySetResult(T result) public bool TrySetResult(T result)
{ {
return core.TrySetResult(result); return core.TrySetResult(result);
} }
[DebuggerHidden]
public bool TrySetCanceled(CancellationToken cancellationToken = default) public bool TrySetCanceled(CancellationToken cancellationToken = default)
{ {
return core.TrySetCanceled(cancellationToken); return core.TrySetCanceled(cancellationToken);
} }
[DebuggerHidden]
public bool TrySetException(Exception exception) public bool TrySetException(Exception exception)
{ {
return core.TrySetException(exception); return core.TrySetException(exception);
} }
[DebuggerHidden]
public T GetResult(short token) public T GetResult(short token)
{ {
try try
@ -611,26 +665,31 @@ namespace Cysharp.Threading.Tasks
} }
} }
[DebuggerHidden]
void IUniTaskSource.GetResult(short token) void IUniTaskSource.GetResult(short token)
{ {
GetResult(token); GetResult(token);
} }
[DebuggerHidden]
public UniTaskStatus GetStatus(short token) public UniTaskStatus GetStatus(short token)
{ {
return core.GetStatus(token); return core.GetStatus(token);
} }
[DebuggerHidden]
public UniTaskStatus UnsafeGetStatus() public UniTaskStatus UnsafeGetStatus()
{ {
return core.UnsafeGetStatus(); return core.UnsafeGetStatus();
} }
[DebuggerHidden]
public void OnCompleted(Action<object> continuation, object state, short token) public void OnCompleted(Action<object> continuation, object state, short token)
{ {
core.OnCompleted(continuation, state, token); core.OnCompleted(continuation, state, token);
} }
[DebuggerHidden]
void IPromisePoolItem.Reset() void IPromisePoolItem.Reset()
{ {
core.Reset(); core.Reset();