Skip to content

Commit

Permalink
Driver: Rename odoc_unit types and fiddle with Landing_pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jonludlam committed Jan 17, 2025
1 parent 06f0189 commit 49837d8
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 77 deletions.
28 changes: 14 additions & 14 deletions src/driver/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

open Bos

type compiled = Odoc_unit.t
type compiled = Odoc_unit.any

let odoc_partial_filename = "__odoc_partial.m"

let mk_byhash (pkgs : Odoc_unit.t list) =
let mk_byhash (pkgs : Odoc_unit.any list) =
List.fold_left
(fun acc (u : Odoc_unit.t) ->
(fun acc (u : Odoc_unit.any) ->
match u.Odoc_unit.kind with
| `Intf { hash; _ } as kind ->
let elt = { u with kind } in
Expand All @@ -18,11 +18,11 @@ let mk_byhash (pkgs : Odoc_unit.t list) =
| _ -> acc)
Util.StringMap.empty pkgs

let init_stats (units : Odoc_unit.t list) =
let init_stats (units : Odoc_unit.any list) =
let total, total_impl, non_hidden, mlds, assets, indexes =
List.fold_left
(fun (total, total_impl, non_hidden, mlds, assets, indexes)
(unit : Odoc_unit.t) ->
(unit : Odoc_unit.any) ->
let total = match unit.kind with `Intf _ -> total + 1 | _ -> total in
let total_impl =
match unit.kind with `Impl _ -> total_impl + 1 | _ -> total_impl
Expand Down Expand Up @@ -56,8 +56,8 @@ let init_stats (units : Odoc_unit.t list) =
open Eio.Std

type partial =
((string * string) * Odoc_unit.intf Odoc_unit.unit list) list
* Odoc_unit.intf Odoc_unit.unit list Util.StringMap.t
((string * string) * Odoc_unit.intf Odoc_unit.t list) list
* Odoc_unit.intf Odoc_unit.t list Util.StringMap.t

let unmarshal filename : partial =
let ic = open_in_bin (Fpath.to_string filename) in
Expand All @@ -73,7 +73,7 @@ let marshal (v : partial) filename =
(fun () -> Marshal.to_channel oc v [])

let find_partials odoc_dir :
Odoc_unit.intf Odoc_unit.unit list Util.StringMap.t * _ =
Odoc_unit.intf Odoc_unit.t list Util.StringMap.t * _ =
let tbl = Hashtbl.create 1000 in
let hashes_result =
OS.Dir.fold_contents ~dotfiles:false ~elements:`Dirs
Expand All @@ -94,7 +94,7 @@ let find_partials odoc_dir :
| Ok h -> (h, tbl)
| Error _ -> (* odoc_dir doesn't exist...? *) (Util.StringMap.empty, tbl)

let compile ?partial ~partial_dir (all : Odoc_unit.t list) =
let compile ?partial ~partial_dir (all : Odoc_unit.any list) =
let hashes = mk_byhash all in
let compile_mod =
(* Modules have a more complicated compilation because:
Expand All @@ -119,7 +119,7 @@ let compile ?partial ~partial_dir (all : Odoc_unit.t list) =
| Some units ->
Ok
(List.map
(fun (unit : Odoc_unit.intf Odoc_unit.unit) ->
(fun (unit : Odoc_unit.intf Odoc_unit.t) ->
let deps = match unit.kind with `Intf { deps; _ } -> deps in
let _fibers =
Fiber.List.map
Expand Down Expand Up @@ -152,7 +152,7 @@ let compile ?partial ~partial_dir (all : Odoc_unit.t list) =
units)
in
let rec compile_mod :
string -> (Odoc_unit.intf Odoc_unit.unit list, exn) Result.t =
string -> (Odoc_unit.intf Odoc_unit.t list, exn) Result.t =
fun hash ->
let units = try Util.StringMap.find hash hashes with _ -> [] in
let r =
Expand Down Expand Up @@ -185,9 +185,9 @@ let compile ?partial ~partial_dir (all : Odoc_unit.t list) =
compile_mod
in

let compile (unit : Odoc_unit.t) =
let compile (unit : Odoc_unit.any) =
match unit.kind with
| `Intf intf -> (compile_mod intf.hash :> (Odoc_unit.t list, _) Result.t)
| `Intf intf -> (compile_mod intf.hash :> (Odoc_unit.any list, _) Result.t)
| `Impl src ->
let includes =
List.fold_left
Expand Down Expand Up @@ -242,7 +242,7 @@ let compile ?partial ~partial_dir (all : Odoc_unit.t list) =
| None -> ());
all

type linked = Odoc_unit.t
type linked = Odoc_unit.any

let link : custom_layout:bool -> compiled list -> _ =
fun ~custom_layout compiled ->
Expand Down
6 changes: 3 additions & 3 deletions src/driver/compile.mli
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
type compiled = Odoc_unit.t
type compiled = Odoc_unit.any

val init_stats : Odoc_unit.t list -> unit
val init_stats : Odoc_unit.any list -> unit

val compile :
?partial:Fpath.t -> partial_dir:Fpath.t -> Odoc_unit.t list -> compiled list
?partial:Fpath.t -> partial_dir:Fpath.t -> Odoc_unit.any list -> compiled list
(** Use [partial] to reuse the output of a previous call to [compile]. Useful in
the voodoo context.
Expand Down
23 changes: 12 additions & 11 deletions src/driver/landing_pages.ml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
type u = unit

open Odoc_unit
open Packages

let fpf = Format.fprintf

let make_index ~dirs ~rel_dir ?(libs = []) ?(pkgs = []) ?index ~enable_warnings
~content () =
let make_index ~dirs ~rel_dir ~libs ~pkgs ~index ~enable_warnings ~content :
Odoc_unit.mld Odoc_unit.t =
let { odoc_dir; odocl_dir; mld_dir; _ } = dirs in
let input_file = Fpath.(mld_dir // rel_dir / "index.mld") in
let odoc_file = Fpath.(odoc_dir // rel_dir / "page-index.odoc") in
Expand Down Expand Up @@ -59,7 +57,8 @@ let library ~dirs ~pkg ~index lib =
in
let rel_dir = lib_dir pkg lib in
let libs = [ (pkg, lib) ] in
make_index ~dirs ~rel_dir ~libs ~index ~content ~enable_warnings:false ()
make_index ~dirs ~rel_dir ~libs ~pkgs:[] ~index:(Some index) ~content
~enable_warnings:false

let package ~dirs ~pkg ~index =
let library_list ppf pkg =
Expand All @@ -86,8 +85,8 @@ let package ~dirs ~pkg ~index =
let content = content pkg in
let rel_dir = doc_dir pkg in
let libs = List.map (fun lib -> (pkg, lib)) pkg.libraries in
make_index ~dirs ~rel_dir ~index ~content ~pkgs:[ pkg ] ~libs
~enable_warnings:false ()
make_index ~dirs ~rel_dir ~index:(Some index) ~content ~pkgs:[ pkg ] ~libs
~enable_warnings:false

let src ~dirs ~pkg ~index =
let content ppf =
Expand All @@ -99,7 +98,8 @@ let src ~dirs ~pkg ~index =
pkg.name
in
let rel_dir = src_dir pkg in
make_index ~dirs ~rel_dir ~index ~content ~enable_warnings:true ()
make_index ~dirs ~pkgs:[] ~libs:[] ~rel_dir ~index:(Some index) ~content
~enable_warnings:true

let package_list ~dirs ~remap all =
let content all ppf =
Expand All @@ -115,7 +115,8 @@ let package_list ~dirs ~remap all =
in
let content = content all in
let rel_dir = Fpath.v "./" in
make_index ~dirs ~rel_dir ~pkgs:all ~content ~enable_warnings:true ()
make_index ~dirs ~rel_dir ~pkgs:all ~libs:[] ~index:None ~content
~enable_warnings:true

let content dir _pkg libs _src subdirs all_libs pfp =
let is_root = Fpath.to_string dir = "./" in
Expand Down Expand Up @@ -156,7 +157,7 @@ let content dir _pkg libs _src subdirs all_libs pfp =
all_libs)

let make_custom dirs index_of (pkg : Packages.t) :
Odoc_unit.mld Odoc_unit.unit list =
Odoc_unit.mld Odoc_unit.t list =
let pkgs = [ pkg ] in
let pkg_dirs =
List.fold_right
Expand Down Expand Up @@ -282,7 +283,7 @@ let make_custom dirs index_of (pkg : Packages.t) :
let idx =
make_index ~dirs ~rel_dir:p ~libs ~pkgs
~content:(content p pkg libs src subdirs all_libs)
?index ~enable_warnings:false ()
~index ~enable_warnings:false
in
idx :: acc)
all_dirs []
23 changes: 10 additions & 13 deletions src/driver/landing_pages.mli
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
type u = unit

open Odoc_unit

val make_index :
dirs:dirs ->
rel_dir:Fpath.t ->
?libs:(Packages.t * Packages.libty) list ->
?pkgs:Packages.t list ->
?index:index ->
libs:(Packages.t * Packages.libty) list ->
pkgs:Packages.t list ->
index:index option ->
enable_warnings:bool ->
content:(Format.formatter -> u) ->
u ->
[> `Mld ] Odoc_unit.unit
content:(Format.formatter -> unit) ->
mld Odoc_unit.t

val library :
dirs:dirs -> pkg:Packages.t -> index:index -> Packages.libty -> mld unit
dirs:dirs -> pkg:Packages.t -> index:index -> Packages.libty -> mld t

val package : dirs:dirs -> pkg:Packages.t -> index:index -> mld unit
val package : dirs:dirs -> pkg:Packages.t -> index:index -> mld t

val src : dirs:dirs -> pkg:Packages.t -> index:index -> mld unit
val src : dirs:dirs -> pkg:Packages.t -> index:index -> mld t

val package_list : dirs:dirs -> remap:bool -> Packages.t list -> mld unit
val package_list : dirs:dirs -> remap:bool -> Packages.t list -> mld t

val make_custom :
dirs -> (Packages.t -> Odoc_unit.index) -> Packages.t -> mld unit list
dirs -> (Packages.t -> Odoc_unit.index) -> Packages.t -> mld t list
14 changes: 7 additions & 7 deletions src/driver/odoc_unit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ let pp_index fmt x =
(Fmt.list Fpath.pp) x.roots Fpath.pp x.output_file x.json Fpath.pp
x.search_dir

type 'a unit = {
type 'a t = {
parent_id : Odoc.Id.t;
input_file : Fpath.t;
output_dir : Fpath.t;
Expand Down Expand Up @@ -101,7 +101,7 @@ type md = [ `Md ]
type asset = [ `Asset ]

type all_kinds = [ impl | intf | mld | asset | md ]
type t = all_kinds unit
type any = all_kinds t

let rec pp_kind : all_kinds Fmt.t =
fun fmt x ->
Expand All @@ -122,7 +122,7 @@ and pp_impl_extra fmt x =
(Odoc.Id.to_string x.src_id)
Fpath.pp x.src_path

and pp : all_kinds unit Fmt.t =
and pp : all_kinds t Fmt.t =
fun fmt x ->
Format.fprintf fmt
"@[<hov>parent_id: %s@;\
Expand Down Expand Up @@ -160,8 +160,8 @@ type dirs = {
mld_dir : Fpath.t;
}

let fix_virtual ~(precompiled_units : intf unit list Util.StringMap.t)
~(units : intf unit list Util.StringMap.t) =
let fix_virtual ~(precompiled_units : intf t list Util.StringMap.t)
~(units : intf t list Util.StringMap.t) =
Logs.debug (fun m ->
m "Fixing virtual libraries: %d precompiled units, %d other units"
(Util.StringMap.cardinal precompiled_units)
Expand Down Expand Up @@ -189,13 +189,13 @@ let fix_virtual ~(precompiled_units : intf unit list Util.StringMap.t)
"Virtual library check: Selecting cmti for hash %s from \
%d possibilities: %a"
uhash (List.length xs) (Fmt.Dump.list pp)
(xs :> t list));
(xs :> any list));
let unit_name =
Fpath.rem_ext unit.input_file |> Fpath.basename
in
match
List.filter
(fun (x : intf unit) ->
(fun (x : intf t) ->
(match x.kind with `Intf { hash; _ } -> uhash = hash)
&& Fpath.has_ext "cmti" x.input_file
&& Fpath.rem_ext x.input_file |> Fpath.basename
Expand Down
12 changes: 6 additions & 6 deletions src/driver/odoc_unit.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type index = {
sidebar : sidebar option;
}

type 'a unit = {
type 'a t = {
parent_id : Odoc.Id.t;
input_file : Fpath.t;
output_dir : Fpath.t;
Expand Down Expand Up @@ -57,9 +57,9 @@ type mld = [ `Mld ]
type md = [ `Md ]
type asset = [ `Asset ]

type t = [ impl | intf | mld | asset | md ] unit
type any = [ impl | intf | mld | asset | md ] t

val pp : t Fmt.t
val pp : any Fmt.t

val pkg_dir : Packages.t -> Fpath.t
val lib_dir : Packages.t -> Packages.libty -> Fpath.t
Expand All @@ -75,9 +75,9 @@ type dirs = {
}

val fix_virtual :
precompiled_units:intf unit list Util.StringMap.t ->
units:intf unit list Util.StringMap.t ->
intf unit list Util.StringMap.t
precompiled_units:intf t list Util.StringMap.t ->
units:intf t list Util.StringMap.t ->
intf t list Util.StringMap.t
(** [fix_virtual ~precompiled_units ~units] replaces the input file
in units representing implementations of virtual libraries.
Implementation units have a [cmt] but no [cmti], even though
Expand Down
Loading

0 comments on commit 49837d8

Please sign in to comment.