diff --git a/src/document/generator.ml b/src/document/generator.ml index fc104b7811..00f99b0788 100644 --- a/src/document/generator.ml +++ b/src/document/generator.ml @@ -110,11 +110,20 @@ module Make (Syntax : SYNTAX) = struct | `SubstitutedMT m -> from_path (m :> Path.t) | `SubstitutedT m -> from_path (m :> Path.t) | `SubstitutedCT m -> from_path (m :> Path.t) - | `Root root -> unresolved [ inline @@ Text root ] + | `Root root -> unresolved [ inline @@ Text (ModuleName.to_string root) ] | `Forward root -> unresolved [ inline @@ Text root ] (* FIXME *) | `Dot (prefix, suffix) -> let link = from_path (prefix :> Path.t) in - link ++ O.txt ("." ^ suffix) + link ++ O.txt ("." ^ ModuleName.to_string suffix) + | `DotT (prefix, suffix) -> + let link = from_path (prefix :> Path.t) in + link ++ O.txt ("." ^ TypeName.to_string suffix) + | `DotMT (prefix, suffix) -> + let link = from_path (prefix :> Path.t) in + link ++ O.txt ("." ^ ModuleTypeName.to_string suffix) + | `DotV (prefix, suffix) -> + let link = from_path (prefix :> Path.t) in + link ++ O.txt ("." ^ ValueName.to_string suffix) | `Apply (p1, p2) -> let link1 = from_path (p1 :> Path.t) in let link2 = from_path (p2 :> Path.t) in diff --git a/src/document/url.ml b/src/document/url.ml index f6951e6779..ac08dc7efa 100644 --- a/src/document/url.ml +++ b/src/document/url.ml @@ -47,13 +47,19 @@ let render_path : Odoc_model.Paths.Path.t -> string = | `Value (p, s) -> render_resolved (p :> t) ^ "." ^ ValueName.to_string s | `Class (p, s) -> render_resolved (p :> t) ^ "." ^ TypeName.to_string s | `ClassType (p, s) -> render_resolved (p :> t) ^ "." ^ TypeName.to_string s + and dot p s = + render_path (p : Odoc_model.Paths.Path.Module.t :> Odoc_model.Paths.Path.t) + ^ "." ^ s and render_path : Odoc_model.Paths.Path.t -> string = fun x -> match x with | `Identifier (id, _) -> Identifier.name id - | `Root root -> root + | `Root root -> ModuleName.to_string root | `Forward root -> root - | `Dot (prefix, suffix) -> render_path (prefix :> t) ^ "." ^ suffix + | `Dot (p, s) -> dot p (ModuleName.to_string s) + | `DotT (p, s) -> dot p (TypeName.to_string s) + | `DotMT (p, s) -> dot p (ModuleTypeName.to_string s) + | `DotV (p, s) -> dot p (ValueName.to_string s) | `Apply (p1, p2) -> render_path (p1 :> t) ^ "(" ^ render_path (p2 :> t) ^ ")" | `Resolved rp -> render_resolved rp diff --git a/src/loader/cmi.ml b/src/loader/cmi.ml index d3522a8e5e..a852c7c2fb 100644 --- a/src/loader/cmi.ml +++ b/src/loader/cmi.ml @@ -741,7 +741,7 @@ let read_type_declaration env parent id decl = let doc, canonical = Doc_attr.attached Odoc_model.Semantics.Expect_canonical container decl.type_attributes in - let canonical = (canonical :> Path.Type.t option) in + let canonical = match canonical with | None -> None | Some s -> Doc_attr.conv_canonical_type s in let params = mark_type_declaration decl in let manifest = opt_map (read_type_expr env) decl.type_manifest in 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_ let source_loc = None in let container = (parent : Identifier.Signature.t :> Identifier.LabelParent.t) in let doc, canonical = Doc_attr.attached Odoc_model.Semantics.Expect_canonical container mtd.mtd_attributes in - let canonical = (canonical :> Path.ModuleType.t option) in + let canonical = match canonical with | None -> None | Some s -> Doc_attr.conv_canonical_module_type s in let expr = opt_map (read_module_type env (id :> Identifier.Signature.t)) mtd.mtd_type in {id; source_loc; doc; canonical; expr } @@ -995,7 +995,7 @@ and read_module_declaration env parent ident (md : Odoc_model.Compat.module_decl let source_loc = None in let container = (parent : Identifier.Signature.t :> Identifier.LabelParent.t) in let doc, canonical = Doc_attr.attached Odoc_model.Semantics.Expect_canonical container md.md_attributes in - let canonical = (canonical :> Path.Module.t option) in + let canonical = match canonical with | None -> None | Some s -> Some (Doc_attr.conv_canonical_module s) in let type_ = match md.md_type with | Mty_alias p -> Alias (Env.Path.read_module env p, None) diff --git a/src/loader/cmt.ml b/src/loader/cmt.ml index d69822cde4..7018848885 100644 --- a/src/loader/cmt.ml +++ b/src/loader/cmt.ml @@ -453,7 +453,7 @@ and read_module_binding env parent mb = in (ModuleType expr, canonical) in - let canonical = (canonical :> Path.Module.t option) in + let canonical = match canonical with | None -> None | Some s -> Some (Doc_attr.conv_canonical_module s) in let hidden = #if OCAML_VERSION >= (4,10,0) match canonical, mid.iv with @@ -613,6 +613,7 @@ let read_implementation root name impl = let sg, canonical = read_structure Odoc_model.Semantics.Expect_canonical (Env.empty ()) id impl in - (id, sg, (canonical :> Odoc_model.Paths.Path.Module.t option)) + let canonical = match canonical with | None -> None | Some s -> Some (Doc_attr.conv_canonical_module s) in + (id, sg, canonical) let _ = Cmti.read_module_expr := read_module_expr diff --git a/src/loader/cmti.ml b/src/loader/cmti.ml index b6c8618feb..945de00f81 100644 --- a/src/loader/cmti.ml +++ b/src/loader/cmti.ml @@ -267,7 +267,7 @@ let read_type_declaration env parent decl = let source_loc = None in let container = (parent : Identifier.Signature.t :> Identifier.LabelParent.t) in let doc, canonical = Doc_attr.attached Odoc_model.Semantics.Expect_canonical container decl.typ_attributes in - let canonical = (canonical :> Path.Type.t option) in + let canonical = match canonical with | None -> None | Some s -> Doc_attr.conv_canonical_type s in let equation = read_type_equation env container decl in let representation = read_type_kind env id decl.typ_kind in {id; source_loc; doc; canonical; equation; representation} @@ -608,7 +608,7 @@ and read_module_type_declaration env parent mtd = (Some expr, canonical) | None -> (None, canonical) in - let canonical = (canonical :> Path.ModuleType.t option) in + let canonical = match canonical with | None -> None | Some s -> Doc_attr.conv_canonical_module_type s in { id; source_loc; doc; canonical; expr } and read_module_declaration env parent md = @@ -636,7 +636,7 @@ and read_module_declaration env parent md = in (ModuleType expr, canonical) in - let canonical = (canonical :> Path.Module.t option) in + let canonical = match canonical with | None -> None | Some s -> Some (Doc_attr.conv_canonical_module s) in let hidden = #if OCAML_VERSION >= (4,10,0) match canonical, mid.iv with @@ -812,4 +812,5 @@ let read_interface root name intf = let sg, canonical = read_signature Odoc_model.Semantics.Expect_canonical (Env.empty ()) id intf in - (id, sg, (canonical :> Odoc_model.Paths.Path.Module.t option)) + let canonical = match canonical with | None -> None | Some s -> Some (Doc_attr.conv_canonical_module s) in + (id, sg, canonical) diff --git a/src/loader/doc_attr.ml b/src/loader/doc_attr.ml index a4e9fd8aab..1f3273533e 100644 --- a/src/loader/doc_attr.ml +++ b/src/loader/doc_attr.ml @@ -259,3 +259,15 @@ let extract_top_comment_class items = match items with | Lang.ClassSignature.Comment (`Docs doc) :: tl -> (tl, split_docs doc) | _ -> items, (empty,empty) + +let rec conv_canonical_module : Odoc_model.Reference.path -> Paths.Path.Module.t = function + | `Dot (parent, name) -> `Dot (conv_canonical_module parent, Names.ModuleName.make_std name) + | `Root name -> `Root (Names.ModuleName.make_std name) + +let conv_canonical_type : Odoc_model.Reference.path -> Paths.Path.Type.t option = function + | `Dot (parent, name) -> Some (`DotT (conv_canonical_module parent, Names.TypeName.make_std name)) + | _ -> None + +let conv_canonical_module_type : Odoc_model.Reference.path -> Paths.Path.ModuleType.t option = function + | `Dot (parent, name) -> Some (`DotMT (conv_canonical_module parent, Names.ModuleTypeName.make_std name)) + | _ -> None diff --git a/src/loader/doc_attr.mli b/src/loader/doc_attr.mli index 643cb581f5..792015a8ad 100644 --- a/src/loader/doc_attr.mli +++ b/src/loader/doc_attr.mli @@ -70,3 +70,8 @@ val extract_top_comment_class : (** Extract the first comment of a class signature. Returns the remaining items. *) val read_location : Location.t -> Odoc_model.Location_.span + +val conv_canonical_module : Odoc_model.Reference.path -> Paths.Path.Module.t +val conv_canonical_type : Odoc_model.Reference.path -> Paths.Path.Type.t option +val conv_canonical_module_type : + Odoc_model.Reference.path -> Paths.Path.ModuleType.t option diff --git a/src/loader/ident_env.cppo.ml b/src/loader/ident_env.cppo.ml index 90143d0467..e0b87df5b8 100644 --- a/src/loader/ident_env.cppo.ml +++ b/src/loader/ident_env.cppo.ml @@ -673,7 +673,7 @@ let is_shadowed module Path = struct let read_module_ident env id = - if Ident.persistent id then `Root (Ident.name id) + if Ident.persistent id then `Root (ModuleName.of_ident id) else try find_module env id with Not_found -> assert false @@ -693,7 +693,7 @@ module Path = struct try `Identifier (find_class_type env id, false) with Not_found -> - `Dot(`Root "*", (Ident.name id)) + `DotT (`Root (ModuleName.make_std "*"), (TypeName.of_ident id)) (* TODO remove this hack once the fix for PR#6650 is in the OCaml release *) @@ -718,9 +718,9 @@ module Path = struct let rec read_module : t -> Path.t -> Paths.Path.Module.t = fun env -> function | Path.Pident id -> read_module_ident env id #if OCAML_VERSION >= (4,8,0) - | Path.Pdot(p, s) -> `Dot(read_module env p, s) + | Path.Pdot(p, s) -> `Dot(read_module env p, ModuleName.make_std s) #else - | Path.Pdot(p, s, _) -> `Dot(read_module env p, s) + | Path.Pdot(p, s, _) -> `Dot(read_module env p, ModuleName.make_std s) #endif | Path.Papply(p, arg) -> `Apply(read_module env p, read_module env arg) #if OCAML_VERSION >= (5,1,0) @@ -730,9 +730,9 @@ module Path = struct let read_module_type env = function | Path.Pident id -> read_module_type_ident env id #if OCAML_VERSION >= (4,8,0) - | Path.Pdot(p, s) -> `Dot(read_module env p, s) + | Path.Pdot(p, s) -> `DotMT(read_module env p, ModuleTypeName.make_std s) #else - | Path.Pdot(p, s, _) -> `Dot(read_module env p, s) + | Path.Pdot(p, s, _) -> `DotMT(read_module env p, ModuleTypeName.make_std s) #endif | Path.Papply(_, _)-> assert false #if OCAML_VERSION >= (5,1,0) @@ -742,9 +742,9 @@ module Path = struct let read_class_type env = function | Path.Pident id -> read_class_type_ident env id #if OCAML_VERSION >= (4,8,0) - | Path.Pdot(p, s) -> `Dot(read_module env p, strip_hash s) + | Path.Pdot(p, s) -> `DotT(read_module env p, TypeName.make_std (strip_hash s)) #else - | Path.Pdot(p, s, _) -> `Dot(read_module env p, strip_hash s) + | Path.Pdot(p, s, _) -> `DotT(read_module env p, TypeName.make_std (strip_hash s)) #endif | Path.Papply(_, _)-> assert false #if OCAML_VERSION >= (5,1,0) @@ -758,9 +758,9 @@ module Path = struct #endif | Path.Pident id -> read_type_ident env id #if OCAML_VERSION >= (4,8,0) - | Path.Pdot(p, s) -> `Dot(read_module env p, strip_hash s) + | Path.Pdot(p, s) -> `DotT(read_module env p, TypeName.make_std (strip_hash s)) #else - | Path.Pdot(p, s, _) -> `Dot(read_module env p, strip_hash s) + | Path.Pdot(p, s, _) -> `DotT(read_module env p, TypeName.make_std (strip_hash s)) #endif | Path.Papply(_, _)-> assert false #if OCAML_VERSION >= (5,1,0) @@ -770,9 +770,9 @@ module Path = struct let read_value env = function | Path.Pident id -> read_value_ident env id #if OCAML_VERSION >= (4,8,0) - | Path.Pdot(p, s) -> `Dot(read_module env p, s) + | Path.Pdot(p, s) -> `DotV(read_module env p, ValueName.make_std s) #else - | Path.Pdot(p, s, _) -> `Dot(read_module env p, s) + | Path.Pdot(p, s, _) -> `DotV(read_module env p, ValueName.make_std s) #endif | Path.Papply(_, _) -> assert false #if OCAML_VERSION >= (5,1,0) diff --git a/src/loader/odoc_loader.ml b/src/loader/odoc_loader.ml index 57934686b1..72bb572629 100644 --- a/src/loader/odoc_loader.ml +++ b/src/loader/odoc_loader.ml @@ -167,7 +167,7 @@ let read_cmt ~make_root ~parent ~filename () = Odoc_model.Paths.Identifier.Mk.module_ (id, Odoc_model.Names.ModuleName.make_std name) in - let path = `Root name in + let path = `Root (Odoc_model.Names.ModuleName.make_std name) in { Odoc_model.Lang.Compilation_unit.Packed.id; path }) items in diff --git a/src/model/names.ml b/src/model/names.ml index 206fc71438..80d7b93552 100644 --- a/src/model/names.ml +++ b/src/model/names.ml @@ -43,6 +43,8 @@ module type Name = sig val shadowed_of_ident : Ident.t -> t + val equal_modulo_shadowing : t -> t -> bool + val equal : t -> t -> bool val compare : t -> t -> int @@ -93,6 +95,15 @@ module Name : Name = struct let shadowed_of_ident id = shadowed_of_string (Ident.name id) + let equal_modulo_shadowing (x : t) (y : t) = + match (x, y) with + | Std x, Std y -> x = y + | Hidden x, Std y -> x = y + | Std x, Hidden y -> x = y + | Hidden x, Hidden y -> x = y + | Shadowed (x, i, s), Shadowed (y, j, t) -> x = y && i = j && s = t + | _, _ -> false + let equal (x : t) (y : t) = x = y let compare = compare diff --git a/src/model/names.mli b/src/model/names.mli index 32c05a7aec..9cf8155058 100644 --- a/src/model/names.mli +++ b/src/model/names.mli @@ -43,6 +43,8 @@ module type Name = sig val shadowed_of_ident : Ident.t -> t + val equal_modulo_shadowing : t -> t -> bool + val equal : t -> t -> bool val compare : t -> t -> int diff --git a/src/model/odoc_model.ml b/src/model/odoc_model.ml index 11d3fa1918..f81a5fe1a7 100644 --- a/src/model/odoc_model.ml +++ b/src/model/odoc_model.ml @@ -9,3 +9,4 @@ module Error = Error module Location_ = Location_ module Compat = Compat module Semantics = Semantics +module Reference = Reference diff --git a/src/model/paths.ml b/src/model/paths.ml index a51a6e03f5..5e35def0ab 100644 --- a/src/model/paths.ml +++ b/src/model/paths.ml @@ -715,9 +715,16 @@ module Path = struct | `SubstitutedMT r -> is_path_hidden (r :> any) | `SubstitutedT r -> is_path_hidden (r :> any) | `SubstitutedCT r -> is_path_hidden (r :> any) - | `Root s -> contains_double_underscore s + | `Root s -> ModuleName.is_hidden s | `Forward _ -> false - | `Dot (p, n) -> n.[0] = '{' || is_path_hidden (p : module_ :> any) + | `Dot (p, n) -> + ModuleName.is_hidden n || is_path_hidden (p : module_ :> any) + | `DotMT (p, n) -> + ModuleTypeName.is_hidden n || is_path_hidden (p : module_ :> any) + | `DotT (p, n) -> + TypeName.is_hidden n || is_path_hidden (p : module_ :> any) + | `DotV (p, n) -> + ValueName.is_hidden n || is_path_hidden (p : module_ :> any) | `Apply (p1, p2) -> is_path_hidden (p1 : module_ :> any) || is_path_hidden (p2 : module_ :> any) diff --git a/src/model/paths_types.ml b/src/model/paths_types.ml index 0357355ae5..8d796ee58e 100644 --- a/src/model/paths_types.ml +++ b/src/model/paths_types.ml @@ -321,9 +321,9 @@ module rec Path : sig [ `Resolved of Resolved_path.module_ | `Identifier of Identifier.path_module * bool | `Substituted of module_ - | `Root of string + | `Root of ModuleName.t | `Forward of string - | `Dot of module_ * string + | `Dot of module_ * ModuleName.t | `Apply of module_ * module_ ] (** @canonical Odoc_model.Paths.Path.Module.t *) @@ -331,27 +331,27 @@ module rec Path : sig [ `Resolved of Resolved_path.module_type | `SubstitutedMT of module_type | `Identifier of Identifier.path_module_type * bool - | `Dot of module_ * string ] + | `DotMT of module_ * ModuleTypeName.t ] (** @canonical Odoc_model.Paths.Path.ModuleType.t *) type type_ = [ `Resolved of Resolved_path.type_ | `SubstitutedT of type_ | `Identifier of Identifier.path_type * bool - | `Dot of module_ * string ] + | `DotT of module_ * TypeName.t ] (** @canonical Odoc_model.Paths.Path.Type.t *) type value = [ `Resolved of Resolved_path.value | `Identifier of Identifier.path_value * bool - | `Dot of module_ * string ] + | `DotV of module_ * ValueName.t ] (** @canonical Odoc_model.Paths.Path.Value.t *) type class_type = [ `Resolved of Resolved_path.class_type | `SubstitutedCT of class_type | `Identifier of Identifier.path_class_type * bool - | `Dot of module_ * string ] + | `DotT of module_ * TypeName.t ] (** @canonical Odoc_model.Paths.Path.ClassType.t *) type any = @@ -361,9 +361,12 @@ module rec Path : sig | `Substituted of module_ | `SubstitutedCT of class_type | `Identifier of Identifier.path_any * bool - | `Root of string + | `Root of ModuleName.t | `Forward of string - | `Dot of module_ * string + | `Dot of module_ * ModuleName.t + | `DotT of module_ * TypeName.t + | `DotMT of module_ * ModuleTypeName.t + | `DotV of module_ * ValueName.t | `Apply of module_ * module_ ] (** @canonical Odoc_model.Paths.Path.t *) end = diff --git a/src/model/reference.ml b/src/model/reference.ml index c3162e6692..36c72c7de9 100644 --- a/src/model/reference.ml +++ b/src/model/reference.ml @@ -1,3 +1,5 @@ +type path = [ `Root of string | `Dot of path * string ] + let expected_err : (Format.formatter -> 'a -> unit) -> 'a -> Location_.span -> Error.t = fun pp_a a -> Error.make "Expected %a." pp_a a @@ -536,10 +538,7 @@ let parse whole_reference_location s : should_not_be_empty ~what:"Reference target" whole_reference_location |> Error.raise_exception) -type path = [ `Root of string | `Dot of Paths.Path.Module.t * string ] - let read_path_longident location s = - let open Paths.Path in let rec loop : string -> int -> path option = fun s pos -> try @@ -549,7 +548,7 @@ let read_path_longident location s = else match loop s (idx - 1) with | None -> None - | Some parent -> Some (`Dot ((parent :> Module.t), name)) + | Some parent -> Some (`Dot (parent, name)) with Not_found -> let name = String.sub s 0 (pos + 1) in if String.length name = 0 then None else Some (`Root name) diff --git a/src/model/reference.mli b/src/model/reference.mli index ece1b44e07..4dae92c326 100644 --- a/src/model/reference.mli +++ b/src/model/reference.mli @@ -1,4 +1,4 @@ -type path = [ `Root of string | `Dot of Paths.Path.Module.t * string ] +type path = [ `Root of string | `Dot of path * string ] val parse : Location_.span -> string -> Paths.Reference.t Error.with_errors_and_warnings diff --git a/src/model/semantics.ml b/src/model/semantics.ml index f9c296493d..cc6b14ce60 100644 --- a/src/model/semantics.ml +++ b/src/model/semantics.ml @@ -10,8 +10,7 @@ type internal_tags_removed = type _ handle_internal_tags = | Expect_status : [ `Default | `Inline | `Open | `Closed ] handle_internal_tags - | Expect_canonical - : [ `Dot of Paths.Path.Module.t * string ] option handle_internal_tags + | Expect_canonical : Reference.path option handle_internal_tags | Expect_none : unit handle_internal_tags let describe_internal_tag = function diff --git a/src/model/semantics.mli b/src/model/semantics.mli index 555d27ea08..0a7eeaf015 100644 --- a/src/model/semantics.mli +++ b/src/model/semantics.mli @@ -2,8 +2,7 @@ type _ handle_internal_tags = | Expect_status : [ `Default | `Inline | `Open | `Closed ] handle_internal_tags - | Expect_canonical - : [ `Dot of Paths.Path.Module.t * string ] option handle_internal_tags + | Expect_canonical : Reference.path option handle_internal_tags | Expect_none : unit handle_internal_tags type sections_allowed = [ `All | `No_titles | `None ] diff --git a/src/model_desc/paths_desc.ml b/src/model_desc/paths_desc.ml index 7fd5dd7631..cf929ff03b 100644 --- a/src/model_desc/paths_desc.ml +++ b/src/model_desc/paths_desc.ml @@ -209,9 +209,16 @@ module General_paths = struct | `Resolved x -> C ("`Resolved", x, resolved_path) | `Identifier (x1, x2) -> C ("`Identifier", ((x1 :> id_t), x2), Pair (identifier, bool)) - | `Root x -> C ("`Root", x, string) + | `Root x -> C ("`Root", x, Names.modulename) | `Forward x -> C ("`Forward", x, string) - | `Dot (x1, x2) -> C ("`Dot", ((x1 :> p), x2), Pair (path, string)) + | `Dot (x1, x2) -> + C ("`Dot", ((x1 :> p), x2), Pair (path, Names.modulename)) + | `DotT (x1, x2) -> + C ("`DotT", ((x1 :> p), x2), Pair (path, Names.typename)) + | `DotMT (x1, x2) -> + C ("`DotMT", ((x1 :> p), x2), Pair (path, Names.moduletypename)) + | `DotV (x1, x2) -> + C ("`DotV", ((x1 :> p), x2), Pair (path, Names.valuename)) | `Apply (x1, x2) -> C ("`Apply", ((x1 :> p), (x2 :> p)), Pair (path, path)) | `Substituted m -> C ("`Substituted", (m :> p), path) diff --git a/src/xref2/component.ml b/src/xref2/component.ml index dd34f3561f..2400ed34d6 100644 --- a/src/xref2/component.ml +++ b/src/xref2/component.ml @@ -1181,7 +1181,8 @@ module Fmt = struct fun c ppf p -> match p with | `Resolved p -> wrap c "resolved" resolved_module_path ppf p - | `Dot (p, str) -> Format.fprintf ppf "%a.%s" (module_path c) p str + | `Dot (p, n) -> + Format.fprintf ppf "%a.%a" (module_path c) p ModuleName.fmt n | `Module (p, n) -> Format.fprintf ppf "%a.%a" (resolved_parent_path c) p ModuleName.fmt n | `Apply (p1, p2) -> @@ -1191,7 +1192,7 @@ module Fmt = struct | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b | `Substituted p -> wrap c "substituted" module_path ppf p | `Forward s -> wrap c "forward" str ppf s - | `Root r -> wrap c "unresolvedroot" str ppf r + | `Root r -> wrap c "unresolvedroot" str ppf (ModuleName.to_string r) and resolved_module_type_path : config -> Format.formatter -> Cpath.Resolved.module_type -> unit = @@ -1224,7 +1225,8 @@ module Fmt = struct wrap2 c "identifier" model_identifier bool ppf (id :> id) b | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b | `Substituted s -> wrap c "substituted" module_type_path ppf s - | `Dot (m, s) -> Format.fprintf ppf "%a.%s" (module_path c) m s + | `DotMT (m, s) -> + Format.fprintf ppf "%a.%a" (module_path c) m ModuleTypeName.fmt s | `ModuleType (m, n) -> Format.fprintf ppf "%a.%a" (resolved_parent_path c) m ModuleTypeName.fmt n @@ -1276,7 +1278,8 @@ module Fmt = struct wrap2 c "identifier" model_identifier bool ppf (id :> id) b | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b | `Substituted s -> wrap c "substituted" type_path ppf s - | `Dot (m, s) -> Format.fprintf ppf "%a.%s" (module_path c) m s + | `DotT (m, s) -> + Format.fprintf ppf "%a.%a" (module_path c) m TypeName.fmt s | `Class (p, t) -> Format.fprintf ppf "%a.%s" (resolved_parent_path c) p (TypeName.to_string t) @@ -1291,7 +1294,8 @@ module Fmt = struct fun c ppf p -> match p with | `Resolved r -> wrap c "resolved" resolved_value_path ppf r - | `Dot (m, s) -> Format.fprintf ppf "%a.%s" (module_path c) m s + | `DotV (m, s) -> + Format.fprintf ppf "%a.%a" (module_path c) m ValueName.fmt s | `Value (p, t) -> Format.fprintf ppf "%a.%s" (resolved_parent_path c) p (ValueName.to_string t) @@ -1320,7 +1324,8 @@ module Fmt = struct wrap2 c "identifier" model_identifier bool ppf (id :> id) b | `Local (id, b) -> wrap2 c "local" ident_fmt bool ppf id b | `Substituted s -> wrap c "substituted" class_type_path ppf s - | `Dot (m, s) -> Format.fprintf ppf "%a.%s" (module_path c) m s + | `DotT (m, s) -> + Format.fprintf ppf "%a.%a" (module_path c) m TypeName.fmt s | `Class (p, t) -> Format.fprintf ppf "%a.%s" (resolved_parent_path c) p (TypeName.to_string t) @@ -1330,14 +1335,22 @@ module Fmt = struct and model_path : config -> Format.formatter -> path -> unit = fun c ppf (p : path) -> + let dot p s = + Format.fprintf ppf "%a.%s" (model_path c) + (p : Odoc_model.Paths.Path.Module.t :> path) + s + in + match p with | `Resolved rp -> wrap c "resolved" model_resolved_path ppf rp | `Identifier (id, b) -> wrap2 c "identifier" model_identifier bool ppf (id :> id) b - | `Root s -> wrap c "root" str ppf s + | `Root s -> wrap c "root" str ppf (ModuleName.to_string s) | `Forward s -> wrap c "forward" str ppf s - | `Dot (parent, s) -> - Format.fprintf ppf "%a.%s" (model_path c) (parent :> path) s + | `Dot (p, s) -> dot p (ModuleName.to_string s) + | `DotMT (p, s) -> dot p (ModuleTypeName.to_string s) + | `DotT (p, s) -> dot p (TypeName.to_string s) + | `DotV (p, s) -> dot p (ValueName.to_string s) | `Apply (func, arg) -> Format.fprintf ppf "%a(%a)" (model_path c) (func :> path) @@ -2034,7 +2047,7 @@ module Of_Lang = struct match identifier Maps.ModuleType.find ident_map.module_types i with | `Identifier i -> `Identifier (i, b) | `Local i -> `Local (i, b)) - | `Dot (path', x) -> `Dot (module_path ident_map path', x) + | `DotMT (path', x) -> `DotMT (module_path ident_map path', x) and type_path : _ -> Odoc_model.Paths.Path.Type.t -> Cpath.type_ = fun ident_map p -> @@ -2045,13 +2058,13 @@ module Of_Lang = struct match identifier Maps.Path.Type.find ident_map.path_types i with | `Identifier i -> `Identifier (i, b) | `Local i -> `Local (i, b)) - | `Dot (path', x) -> `Dot (module_path ident_map path', x) + | `DotT (path', x) -> `DotT (module_path ident_map path', x) and value_path : _ -> Odoc_model.Paths.Path.Value.t -> Cpath.value = fun ident_map p -> match p with | `Resolved r -> `Resolved (resolved_value_path ident_map r) - | `Dot (path', x) -> `Dot (module_path ident_map path', x) + | `DotV (path', x) -> `DotV (module_path ident_map path', x) | `Identifier (i, b) -> `Identifier (i, b) and class_type_path : @@ -2066,7 +2079,7 @@ module Of_Lang = struct with | `Identifier i -> `Identifier (i, b) | `Local i -> `Local (i, b)) - | `Dot (path', x) -> `Dot (module_path ident_map path', x) + | `DotT (path', x) -> `DotT (module_path ident_map path', x) let rec resolved_signature_fragment : map -> diff --git a/src/xref2/cpath.ml b/src/xref2/cpath.ml index aeb39c6540..114a626ebc 100644 --- a/src/xref2/cpath.ml +++ b/src/xref2/cpath.ml @@ -54,9 +54,9 @@ and Cpath : sig | `Substituted of module_ | `Local of Ident.path_module * bool | `Identifier of Identifier.Path.Module.t * bool - | `Root of string + | `Root of ModuleName.t | `Forward of string - | `Dot of module_ * string + | `Dot of module_ * ModuleName.t | `Module of Resolved.parent * ModuleName.t (* Like dot, but typed *) | `Apply of module_ * module_ ] @@ -65,7 +65,7 @@ and Cpath : sig | `Substituted of module_type | `Local of Ident.module_type * bool | `Identifier of Identifier.ModuleType.t * bool - | `Dot of module_ * string + | `DotMT of module_ * ModuleTypeName.t | `ModuleType of Resolved.parent * ModuleTypeName.t ] and type_ = @@ -73,14 +73,14 @@ and Cpath : sig | `Substituted of type_ | `Local of Ident.path_type * bool | `Identifier of Odoc_model.Paths.Identifier.Path.Type.t * bool - | `Dot of module_ * string + | `DotT of module_ * TypeName.t | `Type of Resolved.parent * TypeName.t | `Class of Resolved.parent * TypeName.t | `ClassType of Resolved.parent * TypeName.t ] and value = [ `Resolved of Resolved.value - | `Dot of module_ * string + | `DotV of module_ * ValueName.t | `Value of Resolved.parent * ValueName.t | `Identifier of Identifier.Value.t * bool ] @@ -89,7 +89,7 @@ and Cpath : sig | `Substituted of class_type | `Local of Ident.path_class_type * bool | `Identifier of Odoc_model.Paths.Identifier.Path.ClassType.t * bool - | `Dot of module_ * string + | `DotT of module_ * TypeName.t | `Class of Resolved.parent * TypeName.t | `ClassType of Resolved.parent * TypeName.t ] end = @@ -152,7 +152,7 @@ let is_module_type_substituted : module_type -> bool = function | `Identifier _ -> false | `Local _ -> false | `Substituted _ -> true - | `Dot (a, _) -> is_module_substituted a + | `DotMT (a, _) -> is_module_substituted a | `ModuleType (a, _) -> is_resolved_parent_substituted a let is_type_substituted : type_ -> bool = function @@ -160,7 +160,7 @@ let is_type_substituted : type_ -> bool = function | `Identifier _ -> false | `Local _ -> false | `Substituted _ -> true - | `Dot (a, _) -> is_module_substituted a + | `DotT (a, _) -> is_module_substituted a | `Type (a, _) | `Class (a, _) | `ClassType (a, _) -> is_resolved_parent_substituted a @@ -169,7 +169,7 @@ let is_class_type_substituted : class_type -> bool = function | `Identifier _ -> false | `Local _ -> false | `Substituted _ -> true - | `Dot (a, _) -> is_module_substituted a + | `DotT (a, _) -> is_module_substituted a | `Class (a, _) | `ClassType (a, _) -> is_resolved_parent_substituted a let rec is_module_forward : module_ -> bool = function @@ -223,7 +223,7 @@ and is_module_type_hidden : module_type -> bool = function b || ModuleTypeName.is_hidden t | `Local (_, b) -> b | `Substituted p -> is_module_type_hidden p - | `Dot (p, _) -> is_module_hidden p + | `DotMT (p, _) -> is_module_hidden p | `ModuleType (p, _) -> is_resolved_parent_hidden ~weak_canonical_test:false p and is_resolved_module_type_hidden : Resolved.module_type -> bool = function @@ -247,7 +247,7 @@ and is_type_hidden : type_ -> bool = function | `Identifier ({ iv = `CoreType _; _ }, b) -> b | `Local (_, b) -> b | `Substituted p -> is_type_hidden p - | `Dot (p, _) -> is_module_hidden p + | `DotT (p, _) -> is_module_hidden p | `Type (p, _) | `Class (p, _) | `ClassType (p, _) -> is_resolved_parent_hidden ~weak_canonical_test:false p @@ -272,7 +272,7 @@ and is_class_type_hidden : class_type -> bool = function | `Identifier (_, b) -> b | `Local (_, b) -> b | `Substituted p -> is_class_type_hidden p - | `Dot (p, _) -> is_module_hidden p + | `DotT (p, _) -> is_module_hidden p | `Class (p, _) | `ClassType (p, _) -> is_resolved_parent_hidden ~weak_canonical_test:false p @@ -304,13 +304,13 @@ and module_of_module_reference : Reference.Module.t -> module_ = function | `Dot (_, _) | `Module (_, _) ) as parent), name ) -> - `Dot (module_of_module_reference parent, name) + `Dot (module_of_module_reference parent, ModuleName.make_std name) | `Module ( (( `Resolved (`Identifier { iv = #Identifier.Module.t_pv; _ }) | `Dot (_, _) | `Module (_, _) ) as parent), name ) -> - `Dot (module_of_module_reference parent, ModuleName.to_string name) + `Dot (module_of_module_reference parent, name) | _ -> failwith "Not a module reference" let rec unresolve_resolved_module_path : Resolved.module_ -> module_ = function @@ -328,8 +328,7 @@ let rec unresolve_resolved_module_path : Resolved.module_ -> module_ = function | `Substituted x -> unresolve_resolved_module_path x | `Subst (_, x) -> unresolve_resolved_module_path x | `Hidden x -> unresolve_resolved_module_path x (* should assert false here *) - | `Module (p, m) -> - `Dot (unresolve_resolved_parent_path p, ModuleName.to_string m) + | `Module (p, m) -> `Dot (unresolve_resolved_parent_path p, m) | `Canonical (m, _) -> unresolve_resolved_module_path m | `Apply (m, a) -> `Apply (unresolve_resolved_module_path m, unresolve_resolved_module_path a) @@ -345,16 +344,14 @@ and unresolve_module_path : module_ -> module_ = function | `Root _ as x -> x | `Forward _ as x -> x | `Dot (p, x) -> `Dot (unresolve_module_path p, x) - | `Module (p, x) -> - `Dot (unresolve_resolved_parent_path p, ModuleName.to_string x) + | `Module (p, x) -> `Dot (unresolve_resolved_parent_path p, x) | `Apply (x, y) -> `Apply (unresolve_module_path x, unresolve_module_path y) and unresolve_resolved_module_type_path : Resolved.module_type -> module_type = function | (`Local _ | `Gpath _) as p -> `Resolved p | `Substituted x -> unresolve_resolved_module_type_path x - | `ModuleType (p, n) -> - `Dot (unresolve_resolved_parent_path p, ModuleTypeName.to_string n) + | `ModuleType (p, n) -> `DotMT (unresolve_resolved_parent_path p, n) | `SubstT (_, m) -> unresolve_resolved_module_type_path m | `AliasModuleType (_, m2) -> unresolve_resolved_module_type_path m2 | `CanonicalModuleType (p, _) -> unresolve_resolved_module_type_path p @@ -368,20 +365,16 @@ and unresolve_resolved_type_path : Resolved.type_ -> type_ = function | (`Gpath _ | `Local _) as p -> `Resolved p | `Substituted x -> unresolve_resolved_type_path x | `CanonicalType (t1, _) -> unresolve_resolved_type_path t1 - | `Type (p, n) -> `Dot (unresolve_resolved_parent_path p, TypeName.to_string n) - | `Class (p, n) -> - `Dot (unresolve_resolved_parent_path p, TypeName.to_string n) - | `ClassType (p, n) -> - `Dot (unresolve_resolved_parent_path p, TypeName.to_string n) + | `Type (p, n) -> `DotT (unresolve_resolved_parent_path p, n) + | `Class (p, n) -> `DotT (unresolve_resolved_parent_path p, n) + | `ClassType (p, n) -> `DotT (unresolve_resolved_parent_path p, n) and unresolve_resolved_class_type_path : Resolved.class_type -> class_type = function | (`Local _ | `Gpath _) as p -> `Resolved p | `Substituted x -> unresolve_resolved_class_type_path x - | `Class (p, n) -> - `Dot (unresolve_resolved_parent_path p, TypeName.to_string n) - | `ClassType (p, n) -> - `Dot (unresolve_resolved_parent_path p, TypeName.to_string n) + | `Class (p, n) -> `DotT (unresolve_resolved_parent_path p, n) + | `ClassType (p, n) -> `DotT (unresolve_resolved_parent_path p, n) and unresolve_module_type_path : module_type -> module_type = function | `Resolved m -> unresolve_resolved_module_type_path m diff --git a/src/xref2/env.ml b/src/xref2/env.ml index b25c26b9c8..bab13a2d78 100644 --- a/src/xref2/env.ml +++ b/src/xref2/env.ml @@ -30,7 +30,7 @@ let unique_id = type lookup_type = | Module of Paths.Identifier.Path.Module.t | ModuleType of Paths.Identifier.Path.ModuleType.t - | RootModule of string * [ `Forward | `Resolved of Digest.t ] option + | RootModule of ModuleName.t * [ `Forward | `Resolved of Digest.t ] option | ModuleByName of string * Paths.Identifier.Path.Module.t | FragmentRoot of int @@ -50,7 +50,8 @@ let pp_lookup_type fmt = Format.fprintf fmt "ModuleType %a" (Component.Fmt.model_identifier c) (r :> Identifier.t) - | RootModule (str, res) -> Format.fprintf fmt "RootModule %s %a" str fmtrm res + | RootModule (n, res) -> + Format.fprintf fmt "RootModule %a %a" ModuleName.fmt n fmtrm res | ModuleByName (n, r) -> Format.fprintf fmt "ModuleByName %s, %a" n (Component.Fmt.model_identifier c) @@ -402,7 +403,7 @@ let lookup_root_module name env = match env.resolver with | None -> None | Some r -> ( - match r.lookup_unit (`Name name) with + match r.lookup_unit (`Name (ModuleName.to_string name)) with | Ok Forward_reference -> Some Forward | Error `Not_found -> None | Ok (Found u) -> @@ -516,7 +517,7 @@ let lookup_by_id (scope : 'a scope) id env : 'a option = | _ -> None) let lookup_root_module_fallback name t = - match lookup_root_module name t with + match lookup_root_module (ModuleName.make_std name) t with | Some (Resolved (_, id, m)) -> Some (`Module @@ -866,7 +867,7 @@ let verify_lookups env lookups = match env.resolver with | None -> None | Some r -> ( - match r.lookup_unit (`Name name) with + match r.lookup_unit (`Name (ModuleName.to_string name)) with | Ok Forward_reference -> Some `Forward | Ok (Found u) -> Some (`Resolved u.root.digest) | Error `Not_found -> None) diff --git a/src/xref2/env.mli b/src/xref2/env.mli index 380efa5256..d9c460f1f2 100644 --- a/src/xref2/env.mli +++ b/src/xref2/env.mli @@ -24,7 +24,9 @@ type root = type lookup_type = | Module of Identifier.Path.Module.t | ModuleType of Identifier.ModuleType.t - | RootModule of string * [ `Forward | `Resolved of Digest.t ] option + | RootModule of + Odoc_model.Names.ModuleName.t + * [ `Forward | `Resolved of Digest.t ] option | ModuleByName of string * Identifier.Path.Module.t | FragmentRoot of int @@ -102,7 +104,7 @@ val lookup_unit_by_path : val module_of_unit : Lang.Compilation_unit.t -> Component.Module.t -val lookup_root_module : string -> t -> root option +val lookup_root_module : Odoc_model.Names.ModuleName.t -> t -> root option type 'a scope constraint 'a = [< Component.Element.any ] (** Target of a lookup *) diff --git a/src/xref2/errors.ml b/src/xref2/errors.ml index 3c06680cc3..cfe7d6e911 100644 --- a/src/xref2/errors.ml +++ b/src/xref2/errors.ml @@ -1,5 +1,5 @@ open Odoc_model - +open Names module Tools_error = struct open Paths (** Errors raised by Tools *) @@ -43,7 +43,7 @@ module Tools_error = struct `Lookup_failure of Identifier.Path.Module.t (* Could not find the module in the environment *) - | `Lookup_failure_root of string (* Could not find the root module *) + | `Lookup_failure_root of ModuleName.t (* Could not find the root module *) | `Parent of parent_lookup_error ] and simple_module_type_expr_of_module_error = @@ -213,7 +213,7 @@ module Tools_error = struct Format.fprintf fmt "Lookup failure (module): %a" (model_identifier c) (m :> Odoc_model.Paths.Identifier.t) | `Lookup_failure_root r -> - Format.fprintf fmt "Lookup failure (root module): %s" r + Format.fprintf fmt "Lookup failure (root module): %a" ModuleName.fmt r | `Lookup_failureMT m -> Format.fprintf fmt "Lookup failure (module type): %a" (model_identifier c) @@ -255,7 +255,7 @@ end type kind = [ `OpaqueModule | `Root of string ] let rec kind_of_module_cpath = function - | `Root name -> Some (`Root name) + | `Root name -> Some (`Root (ModuleName.to_string name)) | `Substituted p' | `Dot (p', _) -> kind_of_module_cpath p' | `Apply (a, b) -> ( match kind_of_module_cpath a with @@ -265,7 +265,7 @@ let rec kind_of_module_cpath = function let rec kind_of_module_type_cpath = function | `Substituted p' -> kind_of_module_type_cpath p' - | `Dot (p', _) -> kind_of_module_cpath p' + | `DotMT (p', _) -> kind_of_module_cpath p' | _ -> None (** [Some (`Root _)] for errors during lookup of root modules or [None] for @@ -280,8 +280,8 @@ let rec kind_of_error : Tools_error.any -> kind option = function | None -> kind_of_error (e :> Tools_error.any) | x -> x) | `Lookup_failure { iv = `Root (_, name); _ } -> - Some (`Root (Names.ModuleName.to_string name)) - | `Lookup_failure_root name -> Some (`Root name) + Some (`Root (ModuleName.to_string name)) + | `Lookup_failure_root name -> Some (`Root (ModuleName.to_string name)) | `Parent (`Parent_sig e) -> kind_of_error (e :> Tools_error.any) | `Parent (`Parent_module_type e) -> kind_of_error (e :> Tools_error.any) | `Parent (`Parent_expr e) -> kind_of_error (e :> Tools_error.any) @@ -303,7 +303,7 @@ let kind_of_error ~what = function match what with | `Include (Component.Include.Alias cp) -> kind_of_module_cpath cp | `Module { Odoc_model.Paths.Identifier.iv = `Root (_, name); _ } -> - Some (`Root (Names.ModuleName.to_string name)) + Some (`Root (ModuleName.to_string name)) | _ -> None) open Paths diff --git a/src/xref2/find.ml b/src/xref2/find.ml index bf2491e9a0..77dc564bca 100644 --- a/src/xref2/find.ml +++ b/src/xref2/find.ml @@ -93,23 +93,29 @@ let rec disambiguate = function let module_in_sig sg name = find_in_sig sg (function - | Signature.Module (id, _, m) when N.module_ id = name -> + | Signature.Module (id, _, m) + when ModuleName.equal_modulo_shadowing (N.typed_module id) name -> Some (`FModule (N.typed_module id, Delayed.get m)) | _ -> None) let module_type_in_sig sg name = find_in_sig sg (function - | Signature.ModuleType (id, mt) when N.module_type id = name -> + | Signature.ModuleType (id, mt) + when ModuleTypeName.equal_modulo_shadowing (N.typed_module_type id) name + -> Some (`FModuleType (N.typed_module_type id, Delayed.get mt)) | _ -> None) let type_in_sig sg name = find_in_sig sg (function - | Signature.Type (id, _, m) when N.type_ id = name -> - Some (`FType (N.type' id, Delayed.get m)) - | Class (id, _, c) when N.class_ id = name -> + | Signature.Type (id, _, m) + when TypeName.equal_modulo_shadowing (N.typed_type id) name -> + Some (`FType (N.typed_type id, Delayed.get m)) + | Class (id, _, c) + when TypeName.equal_modulo_shadowing (N.typed_class id) name -> Some (`FClass (N.class' id, c)) - | ClassType (id, _, c) when N.class_type id = name -> + | ClassType (id, _, c) + when TypeName.equal_modulo_shadowing (N.typed_class_type id) name -> Some (`FClassType (N.class_type' id, c)) | _ -> None) @@ -127,7 +133,8 @@ type careful_class = [ class_ | removed_type ] let careful_module_in_sig sg name = let removed_module = function - | Signature.RModule (id, p) when ModuleName.to_string id = name -> + | Signature.RModule (id, p) when ModuleName.equal_modulo_shadowing id name + -> Some (`FModule_removed p) | _ -> None in @@ -137,7 +144,8 @@ let careful_module_in_sig sg name = let careful_module_type_in_sig sg name = let removed_module_type = function - | Signature.RModuleType (id, p) when ModuleTypeName.to_string id = name -> + | Signature.RModuleType (id, p) + when ModuleTypeName.equal_modulo_shadowing id name -> Some (`FModuleType_removed p) | _ -> None in @@ -147,7 +155,7 @@ let careful_module_type_in_sig sg name = let removed_type_in_sig sg name = let removed_type = function - | Signature.RType (id, p, eq) when TypeName.to_string id = name -> + | Signature.RType (id, p, eq) when id = name -> Some (`FType_removed (id, p, eq)) | _ -> None in @@ -160,15 +168,18 @@ let careful_type_in_sig sg name = let datatype_in_sig sg name = find_in_sig sg (function - | Signature.Type (id, _, t) when N.type_ id = name -> + | Signature.Type (id, _, t) + when TypeName.equal_modulo_shadowing (N.typed_type id) name -> Some (`FType (N.type' id, Component.Delayed.get t)) | _ -> None) let class_in_sig sg name = filter_in_sig sg (function - | Signature.Class (id, _, c) when N.class_ id = name -> + | Signature.Class (id, _, c) + when TypeName.equal_modulo_shadowing (N.typed_class id) name -> Some (`FClass (N.class' id, c)) - | Signature.ClassType (id, _, c) when N.class_type id = name -> + | Signature.ClassType (id, _, c) + when TypeName.equal_modulo_shadowing (N.typed_class_type id) name -> Some (`FClassType (N.class_type' id, c)) | _ -> None) @@ -226,7 +237,7 @@ let any_in_comment d name = match xs with | elt :: rest -> ( match elt.Odoc_model.Location_.value with - | `Heading lbl when Ident.Name.label lbl.Label.label = name -> + | `Heading lbl when Ident.Name.typed_label lbl.Label.label = name -> Some (`FLabel lbl) | _ -> inner rest) | [] -> None @@ -258,7 +269,7 @@ let any_in_sig sg name = | Some r -> Some (`In_type (N.type' id, typ, r)) | None -> None) | TypExt typext -> any_in_typext typext name - | Comment (`Docs d) -> any_in_comment d name + | Comment (`Docs d) -> any_in_comment d (LabelName.make_std name) | _ -> None) let signature_in_sig sg name = @@ -271,21 +282,23 @@ let signature_in_sig sg name = let module_type_in_sig sg name = find_in_sig sg (function - | Signature.ModuleType (id, m) when N.module_type id = name -> + | Signature.ModuleType (id, m) + when ModuleTypeName.equal_modulo_shadowing (N.typed_module_type id) name + -> Some (`FModuleType (N.typed_module_type id, Delayed.get m)) | _ -> None) let value_in_sig sg name = - filter_in_sig sg (function + find_in_sig sg (function | Signature.Value (id, m) - when N.value id = name || N.value id = "(" ^ name ^ ")" -> + when ValueName.equal_modulo_shadowing (N.typed_value id) name + || ValueName.to_string (N.typed_value id) + = "(" ^ ValueName.to_string name ^ ")" -> (* For operator, the value will have name [()]. We match that even with name []. *) Some (`FValue (N.typed_value id, Delayed.get m)) | _ -> None) -let value_in_sig_unambiguous sg name = disambiguate (value_in_sig sg name) - let label_in_sig sg name = filter_in_sig sg (function | Signature.Comment (`Docs d) -> any_in_comment d name @@ -293,13 +306,15 @@ let label_in_sig sg name = let exception_in_sig sg name = find_in_sig sg (function - | Signature.Exception (id, e) when N.exception_ id = name -> + | Signature.Exception (id, e) when N.typed_exception id = name -> Some (`FExn (N.typed_exception id, e)) | _ -> None) let extension_in_sig sg name = let rec inner t = function - | ec :: _ when ec.Extension.Constructor.name = name -> Some (`FExt (t, ec)) + | ec :: _ when ec.Extension.Constructor.name = ExtensionName.to_string name + -> + Some (`FExt (t, ec)) | _ :: tl -> inner t tl | [] -> None in @@ -355,13 +370,13 @@ let any_in_class_signature cs name = let method_in_class_signature cs name = find_in_class_signature cs (function - | ClassSignature.Method (id, m) when N.method_ id = name -> - Some (`FMethod (N.typed_method id, m)) + | ClassSignature.Method (id, m) when N.typed_method id = name -> + Some (`FMethod (name, m)) | _ -> None) let instance_variable_in_class_signature cs name = find_in_class_signature cs (function | ClassSignature.InstanceVariable (id, iv) - when N.instance_variable id = name -> - Some (`FInstance_variable (N.typed_instance_variable id, iv)) + when N.typed_instance_variable id = name -> + Some (`FInstance_variable (name, iv)) | _ -> None) diff --git a/src/xref2/find.mli b/src/xref2/find.mli index a62f492a0d..33045ef4e9 100644 --- a/src/xref2/find.mli +++ b/src/xref2/find.mli @@ -59,36 +59,37 @@ type any_in_class_sig = [ instance_variable | method_ ] (** Lookup by name, unambiguous *) -val module_in_sig : Signature.t -> string -> module_ option +val module_in_sig : Signature.t -> ModuleName.t -> module_ option -val type_in_sig : Signature.t -> string -> type_ option +val type_in_sig : Signature.t -> TypeName.t -> type_ option -val datatype_in_sig : Signature.t -> string -> datatype option +val datatype_in_sig : Signature.t -> TypeName.t -> datatype option -val module_type_in_sig : Signature.t -> string -> module_type option +val module_type_in_sig : Signature.t -> ModuleTypeName.t -> module_type option -val exception_in_sig : Signature.t -> string -> exception_ option +val exception_in_sig : Signature.t -> ExceptionName.t -> exception_ option -val extension_in_sig : Signature.t -> string -> extension option +val extension_in_sig : Signature.t -> ExtensionName.t -> extension option val any_in_type : TypeDecl.t -> string -> any_in_type option val any_in_typext : Extension.t -> string -> extension option -val method_in_class_signature : ClassSignature.t -> string -> method_ option +val value_in_sig : Signature.t -> ValueName.t -> value option + +val method_in_class_signature : + ClassSignature.t -> MethodName.t -> method_ option val instance_variable_in_class_signature : - ClassSignature.t -> string -> instance_variable option + ClassSignature.t -> InstanceVariableName.t -> instance_variable option (** Maybe ambiguous *) -val class_in_sig : Signature.t -> string -> class_ list +val class_in_sig : Signature.t -> TypeName.t -> class_ list val signature_in_sig : Signature.t -> string -> signature list -val value_in_sig : Signature.t -> string -> value list - -val label_in_sig : Signature.t -> string -> label list +val label_in_sig : Signature.t -> LabelName.t -> label list val label_parent_in_sig : Signature.t -> string -> label_parent list @@ -100,9 +101,7 @@ val any_in_class_signature : ClassSignature.t -> string -> any_in_class_sig list (** Disambiguated lookups, returns the last match. *) -val class_in_sig_unambiguous : Signature.t -> string -> class_ option - -val value_in_sig_unambiguous : Signature.t -> string -> value option +val class_in_sig_unambiguous : Signature.t -> TypeName.t -> class_ option (** Lookup removed items *) @@ -118,11 +117,11 @@ type careful_type = [ type_ | removed_type ] type careful_class = [ class_ | removed_type ] -val careful_module_in_sig : Signature.t -> string -> careful_module option +val careful_module_in_sig : Signature.t -> ModuleName.t -> careful_module option val careful_module_type_in_sig : - Signature.t -> string -> careful_module_type option + Signature.t -> ModuleTypeName.t -> careful_module_type option -val careful_type_in_sig : Signature.t -> string -> careful_type option +val careful_type_in_sig : Signature.t -> TypeName.t -> careful_type option -val careful_class_in_sig : Signature.t -> string -> careful_class option +val careful_class_in_sig : Signature.t -> TypeName.t -> careful_class option diff --git a/src/xref2/lang_of.ml b/src/xref2/lang_of.ml index ec69a28849..774b66d563 100644 --- a/src/xref2/lang_of.ml +++ b/src/xref2/lang_of.ml @@ -80,8 +80,7 @@ module Path = struct | `Dot (p, s) -> `Dot (module_ map p, s) | `Forward s -> `Forward s | `Apply (m1, m2) -> `Apply (module_ map m1, module_ map m2) - | `Module (`Module p, n) -> - `Dot (`Resolved (resolved_module map p), ModuleName.to_string n) + | `Module (`Module p, n) -> `Dot (`Resolved (resolved_module map p), n) | `Module (_, _) -> failwith "Probably shouldn't happen" and module_type map (p : Cpath.module_type) : @@ -98,9 +97,8 @@ module Path = struct failwith (Format.asprintf "Not_found: %a" Ident.fmt id)), b ) | `Resolved x -> `Resolved (resolved_module_type map x) - | `Dot (p, n) -> `Dot (module_ map p, n) - | `ModuleType (`Module p, n) -> - `Dot (`Resolved (resolved_module map p), ModuleTypeName.to_string n) + | `DotMT (p, n) -> `DotMT (module_ map p, n) + | `ModuleType (`Module p, n) -> `DotMT (`Resolved (resolved_module map p), n) | `ModuleType (_, _) -> failwith "Probably shouldn't happen" and type_ map (p : Cpath.type_) : Odoc_model.Paths.Path.Type.t = @@ -112,13 +110,10 @@ module Path = struct | `Local (id, b) -> `Identifier (Component.PathTypeMap.find id map.path_type, b) | `Resolved x -> `Resolved (resolved_type map x) - | `Dot (p, n) -> `Dot (module_ map p, n) - | `Type (`Module p, n) -> - `Dot (`Resolved (resolved_module map p), TypeName.to_string n) - | `Class (`Module p, n) -> - `Dot (`Resolved (resolved_module map p), TypeName.to_string n) - | `ClassType (`Module p, n) -> - `Dot (`Resolved (resolved_module map p), TypeName.to_string n) + | `DotT (p, n) -> `DotT (module_ map p, n) + | `Type (`Module p, n) -> `DotT (`Resolved (resolved_module map p), n) + | `Class (`Module p, n) -> `DotT (`Resolved (resolved_module map p), n) + | `ClassType (`Module p, n) -> `DotT (`Resolved (resolved_module map p), n) | `Type _ | `Class _ | `ClassType _ -> failwith "Probably shouldn't happen" and class_type map (p : Cpath.class_type) : Odoc_model.Paths.Path.ClassType.t @@ -132,11 +127,9 @@ module Path = struct | `Local (id, b) -> `Identifier (Component.PathClassTypeMap.find id map.path_class_type, b) | `Resolved x -> `Resolved (resolved_class_type map x) - | `Dot (p, n) -> `Dot (module_ map p, n) - | `Class (`Module p, n) -> - `Dot (`Resolved (resolved_module map p), TypeName.to_string n) - | `ClassType (`Module p, n) -> - `Dot (`Resolved (resolved_module map p), TypeName.to_string n) + | `DotT (p, n) -> `DotT (module_ map p, n) + | `Class (`Module p, n) -> `DotT (`Resolved (resolved_module map p), n) + | `ClassType (`Module p, n) -> `DotT (`Resolved (resolved_module map p), n) | `Class _ | `ClassType _ -> failwith "Probably shouldn't happen" and resolved_module map (p : Cpath.Resolved.module_) : diff --git a/src/xref2/link.ml b/src/xref2/link.ml index f0291a0c35..e25cbd68ca 100644 --- a/src/xref2/link.ml +++ b/src/xref2/link.ml @@ -1116,7 +1116,11 @@ let page env page = | Error `Not_found -> Errors.report ~what:(`Child_page page) `Lookup ) | Page.Module_child mod_ -> ( - match Env.lookup_root_module mod_ env with + match + Env.lookup_root_module + (Odoc_model.Names.ModuleName.make_std mod_) + env + with | Some _ -> () | None -> Errors.report ~what:(`Child_module mod_) `Lookup)) page.Lang.Page.children diff --git a/src/xref2/paths.md b/src/xref2/paths.md index 057f848604..8d50064b39 100644 --- a/src/xref2/paths.md +++ b/src/xref2/paths.md @@ -266,7 +266,7 @@ and now we can get the paths for all three type declarations: false) # Common.LangUtils.Lens.(get (Signature.module_ "M" |-- mod_sig |-- type_constr_path "x2") sg);; - : Odoc_model.Paths.Path.Type.t = -`Dot +`DotT (`Identifier ({Odoc_model__Paths_types.iv = `Module @@ -284,10 +284,10 @@ and now we can get the paths for all three type declarations: N); ihash = 1041581453; ikey = "m_N.m_M.r_Root.p_None"}, false), - "t") + t) # Common.LangUtils.Lens.(get (type_constr_path "x3") sg);; - : Odoc_model.Paths.Path.Type.t = -`Dot +`DotT (`Dot (`Identifier ({Odoc_model__Paths_types.iv = @@ -302,8 +302,8 @@ and now we can get the paths for all three type declarations: M); ihash = 716453475; ikey = "m_M.r_Root.p_None"}, false), - "N"), - "t") + N), + t) ``` We can resolve the paths: diff --git a/src/xref2/ref_tools.ml b/src/xref2/ref_tools.ml index bed565f0d5..3b66a97fc3 100644 --- a/src/xref2/ref_tools.ml +++ b/src/xref2/ref_tools.ml @@ -143,10 +143,10 @@ let find_ambiguous ?(kind = `Any) find sg name = Ok x | [] -> Error (`Find_by_name (kind, name)) -let find find sg name = +let find find sg conv name = match find sg name with | Some x -> Ok x - | None -> Error (`Find_by_name (`Any, name)) + | None -> Error (`Find_by_name (`Any, (conv name : string))) let module_lookup_to_signature_lookup env (ref, cp, m) = let rec handle_expansion : Tools.expansion -> _ = function @@ -206,7 +206,8 @@ module M = struct = let parent_cp = Tools.reresolve_parent env parent_cp in let sg = Tools.prefix_signature (parent_cp, sg) in - find Find.module_in_sig sg name >>= fun (`FModule (name, m)) -> + find Find.module_in_sig sg ModuleName.to_string name + >>= fun (`FModule (name, m)) -> Ok (of_component env m (`Module (parent_cp, name)) (`Module (parent, name))) let of_element env (`Module (id, m)) : t = @@ -217,7 +218,10 @@ module M = struct let in_env env name = match env_lookup_by_name Env.s_module name env with | Ok e -> Ok (of_element env e) - | Error _ -> Error (`Parent (`Parent_module (`Lookup_failure_root name))) + | Error _ -> + Error + (`Parent + (`Parent_module (`Lookup_failure_root (ModuleName.make_std name)))) end module Path = struct @@ -268,7 +272,8 @@ module MT = struct let in_signature env ((parent', parent_cp, sg) : signature_lookup_result) name = let sg = Tools.prefix_signature (parent_cp, sg) in - find Find.module_type_in_sig sg name >>= fun (`FModuleType (name, mt)) -> + find Find.module_type_in_sig sg ModuleTypeName.to_string name + >>= fun (`FModuleType (name, mt)) -> Ok (of_component env mt (`ModuleType (parent_cp, name)) @@ -325,7 +330,7 @@ module DT = struct let in_signature _env ((parent', parent_cp, sg) : signature_lookup_result) name = let sg = Tools.prefix_signature (parent_cp, sg) in - find Find.datatype_in_sig sg name >>= function + find Find.datatype_in_sig sg TypeName.to_string name >>= function | `FType (name, t) -> Ok (`T (`Type (parent', name), t)) end @@ -346,7 +351,7 @@ module T = struct let in_signature _env ((parent', parent_cp, sg) : signature_lookup_result) name = let sg = Tools.prefix_signature (parent_cp, sg) in - find Find.type_in_sig sg name >>= function + find Find.type_in_sig sg TypeName.to_string name >>= function | `FType (name, t) -> Ok (`T (`Type (parent', name), t)) | `FClass (name, c) -> Ok (`C (`Class (parent', name), c)) | `FClassType (name, ct) -> Ok (`CT (`ClassType (parent', name), ct)) @@ -363,9 +368,9 @@ module V = struct let of_component _env ~parent_ref name = Ok (`Value (parent_ref, name)) - let in_signature _env ((parent', _, sg) : signature_lookup_result) name = - find_ambiguous ~kind:`S Find.value_in_sig sg (ValueName.to_string name) - >>= fun _ -> Ok (`Value (parent', name)) + let in_signature _env ((parent, _, sg) : signature_lookup_result) name = + find Find.value_in_sig sg ValueName.to_string name >>= function + | `FValue (name, _) -> Ok (`Value (parent, name)) end module L = struct @@ -403,8 +408,9 @@ module L = struct let in_label_parent env (parent : label_parent_lookup_result) name = match parent with | `S (p, _, sg) -> ( - find_ambiguous ~kind:`Label Find.label_in_sig sg - (LabelName.to_string name) + find_ambiguous ~kind:`Label + (fun sg l -> Find.label_in_sig sg (LabelName.make_std l)) + sg (LabelName.to_string name) >>= function | `FLabel lbl -> Ok (`Label ((p :> Resolved.LabelParent.t), name), lbl.text)) @@ -427,7 +433,7 @@ module EC = struct let in_signature _env ((parent', parent_cp, sg) : signature_lookup_result) name = let sg = Tools.prefix_signature (parent_cp, sg) in - find Find.extension_in_sig sg (ExtensionName.to_string name) >>= fun _ -> + find Find.extension_in_sig sg ExtensionName.to_string name >>= fun _ -> Ok (`Extension (parent', name)) end @@ -452,7 +458,7 @@ module ED = struct let in_signature _env ((parent', parent_cp, sg) : signature_lookup_result) name = let sg = Tools.prefix_signature (parent_cp, sg) in - find Find.extension_in_sig sg (ExtensionName.to_string name) + find Find.extension_in_sig sg ExtensionName.to_string name >>= fun (`FExt (ext, _) : Find.extension) -> (* Type extensions always have at least 1 constructor. The reference to the type extension shares the same name as the first constructor. *) @@ -476,7 +482,7 @@ module EX = struct let in_signature _env ((parent', parent_cp, sg) : signature_lookup_result) name = let sg = Tools.prefix_signature (parent_cp, sg) in - find Find.exception_in_sig sg (ExceptionName.to_string name) >>= fun _ -> + find Find.exception_in_sig sg ExceptionName.to_string name >>= fun _ -> Ok (`Exception (parent', name)) end @@ -525,7 +531,7 @@ module CS = struct | `In_type (typ_name, _, `FConstructor _) -> Ok (`Constructor (`Type (parent', typ_name), name))) | `T (parent', t) -> ( - find Find.any_in_type t name_s >>= function + find Find.any_in_type t (fun x -> x) name_s >>= function | `FField _ -> got_a_field name_s | `FPoly cs -> Ok @@ -572,7 +578,7 @@ module F = struct (`Field ((`Type (parent', typ_name) :> Resolved.FieldParent.t), name))) | `T (parent', t) -> ( - find Find.any_in_type t name_s >>= function + find Find.any_in_type t (fun x -> x) name_s >>= function | `FConstructor _ -> got_a_constructor name_s | `FPoly _ -> got_a_constructor name_s | `FField _ -> Ok (`Field ((parent' :> Resolved.FieldParent.t), name))) @@ -593,7 +599,7 @@ module MM = struct let in_env _env name : t ref_result = Error (`Lookup_by_name (`Any, name)) let in_class_signature _env (parent', cs) name = - find Find.method_in_class_signature cs (MethodName.to_string name) + find Find.method_in_class_signature cs MethodName.to_string name >>= fun _ -> Ok (`Method (parent', name)) let of_component _env parent' name = Ok (`Method (parent', name)) @@ -609,7 +615,7 @@ module MV = struct let in_class_signature _env (parent', cs) name = find Find.instance_variable_in_class_signature cs - (InstanceVariableName.to_string name) + InstanceVariableName.to_string name >>= fun _ -> Ok (`InstanceVariable (parent', name)) let of_component _env parent' name = Ok (`InstanceVariable (parent', name)) @@ -683,19 +689,16 @@ let rec resolve_label_parent_reference env (r : LabelParent.t) = | `Root (name, `TType) -> T.in_env env name >>= label_parent_res_of_type_res | `Type (parent, name) -> resolve_signature_reference env parent >>= fun p -> - T.in_signature env p (TypeName.to_string name) - >>= label_parent_res_of_type_res + T.in_signature env p name >>= label_parent_res_of_type_res | `Root (name, `TClass) -> CL.in_env env name >>= fun r -> Ok (`C r) | `Class (parent, name) -> resolve_signature_reference env parent >>= fun p -> - T.in_signature env p (TypeName.to_string name) - >>= class_lookup_result_of_type - >>= fun r -> Ok (`C r) + T.in_signature env p name >>= class_lookup_result_of_type >>= fun r -> + Ok (`C r) | `Root (name, `TClassType) -> CT.in_env env name >>= fun r -> Ok (`CT r) | `ClassType (parent, name) -> resolve_signature_reference env parent >>= fun p -> - T.in_signature env p (TypeName.to_string name) - >>= class_type_lookup_result_of_type + T.in_signature env p name >>= class_type_lookup_result_of_type >>= fun r -> Ok (`CT r) | `Dot (parent, name) -> resolve_label_parent_reference env parent @@ -728,11 +731,11 @@ and resolve_fragment_type_parent_reference (env : Env.t) DT.in_env env name >>= fragment_type_parent_res_of_type_res | `Type (parent, name) -> resolve_signature_reference env parent >>= fun p -> - DT.in_signature env p (TypeName.to_string name) + DT.in_signature env p name | `Dot (parent, name) -> resolve_label_parent_reference env parent >>= signature_lookup_result_of_label_parent - >>= fun p -> DT.in_signature env p name + >>= fun p -> DT.in_signature env p (TypeName.make_std name) | `Module_path p -> Path.module_in_env env p >>= module_lookup_to_signature_lookup env >>= fun r -> Ok (`S r) @@ -749,13 +752,12 @@ and resolve_signature_reference : M.in_env env name >>= module_lookup_to_signature_lookup env | `Module (parent, name) -> resolve_signature_reference env parent >>= fun p -> - M.in_signature env p (ModuleName.to_string name) - >>= module_lookup_to_signature_lookup env + M.in_signature env p name >>= module_lookup_to_signature_lookup env | `Root (name, `TModuleType) -> MT.in_env env name >>= module_type_lookup_to_signature_lookup env | `ModuleType (parent, name) -> resolve_signature_reference env parent >>= fun p -> - MT.in_signature env p (ModuleTypeName.to_string name) + MT.in_signature env p name >>= module_type_lookup_to_signature_lookup env | `Root (name, `TUnknown) -> ( env_lookup_by_name Env.s_signature name env >>= function @@ -792,10 +794,10 @@ and resolve_module_reference env (r : Module.t) : M.t ref_result = | `Dot (parent, name) -> resolve_label_parent_reference env parent >>= signature_lookup_result_of_label_parent - >>= fun p -> M.in_signature env p name + >>= fun p -> M.in_signature env p (ModuleName.make_std name) | `Module (parent, name) -> resolve_signature_reference env parent >>= fun p -> - M.in_signature env p (ModuleName.to_string name) + M.in_signature env p name | `Root (name, _) -> M.in_env env name | `Module_path p -> Path.module_in_env env p @@ -860,7 +862,7 @@ let resolve_reference_dot_page env page name = L.in_page env page name >>= resolved_with_text let resolve_reference_dot_type env ~parent_ref t name = - find Find.any_in_type t name >>= function + find Find.any_in_type t (fun x -> x) name >>= function | `FConstructor _ -> CS.of_component env parent_ref name >>= resolved1 | `FPoly p -> CS.poly_of_component env parent_ref p.name >>= resolved1 | `FField _ -> F.of_component env parent_ref name >>= resolved1 @@ -881,7 +883,12 @@ let resolve_reference_dot env parent name = | `P _ as page -> resolve_reference_dot_page env page name (** Warnings may be generated with [Error.implicit_warning] *) -let resolve_reference : _ -> Reference.t -> _ = +let resolve_reference : + Env.t -> + Reference.t -> + ( Reference.Resolved.t * Odoc_model.Comment.paragraph option, + Errors.Tools_error.reference_lookup_error ) + result = let resolved = resolved3 in fun env r -> match r with @@ -911,25 +918,24 @@ let resolve_reference : _ -> Reference.t -> _ = | `Root (name, (`TModule | `TChildModule)) -> M.in_env env name >>= resolved | `Module (parent, name) -> resolve_signature_reference env parent >>= fun p -> - M.in_signature env p (ModuleName.to_string name) >>= resolved + M.in_signature env p name >>= resolved | `Root (name, `TModuleType) -> MT.in_env env name >>= resolved | `ModuleType (parent, name) -> resolve_signature_reference env parent >>= fun p -> - MT.in_signature env p (ModuleTypeName.to_string name) >>= resolved + MT.in_signature env p name >>= resolved | `Root (name, `TType) -> T.in_env env name >>= resolved_type_lookup | `Type (parent, name) -> resolve_signature_reference env parent >>= fun p -> - T.in_signature env p (TypeName.to_string name) >>= resolved_type_lookup + T.in_signature env p name >>= resolved_type_lookup | `Root (name, `TClass) -> CL.in_env env name >>= resolved2 | `Class (parent, name) -> resolve_signature_reference env parent >>= fun p -> - T.in_signature env p (TypeName.to_string name) - >>= class_lookup_result_of_type >>= resolved2 + T.in_signature env p name >>= class_lookup_result_of_type >>= resolved2 | `Root (name, `TClassType) -> CT.in_env env name >>= resolved2 | `ClassType (parent, name) -> resolve_signature_reference env parent >>= fun p -> - T.in_signature env p (TypeName.to_string name) - >>= class_type_lookup_result_of_type >>= resolved2 + T.in_signature env p name >>= class_type_lookup_result_of_type + >>= resolved2 | `Root (name, `TValue) -> V.in_env env name >>= resolved1 | `Value (parent, name) -> resolve_signature_reference env parent >>= fun p -> diff --git a/src/xref2/shape_tools.cppo.ml b/src/xref2/shape_tools.cppo.ml index e59ff543be..74b8519a08 100644 --- a/src/xref2/shape_tools.cppo.ml +++ b/src/xref2/shape_tools.cppo.ml @@ -67,7 +67,7 @@ let rec shape_of_module_path env : _ -> Shape.t option = match path with | `Resolved _ -> None | `Root name -> ( - match Env.lookup_impl name env with + match Env.lookup_impl (ModuleName.to_string name) env with | Some impl -> ( match impl.shape_info with | Some (shape, _) -> Some shape @@ -75,7 +75,7 @@ let rec shape_of_module_path env : _ -> Shape.t option = | _ -> None) | `Forward _ -> None | `Dot (parent, name) -> - proj (parent :> Odoc_model.Paths.Path.Module.t) Kind.Module name + proj (parent :> Odoc_model.Paths.Path.Module.t) Kind.Module (ModuleName.to_string_unsafe name) | `Apply (parent, arg) -> shape_of_module_path env (parent :> Odoc_model.Paths.Path.Module.t) >>= fun parent -> @@ -87,7 +87,7 @@ let rec shape_of_module_path env : _ -> Shape.t option = shape_of_module_path env m let rec shape_of_kind_path env kind : - _ -> Shape.t option = + Odoc_model.Paths.Path.t -> Shape.t option = let proj parent kind name = let item = Shape.Item.make name kind in match shape_of_module_path env parent with @@ -97,12 +97,19 @@ let rec shape_of_kind_path env kind : fun path -> match path with | `Resolved _ -> None - | `Dot (parent, name) -> proj parent kind name - | `SubstitutedT t -> shape_of_kind_path env kind t - | `SubstitutedMT t -> shape_of_kind_path env kind t - | `SubstitutedCT t -> shape_of_kind_path env kind t + | `DotT (parent, name) -> proj parent kind (TypeName.to_string_unsafe name) + | `DotMT (parent, name) -> proj parent kind (ModuleTypeName.to_string_unsafe name) + | `DotV (parent, name) -> proj parent kind (ValueName.to_string_unsafe name) + | `SubstitutedT t -> shape_of_kind_path env kind (t :> Odoc_model.Paths.Path.t) + | `SubstitutedMT t -> shape_of_kind_path env kind (t :> Odoc_model.Paths.Path.t) + | `SubstitutedCT t -> shape_of_kind_path env kind (t :> Odoc_model.Paths.Path.t) | `Identifier (id, _) -> shape_of_id env (id :> Odoc_model.Paths.Identifier.NonSrc.t) - + | `Substituted t -> shape_of_kind_path env kind (t :> Odoc_model.Paths.Path.t) + | `Forward _ + | `Dot _ + | `Root _ + | `Apply _ -> None + module MkId = Identifier.Mk let unit_of_uid uid = @@ -178,18 +185,18 @@ let lookup_module_path env path = | None -> None | Some query -> lookup_shape env query -let lookup_kind_path kind env path = +let lookup_kind_path kind env (path : Odoc_model.Paths.Path.t) = match shape_of_kind_path env kind path with | None -> None | Some query -> lookup_shape env query -let lookup_value_path = lookup_kind_path Kind.Value +let lookup_value_path env p = lookup_kind_path Kind.Value env (p : Odoc_model.Paths.Path.Value.t :> Odoc_model.Paths.Path.t) -let lookup_type_path : Env.t -> Odoc_model.Paths.Path.Type.t -> _ = lookup_kind_path Kind.Type +let lookup_type_path env p = lookup_kind_path Kind.Type env (p : Odoc_model.Paths.Path.Type.t :> Odoc_model.Paths.Path.t) -let lookup_module_type_path = lookup_kind_path Kind.Module_type +let lookup_module_type_path env p = lookup_kind_path Kind.Module_type env (p : Odoc_model.Paths.Path.ModuleType.t :> Odoc_model.Paths.Path.t) -let lookup_class_type_path = lookup_kind_path Kind.Class_type +let lookup_class_type_path env p = lookup_kind_path Kind.Class_type env (p : Odoc_model.Paths.Path.ClassType.t :> Odoc_model.Paths.Path.t) #else diff --git a/src/xref2/strengthen.ml b/src/xref2/strengthen.ml index 85a66dfebe..96a3ba3118 100644 --- a/src/xref2/strengthen.ml +++ b/src/xref2/strengthen.ml @@ -37,7 +37,7 @@ and sig_items prefix ?canonical sg = (fun (items, s) item -> match item with | Module (id, r, m) -> - let name = Ident.Name.module_ id in + let name = Ident.Name.typed_module id in let canonical = match canonical with | Some p -> Some (`Dot (p, name)) @@ -50,7 +50,7 @@ and sig_items prefix ?canonical sg = ( id, put (fun () -> module_type - (`Dot (prefix, Ident.Name.module_type id)) + (`DotMT (prefix, Ident.Name.typed_module_type id)) (get mt)) ) :: items, s ) @@ -59,7 +59,9 @@ and sig_items prefix ?canonical sg = ( id, r, put (fun () -> - type_decl (`Dot (prefix, Ident.Name.type_ id)) (get t)) ) + type_decl + (`DotT (prefix, Ident.Name.typed_type id)) + (get t)) ) :: items, s ) | Include i -> diff --git a/src/xref2/subst.ml b/src/xref2/subst.ml index 13269966f2..14fdf93916 100644 --- a/src/xref2/subst.ml +++ b/src/xref2/subst.ml @@ -319,7 +319,7 @@ and module_type_path : in Not_replaced r | `Identifier _ -> Not_replaced p - | `Dot (p, n) -> Not_replaced (`Dot (module_path s p, n)) + | `DotMT (p, n) -> Not_replaced (`DotMT (module_path s p, n)) | `ModuleType (p', str) -> Not_replaced (`ModuleType (resolved_parent_path s p', str)) @@ -370,7 +370,7 @@ and type_path : t -> Cpath.type_ -> Cpath.type_ type_or_replaced = | Some (`Renamed x) -> Not_replaced (`Local (x, b)) | None -> Not_replaced (`Local (id, b))) | `Identifier _ -> Not_replaced p - | `Dot (p, n) -> Not_replaced (`Dot (module_path s p, n)) + | `DotT (p, n) -> Not_replaced (`DotT (module_path s p, n)) | `Type (p, n) -> Not_replaced (`Type (resolved_parent_path s p, n)) | `Class (p, n) -> Not_replaced (`Class (resolved_parent_path s p, n)) | `ClassType (p, n) -> Not_replaced (`ClassType (resolved_parent_path s p, n)) @@ -408,7 +408,7 @@ and class_type_path : t -> Cpath.class_type -> Cpath.class_type = | None -> `Local (id, b)) | `Identifier _ -> p | `Substituted p -> `Substituted (class_type_path s p) - | `Dot (p, n) -> `Dot (module_path s p, n) + | `DotT (p, n) -> `DotT (module_path s p, n) | `Class (p, n) -> `Class (resolved_parent_path s p, n) | `ClassType (p, n) -> `ClassType (resolved_parent_path s p, n) diff --git a/src/xref2/test.md b/src/xref2/test.md index bd9f7889eb..33f4110050 100644 --- a/src/xref2/test.md +++ b/src/xref2/test.md @@ -273,7 +273,7 @@ to identify precisely. So the manifest of `u` is now: - : Odoc_model.Lang.TypeExpr.t option = Some (Odoc_model.Lang.TypeExpr.Constr - (`Dot + (`DotT (`Identifier ({Odoc_model__Paths_types.iv = `Module @@ -287,7 +287,7 @@ Some M); ihash = 716453475; ikey = "m_M.r_Root.p_None"}, false), - "t"), + t), [])) ``` @@ -550,7 +550,7 @@ which is `A.B.t`. The compiler has started us off by resolving the - : Odoc_model.Lang.TypeExpr.t option = Some (Odoc_model.Lang.TypeExpr.Constr - (`Dot + (`DotT (`Dot (`Identifier ({Odoc_model__Paths_types.iv = @@ -565,8 +565,8 @@ Some A); ihash = 353272258; ikey = "m_A.r_Root.p_None"}, false), - "B"), - "t"), + B), + t), [])) ``` @@ -615,12 +615,12 @@ we then return along with the fully resolved identifier. ```ocaml env=e1 # fst @@ get_ok @@ Tools.resolve_type env - (`Dot + (`DotT (`Dot (`Resolved (`Gpath (`Identifier (Common.root_module "A"))), - "B"), - "t"));; + ModuleName.make_std "B"), + TypeName.make_std "t"));; - : Cpath.Resolved.type_ = `Type (`Module @@ -697,7 +697,7 @@ Some A); ihash = 353272258; ikey = "m_A.r_Root.p_None"}, false), - "N")), + N)), t)), [])) ``` @@ -759,7 +759,7 @@ Some A); ihash = 353272258; ikey = "m_A.r_Root.p_None"}, false), - "N")), + N)), `Dot (`Identifier ({Odoc_model__Paths_types.iv = @@ -775,7 +775,7 @@ Some A); ihash = 353272258; ikey = "m_A.r_Root.p_None"}, false), - "O")), + O)), t)), [])) ``` @@ -970,7 +970,7 @@ val sg : Tools.expansion = (Odoc_xref2.Component.ModuleType.Path {Odoc_xref2.Component.ModuleType.p_expansion = None; p_path = - `Dot (`Substituted (`Local (`LModule (M, 32), false)), "S")}); + `DotMT (`Substituted (`Local (`LModule (M, 32), false)), S)}); canonical = None; hidden = false}; get = None})]; compiled = false; removed = []; doc = []} @@ -991,7 +991,7 @@ val m : Component.Module.t Component.Delayed.t = (Odoc_xref2.Component.ModuleType.Path {Odoc_xref2.Component.ModuleType.p_expansion = None; p_path = - `Dot + `DotMT (`Substituted (`Module (`Module @@ -1010,7 +1010,7 @@ val m : Component.Module.t Component.Delayed.t = C); ihash = 43786577; ikey = "m_C.r_Root.p_None"})), M)), - "S")}); + S)}); canonical = None; hidden = false}; get = None} # get_ok @@ Tools.expansion_of_module env (Component.Delayed.get m);; @@ -1441,7 +1441,7 @@ The type path we're trying to look up is: - : Odoc_model.Lang.TypeExpr.t option = Some (Odoc_model.Lang.TypeExpr.Constr - (`Dot + (`DotT (`Dot (`Apply (`Apply @@ -1501,8 +1501,8 @@ Some FooBarInt); ihash = 706684202; ikey = "m_FooBarInt.r_Root.p_None"}, false)), - "Foo"), - "bar"), + Foo), + bar), [])) ``` @@ -1595,7 +1595,7 @@ val m : Component.Module.t Component.Delayed.t = (Odoc_xref2.Component.ModuleType.Path {Odoc_xref2.Component.ModuleType.p_expansion = None; p_path = - `Dot + `DotMT (`Apply (`Resolved (`Substituted @@ -1630,7 +1630,7 @@ val m : Component.Module.t Component.Delayed.t = ihash = 818126955; ikey = "r_Root.p_None"}, Bar); ihash = 608577; ikey = "m_Bar.r_Root.p_None"})))), - "T")}); + T)}); canonical = None; hidden = false}; get = None} # let sg' = get_ok @@ Tools.expansion_of_module env (Component.Delayed.get m);; @@ -1647,7 +1647,7 @@ val sg' : Tools.expansion = (Odoc_xref2.Component.ModuleType.Path {Odoc_xref2.Component.ModuleType.p_expansion = None; p_path = - `Dot + `DotMT (`Resolved (`Substituted (`Substituted @@ -1668,7 +1668,7 @@ val sg' : Tools.expansion = Bar); ihash = 608577; ikey = "m_Bar.r_Root.p_None"})))), - "T")}); + T)}); canonical = None; hidden = false}; get = None})]; compiled = false; removed = []; doc = []} @@ -1686,7 +1686,7 @@ val sg' : Tools.expansion = (Odoc_xref2.Component.ModuleType.Path {Odoc_xref2.Component.ModuleType.p_expansion = None; p_path = - `Dot + `DotMT (`Resolved (`Substituted (`Substituted @@ -1707,7 +1707,7 @@ val sg' : Tools.expansion = Bar); ihash = 608577; ikey = "m_Bar.r_Root.p_None"})))), - "T")}); + T)}); canonical = None; hidden = false}; get = None})]; compiled = false; removed = []; doc = []} @@ -1725,7 +1725,7 @@ val sg' : Tools.expansion = (Odoc_xref2.Component.ModuleType.Path {Odoc_xref2.Component.ModuleType.p_expansion = None; p_path = - `Dot + `DotMT (`Resolved (`Substituted (`Substituted @@ -1746,7 +1746,7 @@ val sg' : Tools.expansion = Bar); ihash = 608577; ikey = "m_Bar.r_Root.p_None"})))), - "T")}); + T)}); canonical = None; hidden = false}; get = None})]; compiled = false; removed = []; doc = []} @@ -1764,7 +1764,7 @@ val sg' : Tools.expansion = (Odoc_xref2.Component.ModuleType.Path {Odoc_xref2.Component.ModuleType.p_expansion = None; p_path = - `Dot + `DotMT (`Resolved (`Substituted (`Substituted @@ -1785,7 +1785,7 @@ val sg' : Tools.expansion = Bar); ihash = 608577; ikey = "m_Bar.r_Root.p_None"})))), - "T")}); + T)}); canonical = None; hidden = false}; get = None})]; compiled = false; removed = []; doc = []} @@ -2079,7 +2079,7 @@ Some Dep1); ihash = 393430064; ikey = "m_Dep1.r_Root.p_None"}, false)), - "B")), + B)), c)), [])) ``` @@ -2221,8 +2221,8 @@ Some Dep4); ihash = 1019199703; ikey = "m_Dep4.r_Root.p_None"}, false)), - "Z"), - "Y")), + Z), + Y)), a)), [])) ``` @@ -2908,7 +2908,7 @@ let m_e_i_s_value mod_name n val_name = source_loc = None; value = Odoc_model.Lang.Value.Abstract; doc = []; type_ = Odoc_model.Lang.TypeExpr.Constr - (`Dot + (`DotT (`Identifier ({Odoc_model__Paths_types.iv = `Module @@ -2922,7 +2922,7 @@ let m_e_i_s_value mod_name n val_name = Foo); ihash = 249248993; ikey = "m_Foo.r_Root.p_None"}, false), - "t"), + t), [])} # Common.LangUtils.Lens.get (m_e_i_s_value "Foo3" 0 "id2") sg;; - : Odoc_model.Lang.Value.t = @@ -3021,7 +3021,7 @@ let sg = Common.signature_of_mli_string test_data;; manifest = Some (Odoc_model.Lang.TypeExpr.Constr - (`Dot + (`DotT (`Identifier ({Odoc_model__Paths_types.iv = `Module @@ -3035,7 +3035,7 @@ let sg = Common.signature_of_mli_string test_data;; Foo); ihash = 249248993; ikey = "m_Foo.r_Root.p_None"}, false), - "t"), + t), [])); constraints = []}; representation = None}); @@ -3106,7 +3106,7 @@ let sg = Common.signature_of_mli_string test_data;; manifest = Some (Odoc_model.Lang.TypeExpr.Constr - (`Dot + (`DotT (`Identifier ({Odoc_model__Paths_types.iv = `Module @@ -3120,7 +3120,7 @@ let sg = Common.signature_of_mli_string test_data;; Foo2); ihash = 926621908; ikey = "m_Foo2.r_Root.p_None"}, false), - "t"), + t), [])); constraints = []}; representation = None}); @@ -3223,7 +3223,7 @@ let sg = Common.signature_of_mli_string test_data;; manifest = Some (Odoc_model.Lang.TypeExpr.Constr - (`Dot + (`DotT (`Identifier ({Odoc_model__Paths_types.iv = `Module @@ -3237,7 +3237,7 @@ let sg = Common.signature_of_mli_string test_data;; Foo); ihash = 249248993; ikey = "m_Foo.r_Root.p_None"}, false), - "t"), + t), [])); constraints = []}; representation = None}); @@ -3376,7 +3376,7 @@ let sg = Common.signature_of_mli_string test_data;; Foo); ihash = 249248993; ikey = "m_Foo.r_Root.p_None"}, false), - "Bar"), + Bar), None); canonical = None; hidden = false}); Odoc_model.Lang.Signature.Value @@ -3399,7 +3399,7 @@ let sg = Common.signature_of_mli_string test_data;; source_loc = None; value = Odoc_model.Lang.Value.Abstract; doc = []; type_ = Odoc_model.Lang.TypeExpr.Constr - (`Dot + (`DotT (`Identifier ({Odoc_model__Paths_types.iv = `Module @@ -3419,7 +3419,7 @@ let sg = Common.signature_of_mli_string test_data;; ihash = 38422300; ikey = "m_{Bar}8/shadowed/(XXXX).m_Foo3.r_Root.p_None"}, true), - "t"), + t), [])}]; compiled = false; removed = []; doc = []} ``` diff --git a/src/xref2/tools.ml b/src/xref2/tools.ml index 7968dd0f54..4f06bd97d9 100644 --- a/src/xref2/tools.ml +++ b/src/xref2/tools.ml @@ -21,7 +21,7 @@ let c_mod_poss env p = let rec inner = function | `Dot (p, n) -> ( let rest = List.map (fun p -> `Dot (p, n)) (inner p) in - match Env.lookup_by_name Env.s_module n env with + match Env.lookup_by_name Env.s_module (ModuleName.to_string n) env with | Ok (`Module (id, m)) -> let m = Component.Delayed.get m in `Identifier (id, m.hidden) :: rest @@ -33,9 +33,11 @@ let c_mod_poss env p = let c_modty_poss env p = (* canonical module type paths *) match p with - | `Dot (p, n) -> ( - let rest = List.map (fun p -> `Dot (p, n)) (c_mod_poss env p) in - match Env.lookup_by_name Env.s_module_type n env with + | `DotMT (p, n) -> ( + let rest = List.map (fun p -> `DotMT (p, n)) (c_mod_poss env p) in + match + Env.lookup_by_name Env.s_module_type (ModuleTypeName.to_string n) env + with | Ok (`ModuleType (id, _)) -> `Identifier (id, false) :: rest | Error _ -> rest) | p -> [ p ] @@ -43,9 +45,9 @@ let c_modty_poss env p = let c_ty_poss env p = (* canonical type paths *) match p with - | `Dot (p, n) -> ( - let rest = List.map (fun p -> `Dot (p, n)) (c_mod_poss env p) in - match Env.lookup_by_name Env.s_datatype n env with + | `DotT (p, n) -> ( + let rest = List.map (fun p -> `DotT (p, n)) (c_mod_poss env p) in + match Env.lookup_by_name Env.s_datatype (TypeName.to_string n) env with | Ok (`Type (id, _)) -> `Identifier ((id :> Odoc_model.Paths.Identifier.Path.Type.t), false) :: rest @@ -536,7 +538,7 @@ and handle_type_lookup env id p sg = and handle_value_lookup _env id p sg = match Find.value_in_sig sg id with - | (`FValue (name, _) as v) :: _ -> Ok (`Value (p, name), v) + | Some (`FValue (name, _) as v) -> Ok (`Value (p, name), v) | _ -> Error `Find_failure and handle_class_type_lookup id p sg = @@ -566,7 +568,7 @@ and lookup_module_gpath : >>= fun (_, m) -> Ok (Component.Delayed.put_val m) | `Module (parent, name) -> let find_in_sg sg sub = - match Find.careful_module_in_sig sg (ModuleName.to_string name) with + match Find.careful_module_in_sig sg name with | None -> Error `Find_failure | Some (`FModule (_, m)) -> Ok (Component.Delayed.put_val (Subst.module_ sub m)) @@ -603,7 +605,7 @@ and lookup_module : >>= fun (_, m) -> Ok (Component.Delayed.put_val m) | `Module (parent, name) -> let find_in_sg sg sub = - match Find.careful_module_in_sig sg (ModuleName.to_string name) with + match Find.careful_module_in_sig sg name with | None -> Error `Find_failure | Some (`FModule (_, m)) -> Ok (Component.Delayed.put_val (Subst.module_ sub m)) @@ -638,7 +640,7 @@ and lookup_module_type_gpath : lookup_module_type_gpath env s | `ModuleType (parent, name) -> let find_in_sg sg sub = - match Find.module_type_in_sig sg (ModuleTypeName.to_string name) with + match Find.module_type_in_sig sg name with | None -> Error `Find_failure | Some (`FModuleType (_, mt)) -> Ok (Subst.module_type sub mt) in @@ -662,7 +664,7 @@ and lookup_module_type : lookup_module_type env s | `ModuleType (parent, name) -> let find_in_sg sg sub = - match Find.module_type_in_sig sg (ModuleTypeName.to_string name) with + match Find.module_type_in_sig sg name with | None -> Error `Find_failure | Some (`FModuleType (_, mt)) -> Ok (Subst.module_type sub mt) in @@ -767,9 +769,9 @@ and lookup_type_gpath : >>= fun (`ClassType ({ iv = `ClassType (_, name); _ }, t)) -> Ok (`FClassType (name, t)) | `CanonicalType (t1, _) -> lookup_type_gpath env t1 - | `Type (p, id) -> do_type p (TypeName.to_string id) - | `Class (p, id) -> do_type p (TypeName.to_string id) - | `ClassType (p, id) -> do_type p (TypeName.to_string id) + | `Type (p, id) -> do_type p id + | `Class (p, id) -> do_type p id + | `ClassType (p, id) -> do_type p id | `SubstitutedT t -> lookup_type_gpath env t | `SubstitutedCT t -> lookup_type_gpath env (t :> Odoc_model.Paths.Path.Resolved.Type.t) @@ -786,8 +788,8 @@ and lookup_value_gpath : |> map_error (fun e -> (e :> simple_value_lookup_error)) >>= fun (sg, sub) -> match Find.value_in_sig sg name with - | `FValue (name, t) :: _ -> Ok (`FValue (name, Subst.value sub t)) - | [] -> Error `Find_failure + | Some (`FValue (name, t)) -> Ok (`FValue (name, Subst.value sub t)) + | None -> Error `Find_failure in let res = match p with @@ -795,7 +797,7 @@ and lookup_value_gpath : of_option ~error:(`Lookup_failureV i) (Env.(lookup_by_id s_value) i env) >>= fun (`Value ({ iv = `Value (_, name); _ }, t)) -> Ok (`FValue (name, t)) - | `Value (p, id) -> do_value p (ValueName.to_string id) + | `Value (p, id) -> do_value p id in res @@ -827,8 +829,8 @@ and lookup_class_type_gpath : (Env.(lookup_by_id s_class_type) i env) >>= fun (`ClassType ({ iv = `ClassType (_, name); _ }, t)) -> Ok (`FClassType (name, t)) - | `Class (p, id) -> do_type p (TypeName.to_string id) - | `ClassType (p, id) -> do_type p (TypeName.to_string id) + | `Class (p, id) -> do_type p id + | `ClassType (p, id) -> do_type p id | `SubstitutedCT c -> lookup_class_type_gpath env c in res @@ -858,9 +860,9 @@ and lookup_type : | `Gpath p -> lookup_type_gpath env p | `CanonicalType (t1, _) -> lookup_type env t1 | `Substituted s -> lookup_type env s - | `Type (p, id) -> do_type p (TypeName.to_string id) - | `Class (p, id) -> do_type p (TypeName.to_string id) - | `ClassType (p, id) -> do_type p (TypeName.to_string id) + | `Type (p, id) -> do_type p id + | `Class (p, id) -> do_type p id + | `ClassType (p, id) -> do_type p id in res @@ -874,8 +876,8 @@ and lookup_value : lookup_parent env p |> map_error (fun e -> (e :> simple_value_lookup_error)) >>= fun (sg, sub) -> - handle_value_lookup env (ValueName.to_string id) p sg - >>= fun (_, `FValue (name, c)) -> Ok (`FValue (name, Subst.value sub c)) + handle_value_lookup env id p sg >>= fun (_, `FValue (name, c)) -> + Ok (`FValue (name, Subst.value sub c)) | `Gpath p -> lookup_value_gpath env p and lookup_class_type : @@ -901,8 +903,8 @@ and lookup_class_type : | `Local id -> Error (`LocalType (env, (id :> Ident.path_type))) | `Gpath p -> lookup_class_type_gpath env p | `Substituted s -> lookup_class_type env s - | `Class (p, id) -> do_type p (TypeName.to_string id) - | `ClassType (p, id) -> do_type p (TypeName.to_string id) + | `Class (p, id) -> do_type p id + | `ClassType (p, id) -> do_type p id in res @@ -932,7 +934,7 @@ and resolve_module : Env.t -> Cpath.module_ -> resolve_module_result = lookup_parent env parent |> map_error (fun e -> (e :> simple_module_lookup_error)) >>= fun (parent_sig, sub) -> - handle_module_lookup env (ModuleName.to_string id) parent parent_sig sub + handle_module_lookup env id parent parent_sig sub | `Apply (m1, m2) -> ( let func = resolve_module env m1 in let arg = resolve_module env m2 in @@ -970,7 +972,7 @@ and resolve_module : Env.t -> Cpath.module_ -> resolve_module_result = Error (`Parent (`Parent_sig `UnresolvedForwardPath)) | None -> Error (`Lookup_failure_root r)) | `Forward f -> - resolve_module env (`Root f) + resolve_module env (`Root (ModuleName.make_std f)) |> map_error (fun e -> `Parent (`Parent_module e)) in LookupAndResolveMemo.memoize resolve env' id @@ -979,7 +981,7 @@ and resolve_module_type : Env.t -> Cpath.module_type -> resolve_module_type_result = fun env p -> match p with - | `Dot (parent, id) -> + | `DotMT (parent, id) -> resolve_and_lookup_parent env parent |> map_error (fun e -> (e :> simple_module_type_lookup_error)) >>= fun (parent, parent_sig, sub) -> @@ -990,9 +992,7 @@ and resolve_module_type : lookup_parent env parent |> map_error (fun e -> (e :> simple_module_type_lookup_error)) >>= fun (parent_sig, sub) -> - handle_module_type_lookup env - (ModuleTypeName.to_string id) - parent parent_sig sub + handle_module_type_lookup env id parent parent_sig sub |> of_option ~error:`Find_failure | `Identifier (i, _) -> of_option ~error:(`Lookup_failureMT i) @@ -1012,7 +1012,7 @@ and resolve_type : Env.t -> Cpath.type_ -> resolve_type_result = fun env p -> let result = match p with - | `Dot (parent, id) -> + | `DotT (parent, id) -> resolve_and_lookup_parent env parent |> map_error (fun e -> (e :> simple_type_lookup_error)) >>= fun (parent, parent_sig, sub) -> @@ -1031,7 +1031,7 @@ and resolve_type : Env.t -> Cpath.type_ -> resolve_type_result = |> map_error (fun e -> (e :> simple_type_lookup_error)) >>= fun (parent_sig, sub) -> let result = - match Find.datatype_in_sig parent_sig (TypeName.to_string id) with + match Find.datatype_in_sig parent_sig id with | Some (`FType (name, t)) -> Some (`Type (parent, name), `FType (name, Subst.type_ sub t)) | None -> None @@ -1042,7 +1042,7 @@ and resolve_type : Env.t -> Cpath.type_ -> resolve_type_result = |> map_error (fun e -> (e :> simple_type_lookup_error)) >>= fun (parent_sig, sub) -> let t = - match Find.type_in_sig parent_sig (TypeName.to_string id) with + match Find.type_in_sig parent_sig id with | Some (`FClass (name, t)) -> Some (`Class (parent, name), `FClass (name, Subst.class_ sub t)) | Some _ -> None @@ -1053,8 +1053,7 @@ and resolve_type : Env.t -> Cpath.type_ -> resolve_type_result = lookup_parent env parent |> map_error (fun e -> (e :> simple_type_lookup_error)) >>= fun (parent_sg, sub) -> - handle_type_lookup env (TypeName.to_string id) parent parent_sg - >>= fun (p', t') -> + handle_type_lookup env id parent parent_sg >>= fun (p', t') -> let t = match t' with | `FClass (name, c) -> `FClass (name, Subst.class_ sub c) @@ -1081,7 +1080,7 @@ and resolve_value : Env.t -> Cpath.value -> resolve_value_result = fun env p -> let result = match p with - | `Dot (parent, id) -> + | `DotV (parent, id) -> resolve_module env parent |> map_error (fun e -> `Parent (`Parent_module e)) >>= fun (p, m) -> @@ -1099,10 +1098,10 @@ and resolve_value : Env.t -> Cpath.value -> resolve_value_result = |> map_error (fun e -> (e :> simple_value_lookup_error)) >>= fun (parent_sig, sub) -> let result = - match Find.value_in_sig parent_sig (ValueName.to_string id) with - | `FValue (name, t) :: _ -> + match Find.value_in_sig parent_sig id with + | Some (`FValue (name, t)) -> Some (`Value (parent, name), `FValue (name, Subst.value sub t)) - | [] -> None + | None -> None in of_option ~error:`Find_failure result | `Resolved r -> lookup_value env r >>= fun t -> Ok (r, t) @@ -1116,7 +1115,7 @@ and resolve_class_type : Env.t -> Cpath.class_type -> resolve_class_type_result = fun env p -> match p with - | `Dot (parent, id) -> + | `DotT (parent, id) -> resolve_and_lookup_parent env parent |> map_error (fun e -> (e :> simple_type_lookup_error)) >>= fun (parent, parent_sig, sub) -> @@ -1142,7 +1141,7 @@ and resolve_class_type : Env.t -> Cpath.class_type -> resolve_class_type_result |> map_error (fun e -> (e :> simple_type_lookup_error)) >>= fun (parent_sig, sub) -> let t = - match Find.type_in_sig parent_sig (TypeName.to_string id) with + match Find.type_in_sig parent_sig id with | Some (`FClass (name, t)) -> Some (`Class (parent, name), `FClass (name, Subst.class_ sub t)) | Some _ -> None @@ -1153,8 +1152,7 @@ and resolve_class_type : Env.t -> Cpath.class_type -> resolve_class_type_result lookup_parent env parent |> map_error (fun e -> (e :> simple_type_lookup_error)) >>= fun (parent_sg, sub) -> - handle_class_type_lookup (TypeName.to_string id) parent parent_sg - >>= fun (p', t') -> + handle_class_type_lookup id parent parent_sg >>= fun (p', t') -> let t = match t' with | `FClass (name, c) -> `FClass (name, Subst.class_ sub c) @@ -1740,19 +1738,22 @@ and _ascribe _env ~expansion ~original_expansion = (fun item acc -> match item with | Component.Signature.Module (id, _r, _m) -> - if Find.module_in_sig sg' (Ident.Name.module_ id) = None then - acc + if Find.module_in_sig sg' (Ident.Name.typed_module id) = None + then acc else item :: acc | Component.Signature.ModuleType (id, _m) -> if - Find.module_type_in_sig sg' (Ident.Name.module_type id) = None + Find.module_type_in_sig sg' (Ident.Name.typed_module_type id) + = None then acc else item :: acc | Component.Signature.Type (id, _r, _t) -> - if Find.type_in_sig sg' (Ident.Name.type_ id) = None then acc + if Find.type_in_sig sg' (Ident.Name.typed_type id) = None then + acc else item :: acc | Component.Signature.Value (id, _v) -> - if Find.value_in_sig sg' (Ident.Name.value id) = [] then acc + if Find.value_in_sig sg' (Ident.Name.typed_value id) = None then + acc else item :: acc | _ -> item :: acc) sg.items [] @@ -2115,7 +2116,7 @@ and fixup_type_cfrag (f : Cfrag.resolved_type) : Cfrag.resolved_type = and find_module_with_replacement : Env.t -> Component.Signature.t -> - string -> + ModuleName.t -> ( Component.Module.t Component.Delayed.t, simple_module_lookup_error ) Result.result = @@ -2129,7 +2130,7 @@ and find_module_with_replacement : and find_module_type_with_replacement : Env.t -> Component.Signature.t -> - string -> + ModuleTypeName.t -> ( Component.ModuleType.t Component.Delayed.t, simple_module_type_lookup_error ) Result.result = @@ -2155,7 +2156,8 @@ and resolve_signature_fragment : let open Odoc_utils.OptionMonad in resolve_signature_fragment env (p, sg) parent >>= fun (pfrag, ppath, sg) -> - of_result (find_module_with_replacement env sg name) >>= fun m' -> + of_result (find_module_with_replacement env sg (ModuleName.make_std name)) + >>= fun m' -> let mname = ModuleName.make_std name in let new_path = `Module (ppath, mname) in let new_frag = `Module (pfrag, mname) in @@ -2188,7 +2190,8 @@ and resolve_module_fragment : let open Odoc_utils.OptionMonad in resolve_signature_fragment env (p, sg) parent >>= fun (pfrag, _ppath, sg) -> - of_result (find_module_with_replacement env sg name) >>= fun m' -> + of_result (find_module_with_replacement env sg (ModuleName.make_std name)) + >>= fun m' -> let mname = ModuleName.make_std name in let new_frag = `Module (pfrag, mname) in let m' = Component.Delayed.get m' in @@ -2223,7 +2226,10 @@ and resolve_module_type_fragment : let open Odoc_utils.OptionMonad in resolve_signature_fragment env (p, sg) parent >>= fun (pfrag, _ppath, sg) -> - of_result (find_module_type_with_replacement env sg name) >>= fun mt' -> + of_result + (find_module_type_with_replacement env sg + (ModuleTypeName.make_std name)) + >>= fun mt' -> let mtname = ModuleTypeName.make_std name in let f' = `ModuleType (pfrag, mtname) in let m' = Component.Delayed.get mt' in diff --git a/src/xref2/tools.mli b/src/xref2/tools.mli index f3c4d6f6a6..bc54c338ca 100644 --- a/src/xref2/tools.mli +++ b/src/xref2/tools.mli @@ -6,6 +6,7 @@ *) open Errors.Tools_error +open Odoc_model.Names type expansion = | Signature of Component.Signature.t @@ -181,7 +182,7 @@ val reresolve_parent : Env.t -> Cpath.Resolved.parent -> Cpath.Resolved.parent val handle_module_type_lookup : Env.t -> - string -> + ModuleTypeName.t -> Cpath.Resolved.parent -> Component.Signature.t -> Component.Substitution.t -> diff --git a/test/xref2/cpath/cpath_test.md b/test/xref2/cpath/cpath_test.md index 878202b5c6..fefdbdd0a6 100644 --- a/test/xref2/cpath/cpath_test.md +++ b/test/xref2/cpath/cpath_test.md @@ -1,24 +1,24 @@ +```ocaml env=e1 +open Odoc_model.Names +``` + ### Hidden paths Tests for `weak_canonical_test`. When calling `is_resolved_module_hidden`, we normally would have `weak_canonical_test` false, and we'll check to see whether the canonical part of a path is hidden or not. When `weak_canonical_test` is true, we'll _assume_ that the canonical part will resolve to be a non-hidden path. In the following test, we create a path with an unresolved canonical ```ocaml env=e1 -# let m = `Hidden (`Local (`LModule (Odoc_model.Names.ModuleName.hidden_of_string "M", 1)));; -val m : - [> `Hidden of - [> `Local of [> `LModule of Odoc_model.Names.ModuleName.t * int ] ] ] = +# let m = `Hidden (`Local (`LModule (ModuleName.hidden_of_string "M", 1)));; +val m : [> `Hidden of [> `Local of [> `LModule of ModuleName.t * int ] ] ] = `Hidden (`Local (`LModule (M, 1))) -# let cm = `Root "Foo";; -val cm : [> `Root of string ] = `Root "Foo" +# let cm = `Root (ModuleName.make_std "Foo");; +val cm : [> `Root of ModuleName.t ] = `Root Foo # let p = `Canonical(m, cm);; val p : [> `Canonical of - [> `Hidden of - [> `Local of [> `LModule of Odoc_model.Names.ModuleName.t * int ] - ] ] * - [> `Root of string ] ] = - `Canonical (`Hidden (`Local (`LModule (M, 1))), `Root "Foo") + [> `Hidden of [> `Local of [> `LModule of ModuleName.t * int ] ] ] * + [> `Root of ModuleName.t ] ] = + `Canonical (`Hidden (`Local (`LModule (M, 1))), `Root Foo) ``` At this point, `p` is a path to a hidden module that has an unresolved canonical constructor diff --git a/test/xref2/lib/common.cppo.ml b/test/xref2/lib/common.cppo.ml index 3505a46f87..474d75cfd9 100644 --- a/test/xref2/lib/common.cppo.ml +++ b/test/xref2/lib/common.cppo.ml @@ -1,4 +1,5 @@ open Result +open Odoc_model.Names (* Example usage of these: @@ -38,8 +39,8 @@ let cmt_of_string s = Typemod.type_implementation (Unit_info.make ~source_file:"" "") env p #endif -let parent = Odoc_model.Paths.Identifier.Mk.page (None, Odoc_model.Names.PageName.make_std "None") -let id = Odoc_model.Paths.Identifier.Mk.root (Some parent, Odoc_model.Names.ModuleName.make_std "Root") +let parent = Odoc_model.Paths.Identifier.Mk.page (None, PageName.make_std "None") +let id = Odoc_model.Paths.Identifier.Mk.root (Some parent, ModuleName.make_std "Root") let root_of_compilation_unit ~package ~hidden ~module_name ~digest = ignore(package); @@ -61,7 +62,7 @@ let root = let root_identifier = `Identifier id -let root_module name = Odoc_model.Paths.Identifier.Mk.module_ (id, Odoc_model.Names.ModuleName.make_std name) +let root_module name = Odoc_model.Paths.Identifier.Mk.module_ (id, ModuleName.make_std name) let root_pp fmt (_ : Odoc_model.Root.t) = Format.fprintf fmt "Common.root" @@ -405,7 +406,7 @@ module LangUtils = struct let id = m.Odoc_model.Lang.Module.id in match id.iv with | `Module (_, mname') -> - if Odoc_model.Names.ModuleName.to_string mname' = mname + if ModuleName.to_string mname' = mname then m else inner rest | _ -> inner rest @@ -565,10 +566,10 @@ module LangUtils = struct | `Alias (dest, src) -> Format.fprintf ppf "(%a -> %a)" path (src :> Odoc_model.Paths.Path.t) resolved_path (cast dest) | `AliasModuleType (path, realpath) -> Format.fprintf ppf "(%a -> %a)" resolved_path (cast path) resolved_path (cast realpath) | `Subst (modty, m) -> Format.fprintf ppf "(%a subst-> %a)" resolved_path (cast modty) resolved_path (cast m) - | `Module (p, m) -> Format.fprintf ppf "%a.%s" resolved_path (cast p) (Odoc_model.Names.ModuleName.to_string m) - | `ModuleType (p, mt) -> Format.fprintf ppf "%a.%s" resolved_path (cast p) (Odoc_model.Names.ModuleTypeName.to_string mt) - | `Type (p, t) -> Format.fprintf ppf "%a.%s" resolved_path (cast p) (Odoc_model.Names.TypeName.to_string t) - | `Value (p, t) -> Format.fprintf ppf "%a.%s" resolved_path (cast p) (Odoc_model.Names.ValueName.to_string t) + | `Module (p, m) -> Format.fprintf ppf "%a.%s" resolved_path (cast p) (ModuleName.to_string m) + | `ModuleType (p, mt) -> Format.fprintf ppf "%a.%s" resolved_path (cast p) (ModuleTypeName.to_string mt) + | `Type (p, t) -> Format.fprintf ppf "%a.%s" resolved_path (cast p) (TypeName.to_string t) + | `Value (p, t) -> Format.fprintf ppf "%a.%s" resolved_path (cast p) (ValueName.to_string t) | `OpaqueModule m -> Format.fprintf ppf "opaquemodule(%a)" resolved_path (cast m) | `OpaqueModuleType m -> Format.fprintf ppf "opaquemoduletype(%a)" resolved_path (cast m) | `SubstT (_, _) @@ -588,9 +589,12 @@ module LangUtils = struct match p with | `Resolved rp -> Format.fprintf ppf "resolved[%a]" resolved_path (rp :> Odoc_model.Paths.Path.Resolved.t) | `Identifier (i,b) -> Format.fprintf ppf "identifier(%a,%b)" identifier i b - | `Root s -> Format.fprintf ppf "%s" s + | `Root s -> Format.fprintf ppf "%a" ModuleName.fmt s | `Forward s -> Format.fprintf ppf "%s" s - | `Dot (parent,s) -> Format.fprintf ppf "%a.%s" path (parent :> Odoc_model.Paths.Path.t) s + | `Dot (parent,s) -> Format.fprintf ppf "%a.%a" path (parent :> Odoc_model.Paths.Path.t) ModuleName.fmt s + | `DotMT (parent,s) -> Format.fprintf ppf "%a.%a" path (parent :> Odoc_model.Paths.Path.t) ModuleTypeName.fmt s + | `DotT (parent,s) -> Format.fprintf ppf "%a.%a" path (parent :> Odoc_model.Paths.Path.t) TypeName.fmt s + | `DotV (parent,s) -> Format.fprintf ppf "%a.%a" path (parent :> Odoc_model.Paths.Path.t) ValueName.fmt s | `Apply (func,arg) -> Format.fprintf ppf "%a(%a)" path (func :> Odoc_model.Paths.Path.t) path (arg :> Odoc_model.Paths.Path.t) | `SubstitutedT _|`SubstitutedMT _|`Substituted _|`SubstitutedCT _ -> Format.fprintf ppf "Unimplemented path" @@ -604,8 +608,8 @@ module LangUtils = struct match f with | `Root (`Module p) -> Format.fprintf ppf "root_module(%a)" resolved_path (p :> Odoc_model.Paths.Path.Resolved.t) | `Root (`ModuleType p) -> Format.fprintf ppf "root_module_type(%a)" resolved_path (p :> Odoc_model.Paths.Path.Resolved.t) - | `Module (sg, m) -> Format.fprintf ppf "%a.%s" model_resolved_fragment (sg :> Odoc_model.Paths.Fragment.Resolved.t) (Odoc_model.Names.ModuleName.to_string m) - | `Type (sg, m) -> Format.fprintf ppf "%a.%s" model_resolved_fragment (sg :> Odoc_model.Paths.Fragment.Resolved.t) (Odoc_model.Names.TypeName.to_string m) + | `Module (sg, m) -> Format.fprintf ppf "%a.%s" model_resolved_fragment (sg :> Odoc_model.Paths.Fragment.Resolved.t) (ModuleName.to_string m) + | `Type (sg, m) -> Format.fprintf ppf "%a.%s" model_resolved_fragment (sg :> Odoc_model.Paths.Fragment.Resolved.t) (TypeName.to_string m) | _ -> Format.fprintf ppf "UNIMPLEMENTED model_resolved_fragment" end diff --git a/test/xref2/subst/test.md b/test/xref2/subst/test.md index 6546471615..c0f5c99590 100644 --- a/test/xref2/subst/test.md +++ b/test/xref2/subst/test.md @@ -1,4 +1,6 @@ ```ocaml +open Odoc_model.Names + let resolve_module_name sg name = let rec check = function | Component.Signature.Module (id, _r, _m) :: _rest @@ -25,7 +27,8 @@ let module_substitution ~idents ~targets m test_data = in let m = - match Find.module_in_sig c "S" with + let name = ModuleName.make_std "S" in + match Find.module_in_sig c name with | Some (`FModule (name, m)) -> m | None -> failwith "Error finding module!" in