From 2d1d3218534f863a994219df2875bd190a0da8c3 Mon Sep 17 00:00:00 2001 From: Jon Ludlam Date: Fri, 21 Feb 2025 11:45:13 +0000 Subject: [PATCH] Driver: Rearrange some code for readability --- src/driver/compile.ml | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/driver/compile.ml b/src/driver/compile.ml index 6cf9e9a833..13f9ce3d39 100644 --- a/src/driver/compile.ml +++ b/src/driver/compile.ml @@ -147,26 +147,25 @@ let compile ?partial ~partial_dir (all : Odoc_unit.any list) = in let rec compile_mod : string -> ('a list, [> `Msg of string ]) Result.t = fun hash -> + let map_units = + Fiber.List.map (fun unit -> + match + Hashtbl.find_opt tbl + (hash, Odoc.Id.to_string unit.Odoc_unit.parent_id) + with + | Some p -> + Promise.await p; + None + | None -> + let p, r = Promise.create () in + Hashtbl.add tbl (hash, Odoc.Id.to_string unit.parent_id) p; + let _result = compile_one compile_mod unit in + Promise.resolve r (); + Some unit) + in try let units = Util.StringMap.find hash all_hashes in - let r = - Fiber.List.map - (fun unit -> - match - Hashtbl.find_opt tbl - (hash, Odoc.Id.to_string unit.Odoc_unit.parent_id) - with - | Some p -> - Promise.await p; - None - | None -> - let p, r = Promise.create () in - Hashtbl.add tbl (hash, Odoc.Id.to_string unit.parent_id) p; - let _result = compile_one compile_mod unit in - Promise.resolve r (); - Some unit) - units - in + let r = map_units units in Ok (List.filter_map Fun.id r) with Not_found -> Error (`Msg ("Module with hash " ^ hash ^ " not found"))