Skip to content

Commit 7c26b43

Browse files
panglesdjonludlam
authored andcommitted
Add anchor to the content of functor parameters
Since we don't want to generate the parent id, we needed it to be stored in the environment. Signed-off-by: Paul-Elliot <[email protected]>
1 parent b4084e3 commit 7c26b43

File tree

8 files changed

+67
-39
lines changed

8 files changed

+67
-39
lines changed

src/loader/cmi.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -929,12 +929,12 @@ let rec read_module_type env parent (mty : Odoc_model.Compat.module_type) =
929929
match parameter with
930930
| Unit -> Odoc_model.Lang.FunctorParameter.Unit, env
931931
| Named (id_opt, arg) ->
932-
let name, env = match id_opt with
933-
| Some id -> Ident.name id, Env.add_parameter parent id (ModuleName.of_ident id) env
934-
| None -> "_", env
932+
let id, env = match id_opt with
933+
| None -> Identifier.Mk.parameter(parent, Odoc_model.Names.ModuleName.make_std "_"), env
934+
| Some id -> let env = Env.add_parameter parent id (ModuleName.of_ident id) env in
935+
Ident_env.find_parameter_identifier env id, env
935936
in
936-
let id = Identifier.Mk.parameter(parent, Odoc_model.Names.ModuleName.make_std name) in
937-
let arg = read_module_type env id arg in
937+
let arg = read_module_type env (id :> Identifier.Signature.t) arg in
938938
Odoc_model.Lang.FunctorParameter.Named ({ FunctorParameter. id; expr = arg }), env
939939
in
940940
let res = read_module_type env (Identifier.Mk.result parent) res in

src/loader/cmt.ml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,30 +367,29 @@ let rec read_module_expr env parent label_parent mexpr =
367367
match parameter with
368368
| Unit -> FunctorParameter.Unit, env
369369
| Named (id_opt, _, arg) ->
370-
let name, env =
370+
let id, env =
371371
match id_opt with
372-
| Some id -> Ident.name id, Env.add_parameter parent id (ModuleName.of_ident id) env
373-
| None -> "_", env
372+
| None -> Identifier.Mk.parameter (parent, Odoc_model.Names.ModuleName.make_std "_"), env
373+
| Some id -> let env = Env.add_parameter parent id (ModuleName.of_ident id) env in
374+
Env.find_parameter_identifier env id, env
374375
in
375-
let id = Identifier.Mk.parameter (parent, Odoc_model.Names.ModuleName.make_std name) in
376-
let arg = Cmti.read_module_type env id label_parent arg in
376+
let arg = Cmti.read_module_type env (id :> Identifier.Signature.t) label_parent arg in
377377

378378
Named { id; expr=arg }, env
379379
in
380380
let res = read_module_expr env (Identifier.Mk.result parent) label_parent res in
381381
Functor (f_parameter, res)
382382
#else
383383
| Tmod_functor(id, _, arg, res) ->
384+
let new_env = Env.add_parameter parent id (ModuleName.of_ident id) env in
384385
let f_parameter =
385386
match arg with
386387
| None -> FunctorParameter.Unit
387388
| Some arg ->
388-
let name = Ident.name id in
389-
let id = Identifier.Mk.parameter (parent, ModuleName.make_std name) in
390-
let arg = Cmti.read_module_type env id label_parent arg in
391-
Named { FunctorParameter. id; expr = arg; }
389+
let id = Env.find_parameter_identifier env id in
390+
let arg = Cmti.read_module_type env (id :> Identifier.Signature.t) label_parent arg in
391+
Named { FunctorParameter. id; expr = arg; }
392392
in
393-
let env = Env.add_parameter parent id (ModuleName.of_ident id) env in
394393
let res = read_module_expr env (Identifier.Mk.result parent) label_parent res in
395394
Functor(f_parameter, res)
396395
#endif

src/loader/cmti.ml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,31 +519,30 @@ and read_module_type env parent label_parent mty =
519519
match parameter with
520520
| Unit -> FunctorParameter.Unit, env
521521
| Named (id_opt, _, arg) ->
522-
let name, env =
522+
let id, env =
523523
match id_opt with
524+
| None -> Identifier.Mk.parameter (parent, ModuleName.make_std "_"), env
524525
| Some id ->
525-
Ident.name id, Env.add_parameter parent id (ModuleName.of_ident id) env
526-
| None -> "_", env
526+
let env = Env.add_parameter parent id (ModuleName.of_ident id) env in
527+
Env.find_parameter_identifier env id, env
527528
in
528-
let id = Identifier.Mk.parameter (parent, ModuleName.make_std name) in
529-
let arg = read_module_type env id label_parent arg in
529+
let arg = read_module_type env (id :> Identifier.Signature.t) label_parent arg in
530530
Named { id; expr = arg; }, env
531531
in
532532
let res = read_module_type env (Identifier.Mk.result parent) label_parent res in
533533
Functor (f_parameter, res)
534534
#else
535535
| Tmty_functor(id, _, arg, res) ->
536+
let new_env = Env.add_parameter parent id (ModuleName.of_ident id) env in
536537
let f_parameter =
537538
match arg with
538539
| None -> Odoc_model.Lang.FunctorParameter.Unit
539540
| Some arg ->
540-
let name = Ident.name id in
541-
let id = Identifier.Mk.parameter (parent, Odoc_model.Names.ModuleName.make_std name) in
542-
let arg = read_module_type env id label_parent arg in
541+
let id = Ident_env.find_parameter_identifier new_env id in
542+
let arg = read_module_type env (id :> Identifier.Signature.t) label_parent arg in
543543
Named { FunctorParameter. id; expr = arg }
544544
in
545-
let env = Env.add_parameter parent id (ModuleName.of_ident id) env in
546-
let res = read_module_type env (Identifier.Mk.result parent) label_parent res in
545+
let res = read_module_type new_env (Identifier.Mk.result parent) label_parent res in
547546
Functor( f_parameter, res)
548547
#endif
549548
| Tmty_with(body, subs) -> (

src/loader/ident_env.cppo.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module LocHashtbl = Hashtbl.Make(struct
3131

3232
type t =
3333
{ modules : Id.Module.t Ident.tbl;
34+
parameters : Id.FunctorParameter.t Ident.tbl;
3435
module_paths : P.Module.t Ident.tbl;
3536
module_types : Id.ModuleType.t Ident.tbl;
3637
types : Id.DataType.t Ident.tbl;
@@ -45,6 +46,7 @@ type t =
4546

4647
let empty () =
4748
{ modules = Ident.empty;
49+
parameters = Ident.empty;
4850
module_paths = Ident.empty;
4951
module_types = Ident.empty;
5052
types = Ident.empty;
@@ -578,16 +580,22 @@ let handle_signature_type_items : Paths.Identifier.Signature.t -> Compat.signatu
578580

579581
let add_parameter parent id name env =
580582
let hidden = ModuleName.is_hidden name in
581-
let path = `Identifier (Odoc_model.Paths.Identifier.Mk.parameter(parent, name), hidden) in
583+
let oid = Odoc_model.Paths.Identifier.Mk.parameter(parent, name) in
584+
let path = `Identifier (oid, hidden) in
582585
let module_paths = Ident.add id path env.module_paths in
583-
{ env with module_paths }
586+
let modules = Ident.add id oid env.modules in
587+
let parameters = Ident.add id oid env.parameters in
588+
{ env with module_paths; modules; parameters }
584589

585590
let find_module env id =
586591
Ident.find_same id env.module_paths
587592

588593
let find_module_identifier env id =
589594
Ident.find_same id env.modules
590595

596+
let find_parameter_identifier env id =
597+
Ident.find_same id env.parameters
598+
591599
let find_module_type env id =
592600
Ident.find_same id env.module_types
593601

src/loader/ident_env.cppo.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ val find_module : t -> Ident.t -> Paths.Path.Module.t
4646

4747
val find_module_identifier : t -> Ident.t -> Paths.Identifier.Module.t
4848

49+
val find_parameter_identifier :
50+
t -> Ident.t -> Paths.Identifier.FunctorParameter.t
51+
4952
val find_module_type : t -> Ident.t -> Paths.Identifier.ModuleType.t
5053

5154
val find_value_identifier : t -> Ident.t -> Paths.Identifier.Value.t

src/loader/implementation.ml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,23 @@ module Analysis = struct
297297
| Tmod_structure str ->
298298
let sg = structure env parent str in
299299
sg
300-
| Tmod_functor (_, res) ->
301-
let res =
302-
module_expr env (Odoc_model.Paths.Identifier.Mk.result parent) res
300+
| Tmod_functor (parameter, res) ->
301+
let open Odoc_model.Names in
302+
let x, env =
303+
match parameter with
304+
| Unit -> [], env
305+
| Named (id_opt, _, arg) ->
306+
match id_opt with
307+
| Some id ->
308+
let env = env_wrap
309+
(Ident_env.add_parameter parent id
310+
(ModuleName.of_ident id))
311+
env in
312+
let id = Ident_env.find_module_identifier (get_env env) id in
313+
module_type env (id :> Identifier.Signature.t) arg, env
314+
| None -> [], env
303315
in
304-
res
316+
x @ module_expr env (Odoc_model.Paths.Identifier.Mk.result parent) res
305317
| Tmod_constraint (me, _, constr, _) ->
306318
let c =
307319
match constr with

test/sources/source.t/a.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ type a1 = int
3333
and a2 = a1
3434

3535
module F (M : sig
36-
type t
36+
module A : sig end
3737
end) =
38-
struct end
38+
struct
39+
module B = M.A
40+
end
3941

4042
module FM = F (struct
41-
type t = int
43+
module A = struct end
4244
end)

test/sources/source.t/run.t

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ Files containing some values:
3636
and a2 = a1
3737

3838
module F (M : sig
39-
type t
39+
module A : sig end
4040
end) =
41-
struct end
41+
struct
42+
module B = M.A
43+
end
4244

4345
module FM = F (struct
44-
type t = int
46+
module A = struct end
4547
end)
4648

4749
Source pages require a parent:
@@ -208,6 +210,8 @@ Ids generated in the source code:
208210
id="L40"
209211
id="L41"
210212
id="L42"
213+
id="L43"
214+
id="L44"
211215
id="type-t"
212216
id="type-truc"
213217
id="value-{x}2"
@@ -232,6 +236,7 @@ Ids generated in the source code:
232236
id="type-a1"
233237
id="type-a2"
234238
id="module-F"
235-
id="def_430_436"
239+
id="module-F.parameter-M.module-A"
240+
id="module-F.module-B"
236241
id="module-FM"
237-
id="def_480_492"
242+
id="def_509_530"

0 commit comments

Comments
 (0)