Skip to content

Commit c1d324e

Browse files
panglesdjonludlam
authored andcommitted
fmt
Signed-off-by: Paul-Elliot <[email protected]>
1 parent 1202733 commit c1d324e

File tree

7 files changed

+127
-35
lines changed

7 files changed

+127
-35
lines changed

src/document/generator.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ module Make (Syntax : SYNTAX) = struct
252252
let path id = Url.Path.from_identifier id
253253
let url id = Url.from_path (path id)
254254

255-
let to_link {Lang.Source_info.documentation; implementation} =
255+
let to_link { Lang.Source_info.documentation; implementation } =
256256
let documentation =
257257
let open Paths.Path.Resolved in
258258
match documentation with

src/odoc/bin/main.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,9 +1174,7 @@ module Occurrences = struct
11741174
$ (const index $ dst $ inputs $ inputs_in_file $ warnings_options))
11751175

11761176
let info ~docs =
1177-
let doc =
1178-
"Aggregate hashtables created with odoc count-occurrences."
1179-
in
1177+
let doc = "Aggregate hashtables created with odoc count-occurrences." in
11801178
Term.info "aggregate-occurrences" ~docs ~doc
11811179
end
11821180
end

src/odoc/occurrences.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ let count ~dst ~warnings_options:_ directories =
142142
| Type { documentation = Some (`Resolved p as p'); _ }, _ ->
143143
incr htbl p Odoc_model.Paths.Path.((p' : Type.t :> t))
144144
| _ -> ())
145-
(match unit.source_info with
146-
| None -> []
147-
| Some i ->
148-
i.infos)
145+
(match unit.source_info with None -> [] | Some i -> i.infos)
149146
in
150147
()
151148
in

src/odoc/odoc_link.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ let link_unit ~resolver ~filename m =
88
let open Odoc_model in
99
let open Lang.Compilation_unit in
1010
let m =
11-
if Root.Odoc_file.hidden m.root.file then
12-
{
13-
m with
14-
content = Module { items = []; compiled = false; doc = [] };
15-
expansion = None;
16-
}
17-
else m
11+
if Root.Odoc_file.hidden m.root.file then { m with expansion = None } else m
1812
in
1913
let env = Resolver.build_link_env_for_unit resolver m in
2014
Odoc_xref2.Link.link ~filename env m

src/xref2/link.ml

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,106 @@ and open_ env parent = function
415415
| { Odoc_model__Lang.Open.doc; _ } as open_ ->
416416
{ open_ with doc = comment_docs env parent doc }
417417

418+
module Build_env = struct
419+
let rec unit env t =
420+
let open Compilation_unit in
421+
match t.content with
422+
| Module sg ->
423+
let env = signature env sg in
424+
env
425+
| Pack _ -> env
426+
427+
and signature env s =
428+
let env = Env.open_signature s env in
429+
signature_items env s.items
430+
431+
and simple_expansion : Env.t -> ModuleType.simple_expansion -> Env.t =
432+
fun env m ->
433+
match m with
434+
| Signature sg -> signature env sg
435+
| Functor (arg, sg) ->
436+
let env = Env.add_functor_parameter arg env in
437+
let env = functor_argument env arg in
438+
simple_expansion env sg
439+
440+
and functor_argument env a =
441+
match a with
442+
| FunctorParameter.Unit -> env
443+
| Named arg -> functor_parameter_parameter env arg
444+
445+
and functor_parameter_parameter : Env.t -> FunctorParameter.parameter -> Env.t
446+
=
447+
fun env a -> module_type_expr env a.expr
448+
449+
and module_type_expr : Env.t -> ModuleType.expr -> Env.t =
450+
fun env expr ->
451+
let open ModuleType in
452+
match expr with
453+
| Signature s -> signature env s
454+
| Path { p_path = _; p_expansion = Some p_expansion } ->
455+
simple_expansion env p_expansion
456+
| Path { p_path = _; p_expansion = None } -> env
457+
| With _ -> env
458+
| Functor (arg, res) ->
459+
let env = functor_argument env arg in
460+
let env = Env.add_functor_parameter arg env in
461+
let env = module_type_expr env res in
462+
env
463+
| TypeOf { t_expansion = None; _ } -> env
464+
| TypeOf { t_expansion = Some exp; _ } -> simple_expansion env exp
465+
466+
and signature_items : Env.t -> Signature.item list -> Env.t =
467+
fun env s ->
468+
let open Signature in
469+
List.fold_left
470+
(fun env item ->
471+
match item with
472+
| Module (_, m) -> module_ env m
473+
| ModuleSubstitution m -> Env.open_module_substitution m env
474+
| Type _ -> env
475+
| TypeSubstitution t -> Env.open_type_substitution t env
476+
| ModuleType mt -> module_type env mt
477+
| ModuleTypeSubstitution mts ->
478+
let env = Env.open_module_type_substitution mts env in
479+
module_type_substitution env mts
480+
| Value _ -> env
481+
| Comment _ -> env
482+
| TypExt _ -> env
483+
| Exception _ -> env
484+
| Class _ -> env (* TODO *)
485+
| ClassType _ -> env
486+
| Include i -> include_ env i
487+
| Open _ -> env)
488+
env s
489+
490+
and module_type_substitution : Env.t -> ModuleTypeSubstitution.t -> Env.t =
491+
fun env m -> module_type_expr env m.manifest
492+
493+
and include_ : Env.t -> Include.t -> Env.t =
494+
fun env i ->
495+
let open Include in
496+
signature_items env i.expansion.content.items
497+
498+
and module_type : Env.t -> ModuleType.t -> Env.t =
499+
fun env m ->
500+
match m.expr with None -> env | Some expr -> module_type_expr env expr
501+
502+
and module_ : Env.t -> Module.t -> Env.t =
503+
fun env m ->
504+
let open Module in
505+
let env = module_decl env m.type_ in
506+
match m.type_ with
507+
| Alias (`Resolved _, Some exp) -> simple_expansion env exp
508+
| Alias _ | ModuleType _ -> env
509+
510+
and module_decl : Env.t -> Module.decl -> Env.t =
511+
fun env decl ->
512+
let open Module in
513+
match decl with
514+
| ModuleType expr -> module_type_expr env expr
515+
| Alias (_, None) -> env
516+
| Alias (_, Some e) -> simple_expansion env e
517+
end
418518
let rec unit env t =
419519
let open Compilation_unit in
420520
let content =
@@ -427,11 +527,7 @@ let rec unit env t =
427527
| Pack _ as p -> p
428528
in
429529
let source_info =
430-
let env =
431-
match t.content with
432-
| Module sg -> Env.open_signature sg env
433-
| Pack _ -> env
434-
in
530+
let env = Build_env.unit env t in
435531
let open Source_info in
436532
match t.source_info with
437533
| Some inf ->

test/occurrences/double_wrapped.t/run.t

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,16 @@ Uses of C are not counted, since the canonical destination (Main.C, generated by
6666
Uses of values Y.x and Z.y (in b.ml) are not counted since they come from a "local" module.
6767

6868
$ occurrences_print occurrences.txt | sort
69-
Main was used directly 0 times and indirectly 11 times
70-
Main.A was used directly 4 times and indirectly 6 times
69+
Main was used directly 0 times and indirectly 13 times
70+
Main.A was used directly 4 times and indirectly 8 times
7171
Main.A.(||>) was used directly 1 times and indirectly 0 times
7272
Main.A.M was used directly 2 times and indirectly 0 times
7373
Main.A.t was used directly 1 times and indirectly 0 times
74-
Main.A.x was used directly 2 times and indirectly 0 times
74+
Main.A.x was used directly 4 times and indirectly 0 times
7575
Main.B was used directly 1 times and indirectly 0 times
76+
Main__B was used directly 0 times and indirectly 1 times
77+
Main__B.Z was used directly 0 times and indirectly 1 times
78+
Main__B.Z.y was used directly 1 times and indirectly 0 times
7679
string was used directly 1 times and indirectly 0 times
7780

7881
$ occurrences_print occurrences1.txt | sort
@@ -86,17 +89,20 @@ Uses of values Y.x and Z.y (in b.ml) are not counted since they come from a "loc
8689
string was used directly 1 times and indirectly 0 times
8790

8891
$ occurrences_print occurrences4.txt | sort
89-
Main was used directly 0 times and indirectly 7 times
90-
Main.A was used directly 2 times and indirectly 5 times
92+
Main was used directly 0 times and indirectly 8 times
93+
Main.A was used directly 2 times and indirectly 6 times
9194
Main.A.(||>) was used directly 1 times and indirectly 0 times
9295
Main.A.M was used directly 2 times and indirectly 0 times
9396
Main.A.t was used directly 1 times and indirectly 0 times
94-
Main.A.x was used directly 1 times and indirectly 0 times
97+
Main.A.x was used directly 2 times and indirectly 0 times
98+
Main__B was used directly 0 times and indirectly 1 times
99+
Main__B.Z was used directly 0 times and indirectly 1 times
100+
Main__B.Z.y was used directly 1 times and indirectly 0 times
95101

96102
$ occurrences_print occurrences5.txt | sort
97-
Main was used directly 0 times and indirectly 2 times
98-
Main.A was used directly 1 times and indirectly 1 times
99-
Main.A.x was used directly 1 times and indirectly 0 times
103+
Main was used directly 0 times and indirectly 3 times
104+
Main.A was used directly 1 times and indirectly 2 times
105+
Main.A.x was used directly 2 times and indirectly 0 times
100106

101107
Now we can merge both files
102108

@@ -108,11 +114,14 @@ Now we can merge both files
108114
$ odoc aggregate-occurrences occurrences1.txt occurrences2.txt --file-list files.map -o aggregated.txt
109115

110116
$ occurrences_print aggregated.txt | sort
111-
Main was used directly 0 times and indirectly 11 times
112-
Main.A was used directly 4 times and indirectly 6 times
117+
Main was used directly 0 times and indirectly 13 times
118+
Main.A was used directly 4 times and indirectly 8 times
113119
Main.A.(||>) was used directly 1 times and indirectly 0 times
114120
Main.A.M was used directly 2 times and indirectly 0 times
115121
Main.A.t was used directly 1 times and indirectly 0 times
116-
Main.A.x was used directly 2 times and indirectly 0 times
122+
Main.A.x was used directly 4 times and indirectly 0 times
117123
Main.B was used directly 1 times and indirectly 0 times
124+
Main__B was used directly 0 times and indirectly 1 times
125+
Main__B.Z was used directly 0 times and indirectly 1 times
126+
Main__B.Z.y was used directly 1 times and indirectly 0 times
118127
string was used directly 1 times and indirectly 0 times

test/odoc_print/occurrences_print.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ module H = Hashtbl.Make (Odoc_model.Paths.Identifier)
22

33
let run inp =
44
let ic = open_in_bin inp in
5-
let htbl : Odoc_odoc.Occurrences.Occtbl.t =
6-
Marshal.from_channel ic
7-
in
5+
let htbl : Odoc_odoc.Occurrences.Occtbl.t = Marshal.from_channel ic in
86
Odoc_odoc.Occurrences.Occtbl.iter
97
(fun id { Odoc_odoc.Occurrences.Occtbl.direct; indirect; _ } ->
108
let id = String.concat "." (Odoc_model.Paths.Identifier.fullname id) in

0 commit comments

Comments
 (0)