Skip to content

Commit 7e20799

Browse files
committed
Working module arguments
The way it works is not ideal: we create a synthetic parent id for each module argument (as they can be introduced multiple times with the same name in the same type expression). This id is hidden and we don't render links to hidden ids. This is slightly bad because: - The appearance of unresolved links suggest an error when there is no. - There is no way to distinguish module args from normal modules But let's say it is a good first step!
1 parent 7b2a740 commit 7e20799

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

src/document/generator.ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,20 @@ module Make (Syntax : SYNTAX) = struct
488488
| Lang.TypeExpr.Optional s ) ->
489489
O.txt (s ^ ":")
490490
in
491+
(* let href = *)
492+
(* Url.from_identifier ~stop_before:false *)
493+
(* (m_arg.id :> Paths.Identifier.t) *)
494+
(* in *)
495+
let name =
496+
match m_arg.id.iv with
497+
| `Parameter (_, name) -> ModuleName.to_string name
498+
in
491499
let dst = type_expr dst in
492-
lbl ++ O.txt "(module " ++ O.txt "test" ++ O.txt ":"
493-
++ package m_arg.package ++ O.txt ")" ++ Syntax.Type.arrow ++ dst
500+
lbl ++ O.txt "(module "
501+
++
502+
(* resolved href [ inline @@ Text name ] *)
503+
O.txt name ++ O.txt " : " ++ package m_arg.package ++ O.txt ")"
504+
++ O.sp ++ Syntax.Type.arrow ++ O.sp ++ dst
494505

495506
and package pkg =
496507
Link.from_path (pkg.path :> Paths.Path.t)

src/loader/cmti.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,12 @@ let rec read_core_type env container ctyp =
168168
#endif
169169
#if OCAML_VERSION >= (5,5,0)
170170
| Ttyp_functor (lbl, id, pkg, ret_type) ->
171-
let lbl = read_label lbl in
172-
let e', id = Env.add_module_arg id.txt (ModuleName.of_ident id.txt) env.ident_env in
171+
let lbl = read_label lbl in
172+
let parent = Identifier.fresh_module_arg_parent () in
173+
let e', id =
174+
Env.add_module_arg parent id.txt (ModuleName.hidden_of_ident id.txt)
175+
env.ident_env
176+
in
173177
let env = {env with ident_env = e'} in
174178
let ret = read_core_type env container ret_type in
175179
let package = read_package env container pkg in

src/loader/ident_env.cppo.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ let add_parameter parent id name env =
638638
let parameters = Ident.add id oid env.parameters in
639639
{ env with module_paths; modules; parameters }
640640

641-
let add_module_arg id name env =
642-
let oid = Odoc_model.Paths.Identifier.Mk.(parameter ((root(None, ModuleName.make_std "yoyo")), name)) in
641+
let add_module_arg parent id name env =
642+
let oid = Odoc_model.Paths.Identifier.Mk.(parameter (parent, name)) in
643643
let path = `Identifier (oid, false) in
644644
let module_paths = Ident.add id path env.module_paths in
645645
let modules = Ident.add id oid env.modules in

src/loader/ident_env.cppo.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ val add_parameter :
2424
Paths.Identifier.Signature.t -> Ident.t -> Names.ModuleName.t -> t -> t
2525

2626
val add_module_arg :
27+
Paths.Identifier.Signature.t ->
2728
Ident.t ->
2829
Names.ModuleName.t ->
2930
t ->

src/model/paths.ml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,16 @@ module Identifier = struct
637637
let name = Printf.sprintf "include%d_" !include_parent_counter in
638638
(Mk.module_ (parent, ModuleName.make_std name) :> Signature.t)
639639

640+
let module_arg_parent_counter = ref 0
641+
642+
(* Create a synthetic parent identifier for module arguments, which can't have
643+
unique identifier, as they can be introduced multiple times with the same
644+
name in a single type expression . *)
645+
let fresh_module_arg_parent () : Signature.t =
646+
incr module_arg_parent_counter;
647+
let name = Printf.sprintf "module_arg_%d_" !module_arg_parent_counter in
648+
(Mk.root (None, ModuleName.hidden_of_string name) :> Signature.t)
649+
640650
module Hashtbl = struct
641651
module Any = Hashtbl.Make (Any)
642652
module ContainerPage = Hashtbl.Make (ContainerPage)
@@ -662,7 +672,7 @@ module Path = struct
662672
| `Identifier { iv = `Module (_, m); _ } when Names.ModuleName.is_hidden m
663673
->
664674
true
665-
| `Identifier _ -> false
675+
| `Identifier id -> Identifier.is_hidden id
666676
| `Canonical (_, `Resolved _) -> false
667677
| `Canonical (x, _) ->
668678
(not weak_canonical_test) && inner (x : module_ :> any)
@@ -705,7 +715,7 @@ module Path = struct
705715
let open Paths_types.Path in
706716
function
707717
| `Resolved r -> is_resolved_hidden ~weak_canonical_test:false r
708-
| `Identifier (_, hidden) -> hidden
718+
| `Identifier (id, hidden) -> hidden || Identifier.is_hidden id
709719
| `Substituted r -> is_path_hidden (r :> any)
710720
| `SubstitutedMT r -> is_path_hidden (r :> any)
711721
| `SubstitutedT r -> is_path_hidden (r :> any)

src/model/paths.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ module Identifier : sig
351351
type expression. Uses a lowercase module name (illegal in normal OCaml) to
352352
ensure no clashes with real identifiers. Each call returns a fresh
353353
identifier. *)
354+
355+
val fresh_module_arg_parent : unit -> Signature.t
356+
(** Create a synthetic parent identifier for module arguments, which can't
357+
have unique identifier, as they can be introduced multiple times with the
358+
same name in a single type expression . *)
354359
end
355360

356361
(** Normal OCaml paths (i.e. the ones present in types) *)

0 commit comments

Comments
 (0)