@@ -314,7 +314,13 @@ module Cache_lookup = struct
314
314
outcome would have been [Out_of_date {old_value = None}] instead. *)
315
315
module Failure = struct
316
316
type 'a t =
317
- | Out_of_date of { old_value : 'a option }
317
+ | Out_of_date of
318
+ { (* ['a] is instantiated to ['a Cached_value.t] below but making
319
+ this explicit would require us to move this type and [Result]
320
+ into the recursive module of [M]. We leave this comment to
321
+ explain why using [Option.Unboxed.t] is OK here. *)
322
+ old_value : 'a Option.Unboxed .t
323
+ }
318
324
| Cancelled of { dependency_cycle : Cycle_error .t }
319
325
end
320
326
@@ -325,9 +331,11 @@ module Cache_lookup = struct
325
331
326
332
let _to_string_hum = function
327
333
| Ok _ -> " Ok"
328
- | Failure (Out_of_date { old_value = None } ) -> " Failed (no value)"
329
- | Failure (Out_of_date { old_value = Some _ } ) -> " Failed (old value)"
330
334
| Failure (Cancelled _ ) -> " Failed (dependency cycle)"
335
+ | Failure (Out_of_date { old_value } ) -> (
336
+ match Option.Unboxed. is_none old_value with
337
+ | true -> " Failed (no value)"
338
+ | false -> " Failed (old value)" )
331
339
end
332
340
end
333
341
@@ -341,25 +349,26 @@ module Dag : Dag.S with type value := Dep_node_without_state.packed =
341
349
(* This is similar to [type t = Dag.node Lazy.t] but avoids creating a closure
342
350
with a [dep_node]; the latter is available when we need to [force] a [t]. *)
343
351
module Lazy_dag_node = struct
344
- type t = Dag .node option ref
352
+ type t = Dag .node Option.Unboxed .t ref
345
353
346
- let create () = ref None
354
+ let create () = ref Option.Unboxed. none
347
355
348
356
let force t ~(dep_node : _ Dep_node_without_state.t ) =
349
- match ! t with
350
- | Some (dag_node : Dag.node ) ->
357
+ match Option.Unboxed. is_none ! t with
358
+ | false ->
359
+ let (dag_node : Dag.node ) = Option.Unboxed. get_exn ! t in
351
360
let (T dep_node_passed_first) = Dag. value dag_node in
352
361
(* CR-someday amokhov: It would be great to restructure the code to rule
353
362
out the potential inconsistency between [dep_node]s passed to
354
363
[force]. *)
355
364
assert (Id. equal dep_node.id dep_node_passed_first.id);
356
365
dag_node
357
- | None ->
366
+ | true ->
358
367
let (dag_node : Dag.node ) =
359
368
if ! Counters. enabled then incr Counters. nodes_in_cycle_detection_graph;
360
369
Dag. create_node (Dep_node_without_state. T dep_node)
361
370
in
362
- t := Some dag_node;
371
+ t := Option.Unboxed. some dag_node;
363
372
dag_node
364
373
end
365
374
@@ -525,13 +534,13 @@ module M = struct
525
534
and State : sig
526
535
type 'a t =
527
536
| Cached_value of 'a Cached_value .t
528
- | Out_of_date of { old_value : 'a Cached_value .t option }
537
+ | Out_of_date of { old_value : 'a Cached_value .t Option.Unboxed .t }
529
538
| Restoring of
530
539
{ restore_from_cache :
531
540
'a Cached_value .t Cache_lookup.Result .t Computation0 .t
532
541
}
533
542
| Computing of
534
- { old_value : 'a Cached_value .t option
543
+ { old_value : 'a Cached_value .t Option.Unboxed .t
535
544
; compute : 'a Cached_value .t Computation0 .t
536
545
}
537
546
end =
@@ -978,7 +987,9 @@ module State = struct
978
987
| Computing _ -> Dyn. variant " Computing" [ Opaque ]
979
988
| Out_of_date { old_value } ->
980
989
Dyn. variant " Out_of_date"
981
- [ Dyn. record [ (" old_value" , Dyn. option Cached_value. to_dyn old_value) ]
990
+ [ Dyn. record
991
+ [ (" old_value" , Option.Unboxed. to_dyn Cached_value. to_dyn old_value)
992
+ ]
982
993
]
983
994
end
984
995
@@ -1028,7 +1039,8 @@ end
1028
1039
let invalidate_dep_node (dep_node : _ Dep_node.t ) =
1029
1040
match dep_node.state with
1030
1041
| Cached_value cached_value ->
1031
- dep_node.state < - Out_of_date { old_value = Some cached_value }
1042
+ dep_node.state < -
1043
+ Out_of_date { old_value = Option.Unboxed. some cached_value }
1032
1044
| Out_of_date { old_value = _ } -> ()
1033
1045
| Restoring _ ->
1034
1046
Code_error. raise " invalidate_dep_node called on a node in Restoring state"
@@ -1067,7 +1079,7 @@ let make_dep_node ~spec ~input : _ Dep_node.t =
1067
1079
{ id = Id. gen () ; input; spec }
1068
1080
in
1069
1081
{ without_state = dep_node_without_state
1070
- ; state = Out_of_date { old_value = None }
1082
+ ; state = Out_of_date { old_value = Option.Unboxed. none }
1071
1083
; has_cutoff =
1072
1084
(match spec.allow_cutoff with
1073
1085
| Yes _equal -> true
@@ -1112,11 +1124,13 @@ end = struct
1112
1124
are set to [Deps.empty]), so we can't use [deps_changed] in this
1113
1125
case. *)
1114
1126
Fiber. return
1115
- (Cache_lookup.Result. Failure (Out_of_date { old_value = None }))
1127
+ (Cache_lookup.Result. Failure
1128
+ (Out_of_date { old_value = Option.Unboxed. none }))
1116
1129
| Error { reproducible = false ; _ } ->
1117
1130
(* We do not cache non-reproducible errors. *)
1118
1131
Fiber. return
1119
- (Cache_lookup.Result. Failure (Out_of_date { old_value = None }))
1132
+ (Cache_lookup.Result. Failure
1133
+ (Out_of_date { old_value = Option.Unboxed. none }))
1120
1134
| Ok _ | Error { reproducible = true ; _ } -> (
1121
1135
(* We cache reproducible errors just like normal values. We assume that
1122
1136
all [Memo] computations are deterministic, which means if we rerun a
@@ -1174,14 +1188,15 @@ end = struct
1174
1188
| Unchanged ->
1175
1189
cached_value.last_validated_at < - Run. current () ;
1176
1190
Cache_lookup.Result. Ok cached_value
1177
- | Changed -> Failure (Out_of_date { old_value = Some cached_value })
1191
+ | Changed ->
1192
+ Failure (Out_of_date { old_value = Option.Unboxed. some cached_value })
1178
1193
| Cancelled { dependency_cycle } ->
1179
1194
Failure (Cancelled { dependency_cycle }))
1180
1195
1181
1196
and compute :
1182
1197
'i 'o .
1183
1198
dep_node :('i , 'o ) Dep_node. t
1184
- -> old_value :'o Cached_value. t option
1199
+ -> old_value :'o Cached_value. t Option.Unboxed. t
1185
1200
-> stack_frame :Stack_frame_with_state. t
1186
1201
-> 'o Cached_value. t Fiber. t =
1187
1202
fun ~dep_node ~old_value ~stack_frame ->
@@ -1196,9 +1211,10 @@ end = struct
1196
1211
| Error errors -> Error errors
1197
1212
in
1198
1213
let deps_rev = Stack_frame_with_state. deps_rev stack_frame in
1199
- match old_value with
1200
- | None -> Cached_value. create value ~deps_rev
1201
- | Some old_cv -> (
1214
+ match Option.Unboxed. is_none old_value with
1215
+ | true -> Cached_value. create value ~deps_rev
1216
+ | false -> (
1217
+ let old_cv = Option.Unboxed. get_exn old_value in
1202
1218
match Cached_value. value_changed dep_node old_cv.value value with
1203
1219
| true -> Cached_value. create value ~deps_rev
1204
1220
| false -> Cached_value. confirm_old_value ~deps_rev old_cv)
@@ -1227,7 +1243,7 @@ end = struct
1227
1243
and start_computing :
1228
1244
'i 'o .
1229
1245
dep_node :('i , 'o ) Dep_node. t
1230
- -> old_value :'o Cached_value. t option
1246
+ -> old_value :'o Cached_value. t Option.Unboxed. t
1231
1247
-> 'o Cached_value. t Fiber. t =
1232
1248
fun ~dep_node ~old_value ->
1233
1249
let computation = Computation. create () in
0 commit comments