Skip to content

Commit 6484816

Browse files
committed
Update descriptions and add warnings for use of internal-only public types
1 parent 966d28c commit 6484816

File tree

2 files changed

+102
-77
lines changed

2 files changed

+102
-77
lines changed

src/FSharp.Control.TaskSeq/TaskSeqBuilder.fs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ open FSharp.Control
1919
[<AutoOpen>]
2020
module Internal = // cannot be marked with 'internal' scope
2121

22-
/// Setting from environment variable TASKSEQ_LOG_VERBOSE, which,
23-
/// when set, enables (very) verbose printing of flow and state
2422
let initVerbose () =
2523
try
2624
match Environment.GetEnvironmentVariable "TASKSEQ_LOG_VERBOSE" with
@@ -37,10 +35,8 @@ module Internal = // cannot be marked with 'internal' scope
3735
false
3836

3937

40-
/// Call MoveNext on an IAsyncStateMachine by reference
4138
let inline moveNextRef (x: byref<'T> when 'T :> IAsyncStateMachine) = x.MoveNext()
4239

43-
/// F# requires that we implement interfaces even on an abstract class
4440
let inline raiseNotImpl () =
4541
NotImplementedException "Abstract Class: method or property not implemented"
4642
|> raise
@@ -79,7 +75,7 @@ type TaskSeqStateMachineData<'T>() =
7975

8076
/// A reference to 'self', because otherwise we can't use byref in the resumable code.
8177
[<DefaultValue(false)>]
82-
val mutable boxedSelf: TaskSeq<'T>
78+
val mutable boxedSelf: TaskSeqBase<'T>
8379

8480
member data.PushDispose(disposer: unit -> Task) =
8581
if isNull data.disposalStack then
@@ -91,7 +87,7 @@ type TaskSeqStateMachineData<'T>() =
9187
if not (isNull data.disposalStack) then
9288
data.disposalStack.RemoveAt(data.disposalStack.Count - 1)
9389

94-
and [<AbstractClass; NoEquality; NoComparison>] TaskSeq<'T>() =
90+
and [<AbstractClass; NoEquality; NoComparison>] TaskSeqBase<'T>() =
9591

9692
abstract MoveNextAsyncResult: unit -> ValueTask<bool>
9793

@@ -119,7 +115,7 @@ and [<AbstractClass; NoEquality; NoComparison>] TaskSeq<'T>() =
119115

120116
and [<NoComparison; NoEquality>] TaskSeq<'Machine, 'T
121117
when 'Machine :> IAsyncStateMachine and 'Machine :> IResumableStateMachine<TaskSeqStateMachineData<'T>>>() =
122-
inherit TaskSeq<'T>()
118+
inherit TaskSeqBase<'T>()
123119
let initialThreadId = Environment.CurrentManagedThreadId
124120

125121
/// Shadows the initial machine, just after it is initialized by the F# compiler-generated state.
@@ -304,16 +300,16 @@ and [<NoComparison; NoEquality>] TaskSeq<'Machine, 'T
304300
// assume it's a possibly new, not yet supported case, treat as default
305301
ValueTask.ofIValueTaskSource this version
306302

307-
and TaskSeqCode<'T> = ResumableCode<TaskSeqStateMachineData<'T>, unit>
303+
and ResumableTSC<'T> = ResumableCode<TaskSeqStateMachineData<'T>, unit>
308304
and TaskSeqStateMachine<'T> = ResumableStateMachine<TaskSeqStateMachineData<'T>>
309305
and TaskSeqResumptionFunc<'T> = ResumptionFunc<TaskSeqStateMachineData<'T>>
310306
and TaskSeqResumptionDynamicInfo<'T> = ResumptionDynamicInfo<TaskSeqStateMachineData<'T>>
311307

312308
type TaskSeqBuilder() =
313309

314-
member inline _.Delay(f: unit -> TaskSeqCode<'T>) : TaskSeqCode<'T> = TaskSeqCode<'T>(fun sm -> f().Invoke(&sm))
310+
member inline _.Delay(f: unit -> ResumableTSC<'T>) : ResumableTSC<'T> = ResumableTSC<'T>(fun sm -> f().Invoke(&sm))
315311

316-
member inline _.Run(code: TaskSeqCode<'T>) : IAsyncEnumerable<'T> =
312+
member inline _.Run(code: ResumableTSC<'T>) : IAsyncEnumerable<'T> =
317313
if __useResumableCode then
318314
// This is the static implementation. A new struct type is created.
319315
__stateMachine<TaskSeqStateMachineData<'T>, IAsyncEnumerable<'T>>
@@ -386,11 +382,11 @@ type TaskSeqBuilder() =
386382
|> raise
387383

388384

389-
member inline _.Zero() : TaskSeqCode<'T> =
385+
member inline _.Zero() : ResumableTSC<'T> =
390386
Debug.logInfo "at Zero()"
391387
ResumableCode.Zero()
392388

393-
member inline _.Combine(task1: TaskSeqCode<'T>, task2: TaskSeqCode<'T>) : TaskSeqCode<'T> =
389+
member inline _.Combine(task1: ResumableTSC<'T>, task2: ResumableTSC<'T>) : ResumableTSC<'T> =
394390
Debug.logInfo "at Combine(.., ..)"
395391

396392
ResumableCode.Combine(task1, task2)
@@ -399,8 +395,8 @@ type TaskSeqBuilder() =
399395
member inline _.WhileAsync
400396
(
401397
[<InlineIfLambda>] condition: unit -> ValueTask<bool>,
402-
body: TaskSeqCode<'T>
403-
) : TaskSeqCode<'T> =
398+
body: ResumableTSC<'T>
399+
) : ResumableTSC<'T> =
404400
let mutable condition_res = true
405401

406402
ResumableCode.While(
@@ -436,17 +432,17 @@ type TaskSeqBuilder() =
436432
false)
437433
)
438434

439-
member inline b.While([<InlineIfLambda>] condition: unit -> bool, body: TaskSeqCode<'T>) : TaskSeqCode<'T> =
435+
member inline b.While([<InlineIfLambda>] condition: unit -> bool, body: ResumableTSC<'T>) : ResumableTSC<'T> =
440436
Debug.logInfo "at While(...)"
441437
ResumableCode.While(condition, body)
442438

443-
member inline _.TryWith(body: TaskSeqCode<'T>, catch: exn -> TaskSeqCode<'T>) : TaskSeqCode<'T> =
439+
member inline _.TryWith(body: ResumableTSC<'T>, catch: exn -> ResumableTSC<'T>) : ResumableTSC<'T> =
444440
ResumableCode.TryWith(body, catch)
445441

446-
member inline _.TryFinallyAsync(body: TaskSeqCode<'T>, compensation: unit -> Task) : TaskSeqCode<'T> =
442+
member inline _.TryFinallyAsync(body: ResumableTSC<'T>, compensation: unit -> Task) : ResumableTSC<'T> =
447443
ResumableCode.TryFinallyAsync(
448444

449-
TaskSeqCode<'T>(fun sm ->
445+
ResumableTSC<'T>(fun sm ->
450446
sm.Data.PushDispose(fun () -> compensation ())
451447
body.Invoke(&sm)),
452448

@@ -467,9 +463,9 @@ type TaskSeqBuilder() =
467463
__stack_condition_fin)
468464
)
469465

470-
member inline _.TryFinally(body: TaskSeqCode<'T>, compensation: unit -> unit) : TaskSeqCode<'T> =
466+
member inline _.TryFinally(body: ResumableTSC<'T>, compensation: unit -> unit) : ResumableTSC<'T> =
471467
ResumableCode.TryFinally(
472-
TaskSeqCode<'T>(fun sm ->
468+
ResumableTSC<'T>(fun sm ->
473469
sm.Data.PushDispose(fun () ->
474470
compensation ()
475471
Task.CompletedTask)
@@ -482,7 +478,7 @@ type TaskSeqBuilder() =
482478
true)
483479
)
484480

485-
member inline this.Using(disp: #IAsyncDisposable, body: #IAsyncDisposable -> TaskSeqCode<'T>) : TaskSeqCode<'T> =
481+
member inline this.Using(disp: #IAsyncDisposable, body: #IAsyncDisposable -> ResumableTSC<'T>) : ResumableTSC<'T> =
486482

487483
// A using statement is just a try/finally with the finally block disposing if non-null.
488484
this.TryFinallyAsync(
@@ -494,8 +490,8 @@ type TaskSeqBuilder() =
494490
Task.CompletedTask)
495491
)
496492

497-
member inline _.Yield(v: 'T) : TaskSeqCode<'T> =
498-
TaskSeqCode<'T>(fun sm ->
493+
member inline _.Yield(v: 'T) : ResumableTSC<'T> =
494+
ResumableTSC<'T>(fun sm ->
499495
// This will yield with __stack_fin = false
500496
// This will resume with __stack_fin = true
501497
Debug.logInfo "at Yield"
@@ -546,10 +542,10 @@ module LowPriority =
546542
and ^Awaiter: (member GetResult: unit -> 'TResult1)>
547543
(
548544
task: ^TaskLike,
549-
continuation: ('TResult1 -> TaskSeqCode<'TResult2>)
550-
) : TaskSeqCode<'TResult2> =
545+
continuation: ('TResult1 -> ResumableTSC<'TResult2>)
546+
) : ResumableTSC<'TResult2> =
551547

552-
TaskSeqCode<'TResult2>(fun sm ->
548+
ResumableTSC<'TResult2>(fun sm ->
553549
let mutable awaiter = (^TaskLike: (member GetAwaiter: unit -> ^Awaiter) (task))
554550
let mutable __stack_fin = true
555551

@@ -581,7 +577,7 @@ module LowPriority =
581577
module MediumPriority =
582578
type TaskSeqBuilder with
583579

584-
member inline this.Using(disp: #IDisposable, body: #IDisposable -> TaskSeqCode<'T>) : TaskSeqCode<'T> =
580+
member inline this.Using(disp: #IDisposable, body: #IDisposable -> ResumableTSC<'T>) : ResumableTSC<'T> =
585581

586582
// A using statement is just a try/finally with the finally block disposing if non-null.
587583
this.TryFinally(
@@ -592,22 +588,22 @@ module MediumPriority =
592588
disp.Dispose())
593589
)
594590

595-
member inline this.For(sequence: seq<'TElement>, body: 'TElement -> TaskSeqCode<'T>) : TaskSeqCode<'T> =
591+
member inline this.For(sequence: seq<'TElement>, body: 'TElement -> ResumableTSC<'T>) : ResumableTSC<'T> =
596592
// A for loop is just a using statement on the sequence's enumerator...
597593
this.Using(
598594
sequence.GetEnumerator(),
599595
// ... and its body is a while loop that advances the enumerator and runs the body on each element.
600596
(fun e -> this.While((fun () -> e.MoveNext()), (fun sm -> (body e.Current).Invoke(&sm))))
601597
)
602598

603-
member inline this.YieldFrom(source: seq<'T>) : TaskSeqCode<'T> = this.For(source, (fun v -> this.Yield(v)))
599+
member inline this.YieldFrom(source: seq<'T>) : ResumableTSC<'T> = this.For(source, (fun v -> this.Yield(v)))
604600

605601
member inline this.For
606602
(
607603
source: #IAsyncEnumerable<'TElement>,
608-
body: 'TElement -> TaskSeqCode<'T>
609-
) : TaskSeqCode<'T> =
610-
TaskSeqCode<'T>(fun sm ->
604+
body: 'TElement -> ResumableTSC<'T>
605+
) : ResumableTSC<'T> =
606+
ResumableTSC<'T>(fun sm ->
611607
this
612608
.Using(
613609
source.GetAsyncEnumerator(sm.Data.cancellationToken),
@@ -616,7 +612,7 @@ module MediumPriority =
616612
)
617613
.Invoke(&sm))
618614

619-
member inline this.YieldFrom(source: IAsyncEnumerable<'T>) : TaskSeqCode<'T> =
615+
member inline this.YieldFrom(source: IAsyncEnumerable<'T>) : ResumableTSC<'T> =
620616
this.For(source, (fun v -> this.Yield(v)))
621617

622618
[<AutoOpen>]
@@ -633,8 +629,8 @@ module HighPriority =
633629
// - In contrast, ValueTask<_> *does have* GetResult() -> 'TResult
634630
// - Conclusion: we do not need an extra overload anymore for ValueTask
635631
//
636-
member inline _.Bind(task: Task<'TResult1>, continuation: ('TResult1 -> TaskSeqCode<'T>)) : TaskSeqCode<'T> =
637-
TaskSeqCode<'T>(fun sm ->
632+
member inline _.Bind(task: Task<'TResult1>, continuation: ('TResult1 -> ResumableTSC<'T>)) : ResumableTSC<'T> =
633+
ResumableTSC<'T>(fun sm ->
638634
let mutable awaiter = task.GetAwaiter()
639635
let mutable __stack_fin = true
640636

0 commit comments

Comments
 (0)