@@ -476,63 +476,6 @@ and TaskOptionResumptionDynamicInfo<'TOverall> =
476476
477477and TaskOptionCode < 'TOverall , 'T > = ResumableCode< TaskOptionStateMachineData< 'TOverall>, 'T>
478478
479-
480- module TaskOptionBuilderBase =
481-
482- let rec WhileDynamic
483- (
484- sm : byref < TaskOptionStateMachine < _ >>,
485- condition : unit -> bool ,
486- body : TaskOptionCode < _ , _ >
487- ) : bool =
488- if condition () then
489- if body.Invoke(& sm) then
490- if sm.Data.IsResultNone then
491- // Set the result now to allow short-circuiting of the rest of the CE.
492- // Run/RunDynamic will skip setting the result if it's already been set.
493- // Combine/CombineDynamic will not continue if the result has been set.
494- sm.Data.SetResult()
495- true
496- else
497- WhileDynamic(& sm, condition, body)
498- else
499- let rf = sm.ResumptionDynamicInfo.ResumptionFunc
500-
501- sm.ResumptionDynamicInfo.ResumptionFunc <-
502- ( TaskOptionResumptionFunc<_>( fun sm ->
503- WhileBodyDynamicAux(& sm, condition, body, rf)
504- ))
505-
506- false
507- else
508- true
509-
510- and WhileBodyDynamicAux
511- (
512- sm : byref < TaskOptionStateMachine < _ >>,
513- condition : unit -> bool ,
514- body : TaskOptionCode < _ , _ >,
515- rf : TaskOptionResumptionFunc < _ >
516- ) : bool =
517- if rf.Invoke(& sm) then
518- if sm.Data.IsResultNone then
519- // Set the result now to allow short-circuiting of the rest of the CE.
520- // Run/RunDynamic will skip setting the result if it's already been set.
521- // Combine/CombineDynamic will not continue if the result has been set.
522- sm.Data.SetResult()
523- true
524- else
525- WhileDynamic(& sm, condition, body)
526- else
527- let rf = sm.ResumptionDynamicInfo.ResumptionFunc
528-
529- sm.ResumptionDynamicInfo.ResumptionFunc <-
530- ( TaskOptionResumptionFunc<_>( fun sm -> WhileBodyDynamicAux(& sm, condition, body, rf)
531- ))
532-
533- false
534-
535-
536479type TaskOptionBuilderBase () =
537480
538481 member inline _.Delay
@@ -554,39 +497,6 @@ type TaskOptionBuilderBase() =
554497 true
555498 )
556499
557- static member inline CombineDynamic
558- (
559- sm : byref < TaskOptionStateMachine < _ >>,
560- task1 : TaskOptionCode < 'TOverall , unit >,
561- task2 : TaskOptionCode < 'TOverall , 'T >
562- ) : bool =
563- let shouldContinue = task1.Invoke(& sm)
564-
565- if sm.Data.IsTaskCompleted then
566- true
567- elif shouldContinue then
568- task2.Invoke(& sm)
569- else
570- let rec resume ( mf : TaskOptionResumptionFunc < _ >) =
571- TaskOptionResumptionFunc<_>( fun sm ->
572- let shouldContinue = mf.Invoke(& sm)
573-
574- if sm.Data.IsTaskCompleted then
575- true
576- elif shouldContinue then
577- task2.Invoke(& sm)
578- else
579- sm.ResumptionDynamicInfo.ResumptionFunc <-
580- ( resume ( sm.ResumptionDynamicInfo.ResumptionFunc))
581-
582- false
583- )
584-
585- sm.ResumptionDynamicInfo.ResumptionFunc <-
586- ( resume ( sm.ResumptionDynamicInfo.ResumptionFunc))
587-
588- false
589-
590500 /// Chains together a step with its following step.
591501 /// Note that this requires that the first step has no result.
592502 /// This prevents constructs like `task { return 1; return 2; }`.
@@ -596,20 +506,11 @@ type TaskOptionBuilderBase() =
596506 task2 : TaskOptionCode < 'TOverall , 'T >
597507 ) : TaskOptionCode < 'TOverall , 'T > =
598508
599- TaskOptionCode< 'TOverall, 'T>( fun sm ->
600- if __ useResumableCode then
601- //-- RESUMABLE CODE START
602- // NOTE: The code for code1 may contain await points! Resuming may branch directly
603- // into this code!
604- // printfn "Combine Called Before Invoke --> "
605- let __stack_fin = task1.Invoke(& sm)
606- // printfn "Combine Called After Invoke --> %A " sm.Data.MethodBuilder.Task.Status
607-
608- if sm.Data.IsTaskCompleted then true
609- elif __ stack_ fin then task2.Invoke(& sm)
610- else false
611- else
612- TaskOptionBuilderBase.CombineDynamic(& sm, task1, task2)
509+ ResumableCode.Combine(
510+ task1,
511+ TaskOptionCode< 'TOverall, 'T>( fun sm ->
512+ if sm.Data.IsResultNone then true else task2.Invoke(& sm)
513+ )
613514 )
614515
615516 /// Builds a step that executes the body while the condition predicate is true.
@@ -618,33 +519,17 @@ type TaskOptionBuilderBase() =
618519 [<InlineIfLambda>] condition : unit -> bool ,
619520 body : TaskOptionCode < 'TOverall , unit >
620521 ) : TaskOptionCode < 'TOverall , unit > =
621- TaskOptionCode< 'TOverall, unit>( fun sm ->
622- if __ useResumableCode then
623- //-- RESUMABLE CODE START
624- let mutable __stack_go = true
625-
626- while __ stack_ go
627- && not sm.Data.IsResultNone
628- && condition () do
629- // printfn "While -> %A" sm.Data.Result
630- // NOTE: The body of the state machine code for 'while' may contain await points, so resuming
631- // the code will branch directly into the expanded 'body', branching directly into the while loop
632- let __stack_body_fin = body.Invoke(& sm)
633- // printfn "While After Invoke --> %A" sm.Data.Result
634- // If the body completed, we go back around the loop (__stack_go = true)
635- // If the body yielded, we yield (__stack_go = false)
636- __ stack_ go <- __ stack_ body_ fin
522+ ResumableCode.While(
523+ condition,
524+ TaskOptionCode<_, _>( fun sm ->
525+ let __stack_body_fin = body.Invoke(& sm)
637526
638527 if sm.Data.IsResultNone then
639- // Set the result now to allow short-circuiting of the rest of the CE.
640- // Run/RunDynamic will skip setting the result if it's already been set.
641- // Combine/CombineDynamic will not continue if the result has been set.
642528 sm.Data.SetResult()
643-
644- __ stack_ go
645- //-- RESUMABLE CODE END
646- else
647- TaskOptionBuilderBase.WhileDynamic(& sm, condition, body)
529+ false
530+ else
531+ __ stack_ body_ fin
532+ )
648533 )
649534
650535
0 commit comments