1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114(* Second round of resolution tackles references and forward paths *)openOdoc_modelopenLangmoduleId=Paths.IdentifiermoduleOpt=structletmapf=functionSomex->Some(fx)|None->Noneendletlocationsenvidlocs=letid=(id:>Id.NonSrc.t)inmatchlocswith|Some_aslocs->locs|None->Shape_tools.lookup_defenvid(** 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)=letopenUtils.ResultMonadinmatchsynopsis_from_commentm.docwith|Some_ass->s|None->(letrechandle_expansion:Tools.expansion->_=function|Functor(_,expr)->(matchTools.expansion_of_module_type_expr~mark_substituted:trueenvexprwith|Oke->handle_expansione|Error_ase->e)|Signaturesg->Oksgin(* If there is no doc, look at the expansion. *)matchTools.expansion_of_moduleenvm>>=funexp->handle_expansionexpwith|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,({Odoc_model.Paths.Identifier.iv=`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->()letexpansion_neededselftarget=letself=(self:>Paths.Path.Resolved.t)inlethidden_alias=Paths.Path.Resolved.is_hiddenselfandself_canonical=leti=Paths.Path.Resolved.identifierselfini=(target:>Paths.Identifier.t)inself_canonical||hidden_aliasexceptionLoopletrecis_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)|`CanonicalDataType(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(y,x)->should_resolve(x:>Paths.Path.t)||should_reresolve(y:>t)|`AliasModuleType(x,y)->should_reresolve(x:>t)||should_reresolve(y:>t)|`Type(p,_)|`Value(p,_)|`Class(p,_)|`ClassType(p,_)|`ModuleType(p,_)|`Module(p,_)->should_reresolve(p:>t)|`Constructor(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|_->true(* and should_resolve_constructor : Paths.Path.Constructor.t -> bool = *)(* fun p -> *)(* match p with *)(* | `Resolved p -> should_reresolve (p :> Paths.Path.Resolved.t) *)(* | _ -> true *)lettype_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)(* let value_path : Env.t -> Paths.Path.Value.t -> Paths.Path.Value.t = *)(* fun env p -> *)(* if not (should_resolve (p :> Paths.Path.t)) then p *)(* else *)(* let cp = Component.Of_Lang.(value_path (empty ()) p) in *)(* match cp with *)(* | `Resolved p -> *)(* let result = Tools.reresolve_value env p in *)(* `Resolved Lang_of.(Path.resolved_value (empty ()) result) *)(* | _ -> ( *)(* match Tools.resolve_value_path env cp with *)(* | Ok p' -> *)(* let result = Tools.reresolve_value env p' in *)(* `Resolved Lang_of.(Path.resolved_value (empty ()) result) *)(* | Error e -> *)(* Errors.report ~what:(`Value_path cp) ~tools_error:e `Lookup; *)(* p) *)(* let constructor_path : *)(* Env.t -> Paths.Path.Constructor.t -> Paths.Path.Constructor.t = *)(* fun env p -> *)(* if not (should_resolve_constructor p) then p *)(* else *)(* let cp = Component.Of_Lang.(constructor_path (empty ()) p) in *)(* match cp with *)(* | `Resolved p -> *)(* let result = Tools.reresolve_constructor env p in *)(* `Resolved Lang_of.(Path.resolved_constructor (empty ()) result) *)(* | _ -> ( *)(* match Tools.resolve_constructor_path env cp with *)(* | Ok p' -> *)(* let result = Tools.reresolve_constructor env p' in *)(* `Resolved Lang_of.(Path.resolved_constructor (empty ()) result) *)(* | Error e -> *)(* Errors.report ~what:(`Constructor_path cp) ~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({iv=#Id.Label.t_pv;_}asi)->(matchEnv.lookup_by_idEnv.s_labelienvwith|Some(`Label(_,lbl))->Odoc_model.Comment.link_content_of_inline_elementslbl.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_|`Math_block_|`Verbatim_)asx->x|`List(x,ys)->`List(x,List.rev_map(comment_nestable_block_element_listenvparent)ys|>List.rev)|`Table{data;align}->letdata=letmapfx=List.rev_mapfx|>List.revinmap(map(fun(cell,cell_type)->(comment_nestable_block_element_listenvparentcell,cell_type)))datain`Table{Comment.data;align}|`Modulesrefs->letrefs=List.rev_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)refs|>List.revin`Modulesrefsandcomment_nestable_block_element_listenvparent(xs:Comment.nestable_block_elementComment.with_locationlist)=List.rev_map(with_location(comment_nestable_block_elementenvparent))xs|>List.revandcomment_tagenvparent~loc:_(x:Comment.tag)=matchxwith|`Deprecatedcontent->`Deprecated(comment_nestable_block_element_listenvparentcontent)|`Param(name,content)->`Param(name,comment_nestable_block_element_listenvparentcontent)|`Raise((`Reference(r,reference_content)asorig),content)->(matchRef_tools.resolve_referenceenvr|>Error.raise_warningswith|Okx->`Raise(`Reference(`Resolvedx,reference_content),comment_nestable_block_element_listenvparentcontent)|Errore->Errors.report~what:(`Referencer)~tools_error:(`Referencee)`Resolve;`Raise(orig,comment_nestable_block_element_listenvparentcontent))|`Raise((`Code_span_asorig),content)->`Raise(orig,comment_nestable_block_element_listenvparentcontent)|`Returncontent->`Return(comment_nestable_block_element_listenvparentcontent)|`See(kind,target,content)->`See(kind,target,comment_nestable_block_element_listenvparentcontent)|`Before(version,content)->`Before(version,comment_nestable_block_element_listenvparentcontent)|`Author_|`Since_|`Alert_|`Version_->x(* only contain primitives *)andcomment_block_elementenvparent~loc(x:Comment.block_element)=matchxwith|#Comment.nestable_block_elementasx->(comment_nestable_block_elementenvparent~locx:>Comment.block_element)|`Heading(attrs,label,elems)->letcie=comment_inline_elementenvinletelems=List.rev_map(funele->with_locationcieele)elems|>List.revinleth=(attrs,label,elems)incheck_ambiguous_label~locenvh;`Headingh|`Tagt->`Tag(comment_tagenvparent~loct)andwith_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.rev_map(with_location(comment_block_elementenv(parent:>Id.LabelParent.t)))d|>List.revandcommentenvparent=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->letsg=signatureenv(t.id:>Id.Signature.t)sginModulesg|Pack_asp->pin{twithcontent;linked=true}andvalue_envparentt=letopenValuein{twithlocs=locationsenvt.idt.locs;doc=comment_docsenvparentt.doc;type_=type_expressionenvparent[]t.type_;}andexception_envparente=letopenExceptioninletres=Opt.map(type_expressionenvparent[])e.resinletargs=type_decl_constructor_argumentenvparente.argsinletlocs=locationsenve.ide.locsinletdoc=comment_docsenvparente.docin{ewithlocs;res;args;doc}andextensionenvparentt=letopenExtensioninletconstructorc=letopenConstructorin{cwithlocs=locationsenvc.idc.locs;args=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{cwithlocs=locationsenvc.idc.locs;expr=class_type_exprenvparentc.expr;doc;}andclass_signatureenvparentc=letopenClassSignatureinletenv=Env.open_class_signaturecenvinletmap_item=function|Methodm->Method(method_envparentm)|InstanceVariablei->InstanceVariable(instance_variableenvparenti)|Constraintcst->Constraint(constraint_envparentcst)|Inheritc->Inherit(inherit_envparentc)|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}andconstraint_envparentcst=letopenClassSignature.Constraintinletleft=type_expressionenvparent[]cst.leftandright=type_expressionenvparent[]cst.rightanddoc=comment_docsenvparentcst.docin{left;right;doc}andinherit_envparentih=letopenClassSignature.Inheritinletexpr=class_type_exprenvparentih.expranddoc=comment_docsenvparentih.docin{expr;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.docinletlocs=locationsenvc.idc.locsinlettype_=map_declc.type_in{cwithlocs;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.docin{swithitems;doc}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->letopenModuleinletopenUtils.ResultMonadinletsg_id=(m.id:>Id.Signature.t)inifm.hiddenthenmelselettype_=module_declenvsg_idm.type_inlettype_=matchtype_with|Alias(`Resolvedp,_)->ifexpansion_neededpm.idthenletcp=Component.Of_Lang.(resolved_module_path(empty())p)inmatchTools.expansion_of_module_path~strengthen:falseenv(`Resolvedcp)>>=Expand_tools.handle_expansionenv(m.id:>Id.Signature.t)with|Ok(_,e)->letle=Lang_of.(simple_expansion(empty())sg_ide)inAlias(`Resolvedp,Some(simple_expansionenvsg_idle))|Error_->type_elsetype_|Alias_|ModuleType_->type_inletlocs=locationsenvm.idm.locsinletdoc=comment_docsenvsg_idm.docin{mwithlocs;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.docinletlocs=(locationsenvm.id)m.locsin{mwithlocs;expr=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->letopenModuleTypeinletopenUtils.ResultMonadinletdo_expncur(e:Paths.Path.ModuleType.toption)=match(cur,e)with|Somee,_->Some(simple_expansionenv(id:>Paths.Identifier.Signature.t)e)|None,Some(`Resolvedp_path)->ifexpansion_neededp_pathidthenletcp=Component.Of_Lang.(resolved_module_type_path(empty())p_path)inmatchTools.expansion_of_module_type_expr~mark_substituted:falseenv(Path{p_path=`Resolvedcp;p_expansion=None})>>=Expand_tools.handle_expansionenv(id:>Id.Signature.t)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(Paths.Identifier.Mk.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.docinletlocs=locationsenvt.idt.locsinlethidden_path=matchequation.Equation.manifestwith|Some(Constr(`Resolvedpath,params))whenPaths.Path.Resolved.(is_hidden(path:>t))||Paths.Path.Resolved.(identifier(path:>t))=(t.id:>Paths.Identifier.t)->Some(path,params)|_->Noneinletrepresentation=Opt.map(type_decl_representationenvparent)t.representationinletdefault={twithlocs;equation;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.FieldParent.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.LabelParent.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.LabelParent.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.linked||y.hiddenthenyelseunitxy)letpageenvpage=let()=List.iter(funchild->letcheck_resolves~whatfname=matchfnameenvwith|Some_->()|None->Errors.report~what`Lookupinmatchchildwith|Page.Asset_child_|Page.Source_tree_child_->()|Page.Page_childpage->check_resolves~what:(`Child_pagepage)Env.lookup_pagepage|Page.Module_childmod_->check_resolves~what:(`Child_modulemod_)Env.lookup_root_modulemod_)page.Lang.Page.childrenin{pagewithPage.content=comment_docsenvpage.Page.namepage.content;linked=true;}letresolve_page~filenameenvp=Lookup_failures.catch_failures~filename(fun()->ifp.Lang.Page.linkedthenpelsepageenvp)