diff --git a/src/xref2/compile.ml b/src/xref2/compile.ml index 7844d2c5c1..c8204a228e 100644 --- a/src/xref2/compile.ml +++ b/src/xref2/compile.ml @@ -16,9 +16,9 @@ let type_path : Env.t -> Paths.Path.Type.t -> Paths.Path.Type.t = match p with | `Resolved _ -> p | _ -> ( - let cp = Component.Of_Lang.(type_path empty p) in + let cp = Component.Of_Lang.(type_path (empty ()) p) in match Tools.resolve_type_path env cp with - | Ok p' -> `Resolved (Cpath.resolved_type_path_of_cpath p') + | Ok p' -> `Resolved Lang_of.(Path.resolved_type (empty ()) p') | Error _ -> p) and module_type_path : @@ -27,9 +27,9 @@ and module_type_path : match p with | `Resolved _ -> p | _ -> ( - let cp = Component.Of_Lang.(module_type_path empty p) in + let cp = Component.Of_Lang.(module_type_path (empty ()) p) in match Tools.resolve_module_type_path env cp with - | Ok p' -> `Resolved (Cpath.resolved_module_type_path_of_cpath p') + | Ok p' -> `Resolved Lang_of.(Path.resolved_module_type (empty ()) p') | Error _ -> p) and module_path : Env.t -> Paths.Path.Module.t -> Paths.Path.Module.t = @@ -37,9 +37,9 @@ and module_path : Env.t -> Paths.Path.Module.t -> Paths.Path.Module.t = match p with | `Resolved _ -> p | _ -> ( - let cp = Component.Of_Lang.(module_path empty p) in + let cp = Component.Of_Lang.(module_path (empty ()) p) in match Tools.resolve_module_path env cp with - | Ok p' -> `Resolved (Cpath.resolved_module_path_of_cpath p') + | Ok p' -> `Resolved Lang_of.(Path.resolved_module (empty ()) p') | Error _ -> p) and class_type_path : Env.t -> Paths.Path.ClassType.t -> Paths.Path.ClassType.t @@ -48,10 +48,10 @@ and class_type_path : Env.t -> Paths.Path.ClassType.t -> Paths.Path.ClassType.t match p with | `Resolved _ -> p | _ -> ( - let cp = Component.Of_Lang.(class_type_path empty p) in + let cp = Component.Of_Lang.(class_type_path (empty ()) p) in match Tools.resolve_class_type_path env cp with - | Ok p' -> `Resolved (Cpath.resolved_class_type_path_of_cpath p') - | Error _ -> Cpath.class_type_path_of_cpath cp) + | Ok p' -> `Resolved Lang_of.(Path.resolved_class_type (empty ()) p') + | Error _ -> p) let rec unit env t = let open Compilation_unit in @@ -62,7 +62,8 @@ and content env id = function | Module m -> let sg = Type_of.signature env m in - Module (signature env (id :> Id.Signature.t) sg) + let sg = signature env (id :> Id.Signature.t) sg in + Module sg | Pack p -> Pack p and value_ env parent t = @@ -113,7 +114,7 @@ and class_type env c = Env.(lookup_by_id s_class_type) c.id env >>= fun (`ClassType (_, c')) -> Tools.class_signature_of_class_type env c' >>= fun sg -> let cs = - Lang_of.class_signature Lang_of.empty + Lang_of.class_signature (Lang_of.empty ()) (c.id :> Paths.Identifier.Path.ClassType.t) sg in @@ -169,7 +170,7 @@ and class_ env parent c = Env.(lookup_by_id s_class) c.id env >>= fun (`Class (_, c')) -> Tools.class_signature_of_class env c' >>= fun sg -> let cs = - Lang_of.class_signature Lang_of.empty + Lang_of.class_signature (Lang_of.empty ()) (c.id :> Paths.Identifier.Path.ClassType.t) sg in @@ -206,7 +207,7 @@ and signature_items : Env.t -> Id.Signature.t -> Signature.item list -> _ = else let ty = Component.Delayed.( - put (fun () -> Component.Of_Lang.(module_ empty m'))) + put (fun () -> Component.Of_Lang.(module_ (empty ()) m'))) in let docs = [] in let env' = @@ -221,7 +222,7 @@ and signature_items : Env.t -> Id.Signature.t -> Signature.item list -> _ = | TypeSubstitution t -> std @@ TypeSubstitution (type_decl env t) | ModuleType mt -> let m' = module_type env mt in - let ty = Component.Of_Lang.(module_type empty m') in + let ty = Component.Of_Lang.(module_type (empty ()) m') in let env' = Env.update_module_type mt.id ty env in (ModuleType (module_type env mt) :: items, env') | ModuleTypeSubstitution mt -> @@ -258,13 +259,17 @@ and signature : Env.t -> Id.Signature.t -> Signature.t -> _ = fun env id s -> if s.compiled then s else - let env = Env.open_signature s env in - let items = signature_items env id s.items in - { - items; - compiled = true; - doc = s.doc (* comments are ignored while compiling *); - } + let sg = + let env = Env.open_signature s env in + let items = signature_items env id s.items in + { + Signature.items; + compiled = true; + doc = s.doc (* comments are ignored while compiling *); + } + in + let sg' = Component.Of_Lang.(signature (empty ()) sg) in + Lang_of.(signature (id :> Id.Signature.t) (empty ()) sg') and module_ : Env.t -> Module.t -> Module.t = fun env m -> @@ -300,7 +305,7 @@ and module_type : Env.t -> ModuleType.t -> ModuleType.t = and include_ : Env.t -> Include.t -> Include.t = fun env i -> let open Include in - let decl = Component.Of_Lang.(include_decl empty i.decl) in + let decl = Component.Of_Lang.(include_decl (empty ()) i.decl) in let get_expansion () = match let open Utils.ResultMonad in @@ -315,11 +320,11 @@ and include_ : Env.t -> Include.t -> Include.t = Errors.report ~what:(`Include decl) ~tools_error:e `Expand; i.expansion | Ok sg -> - let map = { Lang_of.empty with shadowed = i.expansion.shadowed } in + let map = Lang_of.with_shadowed i.expansion.shadowed in let sg' = match i.strengthened with | Some p -> - let cp = Component.Of_Lang.(module_path empty p) in + let cp = Component.Of_Lang.(module_path (empty ()) p) in Strengthen.signature cp sg | None -> sg in @@ -376,7 +381,7 @@ and module_type_expr_sub id ~fragment_root (sg_res, env, subs) lsub = let sg_and_sub = match lsub with | Odoc_model.Lang.ModuleType.ModuleEq (frag, decl) -> - let cfrag = Component.Of_Lang.(module_fragment empty frag) in + let cfrag = Component.Of_Lang.(module_fragment (empty ()) frag) in let cfrag', frag' = match Tools.resolve_module_fragment env (fragment_root, sg) cfrag @@ -391,7 +396,7 @@ and module_type_expr_sub id ~fragment_root (sg_res, env, subs) lsub = (cfrag, frag) in let decl' = module_decl env id decl in - let cdecl' = Component.Of_Lang.(module_decl empty decl') in + let cdecl' = Component.Of_Lang.(module_decl (empty ()) decl') in let resolved_csub = Component.ModuleType.ModuleEq (cfrag', cdecl') in @@ -399,7 +404,7 @@ and module_type_expr_sub id ~fragment_root (sg_res, env, subs) lsub = >>= fun sg' -> Ok (sg', Odoc_model.Lang.ModuleType.ModuleEq (frag', decl')) | TypeEq (frag, eqn) -> - let cfrag = Component.Of_Lang.(type_fragment empty frag) in + let cfrag = Component.Of_Lang.(type_fragment (empty ()) frag) in let cfrag', frag' = match Tools.resolve_type_fragment env (fragment_root, sg) cfrag @@ -414,14 +419,14 @@ and module_type_expr_sub id ~fragment_root (sg_res, env, subs) lsub = (cfrag, frag) in let eqn' = type_decl_equation env (id :> Id.Parent.t) eqn in - let ceqn' = Component.Of_Lang.(type_equation empty eqn') in + let ceqn' = Component.Of_Lang.(type_equation (empty ()) eqn') in Tools.fragmap ~mark_substituted:true env (Component.ModuleType.TypeEq (cfrag', ceqn')) sg >>= fun sg' -> Ok (sg', Odoc_model.Lang.ModuleType.TypeEq (frag', eqn')) | ModuleSubst (frag, mpath) -> - let cfrag = Component.Of_Lang.(module_fragment empty frag) in + let cfrag = Component.Of_Lang.(module_fragment (empty ()) frag) in let cfrag', frag' = match Tools.resolve_module_fragment env (fragment_root, sg) cfrag @@ -436,14 +441,14 @@ and module_type_expr_sub id ~fragment_root (sg_res, env, subs) lsub = (cfrag, frag) in let mpath' = module_path env mpath in - let cmpath' = Component.Of_Lang.(module_path empty mpath') in + let cmpath' = Component.Of_Lang.(module_path (empty ()) mpath') in Tools.fragmap ~mark_substituted:true env (Component.ModuleType.ModuleSubst (cfrag', cmpath')) sg >>= fun sg' -> Ok (sg', Odoc_model.Lang.ModuleType.ModuleSubst (frag', mpath')) | TypeSubst (frag, eqn) -> - let cfrag = Component.Of_Lang.(type_fragment empty frag) in + let cfrag = Component.Of_Lang.(type_fragment (empty ()) frag) in let cfrag', frag' = match Tools.resolve_type_fragment env (fragment_root, sg) cfrag @@ -457,14 +462,16 @@ and module_type_expr_sub id ~fragment_root (sg_res, env, subs) lsub = (cfrag, frag) in let eqn' = type_decl_equation env (id :> Id.Parent.t) eqn in - let ceqn' = Component.Of_Lang.(type_equation empty eqn') in + let ceqn' = Component.Of_Lang.(type_equation (empty ()) eqn') in Tools.fragmap ~mark_substituted:true env (Component.ModuleType.TypeSubst (cfrag', ceqn')) sg >>= fun sg' -> Ok (sg', Odoc_model.Lang.ModuleType.TypeSubst (frag', eqn')) | ModuleTypeEq (frag, mty) -> - let cfrag = Component.Of_Lang.(module_type_fragment empty frag) in + let cfrag = + Component.Of_Lang.(module_type_fragment (empty ()) frag) + in let cfrag', frag' = match Tools.resolve_module_type_fragment env (fragment_root, sg) cfrag @@ -479,7 +486,7 @@ and module_type_expr_sub id ~fragment_root (sg_res, env, subs) lsub = (cfrag, frag) in let mty = module_type_expr env id mty in - let mty' = Component.Of_Lang.(module_type_expr empty mty) in + let mty' = Component.Of_Lang.(module_type_expr (empty ()) mty) in let resolved_csub = Component.ModuleType.ModuleTypeEq (cfrag', mty') in @@ -487,7 +494,9 @@ and module_type_expr_sub id ~fragment_root (sg_res, env, subs) lsub = >>= fun sg' -> Ok (sg', Odoc_model.Lang.ModuleType.ModuleTypeEq (frag', mty)) | Odoc_model.Lang.ModuleType.ModuleTypeSubst (frag, mty) -> - let cfrag = Component.Of_Lang.(module_type_fragment empty frag) in + let cfrag = + Component.Of_Lang.(module_type_fragment (empty ()) frag) + in let cfrag', frag' = match Tools.resolve_module_type_fragment env (fragment_root, sg) cfrag @@ -502,7 +511,7 @@ and module_type_expr_sub id ~fragment_root (sg_res, env, subs) lsub = (cfrag, frag) in let mty = module_type_expr env id mty in - let mty' = Component.Of_Lang.(module_type_expr empty mty) in + let mty' = Component.Of_Lang.(module_type_expr (empty ()) mty) in let resolved_csub = Component.ModuleType.ModuleTypeSubst (cfrag', mty') in @@ -558,7 +567,7 @@ and u_module_type_expr : | Path p -> Path (module_type_path env p) | With (subs, expr) -> let expr' = inner expr in - let cexpr = Component.Of_Lang.(u_module_type_expr empty expr') in + let cexpr = Component.Of_Lang.(u_module_type_expr (empty ()) expr') in let subs' = match module_type_map_subs env id cexpr subs with | Some s -> s @@ -587,10 +596,10 @@ and module_type_expr : match cur with | Some e -> Some (simple_expansion env id e) | None -> ( - let ce = Component.Of_Lang.(module_type_expr empty e) in + let ce = Component.Of_Lang.(module_type_expr (empty ()) e) in match Expand_tools.expansion_of_module_type_expr env id ce with | Ok (_, _, ce) -> - let e = Lang_of.simple_expansion Lang_of.empty id ce in + let e = Lang_of.simple_expansion (Lang_of.empty ()) id ce in Some (simple_expansion env id e) | Error `OpaqueModule -> None | Error e -> @@ -607,7 +616,7 @@ and module_type_expr : | With { w_substitutions; w_expansion; w_expr } as e -> ( let w_expansion = get_expansion w_expansion e in let w_expr = u_module_type_expr env id w_expr in - let cexpr = Component.Of_Lang.(u_module_type_expr empty w_expr) in + let cexpr = Component.Of_Lang.(u_module_type_expr (empty ()) w_expr) in let subs' = module_type_map_subs env id cexpr w_substitutions in match subs' with | None -> With { w_substitutions; w_expansion; w_expr } @@ -706,7 +715,7 @@ and type_expression_object env parent o = and type_expression_package env parent p = let open TypeExpr.Package in - let cp = Component.Of_Lang.(module_type_path empty p.path) in + let cp = Component.Of_Lang.(module_type_path (empty ()) p.path) in match Tools.resolve_module_type ~mark_substituted:true ~add_canonical:true env cp with @@ -717,13 +726,14 @@ and type_expression_package env parent p = p | Ok sg -> let substitution (frag, t) = - let cfrag = Component.Of_Lang.(type_fragment empty frag) in + let cfrag = Component.Of_Lang.(type_fragment (empty ()) frag) in let frag' = match Tools.resolve_type_fragment env (`ModuleType path, sg) cfrag with | Some cfrag' -> - `Resolved (Lang_of.(Path.resolved_type_fragment empty) cfrag') + `Resolved + (Lang_of.(Path.resolved_type_fragment (empty ())) cfrag') | None -> Errors.report ~what:(`Type cfrag) `Compile; frag @@ -734,7 +744,7 @@ and type_expression_package env parent p = path = module_type_path env p.path; substitutions = List.map substitution p.substitutions; }) - | Error _ -> { p with path = Cpath.module_type_path_of_cpath cp } + | Error _ -> { p with path = Lang_of.(Path.module_type (empty ()) cp) } and type_expression : Env.t -> Id.Parent.t -> _ -> _ = fun env parent texpr -> @@ -746,16 +756,16 @@ and type_expression : Env.t -> Id.Parent.t -> _ -> _ = Arrow (lbl, type_expression env parent t1, type_expression env parent t2) | Tuple ts -> Tuple (List.map (type_expression env parent) ts) | Constr (path, ts') -> ( - let cp = Component.Of_Lang.(type_path empty path) in + let cp = Component.Of_Lang.(type_path (empty ()) path) in let ts = List.map (type_expression env parent) ts' in match Tools.resolve_type env ~add_canonical:true cp with | Ok (cp, (`FType _ | `FClass _ | `FClassType _)) -> - let p = Cpath.resolved_type_path_of_cpath cp in + let p = Lang_of.(Path.resolved_type (empty ()) cp) in Constr (`Resolved p, ts) | Ok (_cp, `FType_removed (_, x, _eq)) -> (* Substitute type variables ? *) - Lang_of.(type_expr empty parent x) - | Error _ -> Constr (Cpath.type_path_of_cpath cp, ts)) + Lang_of.(type_expr (empty ()) parent x) + | Error _ -> Constr (Lang_of.(Path.type_ (empty ()) cp), ts)) | Polymorphic_variant v -> Polymorphic_variant (type_expression_polyvar env parent v) | Object o -> Object (type_expression_object env parent o) diff --git a/src/xref2/component.ml b/src/xref2/component.ml index c341a9007c..06c5991f6a 100644 --- a/src/xref2/component.ml +++ b/src/xref2/component.ml @@ -1554,6 +1554,14 @@ end module Of_Lang = struct open Odoc_model + module RM = Map.Make (struct + type t = Paths.Path.Resolved.Module.t + + let compare x y = if x == y then 0 else compare x y + end) + + type memos = { mutable rmodpathmemo : Cpath.Resolved.module_ RM.t } + type map = { modules : Ident.module_ Paths.Identifier.Maps.Module.t; module_types : Ident.module_type Paths.Identifier.Maps.ModuleType.t; @@ -1565,10 +1573,12 @@ module Of_Lang = struct Ident.path_class_type Paths.Identifier.Maps.Path.ClassType.t; classes : Ident.class_ Paths.Identifier.Maps.Class.t; class_types : Ident.class_type Paths.Identifier.Maps.ClassType.t; + memos : memos; } - let empty = + let empty () = let open Paths.Identifier.Maps in + let memos = { rmodpathmemo = RM.empty } in { modules = Module.empty; module_types = ModuleType.empty; @@ -1578,6 +1588,7 @@ module Of_Lang = struct path_class_types = Path.ClassType.empty; classes = Class.empty; class_types = ClassType.empty; + memos; } let map_of_idents ids map = @@ -1662,6 +1673,7 @@ module Of_Lang = struct map.path_class_types in { + (empty ()) with modules; module_types; functor_parameters; @@ -1692,17 +1704,24 @@ module Of_Lang = struct let rec resolved_module_path : _ -> Odoc_model.Paths.Path.Resolved.Module.t -> Cpath.Resolved.module_ = fun ident_map p -> - let recurse p = resolved_module_path ident_map p in - match p with - | `Identifier i -> identifier find_any_module ident_map i - | `Module (p, name) -> `Module (`Module (recurse p), name) - | `Apply (p1, p2) -> `Apply (recurse p1, recurse p2) - | `Alias (p1, p2) -> `Alias (recurse p1, recurse p2) - | `Subst (p1, p2) -> - `Subst (resolved_module_type_path ident_map p1, recurse p2) - | `Canonical (p1, p2) -> `Canonical (recurse p1, module_path ident_map p2) - | `Hidden p1 -> `Hidden (recurse p1) - | `OpaqueModule m -> `OpaqueModule (recurse m) + let f () = + let recurse p = resolved_module_path ident_map p in + match p with + | `Identifier i -> identifier find_any_module ident_map i + | `Module (p, name) -> `Module (`Module (recurse p), name) + | `Apply (p1, p2) -> `Apply (recurse p1, recurse p2) + | `Alias (p1, p2) -> `Alias (recurse p1, recurse p2) + | `Subst (p1, p2) -> + `Subst (resolved_module_type_path ident_map p1, recurse p2) + | `Canonical (p1, p2) -> `Canonical (recurse p1, module_path ident_map p2) + | `Hidden p1 -> `Hidden (recurse p1) + | `OpaqueModule m -> `OpaqueModule (recurse m) + in + try RM.find p ident_map.memos.rmodpathmemo + with Not_found -> + let res = f () in + ident_map.memos.rmodpathmemo <- RM.add p res ident_map.memos.rmodpathmemo; + res and resolved_module_type_path : _ -> diff --git a/src/xref2/component.mli b/src/xref2/component.mli index d6e5959bb3..4dc17223c4 100644 --- a/src/xref2/component.mli +++ b/src/xref2/component.mli @@ -609,7 +609,7 @@ end module Of_Lang : sig type map - val empty : map + val empty : unit -> map val identifier : ('a -> 'b -> 'c) -> 'b -> 'a -> [> `Identifier of 'a | `Local of 'c ] diff --git a/src/xref2/cpath.ml b/src/xref2/cpath.ml index 9a8f6e5d69..09594985e3 100644 --- a/src/xref2/cpath.ml +++ b/src/xref2/cpath.ml @@ -88,115 +88,6 @@ end = include Cpath -type local_path_error = - | ErrModule of module_ - | ErrModuleType of module_type - | ErrType of type_ - -exception LocalPath of local_path_error - -let rec resolved_module_path_of_cpath : - Resolved.module_ -> Path.Resolved.Module.t = function - | `Local _ as y -> raise (LocalPath (ErrModule (`Resolved y))) - | `Substituted y -> resolved_module_path_of_cpath y - | `Identifier (#Identifier.Path.Module.t as x) -> `Identifier x - | `Subst (a, b) -> - `Subst - (resolved_module_type_path_of_cpath a, resolved_module_path_of_cpath b) - | `Hidden x -> `Hidden (resolved_module_path_of_cpath x) - | `Canonical (a, b) -> - `Canonical (resolved_module_path_of_cpath a, module_path_of_cpath b) - | `Apply (a, b) -> - `Apply (resolved_module_path_of_cpath a, resolved_module_path_of_cpath b) - | `Alias (a, b) -> - `Alias (resolved_module_path_of_cpath a, resolved_module_path_of_cpath b) - | `Module (p, m) -> `Module (resolved_module_path_of_cpath_parent p, m) - | `OpaqueModule m -> `OpaqueModule (resolved_module_path_of_cpath m) - -and resolved_module_path_of_cpath_parent : - Resolved.parent -> Path.Resolved.Module.t = function - | `Module m -> resolved_module_path_of_cpath m - | `ModuleType _ | `FragmentRoot -> failwith "Can't do it" - -and resolved_module_type_path_of_cpath : - Resolved.module_type -> Path.Resolved.ModuleType.t = function - | `Local _ as y -> raise (LocalPath (ErrModuleType (`Resolved y))) - | `Identifier (#Identifier.ModuleType.t as x) -> `Identifier x - | `Substituted y -> resolved_module_type_path_of_cpath y - | `ModuleType (p, m) -> `ModuleType (resolved_module_path_of_cpath_parent p, m) - | `SubstT (p1, p2) -> - `SubstT - ( resolved_module_type_path_of_cpath p1, - resolved_module_type_path_of_cpath p2 ) - | `AliasModuleType (m1, m2) -> - `AliasModuleType - ( resolved_module_type_path_of_cpath m1, - resolved_module_type_path_of_cpath m2 ) - | `CanonicalModuleType (p1, p2) -> - `CanonicalModuleType - (resolved_module_type_path_of_cpath p1, module_type_path_of_cpath p2) - | `OpaqueModuleType m -> - `OpaqueModuleType (resolved_module_type_path_of_cpath m) - -and resolved_type_path_of_cpath : Resolved.type_ -> Path.Resolved.Type.t = - function - | `Identifier (#Odoc_model.Paths.Identifier.Path.Type.t as x) -> `Identifier x - | `Local _ as y -> raise (LocalPath (ErrType (`Resolved y))) - | `Substituted y -> resolved_type_path_of_cpath y - | `CanonicalType (t1, t2) -> - `CanonicalType (resolved_type_path_of_cpath t1, type_path_of_cpath t2) - | `Type (p, m) -> `Type (resolved_module_path_of_cpath_parent p, m) - | `Class (p, m) -> `Class (resolved_module_path_of_cpath_parent p, m) - | `ClassType (p, m) -> `ClassType (resolved_module_path_of_cpath_parent p, m) - -and resolved_class_type_path_of_cpath : - Resolved.class_type -> Path.Resolved.ClassType.t = function - | `Identifier (#Odoc_model.Paths.Identifier.Path.ClassType.t as x) -> - `Identifier x - | `Local ident -> - raise - (LocalPath (ErrType (`Resolved (`Local (ident :> Ident.path_type))))) - | `Substituted y -> resolved_class_type_path_of_cpath y - | `Class (p, m) -> `Class (resolved_module_path_of_cpath_parent p, m) - | `ClassType (p, m) -> `ClassType (resolved_module_path_of_cpath_parent p, m) - -and module_path_of_cpath : module_ -> Path.Module.t = function - | `Resolved r -> `Resolved (resolved_module_path_of_cpath r) - | `Dot (p, x) -> `Dot (module_path_of_cpath p, x) - | `Module (_p, _n) -> failwith "Probably shouldn't happen" - | `Identifier (x, b) -> `Identifier (x, b) - | `Local _ as y -> raise (LocalPath (ErrModule y)) - | `Substituted p -> module_path_of_cpath p - | `Root x -> `Root x - | `Forward x -> `Forward x - | `Apply (m1, m2) -> `Apply (module_path_of_cpath m1, module_path_of_cpath m2) - -and module_type_path_of_cpath : module_type -> Path.ModuleType.t = function - | `Resolved r -> `Resolved (resolved_module_type_path_of_cpath r) - | `Identifier (x, b) -> `Identifier (x, b) - | `Local _ as y -> raise (LocalPath (ErrModuleType y)) - | `Substituted r -> module_type_path_of_cpath r - | `Dot (p, x) -> `Dot (module_path_of_cpath p, x) - | `ModuleType (_p, _n) -> failwith "Probably shouldn't happen" - -and type_path_of_cpath : type_ -> Path.Type.t = function - | `Resolved r -> `Resolved (resolved_type_path_of_cpath r) - | `Identifier (x, b) -> `Identifier (x, b) - | `Local _ as y -> raise (LocalPath (ErrType y)) - | `Substituted r -> type_path_of_cpath r - | `Dot (p, x) -> `Dot (module_path_of_cpath p, x) - | `Type (_, _) | `Class (_, _) | `ClassType (_, _) -> - failwith "Probably shouldn't happen" - -and class_type_path_of_cpath : class_type -> Path.ClassType.t = function - | `Resolved r -> `Resolved (resolved_class_type_path_of_cpath r) - | `Identifier (x, b) -> `Identifier (x, b) - | `Local (ident, b) -> - raise (LocalPath (ErrType (`Local ((ident :> Ident.path_type), b)))) - | `Substituted r -> class_type_path_of_cpath r - | `Dot (p, x) -> `Dot (module_path_of_cpath p, x) - | `Class (_, _) | `ClassType (_, _) -> failwith "Probably shouldn't happen" - let rec is_resolved_module_substituted : Resolved.module_ -> bool = function | `Local _ -> false | `Substituted _ -> true diff --git a/src/xref2/env.ml b/src/xref2/env.ml index 5075c9bdb8..ef1197ee11 100644 --- a/src/xref2/env.ml +++ b/src/xref2/env.ml @@ -61,7 +61,13 @@ let pp_lookup_type_list fmt ls = in Format.fprintf fmt "[%a]" inner ls -type recorder = { mutable lookups : lookup_type list } +module LookupTypeSet = Set.Make (struct + type t = lookup_type + + let compare = compare +end) + +type recorder = { mutable lookups : LookupTypeSet.t } module Maps = Odoc_model.Paths.Identifier.Maps module StringMap = Map.Make (String) @@ -181,11 +187,11 @@ let has_resolver t = match t.resolver with None -> false | _ -> true let id t = t.id let with_recorded_lookups env f = - let recorder = { lookups = [] } in + let recorder = { lookups = LookupTypeSet.empty } in let env' = { env with recorder = Some recorder } in let restore () = match env.recorder with - | Some r -> r.lookups <- recorder.lookups @ r.lookups + | Some r -> r.lookups <- LookupTypeSet.union recorder.lookups r.lookups | None -> () in try @@ -387,7 +393,7 @@ let module_of_unit : Odoc_model.Lang.Compilation_unit.t -> Component.Module.t = hidden = unit.hidden; } in - let ty = Component.Of_Lang.(module_ empty m) in + let ty = Component.Of_Lang.(module_ (empty ()) m) in ty | Pack _p -> let m = @@ -401,7 +407,7 @@ let module_of_unit : Odoc_model.Lang.Compilation_unit.t -> Component.Module.t = hidden = unit.hidden; } in - let ty = Component.Of_Lang.(module_ empty m) in + let ty = Component.Of_Lang.(module_ (empty ()) m) in ty let lookup_root_module name env = @@ -419,10 +425,15 @@ let lookup_root_module name env = in (match (env.recorder, result) with | Some r, Some Forward -> - r.lookups <- RootModule (name, Some `Forward) :: r.lookups + r.lookups <- + LookupTypeSet.add (RootModule (name, Some `Forward)) r.lookups | Some r, Some (Resolved (root, _, _)) -> - r.lookups <- RootModule (name, Some (`Resolved root.digest)) :: r.lookups - | Some r, None -> r.lookups <- RootModule (name, None) :: r.lookups + r.lookups <- + LookupTypeSet.add + (RootModule (name, Some (`Resolved root.digest))) + r.lookups + | Some r, None -> + r.lookups <- LookupTypeSet.add (RootModule (name, None)) r.lookups | None, _ -> ()); result @@ -448,7 +459,8 @@ let lookup_by_name scope name env = List.iter (function | `Module (id, _) -> - r.lookups <- ModuleByName (name, id) :: r.lookups + r.lookups <- + LookupTypeSet.add (ModuleByName (name, id)) r.lookups | _ -> ()) (results :> Component.Element.any list) | None -> () @@ -475,8 +487,10 @@ let lookup_by_id (scope : 'a scope) id env : 'a option = match env.recorder with | Some r -> ( match (result :> Component.Element.any) with - | `Module (id, _) -> r.lookups <- Module id :: r.lookups - | `ModuleType (id, _) -> r.lookups <- ModuleType id :: r.lookups + | `Module (id, _) -> + r.lookups <- LookupTypeSet.add (Module id) r.lookups + | `ModuleType (id, _) -> + r.lookups <- LookupTypeSet.add (ModuleType id) r.lookups | _ -> ()) | None -> () in @@ -589,7 +603,7 @@ let n = ref 0 let lookup_fragment_root env = let maybe_record_result res = match env.recorder with - | Some r -> r.lookups <- res :: r.lookups + | Some r -> r.lookups <- LookupTypeSet.add res r.lookups | None -> () in match env.fragmentroot with @@ -607,7 +621,8 @@ let add_functor_parameter : Odoc_model.Lang.FunctorParameter.t -> t -> t = Component.Module. { doc = []; - type_ = ModuleType Component.Of_Lang.(module_type_expr empty n.expr); + type_ = + ModuleType Component.Of_Lang.(module_type_expr (empty ()) n.expr); canonical = None; hidden = false; } @@ -682,7 +697,7 @@ let open_class_signature : Odoc_model.Lang.ClassSignature.t -> t -> t = (fun env orig -> match orig with | Odoc_model.Lang.ClassSignature.Method m -> - let ty = method_ empty m in + let ty = method_ (empty ()) m in add_method m.Odoc_model.Lang.Method.id ty env | _ -> env) env s.items @@ -691,26 +706,27 @@ let rec open_signature : Odoc_model.Lang.Signature.t -> t -> t = let open Component in let open Of_Lang in let module L = Odoc_model.Lang in + let ident_map = empty () in fun s e -> List.fold_left (fun env orig -> match ((orig : L.Signature.item), env.linking) with | Type (_, t), _ -> - let ty = type_decl empty t in + let ty = type_decl ident_map t in add_type t.L.TypeDecl.id ty env | Module (_, t), _ -> - let ty = Component.Delayed.put (fun () -> module_ empty t) in + let ty = Component.Delayed.put (fun () -> module_ ident_map t) in add_module (t.L.Module.id :> Identifier.Path.Module.t) ty - (docs empty t.L.Module.doc) + (docs ident_map t.L.Module.doc) env | ModuleType t, _ -> - let ty = module_type empty t in + let ty = module_type ident_map t in add_module_type t.L.ModuleType.id ty env | ModuleTypeSubstitution t, _ -> let ty = - module_type empty + module_type ident_map { id = t.id; doc = t.doc; @@ -720,42 +736,42 @@ let rec open_signature : Odoc_model.Lang.Signature.t -> t -> t = in add_module_type t.L.ModuleTypeSubstitution.id ty env | L.Signature.TypeSubstitution t, _ -> - let ty = type_decl empty t in + let ty = type_decl ident_map t in add_type t.L.TypeDecl.id ty env | L.Signature.ModuleSubstitution m, _ -> let _id = Ident.Of_Identifier.module_ m.id in - let doc = docs empty m.doc in + let doc = docs ident_map m.doc in let ty = Component.Delayed.put (fun () -> Of_Lang.( module_of_module_substitution - (* { empty with modules = [ (m.id, id) ] } *) - empty m)) + (* { ident_map with modules = [ (m.id, id) ] } *) + ident_map m)) in add_module (m.id :> Identifier.Path.Module.t) ty doc env | L.Signature.Class (_, c), _ -> - let ty = class_ empty c in + let ty = class_ ident_map c in add_class c.id ty env | L.Signature.ClassType (_, c), _ -> - let ty = class_type empty c in + let ty = class_type ident_map c in add_class_type c.id ty env | L.Signature.Include i, _ -> open_signature i.expansion.content env | L.Signature.Open o, _ -> open_signature o.expansion env (* The following are only added when linking *) | Comment c, true -> add_comment c env | TypExt te, true -> - let doc = docs empty te.doc in + let doc = docs ident_map te.doc in List.fold_left (fun env tec -> - let ty = extension_constructor empty tec in + let ty = extension_constructor ident_map tec in add_extension_constructor tec.L.Extension.Constructor.id ty env) env te.L.Extension.constructors |> add_cdocs te.L.Extension.parent doc | Exception e, true -> - let ty = exception_ empty e in + let ty = exception_ ident_map e in add_exception e.L.Exception.id ty env | L.Signature.Value v, true -> - let ty = value empty v in + let ty = value ident_map v in add_value v.L.Value.id ty env (* Skip when compiling *) | Exception _, false -> env @@ -868,10 +884,10 @@ let verify_lookups env lookups = true end*) in - let result = not (List.exists bad_lookup lookups) in + let result = not (LookupTypeSet.exists bad_lookup lookups) in (* If we're recording lookups, make sure it looks like we looked all this stuff up *) (match (result, env.recorder) with - | true, Some r -> r.lookups <- r.lookups @ lookups + | true, Some r -> r.lookups <- LookupTypeSet.union r.lookups lookups | _ -> ()); result diff --git a/src/xref2/env.mli b/src/xref2/env.mli index 2b8918a065..da08ba7479 100644 --- a/src/xref2/env.mli +++ b/src/xref2/env.mli @@ -26,11 +26,13 @@ type lookup_type = | ModuleByName of string * Identifier.Path.Module.t | FragmentRoot of int +module LookupTypeSet : Set.S with type elt = lookup_type + val pp_lookup_type_list : Format.formatter -> lookup_type list -> unit type t -val with_recorded_lookups : t -> (t -> 'a) -> lookup_type list * 'a +val with_recorded_lookups : t -> (t -> 'a) -> LookupTypeSet.t * 'a val set_resolver : t -> resolver -> t @@ -172,4 +174,4 @@ val len : int ref val n : int ref -val verify_lookups : t -> lookup_type list -> bool +val verify_lookups : t -> LookupTypeSet.t -> bool diff --git a/src/xref2/lang_of.ml b/src/xref2/lang_of.ml index 21f0aff40e..ea27dbeca6 100644 --- a/src/xref2/lang_of.ml +++ b/src/xref2/lang_of.ml @@ -2,6 +2,14 @@ open Odoc_model open Paths open Names +module RM = Map.Make (struct + type t = Cpath.Resolved.module_ + + let compare x y = if x == y then 0 else compare x y +end) + +type memos = { mutable rmodpathmemo : Path.Resolved.Module.t RM.t } + type maps = { module_ : Identifier.Module.t Component.ModuleMap.t; module_type : Identifier.ModuleType.t Component.ModuleTypeMap.t; @@ -15,6 +23,7 @@ type maps = { fragment_root : Cfrag.root option; (* Shadowed items *) shadowed : Lang.Include.shadowed; + memos : memos; } let empty_shadow = @@ -28,7 +37,8 @@ let empty_shadow = s_class_types = []; } -let empty = +let empty () = + let memos = { rmodpathmemo = RM.empty } in { module_ = Component.ModuleMap.empty; module_type = Component.ModuleTypeMap.empty; @@ -40,9 +50,12 @@ let empty = path_class_type = Component.PathClassTypeMap.empty; fragment_root = None; shadowed = empty_shadow; + memos; } -let with_fragment_root r = { empty with fragment_root = Some r } +let with_fragment_root r = { (empty ()) with fragment_root = Some r } + +let with_shadowed shadowed = { (empty ()) with shadowed } (** Raises [Not_found] *) let lookup_module map : Ident.path_module -> _ = function @@ -127,22 +140,33 @@ module Path = struct and resolved_module map (p : Cpath.Resolved.module_) : Odoc_model.Paths.Path.Resolved.Module.t = - match p with - | `Local id -> - `Identifier - (try lookup_module map id - with Not_found -> - failwith (Format.asprintf "Not_found: %a" Ident.fmt id)) - | `Substituted x -> resolved_module map x - | `Identifier y -> `Identifier y - | `Subst (mty, m) -> - `Subst (resolved_module_type map mty, resolved_module map m) - | `Hidden h -> `Hidden (resolved_module map h) - | `Module (p, n) -> `Module (resolved_parent map p, n) - | `Canonical (r, m) -> `Canonical (resolved_module map r, module_ map m) - | `Apply (m1, m2) -> `Apply (resolved_module map m1, resolved_module map m2) - | `Alias (m1, m2) -> `Alias (resolved_module map m1, resolved_module map m2) - | `OpaqueModule m -> `OpaqueModule (resolved_module map m) + let f () = + match p with + | `Local id -> + `Identifier + (try lookup_module map id + with Not_found -> + failwith (Format.asprintf "Not_found: %a" Ident.fmt id)) + | `Substituted x -> resolved_module map x + | `Identifier y -> `Identifier y + | `Subst (mty, m) -> + `Subst (resolved_module_type map mty, resolved_module map m) + | `Hidden h -> `Hidden (resolved_module map h) + | `Module (p, n) -> `Module (resolved_parent map p, n) + | `Canonical (r, m) -> `Canonical (resolved_module map r, module_ map m) + | `Apply (m1, m2) -> + `Apply (resolved_module map m1, resolved_module map m2) + | `Alias (m1, m2) -> + `Alias (resolved_module map m1, resolved_module map m2) + | `OpaqueModule m -> `OpaqueModule (resolved_module map m) + in + try + let result = RM.find p map.memos.rmodpathmemo in + result + with Not_found -> + let result = f () in + map.memos.rmodpathmemo <- RM.add p result map.memos.rmodpathmemo; + result and resolved_parent map (p : Cpath.Resolved.parent) = match p with diff --git a/src/xref2/lang_of.mli b/src/xref2/lang_of.mli index a312034208..1421a3dc36 100644 --- a/src/xref2/lang_of.mli +++ b/src/xref2/lang_of.mli @@ -1,25 +1,14 @@ (* Lang_of *) open Odoc_model.Paths -type maps = { - module_ : Identifier.Module.t Component.ModuleMap.t; - module_type : Identifier.ModuleType.t Component.ModuleTypeMap.t; - functor_parameter : - (Ident.functor_parameter * Identifier.FunctorParameter.t) list; - type_ : Identifier.Type.t Component.TypeMap.t; - path_type : Identifier.Path.Type.t Component.PathTypeMap.t; - class_ : (Ident.class_ * Identifier.Class.t) list; - class_type : (Ident.class_type * Identifier.ClassType.t) list; - path_class_type : Identifier.Path.ClassType.t Component.PathClassTypeMap.t; - fragment_root : Cfrag.root option; - (* Shadowed items *) - shadowed : Odoc_model.Lang.Include.shadowed; -} - -val empty : maps +type maps + +val empty : unit -> maps val with_fragment_root : Cfrag.root -> maps +val with_shadowed : Odoc_model.Lang.Include.shadowed -> maps + module Opt = Component.Opt module Path : sig diff --git a/src/xref2/link.ml b/src/xref2/link.ml index b6d804e3b6..f89040b687 100644 --- a/src/xref2/link.ml +++ b/src/xref2/link.ml @@ -97,58 +97,57 @@ let type_path : Env.t -> Paths.Path.Type.t -> Paths.Path.Type.t = fun env p -> if not (should_resolve (p :> Paths.Path.t)) then p else - let cp = Component.Of_Lang.(type_path empty p) in + let cp = Component.Of_Lang.(type_path (empty ()) p) in match cp with | `Resolved p -> let result = Tools.reresolve_type env p in - `Resolved (result |> Cpath.resolved_type_path_of_cpath) + `Resolved Lang_of.(Path.resolved_type (empty ()) result) | _ -> ( match Tools.resolve_type_path env cp with | Ok p' -> let result = Tools.reresolve_type env p' in - `Resolved (Cpath.resolved_type_path_of_cpath result) + `Resolved Lang_of.(Path.resolved_type (empty ()) result) | Error e -> Errors.report ~what:(`Type_path cp) ~tools_error:e `Lookup; - Cpath.type_path_of_cpath cp) + p) and module_type_path : Env.t -> Paths.Path.ModuleType.t -> Paths.Path.ModuleType.t = fun env p -> if not (should_resolve (p :> Paths.Path.t)) then p else - let cp = Component.Of_Lang.(module_type_path empty p) in + let cp = Component.Of_Lang.(module_type_path (empty ()) p) in match cp with | `Resolved p -> - `Resolved - (Tools.reresolve_module_type env p - |> Cpath.resolved_module_type_path_of_cpath) + let result = Tools.reresolve_module_type env p in + `Resolved Lang_of.(Path.resolved_module_type (empty ()) result) | _ -> ( match Tools.resolve_module_type_path env cp with | Ok p' -> let result = Tools.reresolve_module_type env p' in - `Resolved (Cpath.resolved_module_type_path_of_cpath result) + `Resolved Lang_of.(Path.resolved_module_type (empty ()) result) | Error e -> Errors.report ~what:(`Module_type_path cp) ~tools_error:e `Resolve; - Cpath.module_type_path_of_cpath cp) + p) and module_path : Env.t -> Paths.Path.Module.t -> Paths.Path.Module.t = fun env p -> if not (should_resolve (p :> Paths.Path.t)) then p else - let cp = Component.Of_Lang.(module_path empty p) in + let cp = Component.Of_Lang.(module_path (empty ()) p) in match cp with | `Resolved p -> let after = Tools.reresolve_module env p in - `Resolved (Cpath.resolved_module_path_of_cpath after) + `Resolved Lang_of.(Path.resolved_module (empty ()) after) | _ -> ( match Tools.resolve_module_path env cp with | Ok p' -> let result = Tools.reresolve_module env p' in - `Resolved (Cpath.resolved_module_path_of_cpath result) + `Resolved Lang_of.(Path.resolved_module (empty ()) result) | Error _ when is_forward p -> p | Error e -> Errors.report ~what:(`Module_path cp) ~tools_error:e `Resolve; - Cpath.module_path_of_cpath cp) + p) let rec comment_inline_element : loc:_ -> Env.t -> Comment.inline_element -> Comment.inline_element = @@ -346,7 +345,9 @@ and signature : Env.t -> Id.Signature.t -> Signature.t -> _ = let env = Env.open_signature s env |> Env.add_docs s.doc in let items = signature_items env id s.items and doc = comment_docs env id s.doc in - { s with items; doc } + let sg = { s with items; doc } in + let sg' = Component.Of_Lang.(signature (empty ()) sg) in + Lang_of.(signature (id :> Id.Signature.t) (empty ()) sg') and signature_items : Env.t -> Id.Signature.t -> Signature.item list -> Signature.item list = @@ -404,12 +405,12 @@ and module_ : Env.t -> Module.t -> Module.t = in let expansion_needed = self_canonical || hidden_alias in if expansion_needed then - let cp = Component.Of_Lang.(resolved_module_path empty p) in + let cp = Component.Of_Lang.(resolved_module_path (empty ()) p) in match Expand_tools.expansion_of_module_alias env m.id (`Resolved cp) with | Ok (_, _, e) -> - let le = Lang_of.(simple_expansion empty sg_id e) in + let le = Lang_of.(simple_expansion (empty ()) sg_id e) in Alias (`Resolved p, Some (simple_expansion env sg_id le)) | Error _ -> type_ else type_ @@ -504,16 +505,16 @@ and handle_fragments env id sg subs = match frag with | `Resolved f -> let cfrag = - Component.Of_Lang.(resolved_module_fragment empty f) + Component.Of_Lang.(resolved_module_fragment (empty ()) f) in `Resolved (Tools.reresolve_module_fragment env cfrag - |> Lang_of.(Path.resolved_module_fragment empty)) + |> Lang_of.(Path.resolved_module_fragment (empty ()))) | _ -> frag in let sg' = Tools.fragmap ~mark_substituted:true env - Component.Of_Lang.(with_module_type_substitution empty lsub) + Component.Of_Lang.(with_module_type_substitution (empty ()) lsub) sg in (sg', ModuleEq (frag', module_decl env id decl) :: subs) @@ -522,16 +523,16 @@ and handle_fragments env id sg subs = match frag with | `Resolved f -> let cfrag = - Component.Of_Lang.(resolved_type_fragment empty f) + Component.Of_Lang.(resolved_type_fragment (empty ()) f) in `Resolved (Tools.reresolve_type_fragment env cfrag - |> Lang_of.(Path.resolved_type_fragment empty)) + |> Lang_of.(Path.resolved_type_fragment (empty ()))) | _ -> frag in let sg' = Tools.fragmap ~mark_substituted:true env - Component.Of_Lang.(with_module_type_substitution empty lsub) + Component.Of_Lang.(with_module_type_substitution (empty ()) lsub) sg in (sg', TypeEq (frag', type_decl_equation env id eqn) :: subs) @@ -540,16 +541,16 @@ and handle_fragments env id sg subs = match frag with | `Resolved f -> let cfrag = - Component.Of_Lang.(resolved_module_type_fragment empty f) + Component.Of_Lang.(resolved_module_type_fragment (empty ()) f) in `Resolved (Tools.reresolve_module_type_fragment env cfrag - |> Lang_of.(Path.resolved_module_type_fragment empty)) + |> Lang_of.(Path.resolved_module_type_fragment (empty ()))) | _ -> frag in let sg' = Tools.fragmap ~mark_substituted:true env - Component.Of_Lang.(with_module_type_substitution empty lsub) + Component.Of_Lang.(with_module_type_substitution (empty ()) lsub) sg in (sg', ModuleTypeEq (frag', module_type_expr env id eqn) :: subs) @@ -558,16 +559,16 @@ and handle_fragments env id sg subs = match frag with | `Resolved f -> let cfrag = - Component.Of_Lang.(resolved_module_fragment empty f) + Component.Of_Lang.(resolved_module_fragment (empty ()) f) in `Resolved (Tools.reresolve_module_fragment env cfrag - |> Lang_of.(Path.resolved_module_fragment empty)) + |> Lang_of.(Path.resolved_module_fragment (empty ()))) | _ -> frag in let sg' = Tools.fragmap ~mark_substituted:true env - Component.Of_Lang.(with_module_type_substitution empty lsub) + Component.Of_Lang.(with_module_type_substitution (empty ()) lsub) sg in (sg', ModuleSubst (frag', module_path env mpath) :: subs) @@ -576,16 +577,16 @@ and handle_fragments env id sg subs = match frag with | `Resolved f -> let cfrag = - Component.Of_Lang.(resolved_type_fragment empty f) + Component.Of_Lang.(resolved_type_fragment (empty ()) f) in `Resolved (Tools.reresolve_type_fragment env cfrag - |> Lang_of.(Path.resolved_type_fragment empty)) + |> Lang_of.(Path.resolved_type_fragment (empty ()))) | _ -> frag in let sg' = Tools.fragmap ~mark_substituted:true env - Component.Of_Lang.(with_module_type_substitution empty lsub) + Component.Of_Lang.(with_module_type_substitution (empty ()) lsub) sg in (sg', TypeSubst (frag', type_decl_equation env id eqn) :: subs) @@ -594,16 +595,16 @@ and handle_fragments env id sg subs = match frag with | `Resolved f -> let cfrag = - Component.Of_Lang.(resolved_module_type_fragment empty f) + Component.Of_Lang.(resolved_module_type_fragment (empty ()) f) in `Resolved (Tools.reresolve_module_type_fragment env cfrag - |> Lang_of.(Path.resolved_module_type_fragment empty)) + |> Lang_of.(Path.resolved_module_type_fragment (empty ()))) | _ -> frag in let sg' = Tools.fragmap ~mark_substituted:true env - Component.Of_Lang.(with_module_type_substitution empty lsub) + Component.Of_Lang.(with_module_type_substitution (empty ()) lsub) sg in (sg', ModuleTypeSubst (frag', module_type_expr env id eqn) :: subs) @@ -619,7 +620,7 @@ and u_module_type_expr : (* No need to link 'unexpanded' module type expressions that are actually expanded... *) | Path p -> Path (module_type_path env p) | With (subs, expr) as unresolved -> ( - let cexpr = Component.Of_Lang.(u_module_type_expr empty expr) in + let cexpr = Component.Of_Lang.(u_module_type_expr (empty ()) expr) in match Tools.signature_of_u_module_type_expr ~mark_substituted:true env cexpr with @@ -651,13 +652,15 @@ and module_type_expr : in let expansion_needed = self_canonical || hidden_alias in if expansion_needed then - let cp = Component.Of_Lang.(resolved_module_type_path empty p_path) in + let cp = + Component.Of_Lang.(resolved_module_type_path (empty ()) p_path) + in match Expand_tools.expansion_of_module_type_expr env id (Path { p_path = `Resolved cp; p_expansion = None }) with | Ok (_, _, e) -> - let le = Lang_of.(simple_expansion empty id e) in + let le = Lang_of.(simple_expansion (empty ()) id e) in Some (simple_expansion env id le) | Error _ -> None else None @@ -669,7 +672,7 @@ and module_type_expr : let p_path = module_type_path env p_path in Path { p_path; p_expansion = do_expn p_expansion (Some p_path) } | With { w_substitutions; w_expansion; w_expr } as unresolved -> ( - let cexpr = Component.Of_Lang.(u_module_type_expr empty w_expr) in + let cexpr = Component.Of_Lang.(u_module_type_expr (empty ()) w_expr) in match Tools.signature_of_u_module_type_expr ~mark_substituted:true env cexpr with @@ -733,13 +736,13 @@ and type_decl : Env.t -> Id.Signature.t -> TypeDecl.t -> TypeDecl.t = let default = { t with equation; doc; representation } in match hidden_path with | Some (p, params) -> ( - let p' = Component.Of_Lang.resolved_type_path Component.Of_Lang.empty p in + let p' = Component.Of_Lang.(resolved_type_path (empty ()) p) in match Tools.lookup_type env p' with | Ok (`FType (_, t')) -> let equation = try Expand_tools.collapse_eqns default.equation - (Lang_of.type_decl_equation Lang_of.empty + (Lang_of.type_decl_equation (Lang_of.empty ()) (parent :> Id.Parent.t) t'.equation) params @@ -814,13 +817,13 @@ and type_expression_object env parent visited o = and type_expression_package env parent visited p = let open TypeExpr.Package in let substitution (frag, t) = - let cfrag = Component.Of_Lang.(type_fragment empty frag) in + let cfrag = Component.Of_Lang.(type_fragment (empty ()) frag) in let frag' = match cfrag with | `Resolved f -> `Resolved (Tools.reresolve_type_fragment env f) | _ -> cfrag in - ( Lang_of.(Path.type_fragment empty frag'), + ( Lang_of.(Path.type_fragment (empty ()) frag'), type_expression env parent visited t ) in { @@ -845,11 +848,11 @@ and type_expression : Env.t -> Id.Signature.t -> _ -> _ = let ts = List.map (type_expression env parent visited) ts' in if not (Paths.Path.is_hidden (path :> Paths.Path.t)) then Constr (path, ts) else - let cp = Component.Of_Lang.(type_path empty path') in + let cp = Component.Of_Lang.(type_path (empty ()) path') in match Tools.resolve_type env ~add_canonical:true cp with | Ok (cp', `FType (_, t)) -> let cp' = Tools.reresolve_type env cp' in - let p = Cpath.resolved_type_path_of_cpath cp' in + let p = Lang_of.(Path.resolved_type (empty ()) cp') in if List.mem p visited then raise Loop else if Cpath.is_resolved_type_hidden cp' then match t.Component.TypeDecl.equation with @@ -865,7 +868,8 @@ and type_expression : Env.t -> Id.Signature.t -> _ -> _ = in let t' = Expand_tools.type_expr map - Lang_of.(type_expr empty (parent :> Id.Parent.t) expr) + Lang_of.( + type_expr (empty ()) (parent :> Id.Parent.t) expr) in type_expression env parent (p :: visited) t' with @@ -880,12 +884,12 @@ and type_expression : Env.t -> Id.Signature.t -> _ -> _ = | _ -> Constr (`Resolved p, ts) else Constr (`Resolved p, ts) | Ok (cp', (`FClass _ | `FClassType _)) -> - let p = Cpath.resolved_type_path_of_cpath cp' in + let p = Lang_of.(Path.resolved_type (empty ()) cp') in Constr (`Resolved p, ts) | Ok (_cp, `FType_removed (_, x, _eq)) -> (* Type variables ? *) - Lang_of.(type_expr empty (parent :> Id.Parent.t) x) - | Error _ -> Constr (Cpath.type_path_of_cpath cp, ts)) + Lang_of.(type_expr (empty ()) (parent :> Id.Parent.t) x) + | Error _ -> Constr (path', ts)) | Polymorphic_variant v -> Polymorphic_variant (type_expression_polyvar env parent visited v) | Object o -> Object (type_expression_object env parent visited o) diff --git a/src/xref2/ref_tools.ml b/src/xref2/ref_tools.ml index a383d0d716..f770c56a75 100644 --- a/src/xref2/ref_tools.ml +++ b/src/xref2/ref_tools.ml @@ -176,7 +176,7 @@ module M = struct | None -> (base_path, base_ref) | Some (`Aliased cp) -> let cp = Tools.reresolve_module env cp in - let p = Lang_of.(Path.resolved_module empty cp) in + let p = Lang_of.(Path.resolved_module (empty ()) cp) in (`Alias (cp, base_path), `Alias (p, base_ref)) | Some (`SubstMT cp) -> let cp = Tools.reresolve_module_type env cp in @@ -212,7 +212,7 @@ module MT = struct | None -> (base_ref, base_path, mt) | Some (`AliasModuleType cp) -> let cp = Tools.reresolve_module_type env cp in - let p = Lang_of.(Path.resolved_module_type empty cp) in + let p = Lang_of.(Path.resolved_module_type (empty ()) cp) in (`AliasModuleType (p, base_ref), `AliasModuleType (cp, base_path), mt) let in_signature env ((parent', parent_cp, sg) : signature_lookup_result) name diff --git a/src/xref2/test.md b/src/xref2/test.md index 19274d2308..1dd7ac537b 100644 --- a/src/xref2/test.md +++ b/src/xref2/test.md @@ -739,7 +739,7 @@ now we can ask for the signature of this module: # let sg = get_ok @@ Tools.signature_of_module env (Component.Delayed.get m);; val sg : Component.Signature.t = {Odoc_xref2.Component.Signature.items = - [Odoc_xref2.Component.Signature.Module (`LModule (M, 45), + [Odoc_xref2.Component.Signature.Module (`LModule (M, 72), Odoc_model.Lang.Signature.Ordinary, {Odoc_xref2.Component.Delayed.v = Some @@ -751,7 +751,7 @@ val sg : Component.Signature.t = None); canonical = None; hidden = false}; get = None}); - Odoc_xref2.Component.Signature.Module (`LModule (N, 46), + Odoc_xref2.Component.Signature.Module (`LModule (N, 73), Odoc_model.Lang.Signature.Ordinary, {Odoc_xref2.Component.Delayed.v = Some @@ -760,7 +760,7 @@ val sg : Component.Signature.t = Odoc_xref2.Component.Module.ModuleType (Odoc_xref2.Component.ModuleType.Path {Odoc_xref2.Component.ModuleType.p_expansion = None; - p_path = `Dot (`Local (`LModule (M, 45), false), "S")}); + p_path = `Dot (`Local (`LModule (M, 72), false), "S")}); canonical = None; hidden = false}; get = None})]; compiled = false; removed = []; doc = []} @@ -793,7 +793,7 @@ val m : Component.Module.t Component.Delayed.t = # get_ok @@ Tools.signature_of_module env (Component.Delayed.get m);; - : Component.Signature.t = {Odoc_xref2.Component.Signature.items = - [Odoc_xref2.Component.Signature.Type (`LType (t, 53), + [Odoc_xref2.Component.Signature.Type (`LType (t, 80), Odoc_model.Lang.Signature.Ordinary, {Odoc_xref2.Component.Delayed.v = Some @@ -1055,7 +1055,7 @@ let test_path = `Resolved (`Identifier (Common.root_module "FooBarInt")));; -let cp = Component.Of_Lang.(module_path empty test_path);; +let cp = Component.Of_Lang.(module_path (empty ()) test_path);; ``` Now let's lookup that module: diff --git a/src/xref2/tools.ml b/src/xref2/tools.ml index 4f0eef8e0a..694aeeefe8 100644 --- a/src/xref2/tools.ml +++ b/src/xref2/tools.ml @@ -16,7 +16,7 @@ let core_types = let open Odoc_model.Paths in List.map (fun decl -> - (Identifier.name decl.id, Component.Of_Lang.(type_decl empty decl))) + (Identifier.name decl.id, Component.Of_Lang.(type_decl (empty ()) decl))) Odoc_model.Predefined.core_types let prefix_substitution path sg = @@ -198,7 +198,7 @@ end module MakeMemo (X : MEMO) = struct module M = Hashtbl.Make (X) - let cache : (X.result * int * Env.lookup_type list) M.t = M.create 10000 + let cache : (X.result * int * Env.LookupTypeSet.t) M.t = M.create 10000 let cache_hits : int M.t = M.create 10000 diff --git a/src/xref2/type_of.ml b/src/xref2/type_of.ml index 558e7a4a78..67436e6a7a 100644 --- a/src/xref2/type_of.ml +++ b/src/xref2/type_of.ml @@ -51,7 +51,7 @@ and module_type_expr_typeof env (id : Id.Signature.t) t = let p, strengthen = match t.t_desc with ModPath p -> (p, false) | StructInclude p -> (p, true) in - let cp = Component.Of_Lang.(module_path empty p) in + let cp = Component.Of_Lang.(module_path (empty ()) p) in let open Expand_tools in let open Utils.ResultMonad in aux_expansion_of_module_alias env ~strengthen cp >>= handle_expansion env id @@ -69,7 +69,7 @@ and module_type_expr env (id : Id.Signature.t) expr = | TypeOf t -> ( match module_type_expr_typeof env id t with | Ok e -> - let se = Lang_of.(simple_expansion empty id e) in + let se = Lang_of.(simple_expansion (empty ()) id e) in TypeOf { t with t_expansion = Some (simple_expansion env se) } | Error e when Errors.is_unexpanded_module_type_of (e :> Errors.Tools_error.any) @@ -86,7 +86,7 @@ and u_module_type_expr env id expr = | TypeOf t -> ( match module_type_expr_typeof env id t with | Ok e -> - let se = Lang_of.(simple_expansion empty id e) in + let se = Lang_of.(simple_expansion (empty ()) id e) in TypeOf { t with t_expansion = Some (simple_expansion env se) } | Error e when Errors.is_unexpanded_module_type_of (e :> Errors.Tools_error.any) diff --git a/test/xref2/aliaschain.t/chain.mli b/test/xref2/aliaschain.t/chain.mli new file mode 100644 index 0000000000..0de0e16300 --- /dev/null +++ b/test/xref2/aliaschain.t/chain.mli @@ -0,0 +1,505 @@ +module A : sig + module B : sig + type t + end +end + +(** @canonical Chain.M1 *) +module M1__ = A +module M1 = M1__ +module M1B = M1.B + +(** @canonical Chain.M2 *) +module M2__ = M1 +module M2=M2__ +module M2B=M2.B + +(** @canonical Chain.M3 *) +module M3__ = M2 +module M3=M3__ +module M3B=M3.B + +(** @canonical Chain.M4 *) +module M4__ = M3 +module M4=M4__ +module M4B=M4.B + +(** @canonical Chain.M5 *) +module M5__ = M4 +module M5=M5__ +module M5B=M5.B + +(** @canonical Chain.M6 *) +module M6__ = M5 +module M6=M6__ +module M6B=M6.B + +(** @canonical Chain.M7 *) +module M7__ = M6 +module M7=M7__ +module M7B=M7.B + +(** @canonical Chain.M8 *) +module M8__ = M7 +module M8=M8__ +module M8B=M8.B + +(** @canonical Chain.M9 *) +module M9__ = M8 +module M9=M9__ +module M9B=M9.B + +(** @canonical Chain.M10 *) +module M10__ = M9 +module M10=M10__ +module M10B=M10.B + +(** @canonical Chain.M11 *) +module M11__ = M10 +module M11=M11__ +module M11B=M11.B + +(** @canonical Chain.M12 *) +module M12__ = M11 +module M12=M12__ +module M12B=M12.B + +(** @canonical Chain.M13 *) +module M13__ = M12 +module M13=M13__ +module M13B=M13.B + +(** @canonical Chain.M14 *) +module M14__ = M13 +module M14=M14__ +module M14B=M14.B + +(** @canonical Chain.M15 *) +module M15__ = M14 +module M15=M15__ +module M15B=M15.B + +(** @canonical Chain.M16 *) +module M16__ = M15 +module M16=M16__ +module M16B=M16.B + +(** @canonical Chain.M17 *) +module M17__ = M16 +module M17=M17__ +module M17B=M17.B + +(** @canonical Chain.M18 *) +module M18__ = M17 +module M18=M18__ +module M18B=M18.B + +(** @canonical Chain.M19 *) +module M19__ = M18 +module M19=M19__ +module M19B=M19.B + +(** @canonical Chain.M20 *) +module M20__ = M19 +module M20=M20__ +module M20B=M20.B + +(** @canonical Chain.M21 *) +module M21__ = M20 +module M21=M21__ +module M21B=M21.B + +(** @canonical Chain.M22 *) +module M22__ = M21 +module M22=M22__ +module M22B=M22.B + +(** @canonical Chain.M23 *) +module M23__ = M22 +module M23=M23__ +module M23B=M23.B + +(** @canonical Chain.M24 *) +module M24__ = M23 +module M24=M24__ +module M24B=M24.B + +(** @canonical Chain.M25 *) +module M25__ = M24 +module M25=M25__ +module M25B=M25.B + +(** @canonical Chain.M26 *) +module M26__ = M25 +module M26=M26__ +module M26B=M26.B + +(** @canonical Chain.M27 *) +module M27__ = M26 +module M27=M27__ +module M27B=M27.B + +(** @canonical Chain.M28 *) +module M28__ = M27 +module M28=M28__ +module M28B=M28.B + +(** @canonical Chain.M29 *) +module M29__ = M28 +module M29=M29__ +module M29B=M29.B + +(** @canonical Chain.M30 *) +module M30__ = M29 +module M30=M30__ +module M30B=M30.B + +(** @canonical Chain.M31 *) +module M31__ = M30 +module M31=M31__ +module M31B=M31.B + +(** @canonical Chain.M32 *) +module M32__ = M31 +module M32=M32__ +module M32B=M32.B + +(** @canonical Chain.M33 *) +module M33__ = M32 +module M33=M33__ +module M33B=M33.B + +(** @canonical Chain.M34 *) +module M34__ = M33 +module M34=M34__ +module M34B=M34.B + +(** @canonical Chain.M35 *) +module M35__ = M34 +module M35=M35__ +module M35B=M35.B + +(** @canonical Chain.M36 *) +module M36__ = M35 +module M36=M36__ +module M36B=M36.B + +(** @canonical Chain.M37 *) +module M37__ = M36 +module M37=M37__ +module M37B=M37.B + +(** @canonical Chain.M38 *) +module M38__ = M37 +module M38=M38__ +module M38B=M38.B + +(** @canonical Chain.M39 *) +module M39__ = M38 +module M39=M39__ +module M39B=M39.B + +(** @canonical Chain.M40 *) +module M40__ = M39 +module M40=M40__ +module M40B=M40.B + +(** @canonical Chain.M41 *) +module M41__ = M40 +module M41=M41__ +module M41B=M41.B + +(** @canonical Chain.M42 *) +module M42__ = M41 +module M42=M42__ +module M42B=M42.B + +(** @canonical Chain.M43 *) +module M43__ = M42 +module M43=M43__ +module M43B=M43.B + +(** @canonical Chain.M44 *) +module M44__ = M43 +module M44=M44__ +module M44B=M44.B + +(** @canonical Chain.M45 *) +module M45__ = M44 +module M45=M45__ +module M45B=M45.B + +(** @canonical Chain.M46 *) +module M46__ = M45 +module M46=M46__ +module M46B=M46.B + +(** @canonical Chain.M47 *) +module M47__ = M46 +module M47=M47__ +module M47B=M47.B + +(** @canonical Chain.M48 *) +module M48__ = M47 +module M48=M48__ +module M48B=M48.B + +(** @canonical Chain.M49 *) +module M49__ = M48 +module M49=M49__ +module M49B=M49.B + +(** @canonical Chain.M50 *) +module M50__ = M49 +module M50=M50__ +module M50B=M50.B + +(** @canonical Chain.M51 *) +module M51__ = M50 +module M51=M51__ +module M51B=M51.B + +(** @canonical Chain.M52 *) +module M52__ = M51 +module M52=M52__ +module M52B=M52.B + +(** @canonical Chain.M53 *) +module M53__ = M52 +module M53=M53__ +module M53B=M53.B + +(** @canonical Chain.M54 *) +module M54__ = M53 +module M54=M54__ +module M54B=M54.B + +(** @canonical Chain.M55 *) +module M55__ = M54 +module M55=M55__ +module M55B=M55.B + +(** @canonical Chain.M56 *) +module M56__ = M55 +module M56=M56__ +module M56B=M56.B + +(** @canonical Chain.M57 *) +module M57__ = M56 +module M57=M57__ +module M57B=M57.B + +(** @canonical Chain.M58 *) +module M58__ = M57 +module M58=M58__ +module M58B=M58.B + +(** @canonical Chain.M59 *) +module M59__ = M58 +module M59=M59__ +module M59B=M59.B + +(** @canonical Chain.M60 *) +module M60__ = M59 +module M60=M60__ +module M60B=M60.B + +(** @canonical Chain.M61 *) +module M61__ = M60 +module M61=M61__ +module M61B=M61.B + +(** @canonical Chain.M62 *) +module M62__ = M61 +module M62=M62__ +module M62B=M62.B + +(** @canonical Chain.M63 *) +module M63__ = M62 +module M63=M63__ +module M63B=M63.B + +(** @canonical Chain.M64 *) +module M64__ = M63 +module M64=M64__ +module M64B=M64.B + +(** @canonical Chain.M65 *) +module M65__ = M64 +module M65=M65__ +module M65B=M65.B + +(** @canonical Chain.M66 *) +module M66__ = M65 +module M66=M66__ +module M66B=M66.B + +(** @canonical Chain.M67 *) +module M67__ = M66 +module M67=M67__ +module M67B=M67.B + +(** @canonical Chain.M68 *) +module M68__ = M67 +module M68=M68__ +module M68B=M68.B + +(** @canonical Chain.M69 *) +module M69__ = M68 +module M69=M69__ +module M69B=M69.B + +(** @canonical Chain.M70 *) +module M70__ = M69 +module M70=M70__ +module M70B=M70.B + +(** @canonical Chain.M71 *) +module M71__ = M70 +module M71=M71__ +module M71B=M71.B + +(** @canonical Chain.M72 *) +module M72__ = M71 +module M72=M72__ +module M72B=M72.B + +(** @canonical Chain.M73 *) +module M73__ = M72 +module M73=M73__ +module M73B=M73.B + +(** @canonical Chain.M74 *) +module M74__ = M73 +module M74=M74__ +module M74B=M74.B + +(** @canonical Chain.M75 *) +module M75__ = M74 +module M75=M75__ +module M75B=M75.B + +(** @canonical Chain.M76 *) +module M76__ = M75 +module M76=M76__ +module M76B=M76.B + +(** @canonical Chain.M77 *) +module M77__ = M76 +module M77=M77__ +module M77B=M77.B + +(** @canonical Chain.M78 *) +module M78__ = M77 +module M78=M78__ +module M78B=M78.B + +(** @canonical Chain.M79 *) +module M79__ = M78 +module M79=M79__ +module M79B=M79.B + +(** @canonical Chain.M80 *) +module M80__ = M79 +module M80=M80__ +module M80B=M80.B + +(** @canonical Chain.M81 *) +module M81__ = M80 +module M81=M81__ +module M81B=M81.B + +(** @canonical Chain.M82 *) +module M82__ = M81 +module M82=M82__ +module M82B=M82.B + +(** @canonical Chain.M83 *) +module M83__ = M82 +module M83=M83__ +module M83B=M83.B + +(** @canonical Chain.M84 *) +module M84__ = M83 +module M84=M84__ +module M84B=M84.B + +(** @canonical Chain.M85 *) +module M85__ = M84 +module M85=M85__ +module M85B=M85.B + +(** @canonical Chain.M86 *) +module M86__ = M85 +module M86=M86__ +module M86B=M86.B + +(** @canonical Chain.M87 *) +module M87__ = M86 +module M87=M87__ +module M87B=M87.B + +(** @canonical Chain.M88 *) +module M88__ = M87 +module M88=M88__ +module M88B=M88.B + +(** @canonical Chain.M89 *) +module M89__ = M88 +module M89=M89__ +module M89B=M89.B + +(** @canonical Chain.M90 *) +module M90__ = M89 +module M90=M90__ +module M90B=M90.B + +(** @canonical Chain.M91 *) +module M91__ = M90 +module M91=M91__ +module M91B=M91.B + +(** @canonical Chain.M92 *) +module M92__ = M91 +module M92=M92__ +module M92B=M92.B + +(** @canonical Chain.M93 *) +module M93__ = M92 +module M93=M93__ +module M93B=M93.B + +(** @canonical Chain.M94 *) +module M94__ = M93 +module M94=M94__ +module M94B=M94.B + +(** @canonical Chain.M95 *) +module M95__ = M94 +module M95=M95__ +module M95B=M95.B + +(** @canonical Chain.M96 *) +module M96__ = M95 +module M96=M96__ +module M96B=M96.B + +(** @canonical Chain.M97 *) +module M97__ = M96 +module M97=M97__ +module M97B=M97.B + +(** @canonical Chain.M98 *) +module M98__ = M97 +module M98=M98__ +module M98B=M98.B + +(** @canonical Chain.M99 *) +module M99__ = M98 +module M99=M99__ +module M99B=M99.B + +(** @canonical Chain.M100 *) +module M100__ = M99 +module M100=M100__ +module M100B=M100.B diff --git a/test/xref2/aliaschain.t/run.t b/test/xref2/aliaschain.t/run.t new file mode 100644 index 0000000000..298daf3386 --- /dev/null +++ b/test/xref2/aliaschain.t/run.t @@ -0,0 +1,8 @@ +A long chain of aliases should produce an odocl file that's a reasonable +size. + + $ ocamlc -c -bin-annot chain.mli + $ odoc compile chain.cmti + $ odoc link chain.odoc -I . + $ du -h chain.odocl | awk '{print $1}' + 24K diff --git a/test/xref2/strengthen/test.md b/test/xref2/strengthen/test.md index cdffb265b1..c19ab53713 100644 --- a/test/xref2/strengthen/test.md +++ b/test/xref2/strengthen/test.md @@ -2,8 +2,8 @@ let simple_strengthening input = let p = Common.root_identifier in let _, sg, _ = Common.model_of_string input in - let c = Component.Of_Lang.(signature empty sg) in - let cp = Component.Of_Lang.(resolved_module_path empty p) in + let c = Component.Of_Lang.(signature (empty ()) sg) in + let cp = Component.Of_Lang.(resolved_module_path (empty ()) p) in let c' = Strengthen.signature (`Resolved cp) c in let open Format in fprintf std_formatter "BEFORE\n======\n%!"; diff --git a/test/xref2/subst/test.md b/test/xref2/subst/test.md index c54ccac289..495b14c7e4 100644 --- a/test/xref2/subst/test.md +++ b/test/xref2/subst/test.md @@ -12,7 +12,7 @@ let resolve_module_name sg name = let module_substitution ~idents ~targets m test_data = let _, sg, _ = Common.model_of_string test_data in - let c = Component.Of_Lang.(signature empty sg) in + let c = Component.Of_Lang.(signature (empty ()) sg) in let subst_idents_mod = resolve_module_name c idents in let subst_targets_mod = resolve_module_name c targets in @@ -95,7 +95,7 @@ let compile mli = let id, sg, _ = Common.model_of_string mli in let env = Env.env_for_testing ~linking:false in Odoc_xref2.Compile.signature env (id :> Odoc_model.Paths.Identifier.Signature.t) sg - |> Of_Lang.signature Of_Lang.empty + |> Of_Lang.(signature (empty ())) ``` ```ocaml @@ -128,28 +128,28 @@ let compile mli = end |} ;; - : Component.Signature.t = -module type Monad/33 = sig - type t/34 - val map/35 : ([a] r(t/34)) -> ((a) -> b) -> [b] r(t/34) - val join/36 : ([[a] r(t/34)] r(t/34)) -> [a] r(t/34) +module type Monad/68 = sig + type t/69 + val map/70 : ([a] r(t/69)) -> ((a) -> b) -> [b] r(t/69) + val join/71 : ([[a] r(t/69)] r(t/69)) -> [a] r(t/69) (removed=[])end -module SomeMonad/32 : sig - type t/37 - include : r(Monad/33) with [r(root(Monad/33).t) = [a] r(t/37)] (sig = - val map/38 : ([a] r(t/37)) -> ((a) -> b) -> [b] r(t/37) - val join/39 : ([[a] r(t/37)] r(t/37)) -> [a] r(t/37) +module SomeMonad/67 : sig + type t/72 + include : r(Monad/68) with [r(root(Monad/68).t) = [a] r(t/72)] (sig = + val map/73 : ([a] r(t/72)) -> ((a) -> b) -> [b] r(t/72) + val join/74 : ([[a] r(t/72)] r(t/72)) -> [a] r(t/72) (removed=[])) (removed=[])end -module ComplexTypeExpr/30 : sig - type t/40 - include : r(Monad/33) with [r(root(Monad/33).t) = ([r(int) * a] r(t/40) * [a * r(int)] r(t/40))] (sig = - val map/41 : (([r(int) * a] r(t/40) * [a * r(int)] r(t/40))) -> ((a) -> b) -> ([r(int) * b] r(t/40) * [b * r(int)] r(t/40)) - val join/42 : (([r(int) * ([r(int) * a] r(t/40) * [a * r(int)] r(t/40))] r(t/40) * [([r(int) * a] r(t/40) * [a * r(int)] r(t/40)) * r(int)] r(t/40))) -> ([r(int) * a] r(t/40) * [a * r(int)] r(t/40)) +module ComplexTypeExpr/65 : sig + type t/75 + include : r(Monad/68) with [r(root(Monad/68).t) = ([r(int) * a] r(t/75) * [a * r(int)] r(t/75))] (sig = + val map/76 : (([r(int) * a] r(t/75) * [a * r(int)] r(t/75))) -> ((a) -> b) -> ([r(int) * b] r(t/75) * [b * r(int)] r(t/75)) + val join/77 : (([r(int) * ([r(int) * a] r(t/75) * [a * r(int)] r(t/75))] r(t/75) * [([r(int) * a] r(t/75) * [a * r(int)] r(t/75)) * r(int)] r(t/75))) -> ([r(int) * a] r(t/75) * [a * r(int)] r(t/75)) (removed=[])) (removed=[])end -module Erase/31 : sig - include : r(Monad/33) with [r(root(Monad/33).t) = a] (sig = val map/43 : (a) -> ((a) -> b) -> b - val join/44 : (a) -> a +module Erase/66 : sig + include : r(Monad/68) with [r(root(Monad/68).t) = a] (sig = val map/78 : (a) -> ((a) -> b) -> b + val join/79 : (a) -> a (removed=[])) (removed=[])end (removed=[]) @@ -172,18 +172,18 @@ More tests with two type variables: end |} ;; - : Component.Signature.t = -module type Monad_2/61 = sig - type t/62 - val map/63 : ([a * err] r(t/62)) -> f:((a) -> b) -> [b * err] r(t/62) - val join/64 : ([[a * e] r(t/62) * e] r(t/62)) -> [a * e] r(t/62) - val both/65 : ([a * e] r(t/62)) -> ([b * e] r(t/62)) -> [(a * b) * e] r(t/62) +module type Monad_2/121 = sig + type t/122 + val map/123 : ([a * err] r(t/122)) -> f:((a) -> b) -> [b * err] r(t/122) + val join/124 : ([[a * e] r(t/122) * e] r(t/122)) -> [a * e] r(t/122) + val both/125 : ([a * e] r(t/122)) -> ([b * e] r(t/122)) -> [(a * b) * e] r(t/122) (removed=[])end -module SwappedVars/60 : sig - type t/66 - include : r(Monad_2/61) with [r(root(Monad_2/61).t) = [b * a] r(t/66)] (sig = - val map/67 : ([err * a] r(t/66)) -> f:((a) -> b) -> [err * b] r(t/66) - val join/68 : ([e * [e * a] r(t/66)] r(t/66)) -> [e * a] r(t/66) - val both/69 : ([e * a] r(t/66)) -> ([e * b] r(t/66)) -> [e * (a * b)] r(t/66) +module SwappedVars/120 : sig + type t/126 + include : r(Monad_2/121) with [r(root(Monad_2/121).t) = [b * a] r(t/126)] (sig = + val map/127 : ([err * a] r(t/126)) -> f:((a) -> b) -> [err * b] r(t/126) + val join/128 : ([e * [e * a] r(t/126)] r(t/126)) -> [e * a] r(t/126) + val both/129 : ([e * a] r(t/126)) -> ([e * b] r(t/126)) -> [e * (a * b)] r(t/126) (removed=[])) (removed=[])end (removed=[]) @@ -204,14 +204,14 @@ Edge cases: end |} ;; - : Component.Signature.t = -module type S/78 = sig - type t/79 - val map/80 : ([a] r(t/79)) -> ((a) -> b) -> [b] r(t/79) +module type S/151 = sig + type t/152 + val map/153 : ([a] r(t/152)) -> ((a) -> b) -> [b] r(t/152) (removed=[])end -module M/77 : sig - type t/81 - include : r(S/78) with [r(root(S/78).t) = [(alias (poly_var [ `A of (a * b) ]) b)] r(t/81)] (sig = - val map/82 : ([(alias (poly_var [ `A of (a * b) ]) b)] r(t/81)) -> ((a) -> b) -> [(alias (poly_var [ `A of (b * b) ]) b)] r(t/81) +module M/150 : sig + type t/154 + include : r(S/151) with [r(root(S/151).t) = [(alias (poly_var [ `A of (a * b) ]) b)] r(t/154)] (sig = + val map/155 : ([(alias (poly_var [ `A of (a * b) ]) b)] r(t/154)) -> ((a) -> b) -> [(alias (poly_var [ `A of (b * b) ]) b)] r(t/154) (removed=[])) (removed=[])end (removed=[])