Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
9be5969
very early prototype
dsyme Jan 30, 2018
b8412b3
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme Feb 14, 2018
41082e2
async stack traces
dsyme Feb 14, 2018
ddf8a43
integrate master
dsyme May 9, 2018
efd785c
async cleanup
dsyme May 9, 2018
d7268ca
minor fix
dsyme May 9, 2018
f684806
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme May 9, 2018
3620df5
integrate async-cleanup
dsyme May 9, 2018
4e7de49
async cleanup
dsyme May 9, 2018
73750f7
integrate async-cleanup
dsyme May 9, 2018
a31caa7
more async cleanup
dsyme May 9, 2018
bef1c38
integrate async-cleanup
dsyme May 9, 2018
60030b7
integrate async-cleanup
dsyme May 9, 2018
54a335c
async cleanup
dsyme May 9, 2018
88e68cf
integrate async-cleanup
dsyme May 9, 2018
2dd05d7
fix build
dsyme May 9, 2018
7462682
more cleanup
dsyme May 9, 2018
6c63a26
Merge branch 'async-cleanup' into async-st
dsyme May 9, 2018
683a777
minor fixes
dsyme May 9, 2018
841454b
integrate cleanup
dsyme May 9, 2018
cd2d7c7
minor fixes
dsyme May 9, 2018
adcb276
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme May 9, 2018
660a881
full exception stacktraces
dsyme May 9, 2018
fa9d4dc
fix test
dsyme May 9, 2018
1742cb9
fix test
dsyme May 9, 2018
4f043dc
code review
dsyme May 9, 2018
d7572f2
cleanup naming
dsyme May 10, 2018
f195fda
fix build
dsyme May 10, 2018
07b3c74
integrate async-cleanup2
dsyme May 10, 2018
b45930b
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme May 10, 2018
d17ed22
undo rethrow and integrate cleanup
dsyme May 10, 2018
3224a07
integrate async-cleanup2
dsyme May 10, 2018
e2b3d09
apply renamings
dsyme May 10, 2018
cb5106b
Further cleanup in control.fs
dsyme May 10, 2018
9ee1027
integrate async-cleanup-4
dsyme May 10, 2018
5916319
integrate async-cleanup-4
dsyme May 10, 2018
cccb41a
add tests and add filtering TryWith, plus other cleanup
dsyme May 11, 2018
d83a22b
integrate cleanup
dsyme May 11, 2018
7686c27
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme May 11, 2018
e35a101
integrate cleanup
dsyme May 11, 2018
f7123d6
fix tests
dsyme May 11, 2018
ef05de3
test only runs on .net framework
dsyme May 11, 2018
d1a6a35
slightly tweak primitives to be more suitable for later optimization
dsyme May 11, 2018
6b2a28f
slightly tweak primitives to be more suitable for later optimization
dsyme May 11, 2018
e27b21d
update baselines
dsyme May 11, 2018
e946976
add check that no line 0 appear in stack
dsyme May 11, 2018
bba01b9
update baseline
dsyme May 11, 2018
5f7f98d
use struct wrapper for async activation
dsyme May 11, 2018
1b08d5a
simplify code
dsyme May 11, 2018
dc6707c
simplify code
dsyme May 11, 2018
4549b0f
update baselines
dsyme May 11, 2018
368d009
update baselines
dsyme May 11, 2018
4c8e9f2
fix baseline
dsyme May 12, 2018
a388e7d
integrate master
dsyme May 12, 2018
5045d64
remove dead code
dsyme May 12, 2018
b0fea33
simplify code
dsyme May 12, 2018
1cd72fe
apply DebuggerHidden in a couple more places
dsyme May 13, 2018
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
673 changes: 390 additions & 283 deletions src/fsharp/FSharp.Core/async.fs

Large diffs are not rendered by default.

163 changes: 117 additions & 46 deletions src/fsharp/FSharp.Core/async.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ namespace Microsoft.FSharp.Control
/// computation expressions can check the cancellation condition regularly. Synchronous
/// computations within an asynchronous computation do not automatically check this condition.</remarks>

[<Sealed>]
[<NoEquality; NoComparison>]
[<CompiledName("FSharpAsync`1")>]
[<Sealed; NoEquality; NoComparison; CompiledName("FSharpAsync`1")>]
type Async<'T>

/// <summary>This static class holds members for creating and manipulating asynchronous computations.</summary>
Expand Down Expand Up @@ -417,7 +415,6 @@ namespace Microsoft.FSharp.Control
static member StartImmediate:
computation:Async<unit> * ?cancellationToken:CancellationToken-> unit


/// <summary>Runs an asynchronous computation, starting immediately on the current operating system,
/// but also returns the execution as <c>System.Threading.Tasks.Task</c>
/// </summary>
Expand All @@ -435,6 +432,112 @@ namespace Microsoft.FSharp.Control
computation:Async<'T> * ?cancellationToken:CancellationToken-> Task<'T>


/// <summary>The F# compiler emits references to this type to implement F# async expressions.</summary>
type AsyncReturn

/// <summary>The F# compiler emits references to this type to implement F# async expressions.</summary>
[<Struct; NoEquality; NoComparison>]
type AsyncActivation<'T> =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some attribute here like CompilerGenerated or Obsolete or something else to indicate users should not use the type directly?


/// <summary>The F# compiler emits calls to this function to implement F# async expressions.</summary>
///
/// <returns>A value indicating asynchronous execution.</returns>
member IsCancellationRequested: bool

/// <summary>The F# compiler emits calls to this function to implement F# async expressions.</summary>
///
/// <returns>A value indicating asynchronous execution.</returns>
member OnSuccess: 'T -> AsyncReturn

/// <summary>The F# compiler emits calls to this function to implement F# async expressions.</summary>
member OnExceptionRaised: unit -> unit

/// <summary>The F# compiler emits calls to this function to implement F# async expressions.</summary>
///
/// <returns>A value indicating asynchronous execution.</returns>
member OnCancellation: unit -> AsyncReturn

/// Used by MailboxProcessor
member internal QueueContinuationWithTrampoline: 'T -> AsyncReturn
/// Used by MailboxProcessor
member internal CallContinuation: 'T -> AsyncReturn

[<NoEquality; NoComparison>]
// Internals used by MailboxProcessor
type internal AsyncResult<'T> =
| Ok of 'T
| Error of ExceptionDispatchInfo
| Canceled of OperationCanceledException

[<Sealed>]
/// <summary>Entry points for generated code</summary>
module AsyncPrimitives =

/// <summary>The F# compiler emits calls to this function to implement F# async expressions.</summary>
///
/// <param name="body">The body of the async computation.</param>
///
/// <returns>The async computation.</returns>
val MakeAsync: body:(AsyncActivation<'T> -> AsyncReturn) -> Async<'T>

/// <summary>The F# compiler emits calls to this function to implement constructs for F# async expressions.</summary>
///
/// <param name="computation">The async computation.</param>
/// <param name="ctxt">The async activation.</param>
///
/// <returns>A value indicating asynchronous execution.</returns>
val Invoke: computation: Async<'T> -> ctxt:AsyncActivation<'T> -> AsyncReturn

/// <summary>The F# compiler emits calls to this function to implement constructs for F# async expressions.</summary>
///
/// <param name="ctxt">The async activation.</param>
/// <param name="result">The result of the first part of the computation.</param>
/// <param name="part2">A function returning the second part of the computation.</param>
///
/// <returns>A value indicating asynchronous execution.</returns>
val CallThenInvoke: ctxt:AsyncActivation<'T> -> result1:'U -> part2:('U -> Async<'T>) -> AsyncReturn

/// <summary>The F# compiler emits calls to this function to implement the <c>let!</c> construct for F# async expressions.</summary>
///
/// <param name="ctxt">The async activation.</param>
/// <param name="part2">A function returning the second part of the computation.</param>
///
/// <returns>An async activation suitable for running part1 of the asynchronous execution.</returns>
val Bind: ctxt:AsyncActivation<'T> -> part1:Async<'U> -> part2:('U -> Async<'T>) -> AsyncReturn

/// <summary>The F# compiler emits calls to this function to implement the <c>try/finally</c> construct for F# async expressions.</summary>
///
/// <param name="ctxt">The async activation.</param>
/// <param name="computation">The computation to protect.</param>
/// <param name="finallyFunction">The finally code.</param>
///
/// <returns>A value indicating asynchronous execution.</returns>
val TryFinally: ctxt:AsyncActivation<'T> -> computation: Async<'T> -> finallyFunction: (unit -> unit) -> AsyncReturn

/// <summary>The F# compiler emits calls to this function to implement the <c>try/with</c> construct for F# async expressions.</summary>
///
/// <param name="ctxt">The async activation.</param>
/// <param name="computation">The computation to protect.</param>
/// <param name="catchFunction">The exception filter.</param>
///
/// <returns>A value indicating asynchronous execution.</returns>
val TryWith: ctxt:AsyncActivation<'T> -> computation: Async<'T> -> catchFunction: (Exception -> Async<'T> option) -> AsyncReturn

[<Sealed; AutoSerializable(false)>]
// Internals used by MailboxProcessor
type internal ResultCell<'T> =
new : unit -> ResultCell<'T>
member GetWaitHandle: unit -> WaitHandle
member Close: unit -> unit
interface IDisposable
member RegisterResult: 'T * reuseThread: bool -> AsyncReturn
member GrabResult: unit -> 'T
member ResultAvailable : bool
member AwaitResult_NoDirectCancelOrTimeout : Async<'T>
member TryWaitForResultSynchronously: ?timeout: int -> 'T option

// Internals used by MailboxProcessor
val internal CreateAsyncResultAsync : AsyncResult<'T> -> Async<'T>

[<CompiledName("FSharpAsyncBuilder")>]
[<Sealed>]
Expand Down Expand Up @@ -473,7 +576,7 @@ namespace Microsoft.FSharp.Control
/// <param name="computation1">The first part of the sequenced computation.</param>
/// <param name="computation2">The second part of the sequenced computation.</param>
/// <returns>An asynchronous computation that runs both of the computations sequentially.</returns>
member Combine : computation1:Async<unit> * computation2:Async<'T> -> Async<'T>
member inline Combine : computation1:Async<unit> * computation2:Async<'T> -> Async<'T>

/// <summary>Creates an asynchronous computation that runs <c>computation</c> repeatedly
/// until <c>guard()</c> becomes false.</summary>
Expand All @@ -496,15 +599,15 @@ namespace Microsoft.FSharp.Control
/// <c>async { ... }</c> computation expression syntax.</remarks>
/// <param name="value">The value to return from the computation.</param>
/// <returns>An asynchronous computation that returns <c>value</c> when executed.</returns>
member Return : value:'T -> Async<'T>
member inline Return : value:'T -> Async<'T>

/// <summary>Delegates to the input computation.</summary>
///
/// <remarks>The existence of this method permits the use of <c>return!</c> in the
/// <c>async { ... }</c> computation expression syntax.</remarks>
/// <param name="computation">The input computation.</param>
/// <returns>The input computation.</returns>
member ReturnFrom : computation:Async<'T> -> Async<'T>
member inline ReturnFrom : computation:Async<'T> -> Async<'T>

/// <summary>Creates an asynchronous computation that runs <c>generator</c>.</summary>
///
Expand Down Expand Up @@ -538,7 +641,7 @@ namespace Microsoft.FSharp.Control
/// <param name="binder">The function to bind the result of <c>computation</c>.</param>
/// <returns>An asynchronous computation that performs a monadic bind on the result
/// of <c>computation</c>.</returns>
member Bind: computation: Async<'T> * binder: ('T -> Async<'U>) -> Async<'U>
member inline Bind: computation: Async<'T> * binder: ('T -> Async<'U>) -> Async<'U>

/// <summary>Creates an asynchronous computation that runs <c>computation</c>. The action <c>compensation</c> is executed
/// after <c>computation</c> completes, whether <c>computation</c> exits normally or by an exception. If <c>compensation</c> raises an exception itself
Expand All @@ -553,7 +656,7 @@ namespace Microsoft.FSharp.Control
/// exception (including cancellation).</param>
/// <returns>An asynchronous computation that executes computation and compensation afterwards or
/// when an exception is raised.</returns>
member TryFinally : computation:Async<'T> * compensation:(unit -> unit) -> Async<'T>
member inline TryFinally : computation:Async<'T> * compensation:(unit -> unit) -> Async<'T>

/// <summary>Creates an asynchronous computation that runs <c>computation</c> and returns its result.
/// If an exception happens then <c>catchHandler(exn)</c> is called and the resulting computation executed instead.</summary>
Expand All @@ -562,11 +665,14 @@ namespace Microsoft.FSharp.Control
///
/// The existence of this method permits the use of <c>try/with</c> in the
/// <c>async { ... }</c> computation expression syntax.</remarks>
///
/// <param name="computation">The input computation.</param>
/// <param name="catchHandler">The function to run when <c>computation</c> throws an exception.</param>
/// <returns>An asynchronous computation that executes <c>computation</c> and calls <c>catchHandler</c> if an
/// exception is thrown.</returns>
member TryWith : computation:Async<'T> * catchHandler:(exn -> Async<'T>) -> Async<'T>
member inline TryWith : computation:Async<'T> * catchHandler:(exn -> Async<'T>) -> Async<'T>

// member inline TryWithFilter : computation:Async<'T> * catchHandler:(exn -> Async<'T> option) -> Async<'T>

/// Generate an object used to build asynchronous computations using F# computation expressions. The value
/// 'async' is a pre-defined instance of this type.
Expand Down Expand Up @@ -659,41 +765,6 @@ namespace Microsoft.FSharp.Control
#endif

// Internals used by MailboxProcessor
module internal AsyncImpl =
module internal AsyncBuilderImpl =
val async : AsyncBuilder

[<Sealed>]
// Internals used by MailboxProcessor
type internal AsyncReturn

[<Sealed>]
// Internals used by MailboxProcessor
type internal AsyncActivation<'T> =
member QueueContinuationWithTrampoline: 'T -> AsyncReturn
member CallContinuation: 'T -> AsyncReturn

[<NoEquality; NoComparison>]
// Internals used by MailboxProcessor
type internal AsyncResult<'T> =
| Ok of 'T
| Error of ExceptionDispatchInfo
| Canceled of OperationCanceledException

// Internals used by MailboxProcessor
module internal AsyncPrimitives =

[<Sealed; AutoSerializable(false)>]
type internal ResultCell<'T> =
new : unit -> ResultCell<'T>
member GetWaitHandle: unit -> WaitHandle
member Close: unit -> unit
interface IDisposable
member RegisterResult: 'T * reuseThread: bool -> AsyncReturn
member GrabResult: unit -> 'T
member ResultAvailable : bool
member AwaitResult_NoDirectCancelOrTimeout : Async<'T>
member TryWaitForResultSynchronously: ?timeout: int -> 'T option

val CreateAsyncResultAsync : AsyncResult<'T> -> Async<'T>

val MakeAsync : (AsyncActivation<'T> -> AsyncReturn) -> Async<'T>
2 changes: 1 addition & 1 deletion src/fsharp/FSharp.Core/mailbox.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.FSharp.Control
open Microsoft.FSharp.Core
open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
open Microsoft.FSharp.Control
open Microsoft.FSharp.Control.AsyncImpl
open Microsoft.FSharp.Control.AsyncBuilderImpl
open Microsoft.FSharp.Control.AsyncPrimitives
open Microsoft.FSharp.Collections

Expand Down
12 changes: 6 additions & 6 deletions src/fsharp/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2764,17 +2764,17 @@ namespace Microsoft.FSharp.Core
// Function Values

[<AbstractClass>]
type FSharpTypeFunc() =
type FSharpTypeFunc [<DebuggerHidden>] () =
abstract Specialize<'T> : unit -> obj

[<AbstractClass>]
type FSharpFunc<'T,'Res>() =
type FSharpFunc<'T,'Res> [<DebuggerHidden>] () =
abstract Invoke : 'T -> 'Res

module OptimizedClosures =

[<AbstractClass>]
type FSharpFunc<'T,'U,'V>() =
type FSharpFunc<'T,'U,'V> [<DebuggerHidden>] () =
inherit FSharpFunc<'T,('U -> 'V)>()
abstract Invoke : 'T * 'U -> 'V
override f.Invoke(t) = (fun u -> f.Invoke(t,u))
Expand All @@ -2787,7 +2787,7 @@ namespace Microsoft.FSharp.Core
member x.Invoke(t,u) = (retype func : FSharpFunc<'T,FSharpFunc<'U,'V>>).Invoke(t).Invoke(u) }

[<AbstractClass>]
type FSharpFunc<'T,'U,'V,'W>() =
type FSharpFunc<'T,'U,'V,'W> [<DebuggerHidden>] () =
inherit FSharpFunc<'T,('U -> 'V -> 'W)>()
abstract Invoke : 'T * 'U * 'V -> 'W
override f.Invoke(t) = (fun u v -> f.Invoke(t,u,v))
Expand All @@ -2805,7 +2805,7 @@ namespace Microsoft.FSharp.Core
member x.Invoke(t,u,v) = (retype func : FSharpFunc<'T,('U -> 'V -> 'W)>).Invoke(t) u v }

[<AbstractClass>]
type FSharpFunc<'T,'U,'V,'W,'X>() =
type FSharpFunc<'T,'U,'V,'W,'X> [<DebuggerHidden>] () =
inherit FSharpFunc<'T,('U -> 'V -> 'W -> 'X)>()
abstract Invoke : 'T * 'U * 'V * 'W -> 'X
static member Adapt(func : 'T -> 'U -> 'V -> 'W -> 'X) =
Expand All @@ -2828,7 +2828,7 @@ namespace Microsoft.FSharp.Core
override f.Invoke(t) = (fun u v w -> f.Invoke(t,u,v,w))

[<AbstractClass>]
type FSharpFunc<'T,'U,'V,'W,'X,'Y>() =
type FSharpFunc<'T,'U,'V,'W,'X,'Y> [<DebuggerHidden>] () =
inherit FSharpFunc<'T,('U -> 'V -> 'W -> 'X -> 'Y)>()
abstract Invoke : 'T * 'U * 'V * 'W * 'X -> 'Y
override f.Invoke(t) = (fun u v w x -> f.Invoke(t,u,v,w,x))
Expand Down
23 changes: 23 additions & 0 deletions tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,29 @@ Microsoft.FSharp.Collections.SetModule: TState FoldBack[T,TState](Microsoft.FSha
Microsoft.FSharp.Collections.SetModule: TState Fold[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpFunc`2[T,TState]], TState, Microsoft.FSharp.Collections.FSharpSet`1[T])
Microsoft.FSharp.Collections.SetModule: T[] ToArray[T](Microsoft.FSharp.Collections.FSharpSet`1[T])
Microsoft.FSharp.Collections.SetModule: Void Iterate[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.Unit], Microsoft.FSharp.Collections.FSharpSet`1[T])
Microsoft.FSharp.Control.AsyncActivation`1[T]: Boolean Equals(System.Object)
Microsoft.FSharp.Control.AsyncActivation`1[T]: Boolean IsCancellationRequested
Microsoft.FSharp.Control.AsyncActivation`1[T]: Boolean get_IsCancellationRequested()
Microsoft.FSharp.Control.AsyncActivation`1[T]: Int32 GetHashCode()
Microsoft.FSharp.Control.AsyncActivation`1[T]: Microsoft.FSharp.Control.AsyncReturn OnCancellation()
Microsoft.FSharp.Control.AsyncActivation`1[T]: Void OnExceptionRaised()
Microsoft.FSharp.Control.AsyncActivation`1[T]: Microsoft.FSharp.Control.AsyncReturn OnSuccess(T)
Microsoft.FSharp.Control.AsyncActivation`1[T]: System.String ToString()
Microsoft.FSharp.Control.AsyncActivation`1[T]: System.Type GetType()
Microsoft.FSharp.Control.AsyncPrimitives: Boolean Equals(System.Object)
Microsoft.FSharp.Control.AsyncPrimitives: Int32 GetHashCode()
Microsoft.FSharp.Control.AsyncPrimitives: Microsoft.FSharp.Control.AsyncReturn Bind[T,TResult](Microsoft.FSharp.Control.AsyncActivation`1[T], Microsoft.FSharp.Control.FSharpAsync`1[TResult], Microsoft.FSharp.Core.FSharpFunc`2[TResult,Microsoft.FSharp.Control.FSharpAsync`1[T]])
Microsoft.FSharp.Control.AsyncPrimitives: Microsoft.FSharp.Control.AsyncReturn CallThenInvoke[T,TResult](Microsoft.FSharp.Control.AsyncActivation`1[T], TResult, Microsoft.FSharp.Core.FSharpFunc`2[TResult,Microsoft.FSharp.Control.FSharpAsync`1[T]])
Microsoft.FSharp.Control.AsyncPrimitives: Microsoft.FSharp.Control.AsyncReturn Invoke[T](Microsoft.FSharp.Control.FSharpAsync`1[T], Microsoft.FSharp.Control.AsyncActivation`1[T])
Microsoft.FSharp.Control.AsyncPrimitives: Microsoft.FSharp.Control.AsyncReturn TryFinally[T](Microsoft.FSharp.Control.AsyncActivation`1[T], Microsoft.FSharp.Control.FSharpAsync`1[T], Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Core.Unit])
Microsoft.FSharp.Control.AsyncPrimitives: Microsoft.FSharp.Control.AsyncReturn TryWith[T](Microsoft.FSharp.Control.AsyncActivation`1[T], Microsoft.FSharp.Control.FSharpAsync`1[T], Microsoft.FSharp.Core.FSharpFunc`2[System.Exception,Microsoft.FSharp.Core.FSharpOption`1[Microsoft.FSharp.Control.FSharpAsync`1[T]]])
Microsoft.FSharp.Control.AsyncPrimitives: Microsoft.FSharp.Control.FSharpAsync`1[T] MakeAsync[T](Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Control.AsyncActivation`1[T],Microsoft.FSharp.Control.AsyncReturn])
Microsoft.FSharp.Control.AsyncPrimitives: System.String ToString()
Microsoft.FSharp.Control.AsyncPrimitives: System.Type GetType()
Microsoft.FSharp.Control.AsyncReturn: Boolean Equals(System.Object)
Microsoft.FSharp.Control.AsyncReturn: Int32 GetHashCode()
Microsoft.FSharp.Control.AsyncReturn: System.String ToString()
Microsoft.FSharp.Control.AsyncReturn: System.Type GetType()
Microsoft.FSharp.Control.CommonExtensions: Boolean Equals(System.Object)
Microsoft.FSharp.Control.CommonExtensions: Int32 GetHashCode()
Microsoft.FSharp.Control.CommonExtensions: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.Unit] AsyncWrite(System.IO.Stream, Byte[], Microsoft.FSharp.Core.FSharpOption`1[System.Int32], Microsoft.FSharp.Core.FSharpOption`1[System.Int32])
Expand Down
Loading