123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914(* A bunch of association lists. Let's hashtbl them up later *)openOdoc_modelopenOdoc_model.NamesopenOdoc_model.Pathstypelookup_unit_result=|Forward_reference|FoundofOdoc_model.Lang.Compilation_unit.t|Not_foundtypelookup_page_result=Odoc_model.Lang.Page.toptiontyperoot=|Resolvedof(Root.t*Odoc_model.Paths.Identifier.Module.t*Component.Module.t)|Forwardtyperesolver={open_units:stringlist;lookup_unit:string->lookup_unit_result;lookup_page:string->lookup_page_result;}letunique_id=leti=ref0infun()->incri;!itypelookup_type=|ModuleofOdoc_model.Paths.Identifier.Path.Module.t|ModuleTypeofOdoc_model.Paths.Identifier.Path.ModuleType.t|RootModuleofstring*[`Forward|`ResolvedofDigest.t]option|ModuleByNameofstring*Odoc_model.Paths.Identifier.Path.Module.t|FragmentRootofintletpp_lookup_typefmt=letfmtrmfmt=function|Some`Forward->Format.fprintffmt"Some (Forward)"|Some(`Resolveddigest)->Format.fprintffmt"Some (Resolved %s)"digest|None->Format.fprintffmt"None"infunction|Moduler->Format.fprintffmt"Module %a"Component.Fmt.model_identifier(r:>Identifier.t)|ModuleTyper->Format.fprintffmt"ModuleType %a"Component.Fmt.model_identifier(r:>Identifier.t)|RootModule(str,res)->Format.fprintffmt"RootModule %s %a"strfmtrmres|ModuleByName(n,r)->Format.fprintffmt"ModuleByName %s, %a"nComponent.Fmt.model_identifier(r:>Identifier.t)|FragmentRooti->Format.fprintffmt"FragmentRoot %d"iletpp_lookup_type_listfmtls=letrecinnerfmt=function|[]->Format.fprintffmt""|[x]->Format.fprintffmt"%a"pp_lookup_typex|x::ys->Format.fprintffmt"%a; %a"pp_lookup_typexinnerysinFormat.fprintffmt"[%a]"innerlsmoduleLookupTypeSet=Set.Make(structtypet=lookup_typeletcompare=compareend)typerecorder={mutablelookups:LookupTypeSet.t}moduleMaps=Odoc_model.Paths.Identifier.MapsmoduleStringMap=Map.Make(String)(** Used only to handle shadowing, see {!Elements}. *)typekind=|Kind_Module|Kind_ModuleType|Kind_Type|Kind_Value|Kind_Label|Kind_Class|Kind_ClassType|Kind_Constructor|Kind_Exception|Kind_Extension|Kind_FieldmoduleElementsByName:sigtypetvalempty:tvaladd:kind->string->[<Component.Element.any]->t->tvalremove:[<Identifier.t]->t->tvalfind_by_name:(Component.Element.any->'boption)->string->t->'blistend=structtypeelem={kind:kind;elem:Component.Element.any}typet=elemlistStringMap.tletempty=StringMap.emptyletaddkindnameelemt=letelem=(elem:>Component.Element.any)inlettl=trylettl=StringMap.findnametinletnot_shadowe=e.kind<>kindinifnot(List.for_allnot_shadowtl)thenList.filternot_shadowtlelsetlwithNot_found->[]inStringMap.addname({kind;elem}::tl)tletremoveidt=letid=(id:>Identifier.t)inletname=Identifier.nameidinletl=StringMap.findnametinmatchList.filter(fune->not(Identifier.equalid(Component.Element.identifiere.elem)))lwith|[]->StringMap.removenamet|xs->StringMap.addnamexs(StringMap.removenamet)letfind_by_namefnamet=letfiltereacc=matchfe.elemwithSomer->r::acc|None->accintryList.fold_rightfilter(StringMap.findnamet)[]withNot_found->[]endmoduleElementsById:sigtypetvalempty:tvaladd:[<Identifier.t]->[<Component.Element.any]->t->tvalremove:[<Identifier.t]->t->tvalfind_by_id:[<Identifier.t]->t->Component.Element.anyoptionend=structmoduleIdMap=Identifier.Maps.Anytypet=Component.Element.anyIdMap.tletempty=IdMap.emptyletaddidentifierelementt=IdMap.add(identifier:>Identifier.t)(element:>Component.Element.any)tletremoveidt=letid=(id:>Identifier.t)inIdMap.removeidtletfind_by_ididentifiert=trySome(IdMap.find(identifier:>Identifier.t)t)withNot_found->Noneendtype'aamb_err=[`Ambiguousof'a*'alist]typet={linking:bool;(* True if this is a linking environment - if not,
we only put in modules, module types, types, classes and class types *)id:int;elts:ElementsByName.t;(** Elements mapped by their name. Queried with {!find_by_name}. *)ids:ElementsById.t;(** Elements mapped by their identifier. Queried with {!find_by_id}. *)ambiguous_labels:Component.Element.labelamb_errIdentifier.Maps.Label.t;resolver:resolveroption;recorder:recorderoption;fragmentroot:(int*Component.Signature.t)option;}letset_resolvertresolver={twithresolver=Someresolver}lethas_resolvert=matcht.resolverwithNone->false|_->trueletidt=t.idletwith_recorded_lookupsenvf=letrecorder={lookups=LookupTypeSet.empty}inletenv'={envwithrecorder=Somerecorder}inletrestore()=matchenv.recorderwith|Somer->r.lookups<-LookupTypeSet.unionrecorder.lookupsr.lookups|None->()intryletresult=fenv'inrestore();(recorder.lookups,result)withe->restore();raiseeletempty={linking=true;id=0;elts=ElementsByName.empty;ids=ElementsById.empty;resolver=None;recorder=None;ambiguous_labels=Identifier.Maps.Label.empty;fragmentroot=None;}letadd_fragment_rootsgenv=letid=unique_id()in{envwithfragmentroot=Some(id,sg);id}(** Implements most [add_*] functions. *)letadd_to_eltskindidentifiercomponentenv=ifnotenv.linkingthenassert(List.memkind[Kind_Module;Kind_ModuleType;Kind_Type;Kind_Class;Kind_ClassType]);let_=letother=ElementsById.find_by_ididentifierenv.idsinmatchotherwith|Some_->(* Format.eprintf "Overriding duplicate env entry: %s\n%!" (Identifier.name identifier); *)()|None->()inletname=Identifier.nameidentifierin{envwithid=unique_id();elts=ElementsByName.addkindnamecomponentenv.elts;ids=ElementsById.addidentifiercomponentenv.ids;}letremoveidentifierenv={envwithid=unique_id();elts=ElementsByName.removeidentifierenv.elts;ids=ElementsById.removeidentifierenv.ids;}letadd_labelidentifierheadingenv=assertenv.linking;letcomp=`Label(identifier,heading)inletname=Identifier.nameidentifierinletambiguous_labels=matchElementsById.find_by_ididentifierenv.idswith|Some(#Component.Element.labelasl)->leterr=trymatchIdentifier.Maps.Label.findidentifierenv.ambiguous_labelswith|`Ambiguous(x,others)->`Ambiguous(x,comp::others)withNot_found->`Ambiguous(l,[comp])inIdentifier.Maps.Label.addidentifiererrenv.ambiguous_labels|Some_->assertfalse|None->env.ambiguous_labelsin{envwithid=unique_id();elts=ElementsByName.addKind_Labelname(comp:>Component.Element.any)env.elts;ambiguous_labels;ids=ElementsById.addidentifiercompenv.ids;}letadd_docs(docs:Odoc_model.Comment.docs)env=assertenv.linking;List.fold_left(funenv->function|{Odoc_model.Location_.value=`Heading(attrs,id,text);location}->letlabel=Ident.Of_Identifier.labelidinadd_labelid{Component.Label.attrs;label;text;location}env|_->env)envdocsletadd_comment(com:Odoc_model.Comment.docs_or_stop)env=matchcomwith`Docsdoc->add_docsdocenv|`Stop->envletadd_cdocsp(docs:Component.CComment.docs)env=List.fold_left(funenvelement->matchelement.Odoc_model.Location_.valuewith|`Headingh->let(`LLabel(name,_))=h.Component.Label.labelinletlabel=`Label(Paths.Identifier.label_parentp,name)inadd_labellabelhenv|_->env)envdocsletadd_moduleidentifiermdocsenv=letenv'=add_to_eltsKind_Moduleidentifier(`Module(identifier,m))envinifenv.linkingthenadd_cdocsidentifierdocsenv'elseenv'letupdate_moduleidentifiermdocsenv=removeidentifierenv|>add_moduleidentifiermdocsletadd_typeidentifiertenv=letopenComponentinletopen_typedeclcs=letadd_consenv(cons:TypeDecl.Constructor.t)=letident=`Constructor(identifier,ConstructorName.make_stdcons.name)inadd_to_eltsKind_Constructorident(`Constructor(ident,cons))envandadd_fieldenv(field:TypeDecl.Field.t)=letident=`Field((identifier:>Odoc_model.Paths.Identifier.Parent.t),FieldName.make_stdfield.name)inadd_to_eltsKind_Fieldident(`Field(ident,field))envinletopenTypeDeclinmatcht.representationwith|Some(Variantcons)->(List.fold_leftadd_conscscons,List.map(funt->t.Constructor.doc)cons)|Some(Recordfields)->(List.fold_leftadd_fieldcsfields,List.map(funt->t.Field.doc)fields)|SomeExtensible|None->(cs,[])inletenv,docs=ifenv.linkingthenopen_typedeclenvelse(env,[])inletenv=add_to_eltsKind_Typeidentifier(`Type(identifier,t))envinifenv.linkingthenadd_cdocsidentifiert.docenv|>List.fold_right(add_cdocsidentifier)docselseenvletadd_module_typeidentifier(t:Component.ModuleType.t)env=letenv'=add_to_eltsKind_ModuleTypeidentifier(`ModuleType(identifier,t))envinifenv'.linkingthenadd_cdocsidentifiert.docenv'elseenv'letupdate_module_typeidentifiermenv=removeidentifierenv|>add_module_typeidentifiermletadd_valueidentifier(t:Component.Value.t)env=add_to_eltsKind_Valueidentifier(`Value(identifier,t))env|>add_cdocsidentifiert.docletadd_classidentifier(t:Component.Class.t)env=letenv'=add_to_eltsKind_Classidentifier(`Class(identifier,t))envinifenv'.linkingthenadd_cdocsidentifiert.docenv'elseenv'letadd_class_typeidentifier(t:Component.ClassType.t)env=letenv'=add_to_eltsKind_ClassTypeidentifier(`ClassType(identifier,t))envinifenv'.linkingthenadd_cdocsidentifiert.docenv'elseenv'letadd_method_identifier_tenv=(* TODO *)envletadd_exceptionidentifier(e:Component.Exception.t)env=add_to_eltsKind_Exceptionidentifier(`Exception(identifier,e))env|>add_cdocsidentifiere.docletadd_extension_constructoridentifier(ec:Component.Extension.Constructor.t)env=add_to_eltsKind_Extensionidentifier(`Extension(identifier,ec))env|>add_cdocsidentifierec.docletmodule_of_unit:Odoc_model.Lang.Compilation_unit.t->Component.Module.t=fununit->matchunit.contentwith|Modules->letm=Odoc_model.Lang.Module.{id=(unit.id:>Odoc_model.Paths.Identifier.Module.t);doc=[];type_=ModuleType(Signatures);canonical=unit.canonical;hidden=unit.hidden;}inletty=Component.Of_Lang.(module_(empty())m)inty|Pack_p->letm=Odoc_model.Lang.Module.{id=(unit.id:>Odoc_model.Paths.Identifier.Module.t);doc=[];type_=ModuleType(Signature{items=[];compiled=true;doc=[]});canonical=unit.canonical;hidden=unit.hidden;}inletty=Component.Of_Lang.(module_(empty())m)intyletlookup_root_modulenameenv=letresult=matchenv.resolverwith|None->None|Somer->(matchr.lookup_unitnamewith|Forward_reference->SomeForward|Not_found->None|Foundu->let(`Root_asid)=u.idinletm=module_of_unituinSome(Resolved(u.root,id,m)))in(match(env.recorder,result)with|Somer,SomeForward->r.lookups<-LookupTypeSet.add(RootModule(name,Some`Forward))r.lookups|Somer,Some(Resolved(root,_,_))->r.lookups<-LookupTypeSet.add(RootModule(name,Some(`Resolvedroot.digest)))r.lookups|Somer,None->r.lookups<-LookupTypeSet.add(RootModule(name,None))r.lookups|None,_->());resultletlookup_pagenameenv=matchenv.resolverwithNone->None|Somer->r.lookup_pagenametype'ascope={filter:Component.Element.any->([<Component.Element.any]as'a)option;check:(t->([<Component.Element.any]as'a)->'aamb_erroption)option;root:string->t->'aoption;}type'amaybe_ambiguous=('a,['aamb_err|`Not_found])Result.resultletmake_scope?(root=fun__->None)?check(filter:_->([<Component.Element.any]as'a)option):'ascope={filter;check;root}letlookup_by_namescopenameenv=letrecord_lookup_resultsenvresults=matchenv.recorderwith|Somer->List.iter(function|`Module(id,_)->r.lookups<-LookupTypeSet.add(ModuleByName(name,id))r.lookups|_->())(results:>Component.Element.anylist)|None->()inmatch(ElementsByName.find_by_namescope.filternameenv.elts,scope.check)with|([x]asresults),Somec->(record_lookup_resultsenvresults;matchcenvxwith|Some(`Ambiguous_ase)->Result.Errore|None->Result.Okx)|([x]asresults),None->record_lookup_resultsenvresults;Result.Okx|(x::tlasresults),_->record_lookup_resultsenvresults;Error(`Ambiguous(x,tl))|[],_->(matchscope.rootnameenvwithSomex->Okx|None->Error`Not_found)letlookup_by_id(scope:'ascope)idenv:'aoption=letrecord_lookup_resultresult=matchenv.recorderwith|Somer->(match(result:>Component.Element.any)with|`Module(id,_)->r.lookups<-LookupTypeSet.add(Moduleid)r.lookups|`ModuleType(id,_)->r.lookups<-LookupTypeSet.add(ModuleTypeid)r.lookups|_->())|None->()inmatchElementsById.find_by_ididenv.idswith|Somex->record_lookup_resultx;scope.filterx|None->(match(id:>Identifier.t)with|`Root(_,name)->scope.root(ModuleName.to_stringname)env|_->None)letlookup_root_module_fallbacknamet=matchlookup_root_modulenametwith|Some(Resolved(_,id,m))->Some(`Module((id:>Identifier.Path.Module.t),Component.Delayed.put_valm))|SomeForward|None->Noneletlookup_page_or_root_module_fallbacknamet=matchlookup_root_module_fallbacknametwith|Some_asx->x|None->(matchlookup_pagenametwith|Somepage->Some(`Page(page.Lang.Page.name,page))|None->None)lets_signature:Component.Element.signaturescope=make_scope~root:lookup_root_module_fallback(function|#Component.Element.signatureasr->Somer|_->None)lets_module:Component.Element.module_scope=make_scope~root:lookup_root_module_fallback(function|#Component.Element.module_asr->Somer|_->None)lets_any:Component.Element.anyscope=make_scope~root:lookup_page_or_root_module_fallback~check:(funenv->function|`Label(id,_)->(trySome(Identifier.Maps.Label.findidenv.ambiguous_labels:>Component.Element.anyamb_err)withNot_found->None)|_->None)(funr->Somer)lets_module_type:Component.Element.module_typescope=make_scope(function|#Component.Element.module_typeasr->Somer|_->None)lets_datatype:Component.Element.datatypescope=make_scope(function#Component.Element.datatypeasr->Somer|_->None)lets_type:Component.Element.type_scope=make_scope(function#Component.Element.type_asr->Somer|_->None)lets_class:Component.Element.class_scope=make_scope(function#Component.Element.class_asr->Somer|_->None)lets_class_type:Component.Element.class_typescope=make_scope(function|#Component.Element.class_typeasr->Somer|_->None)lets_value:Component.Element.valuescope=make_scope(function#Component.Element.valueasr->Somer|_->None)lets_label:Component.Element.labelscope=make_scope~check:(funenv->function|`Label(id,_)->(trySome(Identifier.Maps.Label.findidenv.ambiguous_labels)withNot_found->None))(function#Component.Element.labelasr->Somer|_->None)lets_constructor:Component.Element.constructorscope=make_scope(function|#Component.Element.constructorasr->Somer|_->None)lets_exception:Component.Element.exception_scope=make_scope(function|#Component.Element.exception_asr->Somer|_->None)lets_extension:Component.Element.extensionscope=make_scope(function|#Component.Element.extensionasr->Somer|_->None)lets_field:Component.Element.fieldscope=make_scope(function#Component.Element.fieldasr->Somer|_->None)lets_label_parent:Component.Element.label_parentscope=make_scope~root:lookup_page_or_root_module_fallback(function|#Component.Element.label_parentasr->Somer|_->None)letlen=ref0letn=ref0letlookup_fragment_rootenv=letmaybe_record_resultres=matchenv.recorderwith|Somer->r.lookups<-LookupTypeSet.addresr.lookups|None->()inmatchenv.fragmentrootwith|Some(i,_)asresult->maybe_record_result(FragmentRooti);result|None->Noneletadd_functor_parameter:Odoc_model.Lang.FunctorParameter.t->t->t=funpt->matchpwith|Unit->t|Namedn->letm=Component.Module.{doc=[];type_=ModuleTypeComponent.Of_Lang.(module_type_expr(empty())n.expr);canonical=None;hidden=false;}inadd_module(n.id:>Paths.Identifier.Path.Module.t)(Component.Delayed.put_valm)[]tletadd_functor_args':Odoc_model.Paths.Identifier.Signature.t->Component.ModuleType.expr->t->t=letopenComponentinfunidexprenv->letrecfind_argsparentmty=matchmtywith|ModuleType.Functor(Namedarg,res)->(arg.Component.FunctorParameter.id,`Parameter(parent,Ident.Name.typed_functor_parameterarg.Component.FunctorParameter.id),{Component.Module.doc=[];type_=ModuleTypearg.expr;canonical=None;hidden=false;})::find_args(`Resultparent)res|ModuleType.Functor(Unit,res)->find_args(`Resultparent)res|_->[]in(* We substituted back the parameters as identifiers to maintain the invariant that
components in the environment are 'self-contained' - that is, they only contain
local idents for things that are declared within themselves *)letfold_fn(env,subst)(ident,identifier,m)=letident,identifier=((ident,identifier):>Ident.path_module*Identifier.Path.Module.t)inletdoc=m.Component.Module.docinletm=Component.Delayed.put_val(Subst.module_substm)inletenv'=add_moduleidentifiermdocenvin(env',Subst.add_moduleident(`Resolved(`Identifieridentifier))(`Identifieridentifier)subst)inletenv',_subst=List.fold_leftfold_fn(env,Subst.identity)(find_argsidexpr)inenv'letadd_module_functor_argsmidenv=matchm.Component.Module.type_with|Alias_->env|ModuleTypeexpr->add_functor_args'(id:>Odoc_model.Paths.Identifier.Signature.t)exprenvletadd_module_type_functor_argsmtidenv=matchmt.Component.ModuleType.exprwith|None->env|Someexpr->add_functor_args'(id:>Odoc_model.Paths.Identifier.Signature.t)exprenvletopen_class_signature:Odoc_model.Lang.ClassSignature.t->t->t=letopenComponentinletopenOf_Langinfunsenv->List.fold_left(funenvorig->matchorigwith|Odoc_model.Lang.ClassSignature.Methodm->letty=method_(empty())minadd_methodm.Odoc_model.Lang.Method.idtyenv|_->env)envs.itemsletrecopen_signature:Odoc_model.Lang.Signature.t->t->t=letopenComponentinletopenOf_LanginletmoduleL=Odoc_model.Langinletident_map=empty()infunse->List.fold_left(funenvorig->match((orig:L.Signature.item),env.linking)with|Type(_,t),_->letty=type_declident_maptinadd_typet.L.TypeDecl.idtyenv|Module(_,t),_->letty=Component.Delayed.put(fun()->module_ident_mapt)inadd_module(t.L.Module.id:>Identifier.Path.Module.t)ty(docsident_mapt.L.Module.doc)env|ModuleTypet,_->letty=module_typeident_maptinadd_module_typet.L.ModuleType.idtyenv|ModuleTypeSubstitution_,_|L.Signature.TypeSubstitution_,_|L.Signature.ModuleSubstitution_,_->env|L.Signature.Class(_,c),_->letty=class_ident_mapcinadd_classc.idtyenv|L.Signature.ClassType(_,c),_->letty=class_typeident_mapcinadd_class_typec.idtyenv|L.Signature.Includei,_->open_signaturei.expansion.contentenv|L.Signature.Openo,false->open_signatureo.expansionenv(* The following are only added when linking *)|L.Signature.Openo,true->add_comment(`Docso.doc)(open_signatureo.expansionenv)|Commentc,true->add_commentcenv|TypExtte,true->letdoc=docsident_mapte.docinList.fold_left(funenvtec->letty=extension_constructorident_maptecinadd_extension_constructortec.L.Extension.Constructor.idtyenv)envte.L.Extension.constructors|>add_cdocste.L.Extension.parentdoc|Exceptione,true->letty=exception_ident_mapeinadd_exceptione.L.Exception.idtyenv|L.Signature.Valuev,true->letty=valueident_mapvinadd_valuev.L.Value.idtyenv(* Skip when compiling *)|Exception_,false->env|TypExt_,false->env|Comment_,false->env|L.Signature.Value_,false->env)es.itemsletopen_type_substitution:Odoc_model.Lang.TypeDecl.t->t->t=funtenv->letopenComponentinletopenOf_LanginletmoduleL=Odoc_model.Langinletty=type_decl(empty())tinadd_typet.L.TypeDecl.idtyenvletopen_module_substitution:Odoc_model.Lang.ModuleSubstitution.t->t->t=funmenv->letopenComponentinletopenOf_LanginletmoduleL=Odoc_model.Langinlet_id=Ident.Of_Identifier.module_m.idinletdoc=docs(empty())m.docinletty=Component.Delayed.put(fun()->Of_Lang.(module_of_module_substitution(* { empty with modules = [ (m.id, id) ] } *)(empty())m))inadd_module(m.id:>Identifier.Path.Module.t)tydocenvletopen_module_type_substitution:Odoc_model.Lang.ModuleTypeSubstitution.t->t->t=funtenv->letopenComponentinletopenOf_LanginletmoduleL=Odoc_model.Langinletty=module_type(empty()){id=t.id;doc=t.doc;expr=Somet.manifest;canonical=None}inadd_module_typet.L.ModuleTypeSubstitution.idtyenvletrecclose_signature:Odoc_model.Lang.Signature.t->t->t=letmoduleL=Odoc_model.Langinfunse->assert(note.linking);List.fold_left(funenvorig->match(orig:L.Signature.item)with|Type(_,t)->removet.L.TypeDecl.idenv|Module(_,t)->removet.L.Module.idenv|ModuleTypet->removet.L.ModuleType.idenv|Class(_,c)->removec.idenv|ClassType(_,c)->removec.idenv|Includei->close_signaturei.expansion.contentenv|Openo->close_signatureo.expansionenv|ModuleSubstitution_|ModuleTypeSubstitution_|TypeSubstitution_->env(* The following are only added when linking *)|Exception_->env|TypExt_->env|Comment_->env|Value_->env)es.itemsletinherit_resolverenv=matchenv.resolverwithSomer->set_resolveremptyr|None->emptyletopen_unitsresolverenv=List.fold_left(funenvm->matchresolver.lookup_unitmwith|Foundunit->(matchunit.contentwith|Modulesg->open_signaturesgenv|_->env)|_->env)envresolver.open_unitsletenv_of_unitt~linkingresolver=letopenOdoc_model.Lang.Compilation_unitinletinitial_env=letm=module_of_unittinletdm=Component.Delayed.put(fun()->m)inletenv={emptywithlinking}inenv|>add_module(t.id:>Identifier.Path.Module.t)dmm.docinset_resolverinitial_envresolver|>open_unitsresolverletopen_pagepageenv=add_docspage.Odoc_model.Lang.Page.contentenvletenv_of_pagepageresolver=letinitial_env=open_pagepageemptyinset_resolverinitial_envresolver|>open_unitsresolverletenv_for_referenceresolver=set_resolveremptyresolver|>open_unitsresolverletenv_for_testing~linking={emptywithlinking}letverify_lookupsenvlookups=letbad_lookup=function|Moduleid->letactually_found=matchlookup_by_ids_moduleidenvwith|Some_->true|None->falseintrue<>actually_found|RootModule(name,res)->(letactual_result=matchenv.resolverwith|None->None|Somer->(matchr.lookup_unitnamewith|Forward_reference->Some`Forward|Not_found->None|Foundu->Some(`Resolvedu.root.digest))inmatch(res,actual_result)with|None,None->false|Some`Forward,Some`Forward->false|Some(`Resolveddigest1),Some(`Resolveddigest2)->digest1<>digest2|_->true)|ModuleTypeid->letactually_found=matchlookup_by_ids_module_typeidenvwith|Some_->true|None->falseintrue<>actually_found|ModuleByName(name,result)->(matchlookup_by_names_modulenameenvwith|Ok(`Module(id',_))->result<>id'|Error`Not_found->false|Error(`Ambiguous(hd,tl))->not(List.exists(fun(`Module(id',_))->result=id')(hd::tl)))|FragmentRoot_i->true(* begin
try
let (i', _) = Env.lookup_fragment_root env in
i' <> i
with _ ->
true
end*)inletresult=not(LookupTypeSet.existsbad_lookuplookups)in(* If we're recording lookups, make sure it looks like we
looked all this stuff up *)(match(result,env.recorder)with|true,Somer->r.lookups<-LookupTypeSet.unionr.lookupslookups|_->());result