Skip to content

Commit 0dcbe20

Browse files
committed
Dot constructors are now typed
1 parent 01e5521 commit 0dcbe20

34 files changed

+315
-244
lines changed

src/document/generator.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,20 @@ module Make (Syntax : SYNTAX) = struct
110110
| `SubstitutedMT m -> from_path (m :> Path.t)
111111
| `SubstitutedT m -> from_path (m :> Path.t)
112112
| `SubstitutedCT m -> from_path (m :> Path.t)
113-
| `Root root -> unresolved [ inline @@ Text root ]
113+
| `Root root -> unresolved [ inline @@ Text (ModuleName.to_string root) ]
114114
| `Forward root -> unresolved [ inline @@ Text root ] (* FIXME *)
115115
| `Dot (prefix, suffix) ->
116116
let link = from_path (prefix :> Path.t) in
117-
link ++ O.txt ("." ^ suffix)
117+
link ++ O.txt ("." ^ ModuleName.to_string suffix)
118+
| `DotT (prefix, suffix) ->
119+
let link = from_path (prefix :> Path.t) in
120+
link ++ O.txt ("." ^ TypeName.to_string suffix)
121+
| `DotMT (prefix, suffix) ->
122+
let link = from_path (prefix :> Path.t) in
123+
link ++ O.txt ("." ^ ModuleTypeName.to_string suffix)
124+
| `DotV (prefix, suffix) ->
125+
let link = from_path (prefix :> Path.t) in
126+
link ++ O.txt ("." ^ ValueName.to_string suffix)
118127
| `Apply (p1, p2) ->
119128
let link1 = from_path (p1 :> Path.t) in
120129
let link2 = from_path (p2 :> Path.t) in

src/document/url.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ let render_path : Odoc_model.Paths.Path.t -> string =
4747
| `Value (p, s) -> render_resolved (p :> t) ^ "." ^ ValueName.to_string s
4848
| `Class (p, s) -> render_resolved (p :> t) ^ "." ^ TypeName.to_string s
4949
| `ClassType (p, s) -> render_resolved (p :> t) ^ "." ^ TypeName.to_string s
50+
and dot p s =
51+
render_path (p : Odoc_model.Paths.Path.Module.t :> Odoc_model.Paths.Path.t)
52+
^ "." ^ s
5053
and render_path : Odoc_model.Paths.Path.t -> string =
5154
fun x ->
5255
match x with
5356
| `Identifier (id, _) -> Identifier.name id
54-
| `Root root -> root
57+
| `Root root -> ModuleName.to_string root
5558
| `Forward root -> root
56-
| `Dot (prefix, suffix) -> render_path (prefix :> t) ^ "." ^ suffix
59+
| `Dot (p, s) -> dot p (ModuleName.to_string s)
60+
| `DotT (p, s) -> dot p (TypeName.to_string s)
61+
| `DotMT (p, s) -> dot p (ModuleTypeName.to_string s)
62+
| `DotV (p, s) -> dot p (ValueName.to_string s)
5763
| `Apply (p1, p2) ->
5864
render_path (p1 :> t) ^ "(" ^ render_path (p2 :> t) ^ ")"
5965
| `Resolved rp -> render_resolved rp

src/loader/cmi.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ let read_type_declaration env parent id decl =
741741
let doc, canonical =
742742
Doc_attr.attached Odoc_model.Semantics.Expect_canonical container decl.type_attributes
743743
in
744-
let canonical = (canonical :> Path.Type.t option) in
744+
let canonical = match canonical with | None -> None | Some s -> Doc_attr.conv_canonical_type s in
745745
let params = mark_type_declaration decl in
746746
let manifest = opt_map (read_type_expr env) decl.type_manifest in
747747
let constraints = read_type_constraints env params in
@@ -985,7 +985,7 @@ and read_module_type_declaration env parent id (mtd : Odoc_model.Compat.modtype_
985985
let source_loc = None in
986986
let container = (parent : Identifier.Signature.t :> Identifier.LabelParent.t) in
987987
let doc, canonical = Doc_attr.attached Odoc_model.Semantics.Expect_canonical container mtd.mtd_attributes in
988-
let canonical = (canonical :> Path.ModuleType.t option) in
988+
let canonical = match canonical with | None -> None | Some s -> Doc_attr.conv_canonical_module_type s in
989989
let expr = opt_map (read_module_type env (id :> Identifier.Signature.t)) mtd.mtd_type in
990990
{id; source_loc; doc; canonical; expr }
991991

@@ -995,7 +995,7 @@ and read_module_declaration env parent ident (md : Odoc_model.Compat.module_decl
995995
let source_loc = None in
996996
let container = (parent : Identifier.Signature.t :> Identifier.LabelParent.t) in
997997
let doc, canonical = Doc_attr.attached Odoc_model.Semantics.Expect_canonical container md.md_attributes in
998-
let canonical = (canonical :> Path.Module.t option) in
998+
let canonical = match canonical with | None -> None | Some s -> Some (Doc_attr.conv_canonical_module s) in
999999
let type_ =
10001000
match md.md_type with
10011001
| Mty_alias p -> Alias (Env.Path.read_module env p, None)

src/loader/cmt.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ and read_module_binding env parent mb =
453453
in
454454
(ModuleType expr, canonical)
455455
in
456-
let canonical = (canonical :> Path.Module.t option) in
456+
let canonical = match canonical with | None -> None | Some s -> Some (Doc_attr.conv_canonical_module s) in
457457
let hidden =
458458
#if OCAML_VERSION >= (4,10,0)
459459
match canonical, mid.iv with
@@ -613,6 +613,7 @@ let read_implementation root name impl =
613613
let sg, canonical =
614614
read_structure Odoc_model.Semantics.Expect_canonical (Env.empty ()) id impl
615615
in
616-
(id, sg, (canonical :> Odoc_model.Paths.Path.Module.t option))
616+
let canonical = match canonical with | None -> None | Some s -> Some (Doc_attr.conv_canonical_module s) in
617+
(id, sg, canonical)
617618

618619
let _ = Cmti.read_module_expr := read_module_expr

src/loader/cmti.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ let read_type_declaration env parent decl =
267267
let source_loc = None in
268268
let container = (parent : Identifier.Signature.t :> Identifier.LabelParent.t) in
269269
let doc, canonical = Doc_attr.attached Odoc_model.Semantics.Expect_canonical container decl.typ_attributes in
270-
let canonical = (canonical :> Path.Type.t option) in
270+
let canonical = match canonical with | None -> None | Some s -> Doc_attr.conv_canonical_type s in
271271
let equation = read_type_equation env container decl in
272272
let representation = read_type_kind env id decl.typ_kind in
273273
{id; source_loc; doc; canonical; equation; representation}
@@ -608,7 +608,7 @@ and read_module_type_declaration env parent mtd =
608608
(Some expr, canonical)
609609
| None -> (None, canonical)
610610
in
611-
let canonical = (canonical :> Path.ModuleType.t option) in
611+
let canonical = match canonical with | None -> None | Some s -> Doc_attr.conv_canonical_module_type s in
612612
{ id; source_loc; doc; canonical; expr }
613613

614614
and read_module_declaration env parent md =
@@ -636,7 +636,7 @@ and read_module_declaration env parent md =
636636
in
637637
(ModuleType expr, canonical)
638638
in
639-
let canonical = (canonical :> Path.Module.t option) in
639+
let canonical = match canonical with | None -> None | Some s -> Some (Doc_attr.conv_canonical_module s) in
640640
let hidden =
641641
#if OCAML_VERSION >= (4,10,0)
642642
match canonical, mid.iv with
@@ -812,4 +812,5 @@ let read_interface root name intf =
812812
let sg, canonical =
813813
read_signature Odoc_model.Semantics.Expect_canonical (Env.empty ()) id intf
814814
in
815-
(id, sg, (canonical :> Odoc_model.Paths.Path.Module.t option))
815+
let canonical = match canonical with | None -> None | Some s -> Some (Doc_attr.conv_canonical_module s) in
816+
(id, sg, canonical)

src/loader/doc_attr.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,15 @@ let extract_top_comment_class items =
259259
match items with
260260
| Lang.ClassSignature.Comment (`Docs doc) :: tl -> (tl, split_docs doc)
261261
| _ -> items, (empty,empty)
262+
263+
let rec conv_canonical_module : Odoc_model.Reference.path -> Paths.Path.Module.t = function
264+
| `Dot (parent, name) -> `Dot (conv_canonical_module parent, Names.ModuleName.make_std name)
265+
| `Root name -> `Root (Names.ModuleName.make_std name)
266+
267+
let conv_canonical_type : Odoc_model.Reference.path -> Paths.Path.Type.t option = function
268+
| `Dot (parent, name) -> Some (`DotT (conv_canonical_module parent, Names.TypeName.make_std name))
269+
| _ -> None
270+
271+
let conv_canonical_module_type : Odoc_model.Reference.path -> Paths.Path.ModuleType.t option = function
272+
| `Dot (parent, name) -> Some (`DotMT (conv_canonical_module parent, Names.ModuleTypeName.make_std name))
273+
| _ -> None

src/loader/doc_attr.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@ val extract_top_comment_class :
7070
(** Extract the first comment of a class signature. Returns the remaining items. *)
7171

7272
val read_location : Location.t -> Odoc_model.Location_.span
73+
74+
val conv_canonical_module : Odoc_model.Reference.path -> Paths.Path.Module.t
75+
val conv_canonical_type : Odoc_model.Reference.path -> Paths.Path.Type.t option
76+
val conv_canonical_module_type :
77+
Odoc_model.Reference.path -> Paths.Path.ModuleType.t option

src/loader/ident_env.cppo.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ let is_shadowed
673673
module Path = struct
674674

675675
let read_module_ident env id =
676-
if Ident.persistent id then `Root (Ident.name id)
676+
if Ident.persistent id then `Root (ModuleName.of_ident id)
677677
else
678678
try find_module env id
679679
with Not_found -> assert false
@@ -693,7 +693,7 @@ module Path = struct
693693
try
694694
`Identifier (find_class_type env id, false)
695695
with Not_found ->
696-
`Dot(`Root "*", (Ident.name id))
696+
`DotT (`Root (ModuleName.make_std "*"), (TypeName.of_ident id))
697697
(* TODO remove this hack once the fix for PR#6650
698698
is in the OCaml release *)
699699

@@ -718,9 +718,9 @@ module Path = struct
718718
let rec read_module : t -> Path.t -> Paths.Path.Module.t = fun env -> function
719719
| Path.Pident id -> read_module_ident env id
720720
#if OCAML_VERSION >= (4,8,0)
721-
| Path.Pdot(p, s) -> `Dot(read_module env p, s)
721+
| Path.Pdot(p, s) -> `Dot(read_module env p, ModuleName.make_std s)
722722
#else
723-
| Path.Pdot(p, s, _) -> `Dot(read_module env p, s)
723+
| Path.Pdot(p, s, _) -> `Dot(read_module env p, ModuleName.make_std s)
724724
#endif
725725
| Path.Papply(p, arg) -> `Apply(read_module env p, read_module env arg)
726726
#if OCAML_VERSION >= (5,1,0)
@@ -730,9 +730,9 @@ module Path = struct
730730
let read_module_type env = function
731731
| Path.Pident id -> read_module_type_ident env id
732732
#if OCAML_VERSION >= (4,8,0)
733-
| Path.Pdot(p, s) -> `Dot(read_module env p, s)
733+
| Path.Pdot(p, s) -> `DotMT(read_module env p, ModuleTypeName.make_std s)
734734
#else
735-
| Path.Pdot(p, s, _) -> `Dot(read_module env p, s)
735+
| Path.Pdot(p, s, _) -> `DotMT(read_module env p, ModuleTypeName.make_std s)
736736
#endif
737737
| Path.Papply(_, _)-> assert false
738738
#if OCAML_VERSION >= (5,1,0)
@@ -742,9 +742,9 @@ module Path = struct
742742
let read_class_type env = function
743743
| Path.Pident id -> read_class_type_ident env id
744744
#if OCAML_VERSION >= (4,8,0)
745-
| Path.Pdot(p, s) -> `Dot(read_module env p, strip_hash s)
745+
| Path.Pdot(p, s) -> `DotT(read_module env p, TypeName.make_std (strip_hash s))
746746
#else
747-
| Path.Pdot(p, s, _) -> `Dot(read_module env p, strip_hash s)
747+
| Path.Pdot(p, s, _) -> `DotT(read_module env p, strip_hash s)
748748
#endif
749749
| Path.Papply(_, _)-> assert false
750750
#if OCAML_VERSION >= (5,1,0)
@@ -758,9 +758,9 @@ module Path = struct
758758
#endif
759759
| Path.Pident id -> read_type_ident env id
760760
#if OCAML_VERSION >= (4,8,0)
761-
| Path.Pdot(p, s) -> `Dot(read_module env p, strip_hash s)
761+
| Path.Pdot(p, s) -> `DotT(read_module env p, TypeName.make_std (strip_hash s))
762762
#else
763-
| Path.Pdot(p, s, _) -> `Dot(read_module env p, strip_hash s)
763+
| Path.Pdot(p, s, _) -> `DotT(read_module env p, TypeName.make_std (strip_hash s))
764764
#endif
765765
| Path.Papply(_, _)-> assert false
766766
#if OCAML_VERSION >= (5,1,0)
@@ -770,9 +770,9 @@ module Path = struct
770770
let read_value env = function
771771
| Path.Pident id -> read_value_ident env id
772772
#if OCAML_VERSION >= (4,8,0)
773-
| Path.Pdot(p, s) -> `Dot(read_module env p, s)
773+
| Path.Pdot(p, s) -> `DotV(read_module env p, ValueName.make_std s)
774774
#else
775-
| Path.Pdot(p, s, _) -> `Dot(read_module env p, s)
775+
| Path.Pdot(p, s, _) -> `DotV(read_module env p, ValueName.make_std s)
776776
#endif
777777
| Path.Papply(_, _) -> assert false
778778
#if OCAML_VERSION >= (5,1,0)

src/loader/odoc_loader.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ let read_cmt ~make_root ~parent ~filename () =
167167
Odoc_model.Paths.Identifier.Mk.module_
168168
(id, Odoc_model.Names.ModuleName.make_std name)
169169
in
170-
let path = `Root name in
170+
let path = `Root (Odoc_model.Names.ModuleName.make_std name) in
171171
{ Odoc_model.Lang.Compilation_unit.Packed.id; path })
172172
items
173173
in

src/model/odoc_model.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ module Error = Error
99
module Location_ = Location_
1010
module Compat = Compat
1111
module Semantics = Semantics
12+
module Reference = Reference

0 commit comments

Comments
 (0)