12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751(*
* Copyright (c) 2014 Leo White <lpw25@cl.cam.ac.uk>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)openOdoc_modelopenPathsopenNames(* Sets and maps for components *)moduleSSet=Set.Make(String)moduleSMap=structincludeMap.Make(String)letfilter_itemnamepredmap=tryletv=findnamemapinifpredvthenmapelseremovenamemapwithNot_found->mapletmap_itemnamefmap=tryletv=findnamemapinaddname(fv)mapwithNot_found->mapendmoduleLMap=structtype'at='alistSMap.tletempty=SMap.emptyletaddnameitemmap=tryletitems=SMap.findnamemapinSMap.addname(item::items)mapwithNot_found->SMap.addname[item]map(*
let find name pred map =
let items = SMap.find name map in
List.find pred items
*)letfind_namenamemap=letitems=SMap.findnamemapinmatchitemswith|[]->raiseNot_found|x::_->xletmap_findnamepredmap=letreclooppred=function|[]->raiseNot_found|x::l->matchpredxwith|Somex->x|None->looppredlinletitems=SMap.findnamemapinlooppreditemsletfoldfmapacc=SMap.fold(funname->List.fold_right(fname))mapaccletfilter_itemnamepredmap=tryletitems=SMap.findnamemapinletitems=List.filterpreditemsinmatchitemswith|[]->SMap.removenamemap|_->SMap.addnameitemsmapwithNot_found->mapletmap_itemnamefmap=tryletitems=SMap.findnamemapinletitems=List.mapfitemsinSMap.addnameitemsmapwithNot_found->mapend(* Tables for caches *)type('a,'b)tbl={fresh:int->('a,'b)tbl;find:'a->'b;add:'a->'b->unit;}letmake_tbl(typea)(equal:(a->a->bool)option)(hash:(a->int)option)size=letmakecreatefindadd=letrecfreshsize=lett=createsizeinletfindx=findtxinletaddxy=addtxyin{fresh;find;add}infreshsizeinmatchequal,hashwith|None,None->make(Hashtbl.create?random:None)Hashtbl.findHashtbl.add|_->letequal=matchequalwith|None->(=)|Someeq->eqinlethash=matchhashwith|None->Hashtbl.hash|Someh->hinletmoduleHash=structtypet=aletequal=equallethash=hashendinletmoduleTbl=Hashtbl.Make(Hash)inmakeTbl.createTbl.findTbl.add(* Read labels from documentation *)letdocumentation_labelsaccdoc=List.fold_left(funaccelement->matchelement.Odoc_model.Location_.valuewith|`Heading(_,label,nested_text)->letname=Identifier.namelabelin(name,nested_text)::acc|_->acc)accdocletcomment_labelsacccomment=matchcommentwith|`Stop->acc|`Docsdoc->documentation_labelsaccdocmodulerecSig:sigtypetvalset_canonical:t->(Path.Module.t*Reference.Module.t)option->tvalget_canonical:t->(Path.Module.t*Reference.Module.t)optionvalset_hidden:t->bool->tvalget_hidden:t->boolvalfind_parent_module:string->t->Parent.module_valfind_parent_apply:(Path.Module.t->t)->Path.Module.t->t->Parent.module_valfind_parent_module_type:string->t->Parent.module_typevalfind_parent_signature:string->t->Parent.signaturevalfind_parent_class_signature:string->t->Parent.class_signaturevalfind_parent_datatype:string->t->Parent.datatypevalfind_parent_sig_or_type:string->t->Parent.sig_or_typevalfind_parent_subst:t->Parent.substvalfind_parent:string->t->Parent.anyvalfind_module_element:string->t->Element.signature_modulevalfind_apply_element:t->Element.signature_modulevalfind_module_type_element:string->t->Element.signature_module_typevalfind_type_element:string->t->Element.signature_typevalfind_constructor_element:string->t->Element.signature_constructorvalfind_field_element:string->t->Element.signature_fieldvalfind_extension_element:string->t->Element.signature_extensionvalfind_exception_element:string->t->Element.signature_exceptionvalfind_value_element:string->t->Element.signature_valuevalfind_class_element:string->t->Element.signature_classvalfind_class_type_element:string->t->Element.signature_class_typevalfind_label_element:string->t->Element.signature_labelvalfind_element:string->t->Element.signaturevalfind_section_title:string->t->Odoc_model.Comment.link_contentvallookup_module:string->t->tvallookup_argument:int->t->tvallookup_apply:(Path.Module.t->t)->Path.Module.t->t->tvallookup_module_type:string->t->tvallookup_class_type:string->t->ClassSig.tvallookup_datatype:string->t->Datatype.ttypesignaturevalempty:signaturevaladd_module:string->t->signature->signaturevaladd_module_type:string->t->signature->signaturevaladd_datatype:string->Datatype.t->signature->signaturevaladd_class:string->ClassSig.t->signature->signaturevaladd_class_type:string->ClassSig.t->signature->signaturevaladd_element:string->Element.signature->signature->signaturevaladd_documentation:Odoc_model.Comment.docs->signature->signaturevaladd_comment:Odoc_model.Comment.docs_or_stop->signature->signaturevalinclude_:t->signature->signaturevalmodules:t->(ModuleName.t*t)listvalmodule_types:t->(ModuleTypeName.t*t)listvalpath:(Path.ModuleType.t->t)->Path.ModuleType.t->tvalalias:(Path.Module.t->t)->Path.Module.t->tvalsignature:('b->signature)->'b->tvalfunctor_:(Root.t->Root.t->bool)option->(Root.t->int)option->Identifier.Module.t->t->t->tvalgenerative:t->tvalabstract:tvalunresolved:tvalwith_module:Fragment.Module.t->t->t->tvalwith_module_subst:Fragment.Module.t->t->tvalwith_type_subst:Fragment.Type.t->t->tend=structtypeterm=|PathofPath.ModuleType.t*bool|AliasofPath.Module.t*bool|WithModuleofexpr*Fragment.Module.t*t|WithModuleSubstofexpr*Fragment.Module.t|WithTypeSubstofexpr*Fragment.Type.tandexpr={term:term;expansion:tLazy.t;}andfunctor_={id:Identifier.Module.t;arg:t;res:t;cache:(Path.Module.t,t)tbl;}andsignature={modules:tSMap.t;module_types:tSMap.t;class_signatures:ClassSig.tSMap.t;types:Element.signature_typeSMap.t;parents:Parent.anyLMap.t;elements:Element.signatureLMap.t;section_titles:Odoc_model.Comment.link_contentSMap.t;}andbody=|Exprofexpr|SigofsignatureLazy.t|Functoroffunctor_|Generativeoft|Abstract|Unresolvedandt={canonical:(Path.Module.t*Reference.Module.t)option;hidden:bool;body:body}letset_canonicaltcanonical={twithcanonical}letset_hiddenthidden={twithhidden}letget_canonicalt=t.canonicalletget_hiddent=t.hiddenletmkExprex={canonical=None;body=Exprex;hidden=false}letmkSigsg={canonical=None;body=Sigsg;hidden=false}letmkFunctorfn={canonical=None;body=Functorfn;hidden=false}letgenerativet={canonical=None;body=Generativet;hidden=false}letabstract={canonical=None;body=Abstract;hidden=false}letunresolved={canonical=None;body=Unresolved;hidden=false}letreclift_findfxt=matcht.bodywith|Exprexpr->beginmatchexpr.termwith|Path(_,true)|Alias(_,true)->raiseNot_found|Alias(_,false)->beginlett=Lazy.forceexpr.expansioninmatcht.hiddenwith|false->raiseNot_found|true->lift_findfxtend|_->lift_findfx(Lazy.forceexpr.expansion)end|Sigsg->fx(Lazy.forcesg)|Functorfn->lift_findfxfn.res|Generativet->lift_findfxt|Abstract->raiseNot_found|Unresolved->raiseNot_foundletfind_parent_modulenamet=letfindnamesg=`Module(SMap.findnamesg.modules)inlift_findfindnametletfind_parent_module_typenamet=letfindnamesg=`ModuleType(SMap.findnamesg.module_types)inlift_findfindnametletfind_parent_signaturenamet=letfindnamesg=LMap.map_findname(function|`Module_asx->Somex|`ModuleType_asx->Somex|_->None)sg.parentsinlift_findfindnametletfind_parent_class_signaturenamet=letfindnamesg=LMap.map_findname(function|`Class_asx->Somex|`ClassType_asx->Somex|_->None)sg.parentsinlift_findfindnametletfind_parent_datatypenamet=letfindnamesg=LMap.map_findname(function|`Datatype_asx->Somex|_->None)sg.parentsinlift_findfindnametletfind_parent_sig_or_typenamet=letfindnamesg=LMap.map_findname(function|`Module_asx->Somex|`ModuleType_asx->Somex|`Datatype_asx->Somex|_->None)sg.parentsinlift_findfindnametletrecfind_parent_subst:t->Parent.subst=funt->matcht.bodywith|Exprexpr->beginmatchexpr.termwith|Path(p,true)->Substp|Alias(p,true)->SubstAliasp|Alias(p,false)->beginlett'=Lazy.forceexpr.expansioninmatcht'.hiddenwith|false->SubstAliasp|true->find_parent_substt'end|_->find_parent_subst(Lazy.forceexpr.expansion)end|Sig_->raiseNot_found|Functorfn->find_parent_substfn.res|Generativet->find_parent_substt|Abstract->raiseNot_found|Unresolved->raiseNot_foundletfind_parentnamet=letfindnamesg=LMap.find_namenamesg.parentsinlift_findfindnametletfind_module_elementnamet=letfindnamesg=lett=SMap.findnamesg.modulesin`Module{Element.canonical=t.canonical;hidden=t.hidden;}inlift_findfindnametletrecfind_apply_elementt=matcht.bodywith|Exprexpr->beginmatchexpr.termwith|Path(_,true)|Alias(_,true)->raiseNot_found|Alias(_,false)->beginlett=Lazy.forceexpr.expansioninmatcht.hiddenwith|false->raiseNot_found|true->find_apply_elementtend|_->find_apply_element(Lazy.forceexpr.expansion)end|Sig_->raiseNot_found|Functor_->`Module{Element.canonical=None;hidden=false}|Generative_->raiseNot_found|Abstract->raiseNot_found|Unresolved->raiseNot_foundletfind_module_type_elementnamet=letfindnamesg=ifSMap.memnamesg.module_typesthen`ModuleTypeelseraiseNot_foundinlift_findfindnametletfind_type_elementnamet=letfindnamesg=SMap.findnamesg.typesinlift_findfindnametletfind_constructor_elementnamet=letfindnamesg=LMap.map_findname(function|`Constructor_asx->Somex|`Extensionasx->Somex|`Exceptionasx->Somex|_->None)sg.elementsinlift_findfindnametletfind_field_elementnamet=letfindnamesg=LMap.map_findname(function|`Field_asx->Somex|_->None)sg.elementsinlift_findfindnametletfind_extension_elementnamet=letfindnamesg=LMap.map_findname(function|`Extensionasx->Somex|`Exceptionasx->Somex|_->None)sg.elementsinlift_findfindnametletfind_exception_elementnamet=letfindnamesg=LMap.map_findname(function|`Exceptionasx->Somex|_->None)sg.elementsinlift_findfindnametletfind_value_elementnamet=letfindnamesg=LMap.map_findname(function|`Valueasx->Somex|_->None)sg.elementsinlift_findfindnametletfind_class_elementnamet=letfindnamesg=matchSMap.findnamesg.typeswith|`Classasx->x|_->raiseNot_foundinlift_findfindnametletfind_class_type_elementnamet=letfindnamesg=matchSMap.findnamesg.typeswith|`Classasx->x|`ClassTypeasx->x|_->raiseNot_foundinlift_findfindnametletfind_label_elementnamet=letfindnamesg=LMap.map_findname(function|`Label_asx->Somex|_->None)sg.elementsinlift_findfindnametletfind_section_titlenamet=letfindnamesg=SMap.findnamesg.section_titlesinlift_findfindnametletfind_elementnamet=letfindnamesg=LMap.find_namenamesg.elementsinlift_findfindnametletreclookup_modulenamet=matcht.bodywith|Exprexpr->lookup_modulename(Lazy.forceexpr.expansion)|Sigsg->begintrySMap.findname(Lazy.forcesg).moduleswithNot_found->unresolvedend|Functorfn->lookup_modulenamefn.res|Generativet->lookup_modulenamet|Abstract->unresolved|Unresolved->unresolvedletreclookup_argumentpost=matcht.bodywith|Exprexpr->lookup_argumentpos(Lazy.forceexpr.expansion)|Sig_->unresolved|Functorfn->ifpos=1thenfn.argelselookup_argument(pos-1)fn.res|Generativet->ifpos=1thenunresolvedelselookup_argument(pos-1)t|Abstract->unresolved|Unresolved->unresolvedletreclookup_module_typenamet=matcht.bodywith|Exprexpr->lookup_module_typename(Lazy.forceexpr.expansion)|Sigsg->begintrySMap.findname(Lazy.forcesg).module_typeswithNot_found->unresolvedend|Functorfn->lookup_module_typenamefn.res|Generativet->lookup_module_typenamet|Abstract->unresolved|Unresolved->unresolvedletreclookup_class_typenamet=matcht.bodywith|Exprexpr->lookup_class_typename(Lazy.forceexpr.expansion)|Sigsg->begintrySMap.findname(Lazy.forcesg).class_signatureswithNot_found->ClassSig.unresolvedend|Functorfn->lookup_class_typenamefn.res|Generativet->lookup_class_typenamet|Abstract->ClassSig.unresolved|Unresolved->ClassSig.unresolvedletreclookup_datatypenamet=matcht.bodywith|Exprexpr->lookup_datatypename(Lazy.forceexpr.expansion)|Sigsg->begintryLMap.map_findname(function|`Datatypet->Somet|_->None)(Lazy.forcesg).parentswithNot_found->Datatype.unresolvedend|Functorfn->lookup_datatypenamefn.res|Generativet->lookup_datatypenamet|Abstract->Datatype.unresolved|Unresolved->Datatype.unresolvedletempty={modules=SMap.empty;module_types=SMap.empty;class_signatures=SMap.empty;types=SMap.empty;parents=SMap.empty;elements=SMap.empty;section_titles=SMap.empty;}letadd_modulenamemdsg=letmodules=SMap.addnamemdsg.modulesinletparents=LMap.addname(`Modulemd)sg.parentsinletelements=letmd=`ModuleElement.{canonical=md.canonical;hidden=md.hidden}inLMap.addnamemdsg.elementsin{sgwithmodules;parents;elements}letadd_module_typenamemtysg=letmodule_types=SMap.addnamemtysg.module_typesinletparents=LMap.addname(`ModuleTypemty)sg.parentsinletelements=LMap.addname`ModuleTypesg.elementsin{sgwithmodule_types;parents;elements}letadd_datatypenamedeclsg=lettypes=SMap.addname`Typesg.typesinletparents=LMap.addname(`Datatypedecl)sg.parentsinletelements=letadd_elementname(elem:Element.datatype)acc=let(`Constructor_|`Field_|`Label_aselem)=eleminLMap.addnameelemaccinLMap.foldadd_element(Datatype.elementsdecl)sg.elementsinletelements=LMap.addname`Typeelementsin{sgwithtypes;parents;elements}letadd_classnameclsg=lettypes=SMap.addname`Classsg.typesinletclass_signatures=SMap.addnameclsg.class_signaturesinletparents=LMap.addname(`Classcl)sg.parentsinletelements=LMap.addname`Classsg.elementsin{sgwithtypes;class_signatures;parents;elements}letadd_class_typenamecltysg=lettypes=SMap.addname`ClassTypesg.typesinletclass_signatures=SMap.addnamecltysg.class_signaturesinletparents=LMap.addname(`ClassTypeclty)sg.parentsinletelements=LMap.addname`ClassTypesg.elementsin{sgwithtypes;class_signatures;parents;elements}letadd_elementnameelementsg=letelements=LMap.addnameelementsg.elementsin{sgwithelements}letadd_documentationdocsg=letlabels=documentation_labels[]docinletadd_labelsg(label,txt)=letsg=add_elementlabel(`LabelNone)sginletsection_titles=SMap.addlabeltxtsg.section_titlesin{sgwithsection_titles}inList.fold_leftadd_labelsglabelsletadd_commentcommentsg=letlabels=comment_labels[]commentinletadd_labelsg(label,txt)=letsg=add_elementlabel(`LabelNone)sginletsection_titles=SMap.addlabeltxtsg.section_titlesin{sgwithsection_titles}inList.fold_leftadd_labelsglabelsletstrengthen_submodulepathexpansionnamet=matcht.bodywith|Unresolved->t|Expr{term=Alias(p,b);_}whenb||not(Path.is_hidden(p:>Path.t))->t|_->letpath=Path.module_pathnameinletterm=Alias(path,false)inletexpansion=lazy(lookup_module(ModuleName.to_stringname)(Lazy.forceexpansion))in{twithbody=Expr{term;expansion}}letrecstrengthen_modulepathexpansiont=ifPath.is_hidden(path:Path.Module.t:>Path.t)thentelsematcht.bodywith|Expr{term;expansion=ex}->beginletex'=lazy(strengthen_modulepathexpansion(Lazy.forceex))in{twithbody=Expr{term;expansion=ex'}}end|Sigsg->letsg=lazy(letsg=Lazy.forcesginletmodules=SMap.mapi(funn->strengthen_submodulepathexpansion(ModuleName.of_stringn))sg.modulesin{sgwithmodules})in{twithbody=Sigsg}|Functor_|Generative_|Abstract|Unresolved->tletrecinclude_tsg=matcht.bodywith|Exprexpr->include_(Lazy.forceexpr.expansion)sg|Sigincl->letincl=Lazy.forceinclinletmodules=SMap.foldSMap.addincl.modulessg.modulesinletmodule_types=SMap.foldSMap.addincl.module_typessg.module_typesinletclass_signatures=SMap.foldSMap.addincl.class_signaturessg.class_signaturesinlettypes=SMap.foldSMap.addincl.typessg.typesinletparents=LMap.foldLMap.addincl.parentssg.parentsinletelements=LMap.foldLMap.addincl.elementssg.elementsinletsection_titles=LMap.foldLMap.addincl.section_titlessg.section_titlesin{modules;module_types;class_signatures;types;parents;elements;section_titles}|Functor_|Generative_|Abstract|Unresolved->sgletrecmodulest=matcht.bodywith|Exprexpr->modules(Lazy.forceexpr.expansion)|Sigsg->letsg=Lazy.forcesginSMap.bindingssg.modules|>List.map(fun(x,y)->ModuleName.of_stringx,y)|Functor_|Generative_|Abstract|Unresolved->[]letrecmodule_typest=matcht.bodywith|Exprexpr->module_types(Lazy.forceexpr.expansion)|Sigsg->letsg=Lazy.forcesginSMap.bindingssg.module_types|>List.map(fun(x,y)->ModuleTypeName.of_stringx,y)|Functor_|Generative_|Abstract|Unresolved->[]letpathlookupp=letterm=Path(p,false)inletexpansion=lazy(lookupp)inmkExpr{term;expansion}letaliaslookupp=letterm=Alias(p,false)inletexpansion=lazy(letex=lookuppinstrengthen_modulep(Lazy.from_valex)ex)inmkExpr{term;expansion}letsignaturefx=mkSig(lazy(fx))letfunctor_equalhashidargres=letequal=matchequalwith|None->None|Some_equal->SomePath.Module.equalinlethash=matchhashwith|None->None|Some_hash->SomePath.Module.hashinletcache=make_tblequalhash3inmkFunctor{id;arg;res;cache}letreplace_modulenametsg=letmodules=SMap.map_itemname(fun_->t)sg.modulesinletparents=LMap.map_itemname(function|`Module_->`Modulet|item->item)sg.parentsin{sgwithmodules;parents}letmap_modulenamefsg=letmodules=SMap.map_itemnamefsg.modulesinletparents=LMap.map_itemname(function|`Modulet->`Module(ft)|item->item)sg.parentsin{sgwithmodules;parents}letremove_modulenamesg=letmodules=SMap.removenamesg.modulesinletparents=LMap.filter_itemname(function|`Module_->true|_->false)sg.parentsinletelements=LMap.filter_itemname(function`Module_->false|_->true)sg.elementsin{sgwithmodules;parents;elements}letremove_datatypenamesg=lettypes=SMap.filter_itemname((<>)`Type)sg.typesinletparents=LMap.filter_itemname(function|`Datatype_->true|_->false)sg.parentsinletelements=LMap.filter_itemname((<>)`Type)sg.elementsin{sgwithtypes;parents;elements}letrecwith_modulefrageqt=matcht.bodywith|Exprexpr->letterm=WithModule(expr,frag,eq)inletexpansion=lazy(with_modulefrageq(Lazy.forceexpr.expansion))inmkExpr{term;expansion}|Sigsg->letsg=lazy(letsg=Lazy.forcesginletname,frag=Fragment.Module.splitfraginmatchfragwith|None->replace_modulenameeqsg|Somefrag->map_modulename(with_modulefrageq)sg)inmkSigsg|Functor_|Generative_|Abstract|Unresolved->tletrecwith_module_substfragt=matcht.bodywith|Exprexpr->letterm=WithModuleSubst(expr,frag)inletexpansion=lazy(with_module_substfrag(Lazy.forceexpr.expansion))inmkExpr{term;expansion}|Sigsg->letsg=lazy(letsg=Lazy.forcesginletname,frag=Fragment.Module.splitfraginmatchfragwith|None->remove_modulenamesg|Somefrag->map_modulename(with_module_substfrag)sg)inmkSigsg|Functor_|Generative_|Abstract|Unresolved->tletrecwith_type_substfragt=matcht.bodywith|Exprexpr->letterm=WithTypeSubst(expr,frag)inletexpansion=lazy(with_type_substfrag(Lazy.forceexpr.expansion))inmkExpr{term;expansion}|Sigsg->letsg=lazy(letsg=Lazy.forcesginletname,frag=Fragment.Type.splitfraginmatchfragwith|None->remove_datatypenamesg|Somefrag->map_modulename(with_type_substfrag)sg)inmkSigsg|Functor_|Generative_|Abstract|Unresolved->tletmodule_type_substitutionpathexpansiont=matcht.bodywith|Abstract->letterm=Path(path,true)inmkExpr{term;expansion}|_->tletrecmodule_substitutionpathexpansiont=matcht.bodywith|Expr_->t|Sigsg->letsg=lazy(letsg=Lazy.forcesginletmodules=SMap.mapi(funnamebody->letpath=Path.module_path(ModuleName.of_stringname)inletexpansion=lazy(lookup_modulename(Lazy.forceexpansion))inmodule_substitutionpathexpansionbody)sg.modulesinletmodule_types=SMap.mapi(funnamebody->letpath=Path.module_typepath(ModuleTypeName.of_stringname)inletexpansion=lazy(lookup_module_typename(Lazy.forceexpansion))inmodule_type_substitutionpathexpansionbody)sg.module_typesin{sgwithmodules;module_types})inmkSigsg|Functorfn->letres=module_substitutionpathexpansionfn.resinletcache=fn.cache.fresh3inmkFunctor{fnwithres;cache}|Generativebody->letbody=module_substitutionpathexpansionbodyingenerativebody|Abstract->letterm=Alias(path,true)inmkExpr{term;expansion}|Unresolved->tletrecreduce_signature_identidpath=function|`Root_->None|`Module(p,name)->beginmatchreduce_signature_identidpathpwith|Somep->Some(Path.module_pname)|None->Noneend|`Argument_asid'->ifid=id'thenSomepathelseNone|`ModuleType_->Noneandreduce_module_identidpath(m:Identifier.Module.t)=matchmwith|`Root_->None|`Module(p,name)->beginmatchreduce_signature_identidpathpwith|Somep->Some(Path.module_pname)|None->Noneend|`Argument_asid'->ifid=id'thenSomepathelseNoneandreduce_resolved_module_pathin_argidpath(p:Path.Resolved.Module.t)=matchpwith|`Identifierid'->ifin_argthenreduce_module_identidpathid'elseNone|`Subst(_,p)->reduce_resolved_module_pathin_argidpathp|`SubstAlias(_,p)->reduce_resolved_module_pathin_argidpathp|`Hiddenp->reduce_resolved_module_pathin_argidpathp|`Module(p,name)->beginmatchreduce_resolved_module_pathin_argidpathpwith|Somep->Some(Path.module_pname)|None->Noneend|`Canonical(p,_)->reduce_resolved_module_pathin_argidpathp|`Apply(p,arg)->beginletrp=reduce_resolved_module_pathin_argidpathpinletrarg=reduce_module_pathtrueidpatharginmatchrp,rargwith|None,None->None|None,Somearg->Some(`Resolved(`Apply(p,arg)))|Somep,None->Some(Path.applyparg)|Somep,Somearg->Some(Path.applyparg)endandreduce_resolved_module_type_pathidpath(p:Path.Resolved.ModuleType.t)=matchpwith|`Identifier_->None|`ModuleType(p,name)->beginmatchreduce_resolved_module_pathfalseidpathpwith|Somep->Some(Path.module_typepname)|None->Noneendandreduce_module_pathin_argidpath(p:Path.Module.t)=matchpwith|`Resolvedr->reduce_resolved_module_pathin_argidpathr|`Root_->None|`Forward_->None|`Dot(p,name)->beginmatchreduce_module_pathin_argidpathpwith|Somep->Some(`Dot(p,name))|None->Noneend|`Apply(p,arg)->beginletrp=reduce_module_pathin_argidpathpinletrarg=reduce_module_pathtrueidpatharginmatchrp,rargwith|None,None->None|None,Somearg->Some(`Apply(p,arg))|Somep,None->Some(`Apply(p,arg))|Somep,Somearg->Some(`Apply(p,arg))endandreduce_module_type_pathidpath(m:Path.ModuleType.t)=matchmwith|`Resolvedr->reduce_resolved_module_type_pathidpathr|`Dot(p,name)->beginmatchreduce_module_pathfalseidpathpwith|Somep->Some(`Dot(p,name))|None->Noneendletrecsubst_signature_identidlookuppath(s:Identifier.Signature.t)=matchswith|`Root_->None|`Module(p,name)->beginmatchsubst_signature_identidlookuppathpwith|Some(p,t)->letp=Path.module_pnameinlett=lazy(lookup_module(ModuleName.to_stringname)(Lazy.forcet))inSome(p,t)|None->Noneend|`Argument_asid'->ifid=id'thenSome(path,lazy(lookuppath))elseNone|`ModuleType_->Noneandsubst_module_identidlookuppath(id':Identifier.Module.t)=ifid=id'thenSome(path,lazy(lookuppath))elsematchid'with|(`Root_:Identifier.Module.t)->None|`Module(p,name)->beginmatchsubst_signature_identidlookuppathpwith|Some(p,t)->letp=Path.module_pnameinlett=lazy(lookup_module(ModuleName.to_stringname)(Lazy.forcet))inSome(p,t)|None->Noneend|`Argument_->Noneandsubst_module_type_identidlookup(path:Path.Module.t)(id':Identifier.ModuleType.t)=matchid'with|`ModuleType(p,name)->beginmatchsubst_signature_identidlookuppathpwith|Some(p,t)->letp=Path.module_typepnameinlett=lazy(lookup_module_type(ModuleTypeName.to_stringname)(Lazy.forcet))inSome(p,t)|None->Noneendandsubst_resolved_module_pathidlookuppath(p:Path.Resolved.Module.t)=matchpwith|`Identifierid'->subst_module_identidlookuppathid'|`Subst(_,p)->subst_resolved_module_pathidlookuppathp|`SubstAlias(sub,_)->subst_resolved_module_pathidlookuppathsub|`Hiddenp->subst_resolved_module_pathidlookuppathp|`Module(p,name)->beginmatchsubst_resolved_module_pathidlookuppathpwith|Some(p,t)->letp=Path.module_pnameinlett=lazy(lookup_module(ModuleName.to_stringname)(Lazy.forcet))inSome(p,t)|None->Noneend|`Canonical(p,_)->subst_resolved_module_pathidlookuppathp|`Apply(p,arg)->beginmatchsubst_resolved_module_pathidlookuppathpwith|Some(p,t)->letp=Path.applyparginlett=lazy(lookup_applylookuparg(Lazy.forcet))inSome(p,t)|None->Noneendandsubst_resolved_module_type_pathidlookup(path:Path.Module.t)(p:Path.Resolved.ModuleType.t)=matchpwith|`Identifierid'->subst_module_type_identidlookuppathid'|`ModuleType(p,name)->beginmatchsubst_resolved_module_pathidlookuppathpwith|Some(p,t)->letp=Path.module_typepnameinlett=lazy(lookup_module_type(ModuleTypeName.to_stringname)(Lazy.forcet))inSome(p,t)|None->Noneendandsubst_module_pathidlookuppath(p:Path.Module.t)=matchpwith|`Resolvedr->subst_resolved_module_pathidlookuppathr|`Root_->None|`Forward_->None|`Dot(p,name)->beginmatchsubst_module_pathidlookuppathpwith|Some(p,t)->letp=`Dot(p,name)inlett=lazy(lookup_modulename(Lazy.forcet))inSome(p,t)|None->Noneend|`Apply(p,arg)->beginmatchsubst_module_pathidlookuppathpwith|Some(p,t)->letp=`Apply(p,arg)inlett=lazy(lookup_applylookuparg(Lazy.forcet))inSome(p,t)|None->Noneendandsubst_module_type_pathidlookup(path:Path.Module.t)(p:Path.ModuleType.t)=matchpwith|`Resolvedr->subst_resolved_module_type_pathidlookuppathr|`Dot(p,name)->beginmatchsubst_module_pathidlookuppathpwith|Some(p,t)->letp=`Dot(p,name)inlett=lazy(lookup_module_typename(Lazy.forcet))inSome(p,t)|None->Noneendandsubst_expridlookuppathexpr=matchexpr.termwith|Path(p,sub)->beginletp=matchreduce_module_type_pathidpathpwith|None->p|Somep->pinmatchsubst_module_type_pathidlookuppathpwith|None->letterm=Path(p,sub)inletexpansion=lazy(substidlookuppath(Lazy.forceexpr.expansion))in{term;expansion}|Some(p,t)->letterm=Path(p,sub)inletexpansion=lazy(module_type_substitutionpt(substidlookuppath(Lazy.forceexpr.expansion)))in{term;expansion}end|Alias(p,sub)->beginletp=matchreduce_module_pathfalseidpathpwith|None->p|Somep->pinmatchsubst_module_pathidlookuppathpwith|None->letterm=Alias(p,sub)inletexpansion=lazy(substidlookuppath(Lazy.forceexpr.expansion))in{term;expansion}|Some(p,t)->letterm=Alias(p,sub)inletexpansion=lazy(module_substitutionpt(substidlookuppath(Lazy.forceexpr.expansion)))in{term;expansion}end|WithModule(body,frag,eq)->letbody=subst_expridlookuppathbodyinleteq=substidlookuppatheqinletterm=WithModule(body,frag,eq)inletexpansion=lazy(with_modulefrageq(Lazy.forcebody.expansion))in{term;expansion}|WithModuleSubst(body,frag)->letbody=subst_expridlookuppathbodyinletterm=WithModuleSubst(body,frag)inletexpansion=lazy(with_module_substfrag(Lazy.forcebody.expansion))in{term;expansion}|WithTypeSubst(body,frag)->letbody=subst_expridlookuppathbodyinletterm=WithTypeSubst(body,frag)inletexpansion=lazy(with_type_substfrag(Lazy.forcebody.expansion))in{term;expansion}andsubstidlookuppatht=matcht.bodywith|Exprexpr->mkExpr(subst_expridlookuppathexpr)|Sigsg->letsg=lazy(letsg=Lazy.forcesginletmodules=SMap.map(substidlookuppath)sg.modulesinletmodule_types=SMap.map(substidlookuppath)sg.module_typesin{sgwithmodules;module_types})inmkSigsg|Functorfn->letarg=substidlookuppathfn.arginletres=substidlookuppathfn.resinletcache=fn.cache.fresh3inmkFunctor{id=fn.id;arg;res;cache}|Generativet->generative(substidlookuppatht)|Abstract->abstract|Unresolved->unresolvedandlookup_apply:(Paths_types.Path.module_->t)->Paths_types.Path.module_->t->t=funlookupargt->matcht.bodywith|Exprexpr->lookup_applylookuparg(Lazy.forceexpr.expansion)|Sig_->unresolved|Functorfn->begintryfn.cache.findargwithNot_found->letres=substfn.idlookupargfn.resinfn.cache.addargres;resend|Generative_->unresolved|Abstract->unresolved|Unresolved->unresolvedletrecfind_parent_apply:(Paths_types.Path.module_->t)->Paths_types.Path.module_->t->Parent.module_=funlookupargt->matcht.bodywith|Exprexpr->beginmatchexpr.termwith|Path(_,true)|Alias(_,true)->raiseNot_found|Alias(_,false)->beginlett=Lazy.forceexpr.expansioninmatcht.hiddenwith|false->raiseNot_found|true->find_parent_applylookupargtend|_->find_parent_applylookuparg(Lazy.forceexpr.expansion)end|Sig_->raiseNot_found|Functorfn->begintry`Module(fn.cache.findarg)withNot_found->letres=substfn.idlookupargfn.resinfn.cache.addargres;`Moduleresend|Generative_->raiseNot_found|Abstract->raiseNot_found|Unresolved->raiseNot_foundendandDatatype:sigtypetvalfind_constructor_element:string->t->Element.datatype_constructorvalfind_field_element:string->t->Element.datatype_fieldvalfind_label_element:string->t->Element.datatype_labelvalfind_element:string->t->Element.datatypevaladd_documentation:Odoc_model.Comment.docs->t->tvalabstract:tvalvariant:string->stringlist->tvalrecord:string->stringlist->tvalextensible:tvalunresolved:tvalelements:t->Element.datatypeLMap.tend=structtypevariant={type_name:string;constructors:SSet.t;labels:SSet.t;}typerecord={type_name:string;fields:SSet.t;labels:SSet.t;}typet=|Variantofvariant|Recordofrecord|Unresolvedletfind_constructor_elementname=function|Variantv->ifSSet.memnamev.constructorsthen`Constructorv.type_nameelseraiseNot_found|_->raiseNot_foundletfind_field_elementname=function|Recordr->ifSSet.memnamer.fieldsthen`Fieldr.type_nameelseraiseNot_found|_->raiseNot_foundletfind_label_elementname=function|Variantv->ifSSet.memnamev.labelsthen`Label(Somev.type_name)elseraiseNot_found|Recordr->ifSSet.memnamer.labelsthen`Label(Somer.type_name)elseraiseNot_found|_->raiseNot_foundletfind_elementname=function|Variantv->ifSSet.memnamev.constructorsthen`Constructorv.type_nameelseifSSet.memnamev.labelsthen`Label(Somev.type_name)elseraiseNot_found|Recordr->ifSSet.memnamer.fieldsthen`Fieldr.type_nameelseifSSet.memnamer.labelsthen`Label(Somer.type_name)elseraiseNot_found|_->raiseNot_foundletadd_documentationdoc=function|Variantv->letlbls=documentation_labels[]docinletlabels=List.fold_right(fun(lbl,_)map->SSet.addlblmap)lblsv.labelsinVariant{vwithlabels}|Recordr->letlbls=documentation_labels[]docinletlabels=List.fold_right(fun(lbl,_)map->SSet.addlblmap)lblsr.labelsinRecord{rwithlabels}|Unresolved->Unresolvedletabstract=Unresolvedletvarianttype_nameconstructors=letconstructors=List.fold_rightSSet.addconstructorsSSet.emptyinletlabels=SSet.emptyinletvariant={type_name;constructors;labels}inVariantvariantletrecordtype_namefields=letfields=List.fold_rightSSet.addfieldsSSet.emptyinletlabels=SSet.emptyinletrecord={type_name;fields;labels}inRecordrecordletextensible=Unresolvedletunresolved=Unresolvedletelements=function|Variantv->letelements=SSet.fold(funnameacc->LMap.addname(`Constructorv.type_name)acc)v.constructorsLMap.emptyinletelements=SSet.fold(funnameacc->LMap.addname(`Label(Somev.type_name))acc)v.labelselementsinelements|Recordr->letelements=SSet.fold(funnameacc->LMap.addname(`Fieldr.type_name)acc)r.fieldsLMap.emptyinletelements=SSet.fold(funnameacc->LMap.addname(`Label(Somer.type_name))acc)r.labelselementsinelements|Unresolved->LMap.emptyendandClassSig:sigtypetvalfind_method_element:string->t->Element.class_signature_methodvalfind_instance_variable_element:string->t->Element.class_signature_instance_variablevalfind_label_element:string->t->Element.class_signature_labelvalfind_element:string->t->Element.class_signaturetypesignaturevalempty:signaturevaladd_element:string->Element.class_signature->signature->signaturevaladd_documentation:Odoc_model.Comment.docs->signature->signaturevaladd_comment:Odoc_model.Comment.docs_or_stop->signature->signaturevalinherit_:t->signature->signaturevalconstr:(Path.ClassType.t->t)->Path.ClassType.t->tvalsignature:('b->signature)->'b->tvalunresolved:tend=structtypesignature=Element.class_signatureLMap.ttypedesc=|Sigofsignature|Unresolvedtypet=descLazy.tletfind_method_elementnamet=letdesc=Lazy.forcetinmatchdescwith|Sigcsig->LMap.map_findname(function|`Methodasx->Somex|_->None)csig|Unresolved->raiseNot_foundletfind_instance_variable_elementnamet=letdesc=Lazy.forcetinmatchdescwith|Sigcsig->LMap.map_findname(function|`InstanceVariableasx->Somex|_->None)csig|Unresolved->raiseNot_foundletfind_label_elementnamet=letdesc=Lazy.forcetinmatchdescwith|Sigcsig->LMap.map_findname(function|`Label_asx->Somex|_->None)csig|Unresolved->raiseNot_foundletfind_elementnamet=letdesc=Lazy.forcetinmatchdescwith|Sigcsig->LMap.find_namenamecsig|Unresolved->raiseNot_foundletempty=LMap.emptyletadd_elementnameelementcsig=LMap.addnameelementcsigletadd_documentationdoccsig=letlabels=documentation_labels[]docinletadd_labelcsig(label,_)=add_elementlabel(`LabelNone)csiginList.fold_leftadd_labelcsiglabelsletadd_commentcommentsg=letlabels=comment_labels[]commentinletadd_labelsg(label,_)=add_elementlabel(`LabelNone)sginList.fold_leftadd_labelsglabelsletinherit_tcsig=letdesc=Lazy.forcetinmatchdescwith|Siginhr->LMap.foldLMap.addinhrcsig|Unresolved->csigletconstrfx=lazy(Lazy.force(fx))letsignaturefx=lazy(Sig(fx))letunresolved=lazyUnresolvedendandPage:sigtypetvalfind_label_element:string->t->Element.page_labelvalfind_section_title:string->t->Odoc_model.Comment.link_contentvalof_doc:Odoc_model.Comment.docs->tend=structtypet={labels:Element.page_labelLMap.t;section_titles:Odoc_model.Comment.link_contentSMap.t;}letfind_label_elementnamet=LMap.find_namenamet.labelsletfind_section_titlenamet=SMap.findnamet.section_titlesletof_docdoc=letlabels=documentation_labels[]docinletadd_labelt(label,txt)=letlabels=LMap.addlabel(`LabelNone)t.labelsinletsection_titles=SMap.addlabeltxtt.section_titlesin{labels;section_titles}inList.fold_leftadd_label{labels=LMap.empty;section_titles=SMap.empty}labelsendandParent:sigtypet=[|`ModuleofSig.t|`ModuleTypeofSig.t|`DatatypeofDatatype.t|`ClassofClassSig.t|`ClassTypeofClassSig.t]typesignature=[|`ModuleofSig.t|`ModuleTypeofSig.t]typeclass_signature=[|`ClassofClassSig.t|`ClassTypeofClassSig.t]typedatatype=[|`DatatypeofDatatype.t]typemodule_=[|`ModuleofSig.t]typemodule_type=[|`ModuleTypeofSig.t]typesig_or_type=[|`ModuleofSig.t|`ModuleTypeofSig.t|`DatatypeofDatatype.t]typeany=ttypesubst=|SubstofPath.ModuleType.t|SubstAliasofPath.Module.tend=ParentandElement:sigtypemod_t={canonical:(Path.Module.t*Reference.Module.t)option;hidden:bool}types_module=[|`Moduleofmod_t]types_module_type=[|`ModuleType]types_type=[|`Type]types_constructor=[|`Constructorofstring]types_field=[|`Fieldofstring]types_extension=[|`Extension]types_exception=[|`Exception]types_value=[|`Value]types_class=[|`Class]types_class_type=[|`ClassType]types_method=[|`Method]types_instance_variable=[|`InstanceVariable]types_label=[|`Labelofstringoption]typet=[|s_module|s_module_type|s_type|s_constructor|s_field|s_extension|s_exception|s_value|s_class|s_class_type|s_method|s_instance_variable|s_label]typesignature_module=s_moduletypesignature_module_type=s_module_typetypesignature_type=[s_type|s_class|s_class_type]typesignature_constructor=[s_constructor|s_extension|s_exception]typesignature_field=s_fieldtypesignature_extension=[s_extension|s_exception]typesignature_exception=s_exceptiontypesignature_value=s_valuetypesignature_class=s_classtypesignature_class_type=[s_class|s_class_type]typesignature_label=s_labeltypesignature=[s_module|s_module_type|s_type|s_constructor|s_field|s_extension|s_exception|s_value|s_class|s_class_type|s_label]typedatatype_constructor=s_constructortypedatatype_field=s_fieldtypedatatype_label=s_labeltypedatatype=[s_constructor|s_field|s_label]typeclass_signature_method=s_methodtypeclass_signature_instance_variable=s_instance_variabletypeclass_signature_label=s_labeltypeclass_signature=[s_method|s_instance_variable|s_label]typepage_label=s_labelend=Element