Skip to content

Commit c799142

Browse files
panglesdjonludlam
authored andcommitted
occurrences: review comments
- Handle `Pextra_ty` in `is_persistent` - alias `Tast_iterator.default_iterator` to improve readability - Remove possibility for `jump_to` type to have different types for doc and impl - Factorize all instances of `contains_double_underscore` - Use `ModuleName.is_hidden` instead of inlining its definition... - Handle `ClassType` occurrences in compile, and avoid future miss by having an exhaustive match. Signed-off-by: Paul-Elliot <[email protected]>
1 parent c0ba997 commit c799142

File tree

14 files changed

+42
-69
lines changed

14 files changed

+42
-69
lines changed

src/loader/cmi.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ and read_module_declaration env parent ident (md : Odoc_model.Compat.module_decl
968968
let hidden =
969969
match canonical with
970970
| Some _ -> false
971-
| None -> Odoc_model.Root.contains_double_underscore (Ident.name ident)
971+
| None -> Odoc_model.Names.contains_double_underscore (Ident.name ident)
972972
in
973973
{id; locs; doc; type_; canonical; hidden }
974974

src/loader/cmt.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ and read_module_binding env parent mb =
450450
let hidden =
451451
#if OCAML_VERSION >= (4,10,0)
452452
match canonical, mb.mb_id with
453-
| None, Some id -> Odoc_model.Root.contains_double_underscore (Ident.name id)
453+
| None, Some id -> Odoc_model.Names.contains_double_underscore (Ident.name id)
454454
| _, _ -> false
455455
#else
456456
match canonical with

src/loader/cmti.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ and read_module_declaration env parent md =
628628
let hidden =
629629
#if OCAML_VERSION >= (4,10,0)
630630
match canonical, md.md_id with
631-
| None, Some id -> Odoc_model.Root.contains_double_underscore (Ident.name id)
631+
| None, Some id -> Odoc_model.Names.contains_double_underscore (Ident.name id)
632632
| _,_ -> false
633633
#else
634634
match canonical with

src/loader/ident_env.cppo.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ let add_items : Id.Signature.t -> item list -> t -> unit = fun parent items env
553553

554554
| `Module (t, is_hidden_item, loc) :: rest ->
555555
let name = Ident.name t in
556-
let double_underscore = Odoc_model.Root.contains_double_underscore name in
556+
let double_underscore = Odoc_model.Names.contains_double_underscore name in
557557
let is_hidden = is_hidden_item || module_name_exists name rest || double_underscore in
558558
let identifier =
559559
if is_hidden

src/loader/implementation.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let rec is_persistent : Path.t -> bool = function
55
| Path.Pdot(p, _) -> is_persistent p
66
| Path.Papply(p, _) -> is_persistent p
77
#if OCAML_VERSION >= (5,1,0)
8-
| Path.Pextra_ty _ -> assert false
8+
| Path.Pextra_ty (p, _) -> is_persistent p
99
#endif
1010

1111
let pos_of_loc loc = (loc.Location.loc_start.pos_cnum, loc.loc_end.pos_cnum)

src/loader/odoc_loader.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ let make_compilation_unit ~make_root ~imports ~interface ?sourcefile ~name ~id
8383
imports;
8484
source;
8585
interface;
86-
hidden = Odoc_model.Root.contains_double_underscore name;
86+
hidden = Odoc_model.Names.contains_double_underscore name;
8787
content;
8888
expansion = None;
8989
linked = false;

src/loader/typedtree_traverse.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,37 +94,38 @@ end
9494

9595
let of_cmt env structure =
9696
let poses = ref [] in
97+
let iter = Tast_iterator.default_iterator in
9798
let module_expr iterator mod_expr =
9899
Analysis.module_expr poses mod_expr;
99-
Tast_iterator.default_iterator.module_expr iterator mod_expr
100+
iter.module_expr iterator mod_expr
100101
in
101102
let expr iterator e =
102103
Analysis.expr poses e;
103-
Tast_iterator.default_iterator.expr iterator e
104+
iter.expr iterator e
104105
in
105106
let pat iterator e =
106107
Analysis.pat env poses e;
107-
Tast_iterator.default_iterator.pat iterator e
108+
iter.pat iterator e
108109
in
109110
let typ iterator ctyp_expr =
110111
Analysis.core_type poses ctyp_expr;
111-
Tast_iterator.default_iterator.typ iterator ctyp_expr
112+
iter.typ iterator ctyp_expr
112113
in
113114
let module_type iterator mty =
114115
Analysis.module_type poses mty;
115-
Tast_iterator.default_iterator.module_type iterator mty
116+
iter.module_type iterator mty
116117
in
117118
let class_type iterator cl_type =
118119
Analysis.class_type poses cl_type;
119-
Tast_iterator.default_iterator.class_type iterator cl_type
120+
iter.class_type iterator cl_type
120121
in
121122
let module_binding iterator mb =
122123
Analysis.module_binding env poses mb;
123-
Tast_iterator.default_iterator.module_binding iterator mb
124+
iter.module_binding iterator mb
124125
in
125126
let iterator =
126127
{
127-
Tast_iterator.default_iterator with
128+
iter with
128129
expr;
129130
pat;
130131
module_expr;

src/model/lang.ml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,19 @@ module Source_info = struct
2222
| Unresolved of 'a
2323
| Resolved of Identifier.SourceLocation.t
2424

25-
type ('doc, 'impl) jump_to = {
26-
documentation : 'doc option;
27-
implementation : 'impl jump_to_impl option;
25+
type 'a jump_to = {
26+
documentation : 'a option;
27+
implementation : 'a jump_to_impl option;
2828
}
2929

30-
type 'path jump_1 = ('path, 'path) jump_to
31-
3230
type annotation =
3331
| Definition of Paths.Identifier.SourceLocation.t
34-
| Value of Path.Value.t jump_1
35-
| Module of Path.Module.t jump_1
36-
| ClassType of Path.ClassType.t jump_1
37-
| ModuleType of Path.ModuleType.t jump_1
38-
| Type of Path.Type.t jump_1
39-
| Constructor of Path.Constructor.t jump_1
32+
| Value of Path.Value.t jump_to
33+
| Module of Path.Module.t jump_to
34+
| ClassType of Path.ClassType.t jump_to
35+
| ModuleType of Path.ModuleType.t jump_to
36+
| Type of Path.Type.t jump_to
37+
| Constructor of Path.Constructor.t jump_to
4038

4139
type 'a with_pos = 'a * (int * int)
4240

src/model/names.ml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ let parenthesise name =
1515
| _ -> "(" ^ name ^ ")"
1616
else name
1717

18+
let contains_double_underscore s =
19+
let len = String.length s in
20+
let rec aux i =
21+
if i > len - 2 then false
22+
else if s.[i] = '_' && s.[i + 1] = '_' then true
23+
else aux (i + 1)
24+
in
25+
aux 0
26+
1827
module type Name = sig
1928
type t
2029

@@ -73,14 +82,7 @@ module Name : Name = struct
7382
let fmt ppf x = Format.fprintf ppf "%s" (to_string x)
7483

7584
let is_hidden = function
76-
| Std s ->
77-
let len = String.length s in
78-
let rec aux i =
79-
if i > len - 2 then false
80-
else if s.[i] = '_' && s.[i + 1] = '_' then true
81-
else aux (i + 1)
82-
in
83-
aux 0
85+
| Std s -> contains_double_underscore s
8486
| Internal _ -> true
8587
end
8688

@@ -117,14 +119,7 @@ module SimpleName : SimpleName = struct
117119

118120
let fmt ppf t = Format.pp_print_string ppf (to_string t)
119121

120-
let is_hidden s =
121-
let len = String.length s in
122-
let rec aux i =
123-
if i > len - 2 then false
124-
else if s.[i] = '_' && s.[i + 1] = '_' then true
125-
else aux (i + 1)
126-
in
127-
aux 0
122+
let is_hidden s = contains_double_underscore s
128123
end
129124

130125
module ModuleName = Name

src/model/names.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*)
88

99
val parenthesise : string -> string
10+
val contains_double_underscore : string -> bool
11+
(* not the best place for this but. *)
1012

1113
(** Name is the signature for names that could possibly be internal. Internal
1214
names occur when we generate items that don't have a path that will be

0 commit comments

Comments
 (0)