Skip to content

Commit be87d3a

Browse files
move class_signature_pv from parent to label_parent
Indeed, `parent` is for constructor and fields: they can only have signature or datatype as parent. Signed-off-by: Paul-Elliot <[email protected]> Co-authored-by: Emile Trotignon <[email protected]>
1 parent d318a5f commit be87d3a

File tree

7 files changed

+54
-48
lines changed

7 files changed

+54
-48
lines changed

src/model/paths.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,14 +997,14 @@ module Reference = struct
997997
as sg ->
998998
(parent_signature_identifier sg :> Identifier.Parent.t)
999999
| `Type _ as t -> (parent_type_identifier t :> Identifier.Parent.t)
1000-
| (`Class _ | `ClassType _) as c ->
1001-
(parent_class_signature_identifier c :> Identifier.Parent.t)
10021000

10031001
and label_parent_identifier : label_parent -> Identifier.LabelParent.t =
10041002
function
10051003
| `Identifier id -> id
1004+
| (`Class _ | `ClassType _) as c ->
1005+
(parent_class_signature_identifier c :> Identifier.LabelParent.t)
10061006
| ( `Hidden _ | `Alias _ | `AliasModuleType _ | `Module _ | `ModuleType _
1007-
| `Type _ | `Class _ | `ClassType _ ) as r ->
1007+
| `Type _ ) as r ->
10081008
(parent_identifier r :> Identifier.LabelParent.t)
10091009

10101010
and identifier : t -> Identifier.t = function

src/model/paths_types.ml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ module Identifier = struct
8181
and datatype = datatype_pv id
8282
(** @canonical Odoc_model.Paths.Identifier.DataType.t *)
8383

84-
type parent_pv = [ signature_pv | datatype_pv | class_signature_pv ]
84+
type parent_pv = [ signature_pv | datatype_pv ]
8585
(** @canonical Odoc_model.Paths.Identifier.Parent.t_pv *)
8686

8787
and parent = parent_pv id
8888
(** @canonical Odoc_model.Paths.Identifier.Parent.t *)
8989

90-
type label_parent_pv = [ parent_pv | page_pv ]
90+
type label_parent_pv = [ parent_pv | page_pv | class_signature_pv ]
9191
(** @canonical Odoc_model.Paths.Identifier.LabelParent.t_pv *)
9292

9393
and label_parent = label_parent_pv id
@@ -623,8 +623,6 @@ module rec Reference : sig
623623
| `Dot of label_parent * string
624624
| `Module of signature * ModuleName.t
625625
| `ModuleType of signature * ModuleTypeName.t
626-
| `Class of signature * ClassName.t
627-
| `ClassType of signature * ClassTypeName.t
628626
| `Type of signature * TypeName.t ]
629627
(** @canonical Odoc_model.Paths.Reference.Parent.t *)
630628

@@ -813,8 +811,6 @@ and Resolved_reference : sig
813811
| `Module of signature * ModuleName.t
814812
| `Hidden of module_
815813
| `ModuleType of signature * ModuleTypeName.t
816-
| `Class of signature * ClassName.t
817-
| `ClassType of signature * ClassTypeName.t
818814
| `Type of signature * TypeName.t ]
819815
(** @canonical Odoc_model.Paths.Reference.Resolved.Parent.t *)
820816

src/xref2/compile.ml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,22 @@ and content env id =
103103

104104
and value_ env parent t =
105105
let open Value in
106-
let container = (parent :> Id.Parent.t) in
106+
let container = (parent :> Id.LabelParent.t) in
107107
try { t with type_ = type_expression env container t.type_ }
108108
with _ ->
109109
Errors.report ~what:(`Value t.id) `Compile;
110110
t
111111

112112
and exception_ env parent e =
113113
let open Exception in
114-
let container = (parent :> Id.Parent.t) in
114+
let container = (parent :> Id.LabelParent.t) in
115115
let res = Opt.map (type_expression env container) e.res in
116116
let args = type_decl_constructor_argument env container e.args in
117117
{ e with res; args }
118118

119119
and extension env parent t =
120120
let open Extension in
121-
let container = (parent :> Id.Parent.t) in
121+
let container = (parent :> Id.LabelParent.t) in
122122
let constructor c =
123123
let open Constructor in
124124
{
@@ -133,7 +133,7 @@ and extension env parent t =
133133

134134
and class_type_expr env parent =
135135
let open ClassType in
136-
let container = (parent :> Id.Parent.t) in
136+
let container = (parent :> Id.LabelParent.t) in
137137
function
138138
| Constr (path, texps) ->
139139
Constr
@@ -169,7 +169,7 @@ and class_type env c =
169169

170170
and class_signature env parent c =
171171
let open ClassSignature in
172-
let container = (parent : Id.ClassSignature.t :> Id.Parent.t) in
172+
let container = (parent : Id.ClassSignature.t :> Id.LabelParent.t) in
173173
let env = Env.open_class_signature c env in
174174
let map_item = function
175175
| Method m -> Method (method_ env parent m)
@@ -186,12 +186,12 @@ and class_signature env parent c =
186186

187187
and method_ env parent m =
188188
let open Method in
189-
let container = (parent :> Id.Parent.t) in
189+
let container = (parent :> Id.LabelParent.t) in
190190
{ m with type_ = type_expression env container m.type_ }
191191

192192
and instance_variable env parent i =
193193
let open InstanceVariable in
194-
let container = (parent :> Id.Parent.t) in
194+
let container = (parent :> Id.LabelParent.t) in
195195
{ i with type_ = type_expression env container i.type_ }
196196

197197
and class_constraint env parent cst =
@@ -208,7 +208,7 @@ and inherit_ env parent ih =
208208

209209
and class_ env parent c =
210210
let open Class in
211-
let container = (parent :> Id.Parent.t) in
211+
let container = (parent :> Id.LabelParent.t) in
212212
let expansion =
213213
match
214214
let open Utils.OptionMonad in
@@ -513,7 +513,7 @@ and module_type_expr_sub id ~fragment_root (sg_res, env, subs) lsub =
513513
Errors.report ~what:(`With_type cfrag) `Compile;
514514
(cfrag, frag)
515515
in
516-
let eqn' = type_decl_equation env (id :> Id.Parent.t) eqn in
516+
let eqn' = type_decl_equation env (id :> Id.LabelParent.t) eqn in
517517
let ceqn' = Component.Of_Lang.(type_equation (empty ()) eqn') in
518518
Tools.fragmap ~mark_substituted:true env
519519
(Component.ModuleType.TypeEq (cfrag', ceqn'))
@@ -556,7 +556,7 @@ and module_type_expr_sub id ~fragment_root (sg_res, env, subs) lsub =
556556
Errors.report ~what:(`With_type cfrag) `Compile;
557557
(cfrag, frag)
558558
in
559-
let eqn' = type_decl_equation env (id :> Id.Parent.t) eqn in
559+
let eqn' = type_decl_equation env (id :> Id.LabelParent.t) eqn in
560560
let ceqn' = Component.Of_Lang.(type_equation (empty ()) eqn') in
561561
Tools.fragmap ~mark_substituted:true env
562562
(Component.ModuleType.TypeSubst (cfrag', ceqn'))
@@ -739,7 +739,7 @@ and type_decl : Env.t -> TypeDecl.t -> TypeDecl.t =
739739
let open TypeDecl in
740740
let container =
741741
match t.id.iv with
742-
| `Type (parent, _) -> (parent :> Id.Parent.t)
742+
| `Type (parent, _) -> (parent :> Id.LabelParent.t)
743743
| `CoreType _ -> assert false
744744
in
745745
let equation = type_decl_equation env container t.equation in
@@ -749,7 +749,7 @@ and type_decl : Env.t -> TypeDecl.t -> TypeDecl.t =
749749
{ t with equation; representation }
750750

751751
and type_decl_equation :
752-
Env.t -> Id.Parent.t -> TypeDecl.Equation.t -> TypeDecl.Equation.t =
752+
Env.t -> Id.LabelParent.t -> TypeDecl.Equation.t -> TypeDecl.Equation.t =
753753
fun env parent t ->
754754
let open TypeDecl.Equation in
755755
let manifest = Opt.map (type_expression env parent) t.manifest in
@@ -763,7 +763,7 @@ and type_decl_equation :
763763

764764
and type_decl_representation :
765765
Env.t ->
766-
Id.Parent.t ->
766+
Id.LabelParent.t ->
767767
TypeDecl.Representation.t ->
768768
TypeDecl.Representation.t =
769769
fun env parent r ->
@@ -784,7 +784,10 @@ and type_decl_constructor_argument env parent c =
784784
| Record fs -> Record (List.map (type_decl_field env parent) fs)
785785

786786
and type_decl_constructor :
787-
Env.t -> Id.Parent.t -> TypeDecl.Constructor.t -> TypeDecl.Constructor.t =
787+
Env.t ->
788+
Id.LabelParent.t ->
789+
TypeDecl.Constructor.t ->
790+
TypeDecl.Constructor.t =
788791
fun env parent c ->
789792
let open TypeDecl.Constructor in
790793
let args = type_decl_constructor_argument env parent c.args in
@@ -853,7 +856,7 @@ and type_expression_package env parent p =
853856
}))
854857
| Error _ -> { p with path = Lang_of.(Path.module_type (empty ()) cp) }
855858

856-
and type_expression : Env.t -> Id.Parent.t -> _ -> _ =
859+
and type_expression : Env.t -> Id.LabelParent.t -> _ -> _ =
857860
fun env parent texpr ->
858861
let open TypeExpr in
859862
match texpr with

src/xref2/ident.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ type class_signature =
1616

1717
type datatype = [ `LType of TypeName.t * int ]
1818

19-
type parent = [ signature | datatype | class_signature ]
19+
type parent = [ signature | datatype ]
2020

2121
type label_parent =
22-
[ parent | `LPage of PageName.t * int | `LLeafPage of PageName.t * int ]
22+
[ parent
23+
| `LPage of PageName.t * int
24+
| `LLeafPage of PageName.t * int
25+
| class_signature ]
2326

2427
type module_ =
2528
[ `LRoot of ModuleName.t * int
@@ -143,11 +146,12 @@ module Of_Identifier = struct
143146
match p with
144147
| { iv = #Signature.t_pv; _ } as s -> (signature s :> parent)
145148
| { iv = #DataType.t_pv; _ } as s -> (datatype s :> parent)
146-
| { iv = #ClassSignature.t_pv; _ } as s -> (class_signature s :> parent)
147149

148150
let label_parent : LabelParent.t -> label_parent =
149151
fun p ->
150152
match p with
153+
| { iv = #ClassSignature.t_pv; _ } as s ->
154+
(class_signature s :> label_parent)
151155
| { iv = #Parent.t_pv; _ } as s -> (parent s :> label_parent)
152156
| { iv = `Page (_, n); _ } -> `LPage (n, fresh_int ())
153157
| { iv = `LeafPage (_, n); _ } -> `LLeafPage (n, fresh_int ())

src/xref2/lang_of.ml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,15 @@ and class_decl map parent c =
513513
| Arrow (lbl, t, d) ->
514514
Arrow
515515
( lbl,
516-
type_expr map (parent :> Identifier.Parent.t) t,
516+
type_expr map (parent :> Identifier.LabelParent.t) t,
517517
class_decl map parent d )
518518

519519
and class_type_expr map parent c =
520520
match c with
521521
| Component.ClassType.Constr (p, ts) ->
522522
Constr
523523
( Path.class_type map p,
524-
List.rev_map (type_expr map (parent :> Identifier.Parent.t)) ts
524+
List.rev_map (type_expr map (parent :> Identifier.LabelParent.t)) ts
525525
|> List.rev )
526526
| Signature s -> Signature (class_signature map parent s)
527527

@@ -548,7 +548,7 @@ and class_type map parent id c =
548548

549549
and class_signature map parent sg =
550550
let open Component.ClassSignature in
551-
let pparent = (parent :> Identifier.Parent.t) in
551+
let pparent = (parent :> Identifier.LabelParent.t) in
552552
let items =
553553
List.rev_map
554554
(function
@@ -573,7 +573,7 @@ and method_ map parent id m =
573573
doc = docs (parent :> Identifier.LabelParent.t) m.doc;
574574
private_ = m.private_;
575575
virtual_ = m.virtual_;
576-
type_ = type_expr map (parent :> Identifier.Parent.t) m.type_;
576+
type_ = type_expr map (parent :> Identifier.LabelParent.t) m.type_;
577577
}
578578

579579
and instance_variable map parent id i =
@@ -587,7 +587,7 @@ and instance_variable map parent id i =
587587
doc = docs (parent :> Identifier.LabelParent.t) i.doc;
588588
mutable_ = i.mutable_;
589589
virtual_ = i.virtual_;
590-
type_ = type_expr map (parent :> Identifier.Parent.t) i.type_;
590+
type_ = type_expr map (parent :> Identifier.LabelParent.t) i.type_;
591591
}
592592

593593
and class_constraint map parent cst =
@@ -686,7 +686,7 @@ and value_ map parent id v =
686686
id = identifier;
687687
locs = v.locs;
688688
doc = docs (parent :> Identifier.LabelParent.t) v.doc;
689-
type_ = type_expr map (parent :> Identifier.Parent.t) v.type_;
689+
type_ = type_expr map (parent :> Identifier.LabelParent.t) v.type_;
690690
value = v.value;
691691
}
692692

@@ -712,7 +712,7 @@ and extension_constructor map parent c =
712712
doc = docs (parent :> Identifier.LabelParent.t) c.doc;
713713
args =
714714
type_decl_constructor_argument map (parent :> Identifier.Parent.t) c.args;
715-
res = Opt.map (type_expr map (parent :> Identifier.Parent.t)) c.res;
715+
res = Opt.map (type_expr map (parent :> Identifier.LabelParent.t)) c.res;
716716
}
717717

718718
and module_ map parent id m =
@@ -893,7 +893,8 @@ and type_decl_constructor_argument :
893893
Odoc_model.Lang.TypeDecl.Constructor.argument =
894894
fun map parent a ->
895895
match a with
896-
| Tuple ls -> Tuple (List.map (type_expr map parent) ls)
896+
| Tuple ls ->
897+
Tuple (List.map (type_expr map (parent :> Identifier.LabelParent.t)) ls)
897898
| Record fs -> Record (List.map (type_decl_field map parent) fs)
898899

899900
and type_decl_field :
@@ -907,12 +908,13 @@ and type_decl_field :
907908
id = identifier;
908909
doc = docs (parent :> Identifier.LabelParent.t) f.doc;
909910
mutable_ = f.mutable_;
910-
type_ = type_expr map parent f.type_;
911+
type_ = type_expr map (parent :> Identifier.LabelParent.t) f.type_;
911912
}
912913

913914
and type_decl_equation map (parent : Identifier.Parent.t)
914915
(eqn : Component.TypeDecl.Equation.t) : Odoc_model.Lang.TypeDecl.Equation.t
915916
=
917+
let parent = (parent :> Identifier.LabelParent.t) in
916918
{
917919
params = eqn.params;
918920
private_ = eqn.private_;
@@ -958,14 +960,15 @@ and type_decl_constructor :
958960
let identifier =
959961
Identifier.Mk.constructor (id, ConstructorName.make_std t.name)
960962
in
963+
let parent = (id :> Identifier.LabelParent.t) in
961964
{
962965
id = identifier;
963966
doc = docs (id :> Identifier.LabelParent.t) t.doc;
964967
args = type_decl_constructor_argument map id t.args;
965-
res = Opt.map (type_expr map id) t.res;
968+
res = Opt.map (type_expr map parent) t.res;
966969
}
967970

968-
and type_expr_package map parent t =
971+
and type_expr_package map (parent : Identifier.LabelParent.t) t =
969972
{
970973
Lang.TypeExpr.Package.path =
971974
Path.module_type map t.Component.TypeExpr.Package.path;
@@ -976,8 +979,8 @@ and type_expr_package map parent t =
976979
t.substitutions;
977980
}
978981

979-
and type_expr map (parent : Identifier.Parent.t) (t : Component.TypeExpr.t) :
980-
Odoc_model.Lang.TypeExpr.t =
982+
and type_expr map (parent : Identifier.LabelParent.t) (t : Component.TypeExpr.t)
983+
: Odoc_model.Lang.TypeExpr.t =
981984
try
982985
match t with
983986
| Var s -> Var s
@@ -1009,7 +1012,7 @@ and type_expr_polyvar map parent v =
10091012
c.Component.TypeExpr.Polymorphic_variant.Constructor.name;
10101013
constant = c.constant;
10111014
arguments = List.map (type_expr map parent) c.arguments;
1012-
doc = docs (parent :> Identifier.LabelParent.t) c.doc;
1015+
doc = docs parent c.doc;
10131016
}
10141017
in
10151018
let element = function
@@ -1054,7 +1057,7 @@ and exception_ map parent id (e : Component.Exception.t) :
10541057
doc = docs (parent :> Identifier.LabelParent.t) e.doc;
10551058
args =
10561059
type_decl_constructor_argument map (parent :> Identifier.Parent.t) e.args;
1057-
res = Opt.map (type_expr map (parent :> Identifier.Parent.t)) e.res;
1060+
res = Opt.map (type_expr map (parent :> Identifier.LabelParent.t)) e.res;
10581061
}
10591062

10601063
and block_element parent

src/xref2/lang_of.mli

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,25 +223,25 @@ val type_decl_constructor :
223223

224224
val type_expr_package :
225225
maps ->
226-
Identifier.Parent.t ->
226+
Identifier.LabelParent.t ->
227227
Component.TypeExpr.Package.t ->
228228
Odoc_model.Lang.TypeExpr.Package.t
229229

230230
val type_expr :
231231
maps ->
232-
Identifier.Parent.t ->
232+
Identifier.LabelParent.t ->
233233
Component.TypeExpr.t ->
234234
Odoc_model.Lang.TypeExpr.t
235235

236236
val type_expr_polyvar :
237237
maps ->
238-
Identifier.Parent.t ->
238+
Identifier.LabelParent.t ->
239239
Component.TypeExpr.Polymorphic_variant.t ->
240240
Odoc_model.Lang.TypeExpr.Polymorphic_variant.t
241241

242242
val type_expr_object :
243243
maps ->
244-
Identifier.Parent.t ->
244+
Identifier.LabelParent.t ->
245245
Component.TypeExpr.Object.t ->
246246
Odoc_model.Lang.TypeExpr.Object.t
247247

src/xref2/link.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ and type_expression : Env.t -> Id.Signature.t -> _ -> _ =
10471047
let t' =
10481048
Expand_tools.type_expr map
10491049
Lang_of.(
1050-
type_expr (empty ()) (parent :> Id.Parent.t) expr)
1050+
type_expr (empty ()) (parent :> Id.LabelParent.t) expr)
10511051
in
10521052
type_expression env parent (p :: visited) t'
10531053
with
@@ -1066,7 +1066,7 @@ and type_expression : Env.t -> Id.Signature.t -> _ -> _ =
10661066
Constr (`Resolved p, ts)
10671067
| Ok (_cp, `FType_removed (_, x, _eq)) ->
10681068
(* Type variables ? *)
1069-
Lang_of.(type_expr (empty ()) (parent :> Id.Parent.t) x)
1069+
Lang_of.(type_expr (empty ()) (parent :> Id.LabelParent.t) x)
10701070
| Error _ -> Constr (path', ts))
10711071
| Polymorphic_variant v ->
10721072
Polymorphic_variant (type_expression_polyvar env parent visited v)

0 commit comments

Comments
 (0)