diff --git a/src/document/comment.ml b/src/document/comment.ml index b9ed0e39ec..b1e11c4376 100644 --- a/src/document/comment.ml +++ b/src/document/comment.ml @@ -34,8 +34,6 @@ module Reference = struct | `Alias (_, r) -> render_resolved (r :> t) | `AliasModuleType (_, r) -> render_resolved (r :> t) | `Module (r, s) -> render_resolved (r :> t) ^ "." ^ ModuleName.to_string s - | `Canonical (_, `Resolved r) -> render_resolved (r :> t) - | `Canonical (p, _) -> render_resolved (p :> t) | `Hidden p -> render_resolved (p :> t) | `ModuleType (r, s) -> render_resolved (r :> t) ^ "." ^ ModuleTypeName.to_string s diff --git a/src/document/generator.ml b/src/document/generator.ml index 0907bf83f2..f246c7f947 100644 --- a/src/document/generator.ml +++ b/src/document/generator.ml @@ -1615,18 +1615,19 @@ module Make (Syntax : SYNTAX) = struct in let status = if decl_hidden then `Inline else t.status in - let include_decl = - match t.decl with - | Odoc_model.Lang.Include.Alias mod_path -> - Link.from_path (mod_path :> Paths.Path.t) - | ModuleType mt -> umty mt - in - let _, content = signature t.expansion.content in let summary = - O.render - (O.keyword "include" ++ O.txt " " ++ include_decl - ++ if Syntax.Mod.include_semicolon then O.keyword ";" else O.noop) + if decl_hidden then O.render (O.keyword "include" ++ O.txt " ...") + else + let include_decl = + match t.decl with + | Odoc_model.Lang.Include.Alias mod_path -> + Link.from_path (mod_path :> Paths.Path.t) + | ModuleType mt -> umty mt + in + O.render + (O.keyword "include" ++ O.txt " " ++ include_decl + ++ if Syntax.Mod.include_semicolon then O.keyword ";" else O.noop) in let content = { Include.content; status; summary } in let attr = [ "include" ] in diff --git a/src/html/generator.ml b/src/html/generator.ml index 3000d2502c..6d9ab72bc1 100644 --- a/src/html/generator.ml +++ b/src/html/generator.ml @@ -295,12 +295,12 @@ and items ~resolve l : item Html.elt list = | Include { attr; anchor; doc; content = { summary; status; content } } :: rest -> let doc = spec_doc_div ~resolve doc in - let included_html = (items content :> any Html.elt list) in + let included_html = (items content :> item Html.elt list) in let a_class = if List.length content = 0 then [ "odoc-include"; "shadowed-include" ] else [ "odoc-include" ] in - let content = + let content : item Html.elt list = let details ~open' = let open' = if open' then [ Html.a_open () ] else [] in let summary = @@ -308,16 +308,21 @@ and items ~resolve l : item Html.elt list = let a = spec_class (attr @ extra_class) @ extra_attr in Html.summary ~a @@ anchor_link @ source (inline ~resolve) summary in - [ Html.details ~a:open' summary included_html ] + let inner = + [ + Html.details ~a:open' summary + (included_html :> any Html.elt list); + ] + in + [ Html.div ~a:[ Html.a_class a_class ] (doc @ inner) ] in match status with - | `Inline -> included_html + | `Inline -> doc @ included_html | `Closed -> details ~open':false | `Open -> details ~open':true | `Default -> details ~open':!Tree.open_details in - let inc = [ Html.div ~a:[ Html.a_class a_class ] (doc @ content) ] in - (continue_with [@tailcall]) rest inc + (continue_with [@tailcall]) rest content | Declaration { Item.attr; anchor; content; doc } :: rest -> let extra_attr, extra_class, anchor_link = mk_anchor anchor in let a = spec_class (attr @ extra_class) @ extra_attr in diff --git a/src/loader/cmt.ml b/src/loader/cmt.ml index f607feaa0c..7704635fae 100644 --- a/src/loader/cmt.ml +++ b/src/loader/cmt.ml @@ -546,22 +546,14 @@ and read_include env parent incl = umty_of_mty mty in let content, shadowed = Cmi.read_signature_noenv env parent (Odoc_model.Compat.signature incl.incl_type) in - let rec contains_signature = function - | ModuleType.U.Signature _ -> true - | Path _ -> false - | With (_, w_expr) -> contains_signature w_expr - | TypeOf _ -> false - in + let expansion = { content; shadowed; } in match decl_modty with - | Some m when not (contains_signature m) -> + | Some m -> let decl = ModuleType m in - let expansion = { content; shadowed; } in [Include {parent; doc; decl; expansion; status; strengthened=None; loc }] - | Some (ModuleType.U.Signature { items; _ }) -> - items - | _ -> + | _ -> content.items - + and read_open env parent o = let container = (parent : Identifier.Signature.t :> Identifier.LabelParent.t) in let doc = Doc_attr.attached_no_tag container o.open_attributes in diff --git a/src/loader/cmti.ml b/src/loader/cmti.ml index cac916ff17..a13a7a786b 100644 --- a/src/loader/cmti.ml +++ b/src/loader/cmti.ml @@ -269,11 +269,15 @@ let read_type_declarations env parent rec_flag decls = let open Signature in List.fold_left (fun (acc, recursive) decl -> - let comments = - Doc_attr.standalone_multiple container decl.typ_attributes in - let comments = List.map (fun com -> Comment com) comments in - let decl = read_type_declaration env parent decl in - ((Type (recursive, decl)) :: (List.rev_append comments acc), And)) + if Btype.is_row_name (Ident.name decl.typ_id) + then (acc, recursive) + else begin + let comments = + Doc_attr.standalone_multiple container decl.typ_attributes in + let comments = List.map (fun com -> Comment com) comments in + let decl = read_type_declaration env parent decl in + ((Type (recursive, decl)) :: (List.rev_append comments acc), And) + end) ([], rec_flag) decls |> fst in @@ -743,29 +747,12 @@ and read_include env parent incl = let doc, status = Doc_attr.attached Odoc_model.Semantics.Expect_status container incl.incl_attributes in let content, shadowed = Cmi.read_signature_noenv env parent (Odoc_model.Compat.signature incl.incl_type) in let expr = read_module_type env parent container incl.incl_mod in - let rec contains_signature = function - | ModuleType.U.Signature _ -> true - | Path _ -> false - | With (_, w_expr) -> contains_signature w_expr - | TypeOf _ -> false - in - (* inline type or module substitution is tricky to inline, because the - scope of the substitution is to the end of the signature being inlined. - If we've got one of those, we fall back to inlining the compiler-computed signature *) - let is_inlinable items = - not (List.exists - (function - | Signature.TypeSubstitution _ -> true - | ModuleSubstitution _ -> true - | _ -> false) items) - in - match Odoc_model.Lang.umty_of_mty expr with - | Some uexpr when not (contains_signature uexpr) -> + let umty = Odoc_model.Lang.umty_of_mty expr in + let expansion = { content; shadowed; } in + match umty with + | Some uexpr -> let decl = Include.ModuleType uexpr in - let expansion = { content; shadowed; } in [Include {parent; doc; decl; expansion; status; strengthened=None; loc }] - | Some ModuleType.U.Signature { items; _ } when is_inlinable items -> - items | _ -> content.items diff --git a/src/loader/ident_env.cppo.ml b/src/loader/ident_env.cppo.ml index 562c479a7f..369e46b7d1 100644 --- a/src/loader/ident_env.cppo.ml +++ b/src/loader/ident_env.cppo.ml @@ -156,6 +156,12 @@ let extract_extended_open o = #endif +let filter_map f x = + List.rev + @@ List.fold_left + (fun acc x -> match f x with Some x -> x :: acc | None -> acc) + [] x + let rec extract_signature_tree_items hide_item items = let open Typedtree in match items with @@ -164,7 +170,10 @@ let rec extract_signature_tree_items hide_item items = #else | { sig_desc = Tsig_type (_, decls); _} :: rest -> #endif - List.map (fun decl -> `Type (decl.typ_id, hide_item)) + filter_map (fun decl -> + if Btype.is_row_name (Ident.name decl.typ_id) + then None + else Some (`Type (decl.typ_id, hide_item))) decls @ extract_signature_tree_items hide_item rest #if OCAML_VERSION >= (4,10,0) diff --git a/src/model/paths.ml b/src/model/paths.ml index e0edafdcf9..6873b50071 100644 --- a/src/model/paths.ml +++ b/src/model/paths.ml @@ -914,10 +914,6 @@ module Reference = struct else (Path.Resolved.ModuleType.identifier sub :> Identifier.Signature.t) | `Module (m, n) -> `Module (parent_signature_identifier m, n) - | `Canonical (_, `Resolved r) -> - parent_signature_identifier (r : module_ :> signature) - | `Canonical (r, _) -> - parent_signature_identifier (r : module_ :> signature) | `ModuleType (m, s) -> `ModuleType (parent_signature_identifier m, s) and parent_type_identifier : datatype -> Identifier.DataType.t = function @@ -932,8 +928,8 @@ module Reference = struct and parent_identifier : parent -> Identifier.Parent.t = function | `Identifier id -> id - | ( `Hidden _ | `Alias _ | `AliasModuleType _ | `Module _ | `Canonical _ - | `ModuleType _ ) as sg -> + | (`Hidden _ | `Alias _ | `AliasModuleType _ | `Module _ | `ModuleType _) + as sg -> (parent_signature_identifier sg :> Identifier.Parent.t) | `Type _ as t -> (parent_type_identifier t :> Identifier.Parent.t) | (`Class _ | `ClassType _) as c -> @@ -942,14 +938,14 @@ module Reference = struct and label_parent_identifier : label_parent -> Identifier.LabelParent.t = function | `Identifier id -> id - | ( `Hidden _ | `Alias _ | `AliasModuleType _ | `Module _ | `Canonical _ - | `ModuleType _ | `Type _ | `Class _ | `ClassType _ ) as r -> + | ( `Hidden _ | `Alias _ | `AliasModuleType _ | `Module _ | `ModuleType _ + | `Type _ | `Class _ | `ClassType _ ) as r -> (parent_identifier r :> Identifier.LabelParent.t) and identifier : t -> Identifier.t = function | `Identifier id -> id - | ( `Alias _ | `AliasModuleType _ | `Module _ | `Canonical _ | `Hidden _ - | `Type _ | `Class _ | `ClassType _ | `ModuleType _ ) as r -> + | ( `Alias _ | `AliasModuleType _ | `Module _ | `Hidden _ | `Type _ + | `Class _ | `ClassType _ | `ModuleType _ ) as r -> (label_parent_identifier r :> Identifier.t) | `Field (p, n) -> `Field (parent_identifier p, n) | `Constructor (s, n) -> `Constructor (parent_type_identifier s, n) diff --git a/src/model/paths_types.ml b/src/model/paths_types.ml index 469193ea0d..242f846fc6 100644 --- a/src/model/paths_types.ml +++ b/src/model/paths_types.ml @@ -590,8 +590,7 @@ and Resolved_reference : sig [ `Identifier of Identifier.path_module | `Hidden of module_ | `Alias of Resolved_path.module_ * module_ - | `Module of signature * ModuleName.t - | `Canonical of module_ * Reference.module_ ] + | `Module of signature * ModuleName.t ] (** @canonical Odoc_model.Paths.Reference.Resolved.Module.t *) (* Signature is [ module | moduletype ] *) @@ -600,7 +599,6 @@ and Resolved_reference : sig | `Hidden of module_ | `Alias of Resolved_path.module_ * module_ | `Module of signature * ModuleName.t - | `Canonical of module_ * Reference.module_ | `ModuleType of signature * ModuleTypeName.t | `AliasModuleType of Resolved_path.module_type * module_type ] (** @canonical Odoc_model.Paths.Reference.Resolved.Signature.t *) @@ -618,7 +616,6 @@ and Resolved_reference : sig | `AliasModuleType of Resolved_path.module_type * module_type | `Module of signature * ModuleName.t | `Hidden of module_ - | `Canonical of module_ * Reference.module_ | `ModuleType of signature * ModuleTypeName.t | `Class of signature * ClassName.t | `ClassType of signature * ClassTypeName.t @@ -633,7 +630,6 @@ and Resolved_reference : sig | `AliasModuleType of Resolved_path.module_type * module_type | `Module of signature * ModuleName.t | `Hidden of module_ - | `Canonical of module_ * Reference.module_ | `ModuleType of signature * ModuleTypeName.t | `Class of signature * ClassName.t | `ClassType of signature * ClassTypeName.t @@ -716,7 +712,6 @@ and Resolved_reference : sig | `AliasModuleType of Resolved_path.module_type * module_type | `Module of signature * ModuleName.t | `Hidden of module_ - | `Canonical of module_ * Reference.module_ | `ModuleType of signature * ModuleTypeName.t | `Type of signature * TypeName.t | `Constructor of datatype * ConstructorName.t diff --git a/src/model_desc/paths_desc.ml b/src/model_desc/paths_desc.ml index eca4c6ae37..ead78c4f52 100644 --- a/src/model_desc/paths_desc.ml +++ b/src/model_desc/paths_desc.ml @@ -298,11 +298,6 @@ module General_paths = struct and resolved_reference : rr t = Variant (function - | `Canonical (x1, x2) -> - C - ( "`Canonical", - ((x1 :> rr), (x2 :> r)), - Pair (resolved_reference, reference) ) | `Class (x1, x2) -> C ( "`Class", diff --git a/src/xref2/component.ml b/src/xref2/component.ml index a0fb029a91..37aaf76fe0 100644 --- a/src/xref2/component.ml +++ b/src/xref2/component.ml @@ -1398,11 +1398,6 @@ module Fmt = struct (x :> Odoc_model.Paths.Path.Resolved.t) model_resolved_reference (y :> Odoc_model.Paths.Reference.Resolved.t) - | `Canonical (x, y) -> - Format.fprintf ppf "canonical(%a,%a)" model_resolved_reference - (x :> t) - model_reference - (y :> Odoc_model.Paths.Reference.t) | `Label (parent, name) -> Format.fprintf ppf "%a.%s" model_resolved_reference (parent :> t) @@ -2328,12 +2323,12 @@ module Of_Lang = struct and module_of_module_substitution ident_map (t : Odoc_model.Lang.ModuleSubstitution.t) = let manifest = module_path ident_map t.manifest in - let canonical = Some manifest in + let canonical = None in { Module.doc = docs ident_map t.doc; type_ = Alias (manifest, None); canonical; - hidden = true; + hidden = false; } and signature : _ -> Odoc_model.Lang.Signature.t -> Signature.t = diff --git a/src/xref2/cpath.ml b/src/xref2/cpath.ml index 09594985e3..ff844587b7 100644 --- a/src/xref2/cpath.ml +++ b/src/xref2/cpath.ml @@ -191,11 +191,11 @@ and is_resolved_module_hidden : | `Identifier _ -> false | `Hidden _ -> true | `Canonical (_, `Resolved _) -> false - | `Canonical (p, _) -> weak_canonical_test || inner p - | `Substituted p | `Apply (p, _) -> inner p + | `Canonical (p, _) -> (not weak_canonical_test) && inner p + | `Substituted p -> inner p | `Module (p, _) -> is_resolved_parent_hidden ~weak_canonical_test p | `Subst (p1, p2) -> is_resolved_module_type_hidden p1 || inner p2 - | `Alias (p1, p2) -> inner p1 || inner p2 + | `Alias (p1, p2) | `Apply (p1, p2) -> inner p1 || inner p2 | `OpaqueModule m -> inner m in inner @@ -281,15 +281,11 @@ let rec resolved_module_of_resolved_module_reference : | `Identifier i -> `Identifier i | `Alias (_m1, _m2) -> failwith "gah" | `Hidden s -> `Hidden (resolved_module_of_resolved_module_reference s) - | `Canonical (m1, m2) -> - `Canonical - ( resolved_module_of_resolved_module_reference m1, - module_of_module_reference m2 ) and resolved_module_of_resolved_signature_reference : Reference.Resolved.Signature.t -> Resolved.module_ = function | `Identifier (#Identifier.Module.t as i) -> `Identifier i - | (`Alias _ | `Canonical _ | `Module _ | `Hidden _) as r' -> + | (`Alias _ | `Module _ | `Hidden _) as r' -> resolved_module_of_resolved_module_reference r' | `ModuleType (_, n) -> failwith ("Not a module reference: " ^ ModuleTypeName.to_string n) diff --git a/src/xref2/env.ml b/src/xref2/env.ml index de0fb1d1df..05abdc748c 100644 --- a/src/xref2/env.ml +++ b/src/xref2/env.ml @@ -119,14 +119,23 @@ end = struct let remove id t = let id = (id :> Identifier.t) in let name = Identifier.name id in - let l = StringMap.find name t in + let l = + try StringMap.find name t + with e -> + Format.eprintf "Failed to find %s\n%!" name; + raise e + in match List.filter (fun e -> not (Identifier.equal id (Component.Element.identifier e.elem))) l with - | [] -> StringMap.remove name t + | [] -> ( + try StringMap.remove name t + with Not_found -> + Format.eprintf "Failed to find %s\n%!" name; + raise Not_found) | xs -> StringMap.add name xs (StringMap.remove name t) let find_by_name f name t = diff --git a/src/xref2/ident.ml b/src/xref2/ident.ml index 88e4055a04..3f12e7e5e4 100644 --- a/src/xref2/ident.ml +++ b/src/xref2/ident.ml @@ -228,6 +228,8 @@ module Name = struct let module_ m = ModuleName.to_string (module' m) + let unsafe_module m = ModuleName.to_string_unsafe (module' m) + let path_module : path_module -> string = function | `LRoot (n, _) -> ModuleName.to_string n | `LModule (n, _) -> ModuleName.to_string n @@ -264,11 +266,16 @@ module Name = struct let class_ c = ClassName.to_string (class' c) + let unsafe_class c = ClassName.to_string_unsafe (class' c) + let typed_class : class_ -> ClassName.t = function `LClass (n, _) -> n let module_type : module_type -> string = function | `LModuleType (n, _) -> ModuleTypeName.to_string n + let unsafe_module_type : module_type -> string = function + | `LModuleType (n, _) -> ModuleTypeName.to_string_unsafe n + let typed_module_type : module_type -> ModuleTypeName.t = function | `LModuleType (n, _) -> n @@ -281,6 +288,8 @@ module Name = struct let class_type c = ClassTypeName.to_string (class_type' c) + let unsafe_class_type c = ClassTypeName.to_string_unsafe (class_type' c) + let typed_class_type : class_type -> ClassTypeName.t = function | `LClassType (n, _) -> n diff --git a/src/xref2/lang_of.ml b/src/xref2/lang_of.ml index 63222a60e8..0ecd6ab99f 100644 --- a/src/xref2/lang_of.ml +++ b/src/xref2/lang_of.ml @@ -296,7 +296,7 @@ module ExtractIDs = struct open Component let rec type_decl parent map id = - let name = Ident.Name.type_ id in + let name = Ident.Name.unsafe_type id in let identifier = if List.mem name map.shadowed.s_types then `Type (parent, Odoc_model.Names.TypeName.internal_of_string name) @@ -313,7 +313,7 @@ module ExtractIDs = struct } and module_ parent map id = - let name = Ident.Name.module_ id in + let name = Ident.Name.unsafe_module id in let identifier = if List.mem name map.shadowed.s_modules then `Module (parent, ModuleName.internal_of_string name) @@ -322,7 +322,7 @@ module ExtractIDs = struct { map with module_ = Component.ModuleMap.add id identifier map.module_ } and module_type parent map id = - let name = Ident.Name.module_type id in + let name = Ident.Name.unsafe_module_type id in let identifier = if List.mem name map.shadowed.s_module_types then `ModuleType (parent, ModuleTypeName.internal_of_string name) @@ -334,7 +334,7 @@ module ExtractIDs = struct } and class_ parent map id = - let name = Ident.Name.class_ id in + let name = Ident.Name.unsafe_class id in let identifier = if List.mem name map.shadowed.s_classes then `Class (parent, ClassName.internal_of_string name) @@ -356,7 +356,7 @@ module ExtractIDs = struct } and class_type parent map (id : Ident.class_type) = - let name = Ident.Name.class_type id in + let name = Ident.Name.unsafe_class_type id in let identifier = if List.mem name map.shadowed.s_class_types then `ClassType (parent, ClassTypeName.internal_of_string name) diff --git a/src/xref2/tools.ml b/src/xref2/tools.ml index 8f706e4df9..188501e12a 100644 --- a/src/xref2/tools.ml +++ b/src/xref2/tools.ml @@ -1094,22 +1094,24 @@ and handle_canonical_module env p2 = match m.type_ with | Component.Module.Alias (_, Some _) -> true | Alias (`Resolved p, None) -> - (* check for an alias chain with a canonical in it... *) - let rec check (m, p) = + (* we're an alias - check to see if we're marked as the canonical path. + If not, check for an alias chain with us as canonical in it... *) + let rec check m = match m.Component.Module.canonical with | Some p -> p = p2 (* The canonical path is the same one we're trying to resolve *) | None -> ( - match lookup_module ~mark_substituted:false env p with - | Error _ -> false - | Ok m -> ( - let m = Component.Delayed.get m in - match m.type_ with - | Alias (`Resolved p, _) -> check (m, p) - | _ -> false)) + match m.type_ with + | Component.Module.Alias (`Resolved p, _) -> ( + match lookup_module ~mark_substituted:false env p with + | Error _ -> false + | Ok m -> + let m = Component.Delayed.get m in + check m) + | _ -> false) in - let self_canonical () = check (m, p) in + let self_canonical () = check m in let hidden = Cpath.is_resolved_module_hidden ~weak_canonical_test:true p in diff --git a/test/generators/html/Include.html b/test/generators/html/Include.html index fd98420248..ad8b36c376 100644 --- a/test/generators/html/Include.html +++ b/test/generators/html/Include.html @@ -57,12 +57,10 @@
IncludeInclude_sectionsSomething
once
-
+ foo
+Some text.
Something
a second time: the heading level should be shift here.
-
+ foo
+Some text.
Shifted some more.
- +foo
+Some text.
And let's include it again, but without inlining it this time: the ToC shouldn't grow.
diff --git a/test/generators/html/Ocamlary-module-type-RecollectionModule.html b/test/generators/html/Ocamlary-module-type-RecollectionModule.html index 1ea17107e7..4574465e30 100644 --- a/test/generators/html/Ocamlary-module-type-RecollectionModule.html +++ b/test/generators/html/Ocamlary-module-type-RecollectionModule.html @@ -15,68 +15,80 @@Ocamlary.RecollectionModuletype collection
- =
-
-
- CollectionModule.element
- list
+
+
+
+
+ include
+ sig ... end
-
-
-
- type element
- =
-
- CollectionModule.collection
-
-
-
-
- module
-
- InnerModuleA
-
-
- : sig ...
- end
-
-
- This comment is for InnerModuleA.
- module
- type InnerModuleTypeA
-
- =
- InnerModuleA.InnerModuleTypeA'
-
-
-
- This comment is for InnerModuleTypeA.
type collection
+ =
+
+
+ CollectionModule.element
+ list
+
+
+
+ type element
+ =
+
+ CollectionModule.collection
+
+
+
+
+ module
+
+ InnerModuleA
+
+
+ : sig ...
+ end
+
+
+ This comment is for InnerModuleA.
+ module
+ type InnerModuleTypeA
+
+ =
+ InnerModuleA.InnerModuleTypeA'
+
+
+
+ This comment is for InnerModuleTypeA.