Skip to content

Commit 958bfe5

Browse files
committed
Driver refactor: reenable rendering source code
This commit also includes a fix: previously, the dependencies for the interface were used for the implementation. However, an implementation might have more dependencies than the corresponding interface.
1 parent 1375d6e commit 958bfe5

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

src/driver/compile.ml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ let compile ?partial ~output_dir ?linked_dir:_ (all : Odoc_unit.t list) =
9393
match unit with
9494
| { kind = `Intf _; _ } as intf ->
9595
(intf :: intf_units, impl_units, page_units)
96-
| { kind = `Impl; _ } as impl ->
96+
| { kind = `Impl _; _ } as impl ->
9797
(intf_units, impl :: impl_units, page_units)
9898
| { kind = `Mld; _ } as mld ->
9999
(intf_units, impl_units, mld :: page_units))
@@ -183,8 +183,9 @@ let compile ?partial ~output_dir ?linked_dir:_ (all : Odoc_unit.t list) =
183183
let _compiled_mlds = Fiber.List.map compile_mld mld_units in
184184
let compile_impl (unit : Odoc_unit.impl Odoc_unit.unit) =
185185
let includes = Fpath.Set.of_list unit.include_dirs in
186-
Odoc.compile ~output_dir:unit.output_dir ~input_file:unit.input_file
187-
~includes ~parent_id:unit.parent_id;
186+
let source_id = match unit.kind with `Impl src -> src.src_id in
187+
Odoc.compile_impl ~output_dir:unit.output_dir ~input_file:unit.input_file
188+
~includes ~parent_id:unit.parent_id ~source_id;
188189
Atomic.incr Stats.stats.compiled_impls
189190
in
190191
let _compiled_impls = Fiber.List.map compile_impl impl_units in
@@ -223,7 +224,7 @@ let link : compiled list -> _ =
223224
(match c.kind with
224225
| `Intf _ -> Atomic.incr Stats.stats.linked_units
225226
| `Mld -> Atomic.incr Stats.stats.linked_mlds
226-
| `Impl -> Atomic.incr Stats.stats.linked_impls);
227+
| `Impl _ -> Atomic.incr Stats.stats.linked_impls);
227228
c
228229
in
229230
Fiber.List.map link compiled
@@ -271,6 +272,11 @@ let html_generate output_dir (* ~odocl_dir *) linked =
271272
fun l ->
272273
match l.kind with
273274
| `Intf { hidden = true; _ } -> ()
275+
| `Impl { src_path; _ } ->
276+
Odoc.html_generate ~search_uris:[] ?index:None
277+
~output_dir:(Fpath.to_string output_dir)
278+
~input_file:l.odocl_file ~source:src_path ();
279+
Atomic.incr Stats.stats.generated_units
274280
| _ ->
275281
(* let pkg_dir = l. in *)
276282
(* let search_uris = [ Sherlodoc.db_js_file pkg_dir; Sherlodoc.js_file ] in *)

src/driver/odoc_unit.ml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ type 'a unit = {
1919
type intf_extra = { hidden : bool; hash : string; deps : intf unit list }
2020
and intf = [ `Intf of intf_extra ]
2121

22-
type impl = [ `Impl ]
22+
type impl_extra = { src_id : Odoc.id; src_path : Fpath.t }
23+
type impl = [ `Impl of impl_extra ]
2324

2425
type mld = [ `Mld ]
2526

@@ -112,15 +113,33 @@ let of_packages ~output_dir ~linked_dir (pkgs : Packages.t list) : t list =
112113
let open Fpath in
113114
match impl.mip_src_info with
114115
| None -> None
115-
| Some _ ->
116+
| Some { src_path } ->
116117
let rel_dir = pkg.Packages.pkg_dir / "lib" / libname in
117118
let odoc_dir = output_dir // rel_dir in
118119
let parent_id = rel_dir |> Odoc.id_of_fpath in
119120
let filename = impl.mip_path |> Fpath.rem_ext |> Fpath.basename in
120-
let odoc_file = odoc_dir / (filename ^ ".odoc") in
121-
let odocl_file = linked_dir // rel_dir / (filename ^ ".odocl") in
121+
let odoc_file = odoc_dir / ("impl-" ^ filename ^ ".odoc") in
122+
let odocl_file =
123+
linked_dir // rel_dir / ("impl-" ^ filename ^ ".odocl")
124+
in
122125
let input_file = impl.mip_path in
123-
let kind = `Impl in
126+
let src_name = Fpath.filename src_path in
127+
let src_id =
128+
Fpath.(pkg.pkg_dir / "src" / libname / src_name) |> Odoc.id_of_fpath
129+
in
130+
let deps =
131+
List.filter_map
132+
(fun (_name, hash) ->
133+
match Util.StringMap.find_opt hash hashtable with
134+
| None -> None
135+
| Some (pkg, lib, mod_) ->
136+
let result = of_intf mod_.m_hidden pkg lib mod_.m_intf in
137+
Hashtbl.add cache mod_.m_intf.mif_hash result;
138+
Some result)
139+
impl.mip_deps
140+
in
141+
let include_dirs = List.map (fun u -> u.odoc_dir) deps in
142+
let kind = `Impl { src_id; src_path } in
124143
Some
125144
{
126145
output_dir;
@@ -131,7 +150,7 @@ let of_packages ~output_dir ~linked_dir (pkgs : Packages.t list) : t list =
131150
odoc_file;
132151
odocl_file;
133152
pkg_args;
134-
include_dirs = [];
153+
include_dirs;
135154
kind;
136155
}
137156
in

src/driver/odoc_unit.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ type 'a unit = {
1919
type intf_extra = { hidden : bool; hash : string; deps : intf unit list }
2020
and intf = [ `Intf of intf_extra ]
2121

22-
type impl = [ `Impl ]
22+
type impl_extra = { src_id : Odoc.id; src_path : Fpath.t }
23+
type impl = [ `Impl of impl_extra ]
2324

2425
type mld = [ `Mld ]
2526

src/driver/packages.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ let pp_intf fmt i = Format.fprintf fmt "intf: %a" Fpath.pp i.mif_path
1010

1111
type src_info = { src_path : Fpath.t }
1212

13-
type impl = { mip_path : Fpath.t; mip_src_info : src_info option }
13+
type impl = {
14+
mip_path : Fpath.t;
15+
mip_src_info : src_info option;
16+
mip_deps : dep list;
17+
}
1418

1519
let pp_impl fmt i = Format.fprintf fmt "impl: %a" Fpath.pp i.mip_path
1620

@@ -101,7 +105,12 @@ module Module = struct
101105
m "Found source file %a for %s" Fpath.pp src_path m_name);
102106
Some { src_path }
103107
in
104-
{ mip_src_info; mip_path }
108+
let mip_deps =
109+
match Odoc.compile_deps mip_path with
110+
| Ok { digest = _; deps } -> deps
111+
| Error _ -> failwith "bad deps"
112+
in
113+
{ mip_src_info; mip_path; mip_deps }
105114
in
106115
let state = (exists "cmt", exists "cmti") in
107116

src/driver/packages.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ val pp_intf : Format.formatter -> intf -> unit
1212

1313
type src_info = { src_path : Fpath.t }
1414

15-
type impl = { mip_path : Fpath.t; mip_src_info : src_info option }
15+
type impl = {
16+
mip_path : Fpath.t;
17+
mip_src_info : src_info option;
18+
mip_deps : dep list;
19+
}
1620

1721
val pp_impl : Format.formatter -> impl -> unit
1822

0 commit comments

Comments
 (0)