@@ -4,11 +4,13 @@ let[@inline never] quota_non_positive _ = invalid_arg "quota must be positive"
4
4
5
5
type ready =
6
6
| Spawn of Fiber .t * (Fiber .t -> unit )
7
- | Continue of Fiber .t * (unit , unit ) Effect.Deep .continuation
7
+ | Continue of Fiber .t * (unit , unit ) Effect.Shallow .continuation
8
8
| Resume of
9
9
Fiber .t
10
- * ((exn * Printexc .raw_backtrace ) option , unit ) Effect.Deep .continuation
11
- | Return of Fiber .t * (unit , unit ) Effect.Deep .continuation
10
+ * ( (exn * Printexc .raw_backtrace ) option ,
11
+ unit )
12
+ Effect.Shallow .continuation
13
+ | Return of Fiber .t * (unit , unit ) Effect.Shallow .continuation
12
14
13
15
module Mpscq = Picos_aux_mpscq
14
16
@@ -20,13 +22,15 @@ type t = {
20
22
mutable resume :
21
23
Trigger .t ->
22
24
Fiber .t ->
23
- ((exn * Printexc .raw_backtrace ) option , unit ) Effect.Deep .continuation ->
25
+ ((exn * Printexc .raw_backtrace ) option , unit ) Effect.Shallow .continuation ->
24
26
unit ;
25
- mutable current : ((Fiber .t , unit ) Effect.Deep .continuation -> unit ) option ;
26
- mutable yield : ((unit , unit ) Effect.Deep .continuation -> unit ) option ;
27
- mutable return : ((unit , unit ) Effect.Deep .continuation -> unit ) option ;
28
- mutable discontinue : ((unit , unit ) Effect.Deep .continuation -> unit ) option ;
29
- mutable handler : (unit , unit ) Effect.Deep .handler ;
27
+ mutable current :
28
+ ((Fiber .t , unit ) Effect.Shallow .continuation -> unit ) option ;
29
+ mutable yield : ((unit , unit ) Effect.Shallow .continuation -> unit ) option ;
30
+ mutable return : ((unit , unit ) Effect.Shallow .continuation -> unit ) option ;
31
+ mutable discontinue :
32
+ ((unit , unit ) Effect.Shallow .continuation -> unit ) option ;
33
+ mutable handler : (unit , unit ) Effect.Shallow .handler ;
30
34
quota : int ;
31
35
mutable fiber : Fiber.Maybe .t ;
32
36
mutable remaining_quota : int ;
@@ -45,10 +49,12 @@ let rec next t =
45
49
| Return (fiber , _ ) ->
46
50
Fiber.Maybe. of_fiber fiber);
47
51
match ready with
48
- | Spawn (fiber , main ) -> Effect.Deep. match_with main fiber t.handler
49
- | Return (_ , k ) -> Effect.Deep. continue k ()
50
- | Continue (fiber , k ) -> Fiber. continue fiber k ()
51
- | Resume (fiber , k ) -> Fiber. resume fiber k
52
+ | Spawn (fiber , main ) ->
53
+ let k = Effect.Shallow. fiber main in
54
+ Effect.Shallow. continue_with k fiber t.handler
55
+ | Return (_ , k ) -> Effect.Shallow. continue_with k () t.handler
56
+ | Continue (fiber , k ) -> Fiber. continue_with fiber k () t.handler
57
+ | Resume (fiber , k ) -> Fiber. resume_with fiber k t.handler
52
58
end
53
59
| exception Mpscq. Empty ->
54
60
t.fiber < - Fiber.Maybe. nothing;
@@ -97,7 +103,7 @@ let run_fiber ?quota ?fatal_exn_handler fiber main =
97
103
exnc = (match fatal_exn_handler with None -> raise | Some exnc -> exnc);
98
104
effc =
99
105
(fun (type a ) (e : a Effect.t ) :
100
- ((a , _ ) Effect.Deep . continuation -> _ ) option ->
106
+ ((a , _ ) Effect.Shallow . continuation -> _ ) option ->
101
107
match e with
102
108
| Fiber. Current -> t.current
103
109
| Fiber. Spawn r ->
@@ -121,7 +127,9 @@ let run_fiber ?quota ?fatal_exn_handler fiber main =
121
127
| exception exn ->
122
128
let bt = Printexc. get_raw_backtrace () in
123
129
Some
124
- (fun k -> Effect.Deep. discontinue_with_backtrace k exn bt)
130
+ (fun k ->
131
+ Effect.Shallow. discontinue_with_backtrace k exn bt
132
+ t.handler)
125
133
end
126
134
| Trigger. Await trigger ->
127
135
Some
@@ -133,7 +141,7 @@ let run_fiber ?quota ?fatal_exn_handler fiber main =
133
141
let remaining_quota = t.remaining_quota - 1 in
134
142
if 0 < remaining_quota then begin
135
143
t.remaining_quota < - remaining_quota;
136
- Fiber. resume fiber k
144
+ Fiber. resume_with fiber k t.handler
137
145
end
138
146
else begin
139
147
Mpscq. push t.ready (Resume (fiber, k));
@@ -165,7 +173,7 @@ let run_fiber ?quota ?fatal_exn_handler fiber main =
165
173
Some
166
174
(fun k ->
167
175
let fiber = Fiber.Maybe. to_fiber t.fiber in
168
- Effect.Deep. continue k fiber);
176
+ Effect.Shallow. continue_with k fiber t.handler );
169
177
t.yield < -
170
178
Some
171
179
(fun k ->
@@ -178,7 +186,7 @@ let run_fiber ?quota ?fatal_exn_handler fiber main =
178
186
let remaining_quota = t.remaining_quota - 1 in
179
187
if 0 < remaining_quota then begin
180
188
t.remaining_quota < - remaining_quota;
181
- Effect.Deep. continue k ()
189
+ Effect.Shallow. continue_with k () t.handler
182
190
end
183
191
else begin
184
192
Mpscq. push t.ready (Return (Fiber.Maybe. to_fiber t.fiber, k));
@@ -188,8 +196,9 @@ let run_fiber ?quota ?fatal_exn_handler fiber main =
188
196
Some
189
197
(fun k ->
190
198
let fiber = Fiber.Maybe. to_fiber t.fiber in
191
- Fiber. continue fiber k () );
192
- Effect.Deep. match_with main fiber t.handler
199
+ Fiber. continue_with fiber k () t.handler);
200
+ let k = Effect.Shallow. fiber main in
201
+ Effect.Shallow. continue_with k fiber t.handler
193
202
194
203
let [@ inline never] run ?quota ?fatal_exn_handler fiber main computation =
195
204
run_fiber ?quota ?fatal_exn_handler fiber main;
0 commit comments