123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967(* Second round of resolution tackles references and forward paths *)openOdoc_modelopenLangmoduleId=Paths.IdentifiermoduleOpt=structletmapf=functionSomex->Some(fx)|None->Noneend(** Equivalent to {!Comment.synopsis}. *)letsynopsis_from_comment(docs:Component.CComment.docs)=matchdocswith|({value=#Comment.nestable_block_element;_}ase)::_->(* Only the first element is considered. *)Comment.synopsis[e]|_->Noneletsynopsis_of_moduleenv(m:Component.Module.t)=matchsynopsis_from_commentm.docwith|Some_ass->s|None->((* If there is no doc, look at the expansion. *)matchTools.signature_of_moduleenvmwith|Oksg->synopsis_from_comment(Component.extract_signature_docsg)|Error_->None)letambiguous_label_warninglabel_namelabels=letpp_label_locfmt(`Label(_,x))=Location_.pp_span_startfmtx.Component.Label.locationinLookup_failures.report_warning"@[<2>Label '%s' is ambiguous. The other occurences are:@ %a@]"label_name(Format.pp_print_list~pp_sep:Format.pp_force_newlinepp_label_loc)labels(** Raise a warning when a label explicitly set by the user collides. This
warning triggers even if one of the colliding labels have been automatically
generated. *)letcheck_ambiguous_label~locenv(attrs,(`Label(_,label_name)asid),_)=ifattrs.Comment.heading_label_explicitthen(* Looking for an identical identifier but a different location. *)letconflicting(`Label(id',comp))=Id.equalidid'&¬(Location_.span_equalcomp.Component.Label.locationloc)inletlabel_name=Names.LabelName.to_stringlabel_nameinmatchEnv.lookup_by_nameEnv.s_labellabel_nameenvwith|Oklblwhenconflictinglbl->ambiguous_label_warninglabel_name[lbl]|Error(`Ambiguous(hd,tl))->(matchList.filterconflicting(hd::tl)with|[]->()|xs->ambiguous_label_warninglabel_namexs)|Ok_|Error`Not_found->()exceptionLoopletrecis_forward:Paths.Path.Module.t->bool=function|`Resolved_->false|`Root_->false|`Forward_->true|`Identifier_->false|`Dot(p,_)->is_forwardp|`Apply(p1,p2)->is_forwardp1||is_forwardp2letrecshould_reresolve:Paths.Path.Resolved.t->bool=funp->letopenPaths.Path.Resolvedinmatchpwith|`Identifier_->false|`Subst(x,y)->should_reresolve(x:>t)||should_reresolve(y:>t)|`Hiddenp->should_reresolve(p:>t)|`Canonical(x,y)->should_reresolve(x:>t)||should_resolve(y:>Paths.Path.t)|`CanonicalModuleType(x,y)->should_reresolve(x:>t)||should_resolve(y:>Paths.Path.t)|`CanonicalType(x,y)->should_reresolve(x:>t)||should_resolve(y:>Paths.Path.t)|`Apply(x,y)->should_reresolve(x:>t)||should_reresolve(y:>Paths.Path.Resolved.t)|`SubstT(x,y)->should_reresolve(x:>t)||should_reresolve(y:>t)|`Alias(x,y)->should_reresolve(x:>t)||should_reresolve(y:>t)|`AliasModuleType(x,y)->should_reresolve(x:>t)||should_reresolve(y:>t)|`Type(p,_)|`Class(p,_)|`ClassType(p,_)|`ModuleType(p,_)|`Module(p,_)->should_reresolve(p:>t)|`OpaqueModulem->should_reresolve(m:>t)|`OpaqueModuleTypem->should_reresolve(m:>t)andshould_resolve:Paths.Path.t->bool=funp->matchpwith`Resolvedp->should_reresolvep|_->truelettype_path:Env.t->Paths.Path.Type.t->Paths.Path.Type.t=funenvp->ifnot(should_resolve(p:>Paths.Path.t))thenpelseletcp=Component.Of_Lang.(type_path(empty())p)inmatchcpwith|`Resolvedp->letresult=Tools.reresolve_typeenvpin`ResolvedLang_of.(Path.resolved_type(empty())result)|_->(matchTools.resolve_type_pathenvcpwith|Okp'->letresult=Tools.reresolve_typeenvp'in`ResolvedLang_of.(Path.resolved_type(empty())result)|Errore->Errors.report~what:(`Type_pathcp)~tools_error:e`Lookup;p)letclass_type_path:Env.t->Paths.Path.ClassType.t->Paths.Path.ClassType.t=funenvp->ifnot(should_resolve(p:>Paths.Path.t))thenpelseletcp=Component.Of_Lang.(class_type_path(empty())p)inmatchcpwith|`Resolvedp->letresult=Tools.reresolve_class_typeenvpin`ResolvedLang_of.(Path.resolved_class_type(empty())result)|_->(matchTools.resolve_class_type_pathenvcpwith|Okp'->letresult=Tools.reresolve_class_typeenvp'in`ResolvedLang_of.(Path.resolved_class_type(empty())result)|Errore->Errors.report~what:(`Class_type_pathcp)~tools_error:e`Lookup;p)andmodule_type_path:Env.t->Paths.Path.ModuleType.t->Paths.Path.ModuleType.t=funenvp->ifnot(should_resolve(p:>Paths.Path.t))thenpelseletcp=Component.Of_Lang.(module_type_path(empty())p)inmatchcpwith|`Resolvedp->letresult=Tools.reresolve_module_typeenvpin`ResolvedLang_of.(Path.resolved_module_type(empty())result)|_->(matchTools.resolve_module_type_pathenvcpwith|Okp'->letresult=Tools.reresolve_module_typeenvp'in`ResolvedLang_of.(Path.resolved_module_type(empty())result)|Errore->Errors.report~what:(`Module_type_pathcp)~tools_error:e`Resolve;p)andmodule_path:Env.t->Paths.Path.Module.t->Paths.Path.Module.t=funenvp->ifnot(should_resolve(p:>Paths.Path.t))thenpelseletcp=Component.Of_Lang.(module_path(empty())p)inmatchcpwith|`Resolvedp->letafter=Tools.reresolve_moduleenvpin`ResolvedLang_of.(Path.resolved_module(empty())after)|_->(matchTools.resolve_module_pathenvcpwith|Okp'->letresult=Tools.reresolve_moduleenvp'in`ResolvedLang_of.(Path.resolved_module(empty())result)|Error_whenis_forwardp->p|Errore->Errors.report~what:(`Module_pathcp)~tools_error:e`Resolve;p)letreccomment_inline_element:loc:_->Env.t->Comment.inline_element->Comment.inline_element=fun~loc:_envx->matchxwith|`Styled(s,ls)->`Styled(s,List.map(with_location(comment_inline_elementenv))ls)|`Reference(r,content)asorig->(matchRef_tools.resolve_referenceenvr|>Error.raise_warningswith|Okx->letcontent=(* In case of labels, use the heading text as reference text if
it's not specified. *)match(content,x)with|[],`Identifier(#Id.Label.tasi)->(matchEnv.lookup_by_idEnv.s_labelienvwith|Some(`Label(_,lbl))->lbl.Component.Label.text|None->[])|content,_->contentin`Reference(`Resolvedx,content)|Errore->Errors.report~what:(`Referencer)~tools_error:(`Referencee)`Resolve;orig)|y->yandparagraphenvelts=List.map(with_location(comment_inline_elementenv))eltsandresolve_external_synopsisenvsynopsis=letenv=Env.inherit_resolverenvinparagraphenvsynopsisandcomment_nestable_block_elementenvparent~loc:_(x:Comment.nestable_block_element)=matchxwith|`Paragraphelts->`Paragraph(paragraphenvelts)|(`Code_block_|`Verbatim_)asx->x|`List(x,ys)->`List(x,List.map(List.map(with_location(comment_nestable_block_elementenvparent)))ys)|`Modulesrefs->letrefs=List.map(fun(r:Comment.module_reference)->matchRef_tools.resolve_module_referenceenvr.module_reference|>Error.raise_warningswith|Ok(r,_,m)->letmodule_synopsis=Opt.map(resolve_external_synopsisenv)(synopsis_of_moduleenvm)in{Comment.module_reference=`Resolvedr;module_synopsis}|Errore->Errors.report~what:(`Reference(r.module_reference:>Paths.Reference.t))~tools_error:(`Referencee)`Resolve;r)refsin`Modulesrefsandcomment_block_elementenvparent~loc(x:Comment.block_element)=matchxwith|#Comment.nestable_block_elementasx->(comment_nestable_block_elementenvparent~locx:>Comment.block_element)|`Headinghasx->check_ambiguous_label~locenvh;x|`Tag_asx->xandwith_location:typea.(loc:_->a->a)->aLocation_.with_location->aLocation_.with_location=funfn{value;location=loc}->letvalue=Lookup_failures.with_locationloc(fun()->fn~locvalue)in{value;location=loc}andcomment_docsenvparentd=List.map(with_location(comment_block_elementenv(parent:>Id.LabelParent.t)))dandcommentenvparent=function|`Stop->`Stop|`Docsd->`Docs(comment_docsenvparentd)andopen_envparent=function|{Odoc_model__Lang.Open.doc;_}asopen_->{open_withdoc=comment_docsenvparentdoc}letrecunitenvt=letopenCompilation_unitinletcontent=matcht.contentwith|Modulesg->Module(signatureenv(t.id:>Id.Signature.t)sg)|Pack_asp->pin{twithcontent;linked=true}andvalue_envparentt=letopenValuein{twithdoc=comment_docsenvparentt.doc;type_=type_expressionenvparent[]t.type_;}andexception_envparente=letopenExceptioninletres=Opt.map(type_expressionenvparent[])e.resinletargs=type_decl_constructor_argumentenvparente.argsinletdoc=comment_docsenvparente.docin{ewithres;args;doc}andextensionenvparentt=letopenExtensioninletconstructorc=letopenConstructorin{cwithargs=type_decl_constructor_argumentenvparentc.args;res=Opt.map(type_expressionenvparent[])c.res;doc=comment_docsenvparentc.doc;}inlettype_path=type_pathenvt.type_pathinletconstructors=List.mapconstructort.constructorsinletdoc=comment_docsenvparentt.docin{twithtype_path;constructors;doc}andclass_type_exprenvparent=letopenClassTypeinfunction|Constr(path,texps)->Constr(path,List.map(type_expressionenvparent[])texps)|Signatures->Signature(class_signatureenvparents)andclass_typeenvparentc=letopenClassTypeinletdoc=comment_docsenvparentc.docin{cwithexpr=class_type_exprenvparentc.expr;doc}andclass_signatureenvparentc=letopenClassSignatureinletenv=Env.open_class_signaturecenvinletmap_item=function|Methodm->Method(method_envparentm)|InstanceVariablei->InstanceVariable(instance_variableenvparenti)|Constraint(t1,t2)->Constraint(type_expressionenvparent[]t1,type_expressionenvparent[]t2)|Inheritc->Inherit(class_type_exprenvparentc)|Commentc->Commentcin{self=Opt.map(type_expressionenvparent[])c.self;items=List.mapmap_itemc.items;doc=comment_docsenvparentc.doc;}andmethod_envparentm=letopenMethodinletdoc=comment_docsenvparentm.docin{mwithtype_=type_expressionenvparent[]m.type_;doc}andinstance_variableenvparenti=letopenInstanceVariableinletdoc=comment_docsenvparenti.docin{iwithtype_=type_expressionenvparent[]i.type_;doc}andclass_envparentc=letopenClassinletrecmap_decl=function|ClassTypeexpr->ClassType(class_type_exprenvparentexpr)|Arrow(lbl,expr,decl)->Arrow(lbl,type_expressionenvparent[]expr,map_decldecl)inletdoc=comment_docsenvparentc.docin{cwithtype_=map_declc.type_;doc}andmodule_substitutionenvparentm=letopenModuleSubstitutioninletdoc=comment_docsenvparentm.docin{mwithmanifest=module_pathenvm.manifest;doc}andsignature:Env.t->Id.Signature.t->Signature.t->_=funenvids->letenv=Env.open_signaturesenv|>Env.add_docss.docinletitems=signature_itemsenvids.itemsanddoc=comment_docsenvids.docinletsg={swithitems;doc}inletsg'=Component.Of_Lang.(signature(empty())sg)inLang_of.(signature(id:>Id.Signature.t)(empty())sg')andsignature_items:Env.t->Id.Signature.t->Signature.itemlist->Signature.itemlist=funenvids->letopenSignatureinletitems,_=List.fold_left(fun(items,env)item->letstdi=(i::items,env)inmatchitemwith|Module(r,m)->std@@Module(r,module_envm)|ModuleSubstitutionm->letenv'=Env.open_module_substitutionmenvin(ModuleSubstitution(module_substitutionenvidm)::items,env')|Type(r,t)->std@@Type(r,type_declenvidt)|TypeSubstitutiont->letenv'=Env.open_type_substitutiontenvin(TypeSubstitution(type_declenvidt)::items,env')|ModuleTypemt->std@@ModuleType(module_typeenvmt)|ModuleTypeSubstitutionmts->letenv'=Env.open_module_type_substitutionmtsenvin(ModuleTypeSubstitution(module_type_substitutionenvmts)::items,env')|Valuev->std@@Value(value_envidv)|Commentc->std@@Comment(commentenvidc)|TypExtt->std@@TypExt(extensionenvidt)|Exceptione->std@@Exception(exception_envide)|Class(r,c)->std@@Class(r,class_envidc)|ClassType(r,c)->std@@ClassType(r,class_typeenvidc)|Includei->std@@Include(include_envi)|Openo->std@@Open(open_envido))([],env)sinList.revitemsandsimple_expansion:Env.t->Id.Signature.t->ModuleType.simple_expansion->ModuleType.simple_expansion=funenvidm->matchmwith|Signaturesg->Signature(signatureenvidsg)|Functor(arg,sg)->letenv'=Env.add_functor_parameterargenvinFunctor(functor_argumentenvarg,simple_expansionenv'idsg)andmodule_:Env.t->Module.t->Module.t=funenvm->letopenModuleinletsg_id=(m.id:>Id.Signature.t)inifm.hiddenthenmelselettype_=module_declenvsg_idm.type_inlettype_=matchtype_with|Alias(`Resolvedp,_)->lethidden_alias=Paths.Path.is_hidden(`Resolved(p:>Paths.Path.Resolved.t))inletself_canonical=leti=Paths.Path.Resolved.Module.identifierpini=(m.id:>Paths.Identifier.Path.Module.t)inletexpansion_needed=self_canonical||hidden_aliasinifexpansion_neededthenletcp=Component.Of_Lang.(resolved_module_path(empty())p)inmatchExpand_tools.expansion_of_module_aliasenvm.id(`Resolvedcp)with|Ok(_,_,e)->letle=Lang_of.(simple_expansion(empty())sg_ide)inAlias(`Resolvedp,Some(simple_expansionenvsg_idle))|Error_->type_elsetype_|Alias_|ModuleType_->type_in{mwithdoc=comment_docsenvsg_idm.doc;type_}andmodule_decl:Env.t->Id.Signature.t->Module.decl->Module.decl=funenviddecl->letopenModuleinmatchdeclwith|ModuleTypeexpr->ModuleType(module_type_exprenvidexpr)|Alias(p,e)->Alias(module_pathenvp,Opt.map(simple_expansionenvid)e)andinclude_decl:Env.t->Id.Signature.t->Include.decl->Include.decl=funenviddecl->letopenIncludeinmatchdeclwith|ModuleTypeexpr->ModuleType(u_module_type_exprenvidexpr)|Aliasp->Alias(module_pathenvp)andmodule_type:Env.t->ModuleType.t->ModuleType.t=funenvm->letsg_id=(m.id:>Id.Signature.t)inletopenModuleTypeinletexpr'=matchm.exprwith|None->None|Someexpr->Some(module_type_exprenvsg_idexpr)in(* let self_canonical =
match m.expr with
| Some (Path (`Resolved p)) when Paths.Path.Resolved.ModuleType.canonical_ident p = Some m.id ->
true
| _ -> false
in*)letdoc=comment_docsenvsg_idm.docin{mwithexpr=expr';doc}andmodule_type_substitution:Env.t->ModuleTypeSubstitution.t->ModuleTypeSubstitution.t=funenvm->letsg_id=(m.id:>Id.Signature.t)inletopenModuleTypeSubstitutioninletmanifest'=module_type_exprenvsg_idm.manifestinletdoc=comment_docsenvsg_idm.docin{mwithmanifest=manifest';doc}andinclude_:Env.t->Include.t->Include.t=funenvi->letopenIncludeinletdecl=include_declenvi.parenti.declinletdoc=comment_docsenvi.parenti.docinletexpansion=(* Don't call {!signature} to avoid adding the content of the expansion to
the environment, which is already done recursively by
{!Env.open_signature}. *)letcontent=(* Add context around errors from the expansion. *)Lookup_failures.with_context"While resolving the expansion of include at %a"Location_.pp_span_starti.loc(fun()->let{content;_}=i.expansioninletitems=signature_itemsenvi.parentcontent.itemsanddoc=comment_docsenvi.parentcontent.docin{contentwithitems;doc})in{i.expansionwithcontent}in{iwithdecl;expansion;doc}andfunctor_parameter_parameter:Env.t->FunctorParameter.parameter->FunctorParameter.parameter=funenva->letsg_id=(a.id:>Id.Signature.t)inletexpr=module_type_exprenvsg_ida.exprin{awithexpr}andfunctor_argumentenva=matchawith|FunctorParameter.Unit->FunctorParameter.Unit|Namedarg->Named(functor_parameter_parameterenvarg)andhandle_fragmentsenvidsgsubs=letopenModuleTypeinList.fold_left(fun(sg_res,subs)lsub->match(sg_res,lsub)with|Result.Oksg,ModuleEq(frag,decl)->letfrag'=matchfragwith|`Resolvedf->letcfrag=Component.Of_Lang.(resolved_module_fragment(empty())f)in`Resolved(Tools.reresolve_module_fragmentenvcfrag|>Lang_of.(Path.resolved_module_fragment(empty())))|_->fraginletsg'=Tools.fragmap~mark_substituted:trueenvComponent.Of_Lang.(with_module_type_substitution(empty())lsub)sgin(sg',ModuleEq(frag',module_declenviddecl)::subs)|Oksg,TypeEq(frag,eqn)->letfrag'=matchfragwith|`Resolvedf->letcfrag=Component.Of_Lang.(resolved_type_fragment(empty())f)in`Resolved(Tools.reresolve_type_fragmentenvcfrag|>Lang_of.(Path.resolved_type_fragment(empty())))|_->fraginletsg'=Tools.fragmap~mark_substituted:trueenvComponent.Of_Lang.(with_module_type_substitution(empty())lsub)sgin(sg',TypeEq(frag',type_decl_equationenvideqn)::subs)|Oksg,ModuleTypeEq(frag,eqn)->letfrag'=matchfragwith|`Resolvedf->letcfrag=Component.Of_Lang.(resolved_module_type_fragment(empty())f)in`Resolved(Tools.reresolve_module_type_fragmentenvcfrag|>Lang_of.(Path.resolved_module_type_fragment(empty())))|_->fraginletsg'=Tools.fragmap~mark_substituted:trueenvComponent.Of_Lang.(with_module_type_substitution(empty())lsub)sgin(sg',ModuleTypeEq(frag',module_type_exprenvideqn)::subs)|Oksg,ModuleSubst(frag,mpath)->letfrag'=matchfragwith|`Resolvedf->letcfrag=Component.Of_Lang.(resolved_module_fragment(empty())f)in`Resolved(Tools.reresolve_module_fragmentenvcfrag|>Lang_of.(Path.resolved_module_fragment(empty())))|_->fraginletsg'=Tools.fragmap~mark_substituted:trueenvComponent.Of_Lang.(with_module_type_substitution(empty())lsub)sgin(sg',ModuleSubst(frag',module_pathenvmpath)::subs)|Oksg,TypeSubst(frag,eqn)->letfrag'=matchfragwith|`Resolvedf->letcfrag=Component.Of_Lang.(resolved_type_fragment(empty())f)in`Resolved(Tools.reresolve_type_fragmentenvcfrag|>Lang_of.(Path.resolved_type_fragment(empty())))|_->fraginletsg'=Tools.fragmap~mark_substituted:trueenvComponent.Of_Lang.(with_module_type_substitution(empty())lsub)sgin(sg',TypeSubst(frag',type_decl_equationenvideqn)::subs)|Oksg,ModuleTypeSubst(frag,eqn)->letfrag'=matchfragwith|`Resolvedf->letcfrag=Component.Of_Lang.(resolved_module_type_fragment(empty())f)in`Resolved(Tools.reresolve_module_type_fragmentenvcfrag|>Lang_of.(Path.resolved_module_type_fragment(empty())))|_->fraginletsg'=Tools.fragmap~mark_substituted:trueenvComponent.Of_Lang.(with_module_type_substitution(empty())lsub)sgin(sg',ModuleTypeSubst(frag',module_type_exprenvideqn)::subs)|(Error_ase),lsub->(e,lsub::subs))(Oksg,[])subs|>snd|>List.revandu_module_type_expr:Env.t->Id.Signature.t->ModuleType.U.expr->ModuleType.U.expr=funenvidexpr->matchexprwith|Signatures->Signatures(* No need to link 'unexpanded' module type expressions that are actually expanded... *)|Pathp->Path(module_type_pathenvp)|With(subs,expr)asunresolved->(letcexpr=Component.Of_Lang.(u_module_type_expr(empty())expr)inmatchTools.signature_of_u_module_type_expr~mark_substituted:trueenvcexprwith|Oksg->With(handle_fragmentsenvidsgsubs,u_module_type_exprenvidexpr)|Errore->Errors.report~what:(`Module_type_Ucexpr)~tools_error:e`Resolve;unresolved)|TypeOf{t_desc=StructIncludep;t_expansion}->TypeOf{t_desc=StructInclude(module_pathenvp);t_expansion}|TypeOf{t_desc=ModPathp;t_expansion}->TypeOf{t_desc=ModPath(module_pathenvp);t_expansion}andmodule_type_expr:Env.t->Id.Signature.t->ModuleType.expr->ModuleType.expr=funenvidexpr->letopenModuleTypeinletdo_expncur(e:Paths.Path.ModuleType.toption)=match(cur,e)with|Somee,_->Some(simple_expansionenv(id:>Paths.Identifier.Signature.t)e)|None,Some(`Resolvedp_path)->lethidden_alias=Paths.Path.is_hidden(`Resolved(p_path:>Paths.Path.Resolved.t))inletself_canonical=leti=Paths.Path.Resolved.ModuleType.identifierp_pathin(i:>Id.Signature.t)=idinletexpansion_needed=self_canonical||hidden_aliasinifexpansion_neededthenletcp=Component.Of_Lang.(resolved_module_type_path(empty())p_path)inmatchExpand_tools.expansion_of_module_type_exprenvid(Path{p_path=`Resolvedcp;p_expansion=None})with|Ok(_,_,e)->letle=Lang_of.(simple_expansion(empty())ide)inSome(simple_expansionenvidle)|Error_->NoneelseNone|None,_->Noneinmatchexprwith|Signatures->Signature(signatureenvids)|Path{p_path;p_expansion}->letp_path=module_type_pathenvp_pathinPath{p_path;p_expansion=do_expnp_expansion(Somep_path)}|With{w_substitutions;w_expansion;w_expr}asunresolved->(letcexpr=Component.Of_Lang.(u_module_type_expr(empty())w_expr)inmatchTools.signature_of_u_module_type_expr~mark_substituted:trueenvcexprwith|Oksg->With{w_substitutions=handle_fragmentsenvidsgw_substitutions;w_expansion=do_expnw_expansionNone;w_expr=u_module_type_exprenvidw_expr;}|Errore->Errors.report~what:(`Module_type_Ucexpr)~tools_error:e`Expand;unresolved)|Functor(arg,res)->letarg'=functor_argumentenvarginletenv=Env.add_functor_parameterargenvinletres'=module_type_exprenv(`Resultid)resinFunctor(arg',res')|TypeOf{t_desc=StructIncludep;t_expansion}->TypeOf{t_desc=StructInclude(module_pathenvp);t_expansion=do_expnt_expansionNone;}|TypeOf{t_desc=ModPathp;t_expansion}->TypeOf{t_desc=ModPath(module_pathenvp);t_expansion=do_expnt_expansionNone;}andtype_decl_representation:Env.t->Id.Signature.t->TypeDecl.Representation.t->TypeDecl.Representation.t=funenvparentr->letopenTypeDecl.Representationinmatchrwith|Variantcs->Variant(List.map(type_decl_constructorenvparent)cs)|Recordfs->Record(List.map(type_decl_fieldenvparent)fs)|Extensible->Extensibleandtype_decl:Env.t->Id.Signature.t->TypeDecl.t->TypeDecl.t=funenvparentt->letopenTypeDeclinletequation=type_decl_equationenvparentt.equationinletdoc=comment_docsenvparentt.docinlethidden_path=matchequation.Equation.manifestwith|Some(Constr(`Resolvedpath,params))whenPaths.Path.Resolved.Type.is_hiddenpath||Paths.Path.Resolved.Type.canonical_identpath=(Somet.id:>Paths.Identifier.Path.Type.toption)->Some(path,params)|_->Noneinletrepresentation=Opt.map(type_decl_representationenvparent)t.representationinletdefault={twithequation;doc;representation}inmatchhidden_pathwith|Some(p,params)->(letp'=Component.Of_Lang.(resolved_type_path(empty())p)inmatchTools.lookup_typeenvp'with|Ok(`FType(_,t'))->letequation=tryExpand_tools.collapse_eqnsdefault.equation(Lang_of.type_decl_equation(Lang_of.empty())(parent:>Id.Parent.t)t'.equation)paramswith_->default.equationin{defaultwithequation=type_decl_equationenvparentequation}|Ok(`FClass_|`FClassType_|`FType_removed_)|Error_->default)|None->defaultandtype_decl_equationenvparentt=letopenTypeDecl.Equationinletmanifest=Opt.map(type_expressionenvparent[])t.manifestinletconstraints=List.map(fun(tex1,tex2)->(type_expressionenvparent[]tex1,type_expressionenvparent[]tex2))t.constraintsin{twithmanifest;constraints}andtype_decl_fieldenvparentf=letopenTypeDecl.Fieldinletdoc=comment_docsenvparentf.docin{fwithtype_=type_expressionenvparent[]f.type_;doc}andtype_decl_constructor_argumentenvparentc=letopenTypeDecl.Constructorinmatchcwith|Tuplets->Tuple(List.map(type_expressionenvparent[])ts)|Recordfs->Record(List.map(type_decl_fieldenvparent)fs)andtype_decl_constructorenvparentc=letopenTypeDecl.Constructorinletdoc=comment_docsenvparentc.docinletargs=type_decl_constructor_argumentenvparentc.argsinletres=Opt.map(type_expressionenvparent[])c.resin{cwithdoc;args;res}andtype_expression_polyvarenvparentvisitedv=letopenTypeExpr.Polymorphic_variantinletconstructorc=letopenConstructorinletdoc=comment_docsenvparentc.docin{cwitharguments=List.map(type_expressionenvparentvisited)c.arguments;doc;}inletelement=function|Typet->Type(matchtype_expressionenvparentvisitedtwith|Constr_asx->x|_->t)(* These have to remain Constrs *)|Constructorc->Constructor(constructorc)in{vwithelements=List.mapelementv.elements}andtype_expression_objectenvparentvisitedo=letopenTypeExpr.Objectinletmethod_m={mwithtype_=type_expressionenvparentvisitedm.type_}inletfield=function|Methodm->Method(method_m)|Inheritt->Inherit(type_expressionenvparentvisitedt)in{owithfields=List.mapfieldo.fields}andtype_expression_packageenvparentvisitedp=letopenTypeExpr.Packageinletsubstitution(frag,t)=letcfrag=Component.Of_Lang.(type_fragment(empty())frag)inletfrag'=matchcfragwith|`Resolvedf->`Resolved(Tools.reresolve_type_fragmentenvf)|_->cfragin(Lang_of.(Path.type_fragment(empty())frag'),type_expressionenvparentvisitedt)in{path=module_type_pathenvp.path;substitutions=List.mapsubstitutionp.substitutions;}andtype_expression:Env.t->Id.Signature.t->_->_=funenvparentvisitedtexpr->letopenTypeExprinmatchtexprwith|Var_|Any->texpr|Alias(t,str)->Alias(type_expressionenvparentvisitedt,str)|Arrow(lbl,t1,t2)->Arrow(lbl,type_expressionenvparentvisitedt1,type_expressionenvparentvisitedt2)|Tuplets->Tuple(List.map(type_expressionenvparentvisited)ts)|Constr(path',ts')->(letpath=type_pathenvpath'inletts=List.map(type_expressionenvparentvisited)ts'inifnot(Paths.Path.is_hidden(path:>Paths.Path.t))thenConstr(path,ts)elseletcp=Component.Of_Lang.(type_path(empty())path')inmatchTools.resolve_typeenv~add_canonical:truecpwith|Ok(cp',`FType(_,t))->letcp'=Tools.reresolve_typeenvcp'inletp=Lang_of.(Path.resolved_type(empty())cp')inifList.mempvisitedthenraiseLoopelseifCpath.is_resolved_type_hiddencp'thenmatcht.Component.TypeDecl.equationwith|{manifest=Someexpr;params;_}->(tryletmap=List.fold_left2(funaccparamsub->matchparam.Lang.TypeDecl.descwith|Lang.TypeDecl.Varx->(x,sub)::acc|Any->acc)[]paramstsinlett'=Expand_tools.type_exprmapLang_of.(type_expr(empty())(parent:>Id.Parent.t)expr)intype_expressionenvparent(p::visited)t'with|Loop->Constr(`Resolvedp,ts)|e->Format.eprintf"Caught unexpected exception when expanding type \
declaration (%s)\n\
%!"(Printexc.to_stringe);Constr(`Resolvedp,ts))|_->Constr(`Resolvedp,ts)elseConstr(`Resolvedp,ts)|Ok(cp',(`FClass_|`FClassType_))->letp=Lang_of.(Path.resolved_type(empty())cp')inConstr(`Resolvedp,ts)|Ok(_cp,`FType_removed(_,x,_eq))->(* Type variables ? *)Lang_of.(type_expr(empty())(parent:>Id.Parent.t)x)|Error_->Constr(path',ts))|Polymorphic_variantv->Polymorphic_variant(type_expression_polyvarenvparentvisitedv)|Objecto->Object(type_expression_objectenvparentvisitedo)|Class(path',ts')->(letpath=class_type_pathenvpath'inletts=List.map(type_expressionenvparentvisited)ts'inifnot(Paths.Path.is_hidden(path:>Paths.Path.t))thenClass(path,ts)elseletcp=Component.Of_Lang.(class_type_path(empty())path')inmatchTools.resolve_class_typeenvcpwith|Ok(cp',(`FClass_|`FClassType_))->letcp'=Tools.reresolve_class_typeenvcp'inletp=Lang_of.(Path.resolved_class_type(empty())cp')inClass(`Resolvedp,ts)|_->Class(path',ts))|Poly(strs,t)->Poly(strs,type_expressionenvparentvisitedt)|Packagep->Package(type_expression_packageenvparentvisitedp)letlink~filenamexy=Lookup_failures.catch_failures~filename(fun()->ify.Lang.Compilation_unit.linkedthenyelseunitxy)letpageenvpage=letchildren=List.fold_right(funchildres->matchRef_tools.resolve_referenceenvchild|>Error.raise_warningswith|Okr->`Resolvedr::res|Error_->Errors.report~what:(`Childchild)`Resolve;res)page.Odoc_model.Lang.Page.children[]in{pagewithPage.content=comment_docsenvpage.Page.namepage.content;children;linked=true;}letresolve_page~filenameenvp=Lookup_failures.catch_failures~filename(fun()->ifp.Lang.Page.linkedthenpelsepageenvp)