Skip to content

Commit e8edbc5

Browse files
committed
Formatting and backwards compat
1 parent 0cf5bf3 commit e8edbc5

File tree

9 files changed

+70
-54
lines changed

9 files changed

+70
-54
lines changed

src/loader/implementation.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,6 @@ let of_cmt (source_id : Odoc_model.Paths.Identifier.SourcePage.t)
505505

506506
#else
507507

508-
let of_cmt _ _ _ _ = []
508+
let of_cmt _ _ _ _ = (), []
509509

510510
#endif

src/loader/implementation.mli

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
val of_cmt :
22
Odoc_model.Paths.Identifier.SourcePage.t ->
33
Odoc_model.Paths.Identifier.RootModule.t ->
4-
Typedtree.structure -> Warnings.loc Types.Uid.Tbl.t ->
5-
Odoc_model.Paths.Identifier.Id.source_location Odoc_model.Compat.shape_uid_map * Odoc_model.Lang.Source_info.infos
4+
Typedtree.structure ->
5+
Odoc_model.Compat.uid_to_loc ->
6+
Odoc_model.Paths.Identifier.Id.source_location Odoc_model.Compat.shape_uid_map
7+
* Odoc_model.Lang.Source_info.infos
68
(** Extract all implementation information from a [cmt]: the shape, and the
79
{{!Odoc_model.Lang.Source_info.infos}source infos} (local and global
810
definitions and occurrences).

src/loader/odoc_loader.ml

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,25 @@ exception Not_an_interface
4242

4343
exception Make_root_error of string
4444

45+
#if OCAML_VERSION >= (4, 14, 0)
4546
(** [cmt_info.cmt_annots = Implementation _] *)
4647
let read_cmt_infos' source_id_opt id cmt_info =
4748
match Odoc_model.Compat.shape_of_cmt_infos cmt_info with
48-
| Some shape -> begin
49-
let uid_to_loc = cmt_info.cmt_uid_to_loc in
50-
match source_id_opt, cmt_info.cmt_annots with
51-
| Some source_id, Implementation impl ->
52-
let (map, source_infos) = Implementation.of_cmt source_id id impl uid_to_loc in
53-
(Some shape, map, Some { Odoc_model.Lang.Source_info.id=source_id; infos = source_infos})
54-
| _, _ ->
55-
(Some shape, Odoc_model.Compat.empty_map, None)
56-
end
49+
| Some shape -> (
50+
let uid_to_loc = cmt_info.cmt_uid_to_loc in
51+
match (source_id_opt, cmt_info.cmt_annots) with
52+
| Some source_id, Implementation impl ->
53+
let map, source_infos =
54+
Implementation.of_cmt source_id id impl uid_to_loc
55+
in
56+
( Some shape,
57+
map,
58+
Some
59+
{
60+
Odoc_model.Lang.Source_info.id = source_id;
61+
infos = source_infos;
62+
} )
63+
| _, _ -> (Some shape, Odoc_model.Compat.empty_map, None))
5764
| None -> (None, Odoc_model.Compat.empty_map, None)
5865

5966
let read_cmt_infos source_id_opt id ~filename () =
@@ -64,6 +71,13 @@ let read_cmt_infos source_id_opt id ~filename () =
6471
| Implementation _ -> read_cmt_infos' source_id_opt id cmt_info
6572
| _ -> raise Not_an_implementation)
6673

74+
#else
75+
76+
let read_cmt_infos _source_id_opt _id ~filename:_ () =
77+
(None, Odoc_model.Compat.empty_map, None)
78+
79+
#endif
80+
6781
let make_compilation_unit ~make_root ~imports ~interface ?sourcefile ~name ~id
6882
?canonical ?shape ~uid_to_id ~source_info content =
6983
let open Odoc_model.Lang.Compilation_unit in
@@ -106,6 +120,7 @@ let make_compilation_unit ~make_root ~imports ~interface ?sourcefile ~name ~id
106120
uid_to_id;
107121
}
108122

123+
109124
let compilation_unit_of_sig ~make_root ~imports ~interface ?sourcefile ~name ~id
110125
?canonical ?shape ~uid_to_id sg =
111126
let content = Odoc_model.Lang.Compilation_unit.Module sg in
@@ -126,15 +141,15 @@ let read_cmti ~make_root ~parent ~filename ~cmt_filename_opt ~source_id_opt () =
126141
cmt_info.cmt_builddir )
127142
in
128143
let id, sg, canonical = Cmti.read_interface parent name intf in
129-
let (shape, uid_to_id, source_info) =
144+
let shape, uid_to_id, source_info =
130145
match cmt_filename_opt with
131146
| Some cmt_filename ->
132-
read_cmt_infos source_id_opt id ~filename:cmt_filename ()
133-
| None ->
134-
(None, Odoc_model.Compat.empty_map, None)
147+
read_cmt_infos source_id_opt id ~filename:cmt_filename ()
148+
| None -> (None, Odoc_model.Compat.empty_map, None)
135149
in
136150
compilation_unit_of_sig ~make_root ~imports:cmt_info.cmt_imports
137-
~interface ~sourcefile ~name ~id ?shape ~uid_to_id ~source_info ?canonical sg)
151+
~interface ~sourcefile ~name ~id ?shape ~uid_to_id ~source_info
152+
?canonical sg)
138153
| _ -> raise Not_an_interface
139154

140155
let read_cmt ~make_root ~parent ~filename ~source_id_opt () =
@@ -176,14 +191,15 @@ let read_cmt ~make_root ~parent ~filename ~source_id_opt () =
176191
items
177192
in
178193
let content = Odoc_model.Lang.Compilation_unit.Pack items in
179-
make_compilation_unit ~make_root ~imports ~interface ~sourcefile
180-
~name ~id ~uid_to_id:Odoc_model.Compat.empty_map ~source_info:None content
194+
make_compilation_unit ~make_root ~imports ~interface ~sourcefile ~name
195+
~id ~uid_to_id:Odoc_model.Compat.empty_map ~source_info:None content
181196
| Implementation impl ->
182197
let id, sg, canonical = Cmt.read_implementation parent name impl in
183-
let (shape, uid_to_id, source_info) =
184-
read_cmt_infos source_id_opt id ~filename () in
198+
let shape, uid_to_id, source_info =
199+
read_cmt_infos source_id_opt id ~filename ()
200+
in
185201
compilation_unit_of_sig ~make_root ~imports ~interface ~sourcefile
186-
~name ~id ?canonical ?shape ~uid_to_id ~source_info sg
202+
~name ~id ?canonical ?shape ~uid_to_id ~source_info sg
187203
| _ -> raise Not_an_implementation)
188204

189205
let read_cmi ~make_root ~parent ~filename () =
@@ -194,7 +210,8 @@ let read_cmi ~make_root ~parent ~filename () =
194210
Cmi.read_interface parent name
195211
(Odoc_model.Compat.signature cmi_info.cmi_sign)
196212
in
197-
compilation_unit_of_sig ~make_root ~imports ~interface ~name ~id ~source_info:None ~uid_to_id:Odoc_model.Compat.empty_map sg
213+
compilation_unit_of_sig ~make_root ~imports ~interface ~name ~id
214+
~source_info:None ~uid_to_id:Odoc_model.Compat.empty_map sg
198215
| _ -> raise Corrupted
199216

200217
(** Catch errors from reading the object files and some internal errors *)
@@ -211,7 +228,8 @@ let wrap_errors ~filename f =
211228
| Make_root_error m -> error_msg filename m)
212229

213230
let read_cmti ~make_root ~parent ~filename ~source_id_opt ~cmt_filename_opt =
214-
wrap_errors ~filename (read_cmti ~make_root ~parent ~filename ~source_id_opt ~cmt_filename_opt)
231+
wrap_errors ~filename
232+
(read_cmti ~make_root ~parent ~filename ~source_id_opt ~cmt_filename_opt)
215233

216234
let read_cmt ~make_root ~parent ~filename ~source_id_opt =
217235
wrap_errors ~filename (read_cmt ~make_root ~parent ~filename ~source_id_opt)

src/loader/odoc_loader.mli

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ val read_cmt :
2626
parent:Identifier.ContainerPage.t option ->
2727
filename:string ->
2828
source_id_opt:Identifier.SourcePage.t option ->
29-
( Lang.Compilation_unit.t, Error.t )
30-
result
31-
Error.with_warnings
29+
(Lang.Compilation_unit.t, Error.t) result Error.with_warnings
3230

3331
val read_cmi :
3432
make_root:make_root ->

src/model/compat.cppo.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ type shape = Shape.t
232232

233233
type 'a shape_uid_map = 'a Shape.Uid.Map.t
234234

235+
type uid_to_loc = Warnings.loc Types.Uid.Tbl.t
235236
let empty_map = Shape.Uid.Map.empty
236237

237238
let shape_of_cmt_infos : Cmt_format.cmt_infos -> shape option = fun x -> x.cmt_impl_shape
@@ -242,6 +243,7 @@ type shape = unit
242243

243244
type 'a shape_uid_map = unit
244245

246+
type uid_to_loc = unit
245247
let empty_map = ()
246248

247249
let shape_of_cmt_infos : Cmt_format.cmt_infos -> shape option = fun _ -> None

src/odoc/bin/main.ml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ end = struct
187187
"Either --package or --parent should be specified, not both")
188188
in
189189
let source =
190-
match
191-
(source_parent_file, source_name)
192-
with
190+
match (source_parent_file, source_name) with
193191
| Some parent, Some name -> Ok (Some (parent, name))
194192
| Some _, None | None, Some _ ->
195193
Error
@@ -198,11 +196,10 @@ end = struct
198196
same time.")
199197
| None, None -> Ok None
200198
in
201-
begin
202-
if Fs.File.get_ext input = ".cmt" && cmt_filename_opt <> None then
203-
Error (`Cli_error "--cmt is redundant if the input is a cmt file")
204-
else Ok ()
205-
end >>= fun () ->
199+
(if Fs.File.get_ext input = ".cmt" && cmt_filename_opt <> None then
200+
Error (`Cli_error "--cmt is redundant if the input is a cmt file")
201+
else Ok ())
202+
>>= fun () ->
206203
parent_cli_spec >>= fun parent_cli_spec ->
207204
source >>= fun source ->
208205
Fs.Directory.mkdir_p (Fs.File.dirname output);

src/odoc/compile.ml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ let resolve_imports resolver imports =
9797
imports
9898

9999
(** Raises warnings and errors. *)
100-
let resolve_and_substitute ~resolver ~make_root ~source_id_opt ~cmt_filename_opt ~hidden
101-
(parent : Paths.Identifier.ContainerPage.t option) input_file input_type =
100+
let resolve_and_substitute ~resolver ~make_root ~source_id_opt ~cmt_filename_opt
101+
~hidden (parent : Paths.Identifier.ContainerPage.t option) input_file
102+
input_type =
102103
let filename = Fs.File.to_string input_file in
103104
let unit =
104105
match input_type with
105106
| `Cmti ->
106-
Odoc_loader.read_cmti ~make_root ~parent ~filename ~source_id_opt ~cmt_filename_opt
107+
Odoc_loader.read_cmti ~make_root ~parent ~filename ~source_id_opt
108+
~cmt_filename_opt
107109
|> Error.raise_errors_and_warnings
108110
| `Cmt ->
109111
Odoc_loader.read_cmt ~make_root ~parent ~filename ~source_id_opt
@@ -119,9 +121,7 @@ let resolve_and_substitute ~resolver ~make_root ~source_id_opt ~cmt_filename_opt
119121
else
120122
Printf.sprintf " Using %S while you should use the .cmti file" filename);
121123
(* Resolve imports, used by the [link-deps] command. *)
122-
let unit =
123-
{ unit with imports = resolve_imports resolver unit.imports }
124-
in
124+
let unit = { unit with imports = resolve_imports resolver unit.imports } in
125125
let env = Resolver.build_compile_env_for_unit resolver unit in
126126
let compiled =
127127
Odoc_xref2.Compile.compile ~filename env unit |> Error.raise_warnings
@@ -254,9 +254,11 @@ let compile ~resolver ~parent_cli_spec ~hidden ~children ~output
254254
parent resolver parent_cli_spec >>= fun parent_spec ->
255255
let ext = Fs.File.get_ext input in
256256
if ext = ".mld" then
257-
check_is_none "Not expecting source (--source-*) when compiling pages." source
257+
check_is_none "Not expecting source (--source-*) when compiling pages."
258+
source
258259
>>= fun () ->
259-
check_is_none "Not expecting cmt filename (--cmt) when compiling pages." cmt_filename_opt
260+
check_is_none "Not expecting cmt filename (--cmt) when compiling pages."
261+
cmt_filename_opt
260262
>>= fun () -> mld ~parent_spec ~output ~warnings_options ~children input
261263
else
262264
check_is_empty "Not expecting children (--child) when compiling modules."
@@ -273,8 +275,7 @@ let compile ~resolver ~parent_cli_spec ~hidden ~children ~output
273275
match page.Lang.SourceTree.name with
274276
| { Paths.Identifier.iv = `Page _; _ } as parent_id ->
275277
let id = Paths.Identifier.Mk.source_page (parent_id, name) in
276-
if
277-
List.exists (Paths.Identifier.equal id) page.source_children
278+
if List.exists (Paths.Identifier.equal id) page.source_children
278279
then Ok (Some id)
279280
else err_not_parent ()
280281
| { iv = `LeafPage _; _ } -> err_not_parent ())
@@ -294,8 +295,8 @@ let compile ~resolver ~parent_cli_spec ~hidden ~children ~output
294295
let make_root = root_of_compilation_unit ~parent_spec ~hidden ~output in
295296
let result =
296297
Error.catch_errors_and_warnings (fun () ->
297-
resolve_and_substitute ~resolver ~make_root ~hidden ~source_id_opt ~cmt_filename_opt
298-
parent input input_type)
298+
resolve_and_substitute ~resolver ~make_root ~hidden ~source_id_opt
299+
~cmt_filename_opt parent input input_type)
299300
in
300301
(* Extract warnings to write them into the output file *)
301302
let _, warnings = Error.unpack_warnings result in

src/odoc/resolver.mli

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@ val lookup_page : t -> string -> Odoc_model.Lang.Page.t option
3737
(** Helpers for creating xref2 env. *)
3838

3939
val build_compile_env_for_unit :
40-
t ->
41-
Odoc_model.Lang.Compilation_unit.t ->
42-
Odoc_xref2.Env.t
40+
t -> Odoc_model.Lang.Compilation_unit.t -> Odoc_xref2.Env.t
4341
(** Initialize the environment for compiling the given module. *)
4442

4543
val build_link_env_for_unit :
46-
t ->
47-
Odoc_model.Lang.Compilation_unit.t ->
48-
Odoc_xref2.Env.t
44+
t -> Odoc_model.Lang.Compilation_unit.t -> Odoc_xref2.Env.t
4945
(** Initialize the environment for linking the given module. *)
5046

5147
val build_env_for_page : t -> Odoc_model.Lang.Page.t -> Odoc_xref2.Env.t

src/xref2/link.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ end
99

1010
let locations env id locs =
1111
let id = (id :> Id.NonSrc.t) in
12-
match locs with Some _ as locs -> locs | None -> Shape_tools.lookup_def env id
12+
match locs with
13+
| Some _ as locs -> locs
14+
| None -> Shape_tools.lookup_def env id
1315

1416
(** Equivalent to {!Comment.synopsis}. *)
1517
let synopsis_from_comment (docs : Component.CComment.docs) =

0 commit comments

Comments
 (0)