Skip to content

Commit ab0d07d

Browse files
committed
format, limit
1 parent 92f08b1 commit ab0d07d

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/Compiler/Utilities/Cancellable.fs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type Trampoline(cancellationToken: CancellationToken) =
9090
let mutable bindDepth = 0
9191

9292
[<Literal>]
93-
static let bindDepthLimit = 1000
93+
static let bindDepthLimit = 100
9494

9595
static let current = new ThreadLocal<Trampoline>()
9696

@@ -101,8 +101,7 @@ type Trampoline(cancellationToken: CancellationToken) =
101101
member this.ThrowIfCancellationRequested() =
102102
cancellationToken.ThrowIfCancellationRequested()
103103

104-
member this.ShoudBounce =
105-
bindDepth % bindDepthLimit = 0
104+
member this.ShoudBounce = bindDepth % bindDepthLimit = 0
106105

107106
static member Install ct = current.Value <- Trampoline ct
108107

@@ -116,7 +115,8 @@ type Trampoline(cancellationToken: CancellationToken) =
116115

117116
member this.RunImmediate(invocation: ITrampolineInvocation) =
118117
bindDepth <- bindDepth + 1
119-
try
118+
119+
try
120120
// This can throw, which is fine. We want the exception to propagate to the calling machine.
121121
invocation.MoveNext()
122122

@@ -130,7 +130,6 @@ type Trampoline(cancellationToken: CancellationToken) =
130130
finally
131131
bindDepth <- bindDepth - 1
132132

133-
134133
static member Current = current.Value
135134

136135
type ITrampolineInvocation<'T> =
@@ -140,7 +139,9 @@ type ITrampolineInvocation<'T> =
140139
[<AutoOpen>]
141140
module ExceptionDispatchInfoHelpers =
142141
type ExceptionDispatchInfo with
143-
member edi.ThrowAny() = edi.Throw(); Unchecked.defaultof<_>
142+
member edi.ThrowAny() =
143+
edi.Throw()
144+
Unchecked.defaultof<_>
144145

145146
static member RestoreOrCapture(exn: exn) =
146147
match Trampoline.Current.LastError with
@@ -155,20 +156,19 @@ type ICancellableInvokable<'T> =
155156
abstract Create: bool -> ITrampolineInvocation<'T>
156157

157158
[<NoEquality; NoComparison>]
158-
type CancellableInvocation<'T, 'Machine when 'Machine :> IAsyncStateMachine and 'Machine :> ICancellableStateMachine<'T>>(machine: 'Machine, delayed: bool)
159-
=
159+
type CancellableInvocation<'T, 'Machine when 'Machine :> IAsyncStateMachine and 'Machine :> ICancellableStateMachine<'T>>
160+
(machine: 'Machine, delayed: bool) =
160161
let mutable machine = machine
161162
let mutable storedException = ValueNone
162163
let mutable finished = false
163164

164-
new (machine) = CancellableInvocation(machine, false)
165+
new(machine) = CancellableInvocation(machine, false)
165166

166167
interface ITrampolineInvocation<'T> with
167168
member this.MoveNext() =
168169
let pushDelayed () =
169170
match machine.Data.NextInvocation with
170-
| ValueSome delayed ->
171-
Trampoline.Current.RunDelayed(this, delayed)
171+
| ValueSome delayed -> Trampoline.Current.RunDelayed(this, delayed)
172172
| _ -> finished <- true
173173

174174
if delayed then
@@ -185,16 +185,19 @@ type CancellableInvocation<'T, 'Machine when 'Machine :> IAsyncStateMachine and
185185

186186
member _.Result = machine.Data.Result
187187
member _.IsCompleted = finished
188-
member _.ReplayExceptionIfStored () = storedException |> ValueOption.iter _.Throw()
188+
189+
member _.ReplayExceptionIfStored() =
190+
storedException |> ValueOption.iter _.Throw()
189191

190192
interface ICancellableInvokable<'T> with
191-
member _.Create(delayed) = CancellableInvocation<_, _>(machine, delayed)
193+
member _.Create(delayed) =
194+
CancellableInvocation<_, _>(machine, delayed)
192195

193196
[<Struct; NoComparison>]
194197
type Cancellable<'T>(invokable: ICancellableInvokable<'T>) =
195-
198+
196199
member _.GetInvocation(delayed) = invokable.Create(delayed)
197-
200+
198201
[<AutoOpen>]
199202
module CancellableCode =
200203

@@ -263,8 +266,7 @@ type CancellableBuilder() =
263266
: CancellableCode<'Data, 'T> =
264267
CancellableCode(fun sm ->
265268
if __useResumableCode then
266-
let mutable invocation =
267-
code.GetInvocation Trampoline.Current.ShoudBounce
269+
let mutable invocation = code.GetInvocation Trampoline.Current.ShoudBounce
268270

269271
if Trampoline.Current.ShoudBounce then
270272
// Suspend this state machine and schedule both parts to run on the trampoline.
@@ -314,8 +316,7 @@ type CancellableBuilder() =
314316
let __stack_code_fin = code.Invoke(&sm)
315317

316318
if __stack_code_fin then
317-
sm.ResumptionPoint <- -1
318-
))
319+
sm.ResumptionPoint <- -1))
319320

320321
(SetStateMachineMethodImpl<_>(fun _ _ -> ()))
321322

@@ -338,7 +339,6 @@ type CancellableBuilder() =
338339

339340
Cancellable(CancellableInvocation(sm))
340341

341-
342342
namespace Internal.Utilities.Library
343343

344344
open System

0 commit comments

Comments
 (0)