1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635openOdoc_model.Names(* Add [result] and a bind operator over it in scope *)openUtilsopenResultMonadtypeexpansion=|SignatureofComponent.Signature.t|FunctorofComponent.FunctorParameter.t*Component.ModuleType.exprtype('a,'b)either=Leftof'a|Rightof'bletfilter_mapfx=List.rev@@List.fold_left(funaccx->matchfxwithSomex->x::acc|None->acc)[]xtypemodule_modifiers=[`AliasedofCpath.Resolved.module_|`SubstMTofCpath.Resolved.module_type]typemodule_type_modifiers=[`AliasModuleTypeofCpath.Resolved.module_type](* These three functions take a fully-qualified canonical path and return
a list of shorter possibilities to test *)letc_mod_possenvp=(* canonical module paths *)letrecinner=function|`Dot(p,n)->(letrest=List.map(funp->`Dot(p,n))(innerp)inmatchEnv.lookup_by_nameEnv.s_modulenenvwith|Ok(`Module(id,m))->letm=Component.Delayed.getmin`Identifier(id,m.hidden)::rest|Error_->rest)|p->[p]ininnerpletc_modty_possenvp=(* canonical module type paths *)matchpwith|`Dot(p,n)->(letrest=List.map(funp->`Dot(p,n))(c_mod_possenvp)inmatchEnv.lookup_by_nameEnv.s_module_typenenvwith|Ok(`ModuleType(id,_))->`Identifier(id,false)::rest|Error_->rest)|p->[p]letc_ty_possenvp=(* canonical type paths *)matchpwith|`Dot(p,n)->(letrest=List.map(funp->`Dot(p,n))(c_mod_possenvp)inmatchEnv.lookup_by_nameEnv.s_datatypenenvwith|Ok(`Type(id,_))->`Identifier((id:>Odoc_model.Paths.Identifier.Path.Type.t),false)::rest|Error_->rest)|p->[p]letc_daty_possenvp=(* canonical datatype paths *)matchpwith|`Dot(p,n)->(letrest=List.map(funp->`Dot(p,n))(c_mod_possenvp)inmatchEnv.lookup_by_nameEnv.s_datatypenenvwith|Ok(`Type(id,_))->`Identifier((id:>Odoc_model.Paths.Identifier.Path.DataType.t),false)::rest|Error_->rest)|p->[p](* Small helper function for resolving canonical paths.
[canonical_helper env resolve lang_of possibilities p2] takes the
fully-qualified path [p2] and returns the shortest resolved path
whose identifier is the same as the resolved fully qualified path.
[resolve] is a function that resolves an arbitrary unresolved path,
[lang_of] turns a resolved path into a generic resolved Lang path
and [possibilities] is a function that, given the fully qualified
unresolved path, returns an ordered list of all possible unresolved
paths starting with the shortest and including the longest one. *)letcanonical_helper:'unresolved'resolved.Env.t->(Env.t->'unresolved->('resolved*'result,_)result)->('resolved->Odoc_model.Paths.Path.Resolved.t)->(Env.t->'unresolved->'unresolvedlist)->'unresolved->('resolved*'result)option=funenvresolvelang_ofpossibilitiesp2->letresolvep=matchresolveenvpwithOkrp->Somerp|Error_->Noneinletget_identifiercpath=Odoc_model.Paths.Path.Resolved.identifier(lang_ofcpath)inmatchresolvep2with|None->None|Some(rp2,_)->(letfallback_id=get_identifierrp2inletresolved=filter_mapresolve(possibilitiesenvp2)inletfind_fn(r,_)=get_identifierr=fallback_idintrySome(List.findfind_fnresolved)with_->None)letprefix_substitutionpathsg=letopenComponent.Signatureinletrecget_subsub'is=matchiswith|[]->sub'|Type(id,_,_)::rest->letname=Ident.Name.typed_typeidinget_sub(Subst.add_typeid(`Type(path,name))(`Type(path,name))sub')rest|Module(id,_,_)::rest->letname=Ident.Name.typed_moduleidinget_sub(Subst.add_module(id:>Ident.path_module)(`Module(path,name))(`Module(path,name))sub')rest|ModuleType(id,_)::rest->letname=Ident.Name.typed_module_typeidinget_sub(Subst.add_module_typeid(`ModuleType(path,name))(`ModuleType(path,name))sub')rest|ModuleTypeSubstitution(id,_)::rest->letname=Ident.Name.typed_module_typeidinget_sub(Subst.add_module_typeid(`ModuleType(path,name))(`ModuleType(path,name))sub')rest|ModuleSubstitution(id,_)::rest->letname=Ident.Name.typed_moduleidinget_sub(Subst.add_module(id:>Ident.path_module)(`Module(path,name))(`Module(path,name))sub')rest|TypeSubstitution(id,_)::rest->letname=Ident.Name.typed_typeidinget_sub(Subst.add_typeid(`Type(path,name))(`Type(path,name))sub')rest|Exception_::rest|TypExt_::rest|Value(_,_)::rest|Comment_::rest->get_subsub'rest|Class(id,_,_)::rest->letname=Ident.Name.typed_classidinget_sub(Subst.add_classid(`Class(path,name))(`Class(path,name))sub')rest|ClassType(id,_,_)::rest->letname=Ident.Name.typed_class_typeidinget_sub(Subst.add_class_typeid(`ClassType(path,name))(`ClassType(path,name))sub')rest|Includei::rest->get_sub(get_subsub'i.expansion_.items)rest|Openo::rest->get_sub(get_subsub'o.expansion.items)restinletextend_sub_removedremovedsub=List.fold_right(funitemmap->matchitemwith|Component.Signature.RModule(id,_)->letname=Ident.Name.typed_moduleidinSubst.add_module(id:>Ident.path_module)(`Module(path,name))(`Module(path,name))map|Component.Signature.RModuleType(id,_)->letname=Ident.Name.typed_module_typeidinSubst.add_module_type(id:>Ident.module_type)(`ModuleType(path,name))(`ModuleType(path,name))map|Component.Signature.RType(id,_,_)->letname=Ident.Name.typed_typeidinSubst.add_typeid(`Type(path,name))(`Type(path,name))map)removedsubinget_subSubst.identitysg.items|>extend_sub_removedsg.removedletprefix_signature(path,sg)=letopenComponent.Signatureinletsub=prefix_substitutionpathsginletitems=List.map(function|Module(id,r,m)->Module(Ident.Rename.module_id,r,Component.Delayed.put(fun()->Subst.module_sub(Component.Delayed.getm)))|ModuleType(id,mt)->ModuleType(Ident.Rename.module_typeid,Component.Delayed.put(fun()->Subst.module_typesub(Component.Delayed.getmt)))|Type(id,r,t)->Type(Ident.Rename.type_id,r,Component.Delayed.put(fun()->Subst.type_sub(Component.Delayed.gett)))|TypeSubstitution(id,t)->TypeSubstitution(Ident.Rename.type_id,Subst.type_subt)|ModuleSubstitution(id,m)->ModuleSubstitution(Ident.Rename.module_id,Subst.module_substitutionsubm)|ModuleTypeSubstitution(id,m)->ModuleTypeSubstitution(Ident.Rename.module_typeid,Subst.module_type_substitutionsubm)|Exception(id,e)->Exception(id,Subst.exception_sube)|TypExtt->TypExt(Subst.extensionsubt)|Value(id,v)->Value(id,Component.Delayed.put(fun()->Subst.valuesub(Component.Delayed.getv)))|Class(id,r,c)->Class(Ident.Rename.class_id,r,Subst.class_subc)|ClassType(id,r,c)->ClassType(Ident.Rename.class_typeid,r,Subst.class_typesubc)|Includei->Include(Subst.include_subi)|Openo->Open(Subst.open_subo)|Commentc->Commentc)sg.itemsin{sgwithitems}openErrors.Tools_errortyperesolve_module_result=(Cpath.Resolved.module_*Component.Module.tComponent.Delayed.t,simple_module_lookup_error)Result.resulttyperesolve_module_type_result=(Cpath.Resolved.module_type*Component.ModuleType.t,simple_module_type_lookup_error)Result.resulttyperesolve_type_result=(Cpath.Resolved.type_*Find.careful_type,simple_type_lookup_error)Result.resulttyperesolve_datatype_result=(Cpath.Resolved.datatype*Find.careful_datatype,simple_datatype_lookup_error)Result.resulttyperesolve_value_result=(Cpath.Resolved.value*Find.value,simple_value_lookup_error)Result.resulttyperesolve_constructor_result=(Cpath.Resolved.constructor*Find.constructor,simple_constructor_lookup_error)Result.resulttyperesolve_class_type_result=(Cpath.Resolved.class_type*Find.careful_class,simple_type_lookup_error)Result.resulttype('a,'b,'c)sig_map={type_:'a;module_:'b;module_type:'c}letid_map={type_=None;module_=None;module_type=None}moduletypeMEMO=sigtyperesultincludeHashtbl.HashedTypeendmoduleMakeMemo(X:MEMO)=structmoduleM=Hashtbl.Make(X)letcache:(X.result*int*Env.LookupTypeSet.t)M.t=M.create10000letenabled=reftrueletmemoizefenvarg=ifnot!enabledthenfenvargelseletenv_id=Env.idenvinletno_memo()=letlookups,result=Env.with_recorded_lookupsenv(funenv'->fenv'arg)inM.addcachearg(result,env_id,lookups);resultinmatchM.find_allcacheargwith|[]->no_memo()|xs->letrecfind_fast=function|(result,env_id',_)::_whenenv_id'=env_id->result|_::ys->find_fastys|[]->findxsandfind=function|(m,_,lookups)::xs->ifEnv.verify_lookupsenvlookupsthenmelsefindxs|[]->no_memo()infind_fastxsletclear()=M.clearcacheendmoduleLookupModuleMemo=MakeMemo(structtypet=bool*Cpath.Resolved.module_typeresult=(Component.Module.tComponent.Delayed.t,simple_module_lookup_error)Result.resultletequal=(=)lethash=Hashtbl.hashend)moduleLookupParentMemo=MakeMemo(structtypet=bool*Cpath.Resolved.parenttyperesult=(Component.Signature.t*Component.Substitution.t,[`Parentofparent_lookup_error])Result.resultletequal=(=)lethash=Hashtbl.hashend)moduleLookupAndResolveMemo=MakeMemo(structtypet=bool*bool*Cpath.module_typeresult=resolve_module_resultletequal=(=)lethash=Hashtbl.hashend)moduleHandleCanonicalModuleMemo=MakeMemo(structtypet=Odoc_model.Paths.Path.Module.ttyperesult=Odoc_model.Paths.Path.Module.tletequalx3y3=x3=y3lethashy=Hashtbl.hashyend)moduleExpansionOfModuleMemo=MakeMemo(structtypet=Cpath.Resolved.module_typeresult=(expansion,expansion_of_module_error)Result.resultletequal=(=)lethash=Hashtbl.hashend)letdisable_all_caches()=LookupModuleMemo.enabled:=false;LookupAndResolveMemo.enabled:=false;ExpansionOfModuleMemo.enabled:=false;LookupParentMemo.enabled:=falseletreset_caches()=LookupModuleMemo.clear();LookupAndResolveMemo.clear();ExpansionOfModuleMemo.clear();LookupParentMemo.clear()letsimplify_module:Env.t->Cpath.Resolved.module_->Cpath.Resolved.module_=funenvm->letopenOdoc_model.Paths.Identifierinmatchmwith|`Module(`Module(`Gpath(`Identifierp)),name)->(letident=(Mk.module_((p:>Signature.t),name):Path.Module.t)inmatchEnv.(lookup_by_ids_module(ident:>Signature.t)env)with|Some_->`Gpath(`Identifierident)|None->m)|_->mletsimplify_module_type:Env.t->Cpath.Resolved.module_type->Cpath.Resolved.module_type=funenvm->letopenOdoc_model.Paths.Identifierinmatchmwith|`ModuleType(`Module(`Gpath(`Identifierp)),name)->(letident=(Mk.module_type((p:>Signature.t),name):Path.ModuleType.t)inmatchEnv.(lookup_by_ids_module_type(ident:>Signature.t)env)with|Some_->`Gpath(`Identifierident)|None->m)|_->mletsimplify_type:Env.t->Cpath.Resolved.type_->Cpath.Resolved.type_=funenvm->letopenOdoc_model.Paths.Identifierinmatchmwith|`Type(`Module(`Gpath(`Identifierp)),name)->(letident=(Mk.type_((p:>Signature.t),name):Path.Type.t)inmatchEnv.(lookup_by_ids_datatype(ident:>Path.Type.t)env)with|Some_->`Gpath(`Identifierident)|None->m)|_->mletsimplify_datatype:Env.t->Cpath.Resolved.datatype->Cpath.Resolved.datatype=funenvm->letopenOdoc_model.Paths.Identifierinmatchmwith|`Type(`Module(`Gpath(`Identifierp)),name)->(letident=(Mk.type_((p:>Signature.t),name):Path.DataType.t)inmatchEnv.(lookup_by_ids_datatype(ident:>Path.Type.t)env)with|Some_->`Gpath(`Identifierident)|None->m)|_->mletrechandle_apply~mark_substitutedenvfunc_patharg_pathm=letrecfind_functormty=matchmtywith|Component.ModuleType.Functor(Namedarg,expr)->Ok(arg.Component.FunctorParameter.id,expr)|Component.ModuleType.Path{p_path;_}->(matchresolve_module_type~mark_substituted:false~add_canonical:trueenvp_pathwith|Ok(_,{Component.ModuleType.expr=Somemty';_})->find_functormty'|_->Error`OpaqueModule)|_->Error`ApplyNotFunctorinmodule_type_expr_of_moduleenvm>>=funmty'->find_functormty'>>=fun(arg_id,result)->letnew_module={mwithComponent.Module.type_=ModuleTyperesult}inletsubstitution=ifmark_substitutedthen`Substitutedarg_pathelsearg_pathinletpath=`Apply(func_path,arg_path)inletsubst=Subst.add_module(arg_id:>Ident.path_module)(`Resolvedsubstitution)substitutionSubst.identityinletsubst=Subst.unresolve_opaque_pathssubstinOk(path,Subst.module_substnew_module)andadd_canonical_path:Component.Module.t->Cpath.Resolved.module_->Cpath.Resolved.module_=funmp->matchpwith|`Canonical_->p|_->(matchm.Component.Module.canonicalwith|Somecp->`Canonical(p,cp)|None->p)andadd_canonical_path_mt:Component.ModuleType.t->Cpath.Resolved.module_type->Cpath.Resolved.module_type=funmp->matchpwith|`CanonicalModuleType_->p|_->(matchm.canonicalwith|Somecp->`CanonicalModuleType(p,cp)|None->p)andget_substituted_module_type:Env.t->Component.ModuleType.expr->Cpath.Resolved.module_typeoption=funenvexpr->matchexprwith|Component.ModuleType.Path{p_path;_}->ifCpath.is_module_type_substitutedp_paththenmatchresolve_module_type~mark_substituted:true~add_canonical:trueenvp_pathwith|Ok(resolved_path,_)->Someresolved_path|Error_->NoneelseNone|_->Noneandget_module_type_path_modifiers:Env.t->add_canonical:bool->Component.ModuleType.t->module_type_modifiersoption=funenv~add_canonicalm->letalias_ofexpr=matchexprwith|Component.ModuleType.Pathalias_path->(matchresolve_module_type~mark_substituted:true~add_canonicalenvalias_path.p_pathwith|Ok(resolved_alias_path,_)->Someresolved_alias_path|Error_->None)(* | Functor (_arg, res) -> alias_of res *)|_->Noneinmatchm.exprwith|Somee->(matchalias_ofewithSomee->Some(`AliasModuleTypee)|None->None)|None->Noneandprocess_module_typeenv~add_canonicalmp'=letopenComponent.ModuleTypeinletopenOptionMonadin(* Loop through potential chains of module_type equalities, looking for substitutions *)letsubstpath=m.expr>>=get_substituted_module_typeenv>>=funp->Some(`SubstT(p,p'))inletp'=matchsubstpathwithSomep->p|None->p'inletp''=matchget_module_type_path_modifiersenv~add_canonicalmwith|Some(`AliasModuleTypee)->`AliasModuleType(e,p')|None->p'inletp'''=ifadd_canonicalthenadd_canonical_path_mtmp''elsep''inp'''andget_module_path_modifiers:Env.t->add_canonical:bool->Component.Module.t->_option=funenv~add_canonicalm->matchm.type_with|Alias(alias_path,_)->(matchresolve_module~mark_substituted:true~add_canonicalenvalias_pathwith|Ok(resolved_alias_path,_)->Some(`Aliasedresolved_alias_path)|Error_->None)|ModuleTypet->(matchget_substituted_module_typeenvtwith|Somes->Some(`SubstMTs)|None->None)andprocess_module_pathenv~add_canonicalmrp=letrp=ifm.Component.Module.hiddenthen`Hiddenrpelserpinletrp'=matchget_module_path_modifiersenv~add_canonicalmwith|None->rp|Some(`Aliasedrp')->letdest_hidden=Cpath.is_resolved_module_hidden~weak_canonical_test:truerp'inifdest_hiddenthenrpelseletunresolved_rp=tryCpath.unresolve_resolved_module_pathrpwith_->`Resolvedrpin(* Keep the resolved path for the canonical processing below in handle_canonical_module.strip_alias *)`Alias(rp',unresolved_rp,Somerp)|Some(`SubstMTp')->`Subst(p',rp)inletp''=ifadd_canonicalthenadd_canonical_pathmrp'elserp'inp''andhandle_module_lookupenv~add_canonicalidrparentsgsub=matchFind.careful_module_in_sigsgidwith|Some(`FModule(name,m))->letrp'=simplify_moduleenv(`Module(rparent,name))inletm'=Subst.module_subminletmd'=Component.Delayed.put_valm'inOk(process_module_pathenv~add_canonicalm'rp',md')|Some(`FModule_removedp)->lookup_module~mark_substituted:falseenvp>>=funm->Ok(p,m)|None->Error`Find_failureandhandle_module_type_lookupenv~add_canonicalidpsgsub=letopenOptionMonadinFind.module_type_in_sigsgid>>=fun(`FModuleType(name,mt))->letmt=Subst.module_typesubmtinletp'=simplify_module_typeenv(`ModuleType(p,name))inletp''=process_module_typeenv~add_canonicalmtp'inSome(p'',mt)andhandle_type_lookupenvidpsg=matchFind.careful_type_in_sigsgidwith|Some(`FClass(name,_)ast)->Ok(`Class(p,name),t)|Some(`FClassType(name,_)ast)->Ok(`ClassType(p,name),t)|Some(`FType(name,_)ast)->Ok(simplify_typeenv(`Type(p,name)),t)|Some(`FType_removed(name,_,_)ast)->Ok(`Type(p,name),t)|None->Error`Find_failureandhandle_datatype_lookupenvidpsg=matchFind.careful_datatype_in_sigsgidwith|Some(`FType(name,_)ast)->Ok(simplify_datatypeenv(`Type(p,name)),t)|Some(`FType_removed(name,_,_)ast)->Ok(`Type(p,name),t)|None->Error`Find_failureandhandle_value_lookup_envidpsg=matchFind.value_in_sigsgidwith|(`FValue(name,_)asv)::_->Ok(`Value(p,name),v)|_->Error`Find_failureandhandle_constructor_lookup_envidpt=matchFind.constructor_in_typetidwith|Some(`FConstructorconsasv)->Ok(`Constructor(p,ConstructorName.make_stdcons.name),v)|_->Error`Find_failureandhandle_class_type_lookupidpsg=matchFind.careful_class_in_sigsgidwith|Some(`FClass(name,_)ast)->Ok(`Class(p,name),t)|Some(`FClassType(name,_)ast)->Ok(`ClassType(p,name),t)|Some(`FType_removed(_name,_,_)as_t)->Error`Class_replaced|None->Error`Find_failureandlookup_module_gpath:mark_substituted:bool->Env.t->Odoc_model.Paths.Path.Resolved.Module.t->(Component.Module.tComponent.Delayed.t,simple_module_lookup_error)Result.result=fun~mark_substitutedenvpath->matchpathwith|`Identifieri->of_option~error:(`Lookup_failurei)(Env.(lookup_by_ids_module)ienv)>>=fun(`Module(_,m))->Okm|`Apply(functor_path,argument_path)->lookup_module_gpath~mark_substitutedenvfunctor_path>>=funfunctor_module->letfunctor_module=Component.Delayed.getfunctor_moduleinhandle_apply~mark_substitutedenv(`Gpathfunctor_path)(`Gpathargument_path)functor_module|>map_error(fune->`Parent(`Parent_expre))>>=fun(_,m)->Ok(Component.Delayed.put_valm)|`Module(parent,name)->letfind_in_sgsgsub=matchFind.careful_module_in_sigsg(ModuleName.to_stringname)with|None->Error`Find_failure|Some(`FModule(_,m))->Ok(Component.Delayed.put_val(Subst.module_subm))|Some(`FModule_removedp)->lookup_module~mark_substitutedenvpinlookup_parent_gpath~mark_substitutedenvparent|>map_error(fune->(e:>simple_module_lookup_error))>>=fun(sg,sub)->find_in_sgsgsub|`Alias(p,_)->lookup_module_gpath~mark_substitutedenvp|`Subst(_,p)->lookup_module_gpath~mark_substitutedenvp|`Hiddenp->lookup_module_gpath~mark_substitutedenvp|`Canonical(p,_)->lookup_module_gpath~mark_substitutedenvp|`OpaqueModulem->lookup_module_gpath~mark_substitutedenvmandlookup_module:mark_substituted:bool->Env.t->Cpath.Resolved.module_->(Component.Module.tComponent.Delayed.t,simple_module_lookup_error)Result.result=fun~mark_substituted:menv'path'->letlookupenv(mark_substituted,(path:ExpansionOfModuleMemo.M.key))=matchpathwith|`Locallpath->Error(`Local(env,lpath))|`Gpathp->lookup_module_gpath~mark_substitutedenvp|`Substitutedx->lookup_module~mark_substitutedenvx|`Apply(functor_path,argument_path)->lookup_module~mark_substitutedenvfunctor_path>>=funfunctor_module->letfunctor_module=Component.Delayed.getfunctor_moduleinhandle_apply~mark_substitutedenvfunctor_pathargument_pathfunctor_module|>map_error(fune->`Parent(`Parent_expre))>>=fun(_,m)->Ok(Component.Delayed.put_valm)|`Module(parent,name)->letfind_in_sgsgsub=matchFind.careful_module_in_sigsg(ModuleName.to_stringname)with|None->Error`Find_failure|Some(`FModule(_,m))->Ok(Component.Delayed.put_val(Subst.module_subm))|Some(`FModule_removedp)->lookup_module~mark_substitutedenvpinlookup_parent~mark_substitutedenvparent|>map_error(fune->(e:>simple_module_lookup_error))>>=fun(sg,sub)->find_in_sgsgsub|`Alias(_,cs,_)->(matchresolve_module~mark_substituted~add_canonical:falseenvcswith|Ok(_,r)->Okr|Errore->Errore)|`Subst(_,p)->lookup_module~mark_substitutedenvp|`Hiddenp->lookup_module~mark_substitutedenvp|`Canonical(p,_)->lookup_module~mark_substitutedenvp|`OpaqueModulem->lookup_module~mark_substitutedenvminLookupModuleMemo.memoizelookupenv'(m,path')andlookup_module_type_gpath:mark_substituted:bool->Env.t->Odoc_model.Paths.Path.Resolved.ModuleType.t->(Component.ModuleType.t,simple_module_type_lookup_error)Result.result=fun~mark_substitutedenvpath->matchpathwith|`Identifieri->of_option~error:(`Lookup_failureMTi)(Env.(lookup_by_ids_module_type)ienv)>>=fun(`ModuleType(_,mt))->Okmt|`CanonicalModuleType(s,_)|`SubstT(_,s)->lookup_module_type_gpath~mark_substitutedenvs|`ModuleType(parent,name)->letfind_in_sgsgsub=matchFind.module_type_in_sigsg(ModuleTypeName.to_stringname)with|None->Error`Find_failure|Some(`FModuleType(_,mt))->Ok(Subst.module_typesubmt)inlookup_parent_gpath~mark_substitutedenvparent|>map_error(fune->(e:>simple_module_type_lookup_error))>>=fun(sg,sub)->find_in_sgsgsub|`AliasModuleType(_,mt)->lookup_module_type_gpath~mark_substitutedenvmt|`OpaqueModuleTypem->lookup_module_type_gpath~mark_substitutedenvmandlookup_module_type:mark_substituted:bool->Env.t->Cpath.Resolved.module_type->(Component.ModuleType.t,simple_module_type_lookup_error)Result.result=fun~mark_substitutedenvpath->letlookupenv=matchpathwith|`Locall->Error(`LocalMT(env,l))|`Gpathp->lookup_module_type_gpath~mark_substitutedenvp|`Substituteds|`CanonicalModuleType(s,_)|`SubstT(_,s)->lookup_module_type~mark_substitutedenvs|`ModuleType(parent,name)->letfind_in_sgsgsub=matchFind.module_type_in_sigsg(ModuleTypeName.to_stringname)with|None->Error`Find_failure|Some(`FModuleType(_,mt))->Ok(Subst.module_typesubmt)inlookup_parent~mark_substituted:trueenvparent|>map_error(fune->(e:>simple_module_type_lookup_error))>>=fun(sg,sub)->find_in_sgsgsub|`AliasModuleType(_,mt)->lookup_module_type~mark_substitutedenvmt|`OpaqueModuleTypem->lookup_module_type~mark_substitutedenvminlookupenvandlookup_parent:mark_substituted:bool->Env.t->Cpath.Resolved.parent->(Component.Signature.t*Component.Substitution.t,[`Parentofparent_lookup_error])Result.result=fun~mark_substituted:menv'parent'->letlookupenv(mark_substituted,parent)=matchparentwith|`Modulep->lookup_module~mark_substitutedenvp|>map_error(fune->`Parent(`Parent_modulee))>>=funm->letm=Component.Delayed.getminexpansion_of_moduleenvm|>map_error(fune->`Parent(`Parent_sige))>>=assert_not_functor>>=funsg->Ok(sg,prefix_substitutionparentsg)|`ModuleTypep->lookup_module_type~mark_substitutedenvp|>map_error(fune->`Parent(`Parent_module_typee))>>=funmt->expansion_of_module_typeenvmt|>map_error(fune->`Parent(`Parent_sige))>>=assert_not_functor>>=funsg->Ok(sg,prefix_substitutionparentsg)|`FragmentRoot->Env.lookup_fragment_rootenv|>of_option~error:(`Parent`Fragment_root)>>=fun(_,sg)->Ok(sg,prefix_substitutionparentsg)inLookupParentMemo.memoizelookupenv'(m,parent')andlookup_parent_gpath:mark_substituted:bool->Env.t->Odoc_model.Paths.Path.Resolved.Module.t->(Component.Signature.t*Component.Substitution.t,[`Parentofparent_lookup_error])Result.result=fun~mark_substitutedenvparent->lookup_module_gpath~mark_substitutedenvparent|>map_error(fune->`Parent(`Parent_modulee))>>=funm->letm=Component.Delayed.getminexpansion_of_moduleenvm|>map_error(fune->`Parent(`Parent_sige))>>=assert_not_functor>>=funsg->Ok(sg,prefix_substitution(`Module(`Gpathparent))sg)andlookup_type_gpath:Env.t->Odoc_model.Paths.Path.Resolved.Type.t->(Find.careful_type,simple_type_lookup_error)Result.result=funenvp->letdo_typepname=lookup_parent_gpath~mark_substituted:trueenvp|>map_error(fune->(e:>simple_type_lookup_error))>>=fun(sg,sub)->matchFind.careful_type_in_sigsgnamewith|Some(`FClass(name,c))->Ok(`FClass(name,Subst.class_subc))|Some(`FClassType(name,ct))->Ok(`FClassType(name,Subst.class_typesubct))|Some(`FType(name,t))->Ok(`FType(name,Subst.type_subt))|Some(`FType_removed(name,texpr,eq))->Ok(`FType_removed(name,Subst.type_exprsubtexpr,eq))|None->Error`Find_failureinletres=matchpwith|`Identifier{iv=`CoreTypename;_}->(* CoreTypes aren't put into the environment, so they can't be handled
by the next clause. They are already resolved. *)Ok(`FType(name,Component.Of_Lang.(type_decl(empty())(Odoc_model.Predefined.type_of_core_type(TypeName.to_stringname)))))|`Identifier({iv=`Type_;_}asi)->of_option~error:(`Lookup_failureTi)(Env.(lookup_by_ids_datatype)ienv)>>=fun(`Type({iv=`CoreTypename|`Type(_,name);_},t))->Ok(`FType(name,t))|`Identifier({iv=`Class_;_}asi)->of_option~error:(`Lookup_failureTi)(Env.(lookup_by_ids_class)ienv)>>=fun(`Class({iv=`Class(_,name);_},t))->Ok(`FClass(name,t))|`Identifier({iv=`ClassType_;_}asi)->of_option~error:(`Lookup_failureTi)(Env.(lookup_by_ids_class_type)ienv)>>=fun(`ClassType({iv=`ClassType(_,name);_},t))->Ok(`FClassType(name,t))|`CanonicalType(t1,_)->lookup_type_gpathenvt1|`Type(p,id)->do_typep(TypeName.to_stringid)|`Class(p,id)->do_typep(ClassName.to_stringid)|`ClassType(p,id)->do_typep(ClassTypeName.to_stringid)inresandlookup_datatype_gpath:Env.t->Odoc_model.Paths.Path.Resolved.DataType.t->(Find.careful_datatype,simple_datatype_lookup_error)Result.result=funenvp->letdo_typepname=lookup_parent_gpath~mark_substituted:trueenvp|>map_error(fune->(e:>simple_datatype_lookup_error))>>=fun(sg,sub)->matchFind.careful_datatype_in_sigsgnamewith|Some(`FType(name,t))->Ok(`FType(name,Subst.type_subt))|Some(`FType_removed(name,texpr,eq))->Ok(`FType_removed(name,Subst.type_exprsubtexpr,eq))|None->Error`Find_failureinletres=matchpwith|`Identifier{iv=`CoreTypename;_}->(* CoreTypes aren't put into the environment, so they can't be handled by the
next clause. We just look them up here in the list of core types *)Ok(`FType(name,Component.Of_Lang.(type_decl(empty())(Odoc_model.Predefined.type_of_core_type(TypeName.to_stringname)))))|`Identifier({iv=`Type_;_}asi)->of_option~error:(`Lookup_failureTi)(Env.(lookup_by_ids_datatype)ienv)>>=fun(`Type({iv=`CoreTypename|`Type(_,name);_},t))->Ok(`FType(name,t))|`CanonicalDataType(t1,_)->lookup_datatype_gpathenvt1|`Type(p,id)->do_typep(TypeName.to_stringid)inresandlookup_class_type_gpath:Env.t->Odoc_model.Paths.Path.Resolved.ClassType.t->(Find.careful_class,simple_type_lookup_error)Result.result=funenvp->letdo_typepname=lookup_parent_gpath~mark_substituted:trueenvp|>map_error(fune->(e:>simple_type_lookup_error))>>=fun(sg,sub)->matchFind.careful_class_in_sigsgnamewith|Some(`FClass(name,c))->Ok(`FClass(name,Subst.class_subc))|Some(`FClassType(name,ct))->Ok(`FClassType(name,Subst.class_typesubct))|Some(`FType_removed(name,texpr,eq))->Ok(`FType_removed(name,Subst.type_exprsubtexpr,eq))|None->Error`Find_failureinletres=matchpwith|`Identifier({iv=`Class_;_}asi)->of_option~error:(`Lookup_failureTi)(Env.(lookup_by_ids_class)ienv)>>=fun(`Class({iv=`Class(_,name);_},t))->Ok(`FClass(name,t))|`Identifier({iv=`ClassType_;_}asi)->of_option~error:(`Lookup_failureTi)(Env.(lookup_by_ids_class_type)ienv)>>=fun(`ClassType({iv=`ClassType(_,name);_},t))->Ok(`FClassType(name,t))|`Class(p,id)->do_typep(ClassName.to_stringid)|`ClassType(p,id)->do_typep(ClassTypeName.to_stringid)inresandlookup_type:Env.t->Cpath.Resolved.type_->(Find.careful_type,simple_type_lookup_error)Result.result=funenvp->letdo_typepname=lookup_parent~mark_substituted:trueenvp|>map_error(fune->(e:>simple_type_lookup_error))>>=fun(sg,sub)->handle_type_lookupenvnamepsg>>=fun(_,t')->lett=matcht'with|`FClass(name,c)->`FClass(name,Subst.class_subc)|`FClassType(name,ct)->`FClassType(name,Subst.class_typesubct)|`FType(name,t)->`FType(name,Subst.type_subt)|`FType_removed(name,texpr,eq)->`FType_removed(name,Subst.type_exprsubtexpr,eq)inOktinletres=matchpwith|`Localid->Error(`LocalType(env,id))|`Gpathp->lookup_type_gpathenvp|`CanonicalType(t1,_)->lookup_typeenvt1|`Substituteds->lookup_typeenvs|`Type(p,id)->do_typep(TypeName.to_stringid)|`Class(p,id)->do_typep(ClassName.to_stringid)|`ClassType(p,id)->do_typep(ClassTypeName.to_stringid)inresandlookup_datatype:Env.t->Cpath.Resolved.datatype->(Find.careful_datatype,simple_datatype_lookup_error)Result.result=funenvp->letdo_typepname=lookup_parent~mark_substituted:trueenvp|>map_error(fune->(e:>simple_datatype_lookup_error))>>=fun(sg,sub)->handle_datatype_lookupenvnamepsg>>=fun(_,t')->lett=matcht'with|`FType(name,t)->`FType(name,Subst.type_subt)|`FType_removed(name,texpr,eq)->`FType_removed(name,Subst.type_exprsubtexpr,eq)inOktinletres=matchpwith|`Localid->Error(`LocalDataType(env,id))|`Gpathp->lookup_datatype_gpathenvp|`CanonicalDataType(t1,_)->lookup_datatypeenvt1|`Substituteds->lookup_datatypeenvs|`Type(p,id)->do_typep(TypeName.to_stringid)inresandlookup_value:Env.t->Cpath.Resolved.value->(Find.value,simple_value_lookup_error)Result.result=funenv(`Value(p,id))->lookup_parent~mark_substituted:trueenvp|>map_error(fune->(e:>simple_value_lookup_error))>>=fun(sg,sub)->handle_value_lookupenv(ValueName.to_stringid)psg>>=fun(_,`FValue(name,c))->Ok(`FValue(name,Subst.valuesubc))andlookup_constructor:Env.t->Cpath.Resolved.constructor->(Find.constructor,simple_constructor_lookup_error)Result.result=funenv(`Constructor(parent,name))->lookup_datatypeenvparent|>map_error(fune->(`ParentCe:>simple_constructor_lookup_error))>>=funt->matchtwith|`FType(_,t)->handle_constructor_lookupenv(ConstructorName.to_stringname)parentt>>=fun(_,x)->Okx|`FType_removed_->Error`Find_failureandlookup_class_type:Env.t->Cpath.Resolved.class_type->(Find.careful_class,simple_type_lookup_error)Result.result=funenvp->letdo_typepname=lookup_parent~mark_substituted:trueenvp|>map_error(fune->(e:>simple_type_lookup_error))>>=fun(sg,sub)->handle_class_type_lookupnamepsg>>=fun(_,t')->lett=matcht'with|`FClass(name,c)->`FClass(name,Subst.class_subc)|`FClassType(name,ct)->`FClassType(name,Subst.class_typesubct)|`FType_removed(name,texpr,eq)->`FType_removed(name,Subst.type_exprsubtexpr,eq)inOktinletres=matchpwith|`Localid->Error(`LocalType(env,(id:>Ident.path_type)))|`Gpathp->lookup_class_type_gpathenvp|`Substituteds->lookup_class_typeenvs|`Class(p,id)->do_typep(ClassName.to_stringid)|`ClassType(p,id)->do_typep(ClassTypeName.to_stringid)inresandresolve_module:mark_substituted:bool->add_canonical:bool->Env.t->Cpath.module_->resolve_module_result=fun~mark_substituted~add_canonicalenv'path->letid=(mark_substituted,add_canonical,path)inletresolveenv(mark_substituted,add_canonical,p)=matchpwith|`Dot(parent,id)->resolve_module~mark_substituted~add_canonicalenvparent|>map_error(fune'->`Parent(`Parent_modulee'))>>=fun(p,m)->letm=Component.Delayed.getminexpansion_of_module_cachedenvpm|>map_error(fune->`Parent(`Parent_sige))>>=assert_not_functor>>=funparent_sig->letsub=prefix_substitution(`Modulep)parent_siginhandle_module_lookupenv~add_canonicalid(`Modulep)parent_sigsub|`Module(parent,id)->lookup_parent~mark_substitutedenvparent|>map_error(fune->(e:>simple_module_lookup_error))>>=fun(parent_sig,sub)->handle_module_lookupenv~add_canonical(ModuleName.to_stringid)parentparent_sigsub|`Apply(m1,m2)->(letfunc=resolve_module~mark_substituted~add_canonicalenvm1inletarg=resolve_module~mark_substituted~add_canonicalenvm2inmatch(func,arg)with|Ok(func_path',m),Ok(arg_path',_)->(letm=Component.Delayed.getminmatchhandle_apply~mark_substitutedenvfunc_path'arg_path'mwith|Ok(p,m)->Ok(p,Component.Delayed.put_valm)|Errore->Error(`Parent(`Parent_expre)))|Errore,_->Errore|_,Errore->Errore)|`Identifier(i,hidden)->of_option~error:(`Lookup_failurei)(Env.(lookup_by_ids_module)ienv)>>=fun(`Module(_,m))->letrp=ifhiddenthen`Hidden(`Gpath(`Identifieri))else`Gpath(`Identifieri)inOk(process_module_pathenv~add_canonical(Component.Delayed.getm)rp,m)|`Local(p,_)->Error(`Local(env,p))|`Resolvedr->lookup_module~mark_substitutedenvr>>=funm->Ok(r,m)|`Substituteds->resolve_module~mark_substituted~add_canonicalenvs|>map_error(fune->`Parent(`Parent_modulee))>>=fun(p,m)->Ok(`Substitutedp,m)|`Rootr->(matchEnv.lookup_root_modulerenvwith|Some(Env.Resolved(_,p,m))->letp=`Gpath(`Identifier(p:>Odoc_model.Paths.Identifier.Path.Module.t))inletp=process_module_pathenv~add_canonicalmpinOk(p,Component.Delayed.put_valm)|SomeEnv.Forward->Error(`Parent(`Parent_sig`UnresolvedForwardPath))|None->Error(`Lookup_failure_rootr))|`Forwardf->resolve_module~mark_substituted~add_canonicalenv(`Rootf)|>map_error(fune->`Parent(`Parent_modulee))inLookupAndResolveMemo.memoizeresolveenv'idandresolve_module_type:mark_substituted:bool->add_canonical:bool->Env.t->Cpath.module_type->resolve_module_type_result=fun~mark_substituted~add_canonicalenvp->matchpwith|`Dot(parent,id)->resolve_module~mark_substituted~add_canonical:trueenvparent|>map_error(fune->`Parent(`Parent_modulee))>>=fun(p,m)->letm=Component.Delayed.getminexpansion_of_module_cachedenvpm|>map_error(fune->`Parent(`Parent_sige))>>=assert_not_functor>>=funparent_sg->letsub=prefix_substitution(`Modulep)parent_sginof_option~error:`Find_failure(handle_module_type_lookupenv~add_canonicalid(`Modulep)parent_sgsub)>>=fun(p',mt)->Ok(p',mt)|`ModuleType(parent,id)->lookup_parent~mark_substitutedenvparent|>map_error(fune->(e:>simple_module_type_lookup_error))>>=fun(parent_sig,sub)->handle_module_type_lookupenv~add_canonical(ModuleTypeName.to_stringid)parentparent_sigsub|>of_option~error:`Find_failure|`Identifier(i,_)->of_option~error:(`Lookup_failureMTi)(Env.(lookup_by_ids_module_type)ienv)>>=fun(`ModuleType(_,mt))->letp=`Gpath(`Identifieri)inletp'=process_module_typeenv~add_canonicalmtpinOk(p',mt)|`Local(l,_)->Error(`LocalMT(env,l))|`Resolvedr->lookup_module_type~mark_substitutedenvr>>=funm->Ok(r,m)|`Substituteds->resolve_module_type~mark_substituted~add_canonicalenvs|>map_error(fune->`Parent(`Parent_module_typee))>>=fun(p,m)->Ok(`Substitutedp,m)andresolve_type:Env.t->add_canonical:bool->Cpath.type_->resolve_type_result=funenv~add_canonicalp->letresult=matchpwith|`Dot(parent,id)->resolve_module~mark_substituted:true~add_canonical:trueenvparent|>map_error(fune->`Parent(`Parent_modulee))>>=fun(p,m)->letm=Component.Delayed.getminexpansion_of_module_cachedenvpm|>map_error(fune->`Parent(`Parent_sige))>>=assert_not_functor>>=funsg->letsub=prefix_substitution(`Modulep)sginhandle_type_lookupenvid(`Modulep)sg>>=fun(p',t')->lett=matcht'with|`FClass(name,c)->`FClass(name,Subst.class_subc)|`FClassType(name,ct)->`FClassType(name,Subst.class_typesubct)|`FType(name,t)->`FType(name,Subst.type_subt)|`FType_removed(name,texpr,eq)->`FType_removed(name,Subst.type_exprsubtexpr,eq)inOk(p',t)|`Type(parent,id)->lookup_parent~mark_substituted:trueenvparent|>map_error(fune->(e:>simple_type_lookup_error))>>=fun(parent_sig,sub)->letresult=matchFind.datatype_in_sigparent_sig(TypeName.to_stringid)with|Some(`FType(name,t))->Some(`Type(parent,name),`FType(name,Subst.type_subt))|None->Noneinof_option~error:`Find_failureresult|`Class(parent,id)->lookup_parent~mark_substituted:trueenvparent|>map_error(fune->(e:>simple_type_lookup_error))>>=fun(parent_sig,sub)->lett=matchFind.type_in_sigparent_sig(ClassName.to_stringid)with|Some(`FClass(name,t))->Some(`Class(parent,name),`FClass(name,Subst.class_subt))|Some_->None|None->Noneinof_option~error:`Find_failuret|`ClassType(parent,id)->lookup_parent~mark_substituted:trueenvparent|>map_error(fune->(e:>simple_type_lookup_error))>>=fun(parent_sg,sub)->handle_type_lookupenv(ClassTypeName.to_stringid)parentparent_sg>>=fun(p',t')->lett=matcht'with|`FClass(name,c)->`FClass(name,Subst.class_subc)|`FClassType(name,ct)->`FClassType(name,Subst.class_typesubct)|`FType(name,t)->`FType(name,Subst.type_subt)|`FType_removed(name,texpr,eq)->`FType_removed(name,Subst.type_exprsubtexpr,eq)inOk(p',t)|`Identifier(i,_)->leti'=`Identifieriinlookup_typeenv(`Gpathi')>>=funt->Ok(`Gpathi',t)|`Resolvedr->lookup_typeenvr>>=funt->Ok(r,t)|`Local(l,_)->Error(`LocalType(env,l))|`Substituteds->resolve_typeenv~add_canonicals>>=fun(p,m)->Ok(`Substitutedp,m)inresult>>=fun(p,t)->matchtwith|`FType(_,{canonical=Somec;_})->ifadd_canonicalthenOk(`CanonicalType(p,c),t)elseresult|_->resultandresolve_datatype:Env.t->add_canonical:bool->Cpath.datatype->resolve_datatype_result=funenv~add_canonicalp->let(>>>)=OptionMonad.bindinletrecid_datatype_of_type(id:Odoc_model.Comment.Identifier.Id.path_type):Odoc_model.Comment.Identifier.Id.path_datatypeoption=matchidwith|{iv=`Class_|`ClassType_;_}->None|{iv=`CoreType_|`Type_;_}ast->Sometandresolved_datatype_of_type(c:Odoc_model.Comment.Path.Resolved.Type.t):Odoc_model.Comment.Path.Resolved.DataType.toption=matchcwith|`Identifierid->id_datatype_of_typeid>>>funid->Some(`Identifierid)|`CanonicalType(t,p)->resolved_datatype_of_typet>>>funt->datatype_of_typep>>>funp->Some(`CanonicalDataType(t,p))|`Type(m,t)->Some(`Type(m,t))|`Class_->None|`ClassType_->Noneanddatatype_of_type(c:Odoc_model.Comment.Path.Type.t)=matchcwith|`Dot(c,s)->Some(`Dot(c,s))|`Identifier(id,b)->id_datatype_of_typeid>>>funid->Some(`Identifier(id,b))|`Resolvedr->resolved_datatype_of_typer>>>funr->Some(`Resolvedr)inletresult=matchpwith|`Dot(parent,id)->resolve_module~mark_substituted:true~add_canonical:trueenvparent|>map_error(fune->`Parent(`Parent_modulee))>>=fun(p,m)->letm=Component.Delayed.getminexpansion_of_module_cachedenvpm|>map_error(fune->`Parent(`Parent_sige))>>=assert_not_functor>>=funsg->letsub=prefix_substitution(`Modulep)sginhandle_datatype_lookupenvid(`Modulep)sg>>=fun(p',t')->lett=matcht'with|`FType(name,t)->`FType(name,Subst.type_subt)|`FType_removed(name,texpr,eq)->`FType_removed(name,Subst.type_exprsubtexpr,eq)inOk(p',t)|`Type(parent,id)->lookup_parent~mark_substituted:trueenvparent|>map_error(fune->(e:>simple_datatype_lookup_error))>>=fun(parent_sig,sub)->letresult=matchFind.datatype_in_sigparent_sig(TypeName.to_stringid)with|Some(`FType(name,t))->Some(`Type(parent,name),`FType(name,Subst.type_subt))|None->Noneinof_option~error:`Find_failureresult|`Identifier(i,_)->leti'=`Identifieriinlookup_datatypeenv(`Gpathi')>>=funt->Ok(`Gpathi',t)|`Resolvedr->lookup_datatypeenvr>>=funt->Ok(r,t)|`Local(l,_)->Error(`LocalDataType(env,l))|`Substituteds->resolve_datatypeenv~add_canonicals>>=fun(p,m)->Ok(`Substitutedp,m)inresult>>=fun(p,t)->matchtwith|`FType(_,{canonical=Somec;_})->ifadd_canonicalthenmatchdatatype_of_typecwith|None->result|Somec->Ok(`CanonicalDataType(p,c),t)elseresult|_->resultandresolve_value:Env.t->Cpath.value->resolve_value_result=funenvp->letresult=matchpwith|`Dot(parent,id)->resolve_module~mark_substituted:true~add_canonical:trueenvparent|>map_error(fune->`Parent(`Parent_modulee))>>=fun(p,m)->letm=Component.Delayed.getminexpansion_of_module_cachedenvpm|>map_error(fune->`Parent(`Parent_sige))>>=assert_not_functor>>=funsg->letsub=prefix_substitution(`Modulep)sginhandle_value_lookupenvid(`Modulep)sg>>=fun(p',`FValue(name,c))->Ok(p',`FValue(name,Subst.valuesubc))|`Value(parent,id)->lookup_parent~mark_substituted:trueenvparent|>map_error(fune->(e:>simple_value_lookup_error))>>=fun(parent_sig,sub)->letresult=matchFind.value_in_sigparent_sig(ValueName.to_stringid)with|`FValue(name,t)::_->Some(`Value(parent,name),`FValue(name,Subst.valuesubt))|[]->Noneinof_option~error:`Find_failureresult|`Resolvedr->lookup_valueenvr>>=funt->Ok(r,t)inresultandresolve_constructor:Env.t->Cpath.constructor->resolve_constructor_result=funenvp->matchpwith|`Dot(parent,id)->(resolve_datatype~add_canonical:trueenvparent|>map_error(fune->`ParentCe)>>=fun(p,m)->matchmwith|`FType(_,t)->handle_constructor_lookupenvidpt>>=fun(p',`FConstructorc)->Ok(p',`FConstructorc)|`FType_removed_->Error`Find_failure)|`Constructor(parent,id)->(lookup_datatypeenvparent|>map_error(fune->(`ParentCe:>simple_constructor_lookup_error))>>=funparent_type->matchparent_typewith|`FType_removed_->Error`Find_failure|`FType(_,t)->handle_constructor_lookupenv(ConstructorName.to_stringid)parentt)|`Resolvedr->letx=lookup_constructorenvrinx>>=funt->Ok(r,t)andresolve_class_type:Env.t->Cpath.class_type->resolve_class_type_result=funenvp->matchpwith|`Dot(parent,id)->resolve_module~mark_substituted:true~add_canonical:trueenvparent|>map_error(fune->`Parent(`Parent_modulee))>>=fun(p,m)->letm=Component.Delayed.getminexpansion_of_module_cachedenvpm|>map_error(fune->`Parent(`Parent_sige))>>=assert_not_functor>>=funsg->letsub=prefix_substitution(`Modulep)sginhandle_class_type_lookupid(`Modulep)sg>>=fun(p',t')->lett=matcht'with|`FClass(name,c)->`FClass(name,Subst.class_subc)|`FClassType(name,ct)->`FClassType(name,Subst.class_typesubct)|`FType_removed(name,texpr,eq)->`FType_removed(name,Subst.type_exprsubtexpr,eq)inOk(p',t)|`Identifier(i,_)->leti'=`Identifieriinletid=`Gpathi'inlookup_class_typeenvid>>=funt->Ok(id,t)|`Resolvedr->lookup_class_typeenvr>>=funt->Ok(r,t)|`Local(l,_)->Error(`LocalType(env,(l:>Ident.path_type)))|`Substituteds->resolve_class_typeenvs>>=fun(p,m)->Ok(`Substitutedp,m)|`Class(parent,id)->lookup_parent~mark_substituted:trueenvparent|>map_error(fune->(e:>simple_type_lookup_error))>>=fun(parent_sig,sub)->lett=matchFind.type_in_sigparent_sig(ClassName.to_stringid)with|Some(`FClass(name,t))->Some(`Class(parent,name),`FClass(name,Subst.class_subt))|Some_->None|None->Noneinof_option~error:`Find_failuret|`ClassType(parent,id)->lookup_parent~mark_substituted:trueenvparent|>map_error(fune->(e:>simple_type_lookup_error))>>=fun(parent_sg,sub)->handle_class_type_lookup(ClassTypeName.to_stringid)parentparent_sg>>=fun(p',t')->lett=matcht'with|`FClass(name,c)->`FClass(name,Subst.class_subc)|`FClassType(name,ct)->`FClassType(name,Subst.class_typesubct)|`FType_removed(name,texpr,eq)->`FType_removed(name,Subst.type_exprsubtexpr,eq)inOk(p',t)andreresolve_module_gpath:Env.t->Odoc_model.Paths.Path.Resolved.Module.t->Odoc_model.Paths.Path.Resolved.Module.t=funenvpath->matchpathwith|`Identifier_->path|`Apply(functor_path,argument_path)->`Apply(reresolve_module_gpathenvfunctor_path,reresolve_module_gpathenvargument_path)|`Module(parent,name)->`Module(reresolve_module_gpathenvparent,name)|`Alias(p1,p2)->letdest'=reresolve_module_gpathenvp1inifOdoc_model.Paths.Path.Resolved.Module.is_hidden~weak_canonical_test:falsedest'thenletcp2=Component.Of_Lang.(module_path(empty())p2)inmatchresolve_moduleenv~mark_substituted:false~add_canonical:truecp2with|Ok(`Alias(_,_,Somep3),_)->letp=reresolve_moduleenvp3inLang_of.(Path.resolved_module(empty())p)|_->`Alias(dest',p2)else`Alias(dest',p2)|`Subst(p1,p2)->`Subst(reresolve_module_type_gpathenvp1,reresolve_module_gpathenvp2)|`Hiddenp->letp'=reresolve_module_gpathenvpin`Hiddenp'|`Canonical(p,`Resolvedp2)->`Canonical(reresolve_module_gpathenvp,`Resolved(reresolve_module_gpathenvp2))|`Canonical(p,p2)->`Canonical(reresolve_module_gpathenvp,handle_canonical_moduleenvp2)|`OpaqueModulem->`OpaqueModule(reresolve_module_gpathenvm)andstrip_canonical:c:Odoc_model.Paths.Path.Module.t->Cpath.Resolved.module_->Cpath.Resolved.module_=fun~cpath->matchpathwith|`Canonical(x,y)wheny=c->strip_canonical~cx|`Canonical(x,y)->`Canonical(strip_canonical~cx,y)|`Alias(x,y,z)->`Alias(strip_canonical~cx,y,z)|`Subst(x,y)->`Subst(x,strip_canonical~cy)|`Hiddenx->`Hidden(strip_canonical~cx)|`OpaqueModulex->`OpaqueModule(strip_canonical~cx)|`Substitutedx->`Substituted(strip_canonical~cx)|`Gpathp->`Gpath(strip_canonical_gpath~cp)|`Local_|`Apply_|`Module_->pathandstrip_canonical_gpath:c:Odoc_model.Paths.Path.Module.t->Odoc_model.Paths.Path.Resolved.Module.t->Odoc_model.Paths.Path.Resolved.Module.t=fun~cpath->matchpathwith|`Canonical(x,y)wheny=c->strip_canonical_gpath~cx|`Canonical(x,y)->`Canonical(strip_canonical_gpath~cx,y)|`Alias(x,y)->`Alias(strip_canonical_gpath~cx,y)|`Subst(x,y)->`Subst(x,strip_canonical_gpath~cy)|`Hiddenx->`Hidden(strip_canonical_gpath~cx)|`OpaqueModulex->`OpaqueModule(strip_canonical_gpath~cx)|`Apply_|`Module_|`Identifier_->pathandreresolve_module:Env.t->Cpath.Resolved.module_->Cpath.Resolved.module_=funenvpath->matchpathwith|`Local_->path|`Gpathg->`Gpath(reresolve_module_gpathenvg)|`Substitutedx->`Substituted(reresolve_moduleenvx)|`Apply(functor_path,argument_path)->`Apply(reresolve_moduleenvfunctor_path,reresolve_moduleenvargument_path)|`Module(parent,name)->`Module(reresolve_parentenvparent,name)|`Alias(p1,p2,p3opt)->letdest'=reresolve_moduleenvp1inifCpath.is_resolved_module_hidden~weak_canonical_test:falsedest'thenmatchp3optwith|Somep3->reresolve_moduleenvp3|None->(matchresolve_moduleenv~mark_substituted:false~add_canonical:truep2with|Ok(`Alias(_,_,Somep3),_)->reresolve_moduleenvp3|_->`Alias(dest',p2,None))else`Alias(dest',p2,p3opt)|`Subst(p1,p2)->`Subst(reresolve_module_typeenvp1,reresolve_moduleenvp2)|`Hiddenp->letp'=reresolve_moduleenvpin`Hiddenp'|`Canonical(p,`Resolvedp2)->letcp2=Component.Of_Lang.(resolved_module_path(empty())p2)inletcp2'=reresolve_moduleenvcp2inletp2'=Lang_of.(Path.resolved_module(empty())cp2')in`Canonical(reresolve_moduleenvp,`Resolvedp2')|`Canonical(p,p2)->(matchhandle_canonical_moduleenvp2with|`Resolved_asr->`Canonical(p,r)|r->`Canonical(reresolve_moduleenvp,r))|`OpaqueModulem->`OpaqueModule(reresolve_moduleenvm)andhandle_canonical_module_realenvp2=(* Canonical paths are always fully qualified, but this isn't
necessarily good for rendering, as the full path would
always be written out whenever a canonical module path is
encountered.
Instead the intent of this code is to try to find the shortest
path that still correctly references the canonical module.
It works by starting with the fully qualified path, e.g.
A.B.C.D where A is a root module. It then makes the list
of possibilities (A).B.C.D (A.B).C.D (A.B.C).D and (A.B.C.D)
where brackets represent the part that's an identifier.
It then resolved each one in turn and calculates the
identifier of the resolved path. The shortest path that
has the same identifier as the fully-qualified path is
chosen as the canonical path.
When doing this, we end up resolving each possibility.
Additionally, we need to 'reresolve' - resolve the canonical
references - while we're doing this. This is because the
parent parts of the resolved path can contain aliases and
canonical paths themselves which require resolving in order
to check the identifier is the same.
However, we first need to strip off any alias/canonical paths
in the resolved module, as we want the identifier for the
module itself, not any aliased module, and the canonical path
_ought_ to be the same as the one we're _currently_ resolving
anyway, so we'd end up looping forever. Note that it's not
sufficient to simply ask not to add on the canonical paths
at this point (ie, ~add_canonical=false) as the alias chain
may include modules that have already been resolved and hence
have canonical constructors in their resolved paths.
*)(* [strip p] strips the top-level aliases and canonical paths from
the path [p]. Any aliases/canonicals in parents are left as is. *)letstrip:Cpath.Resolved.module_->Cpath.Resolved.module_=funx->matchxwith`Alias(_,_,Somep)->strip_canonical~c:p2p|_->xin(* Resolve the path, then 'reresolve', making sure to strip off the
top-level alias and canonicals to avoid looping forever *)letresolveenvp=resolve_moduleenv~mark_substituted:false~add_canonical:falsep>>=fun(p,m)->Ok(reresolve_moduleenv(stripp),m)inletlang_ofcpath=(Lang_of.(Path.resolved_module(empty())cpath):>Odoc_model.Paths.Path.Resolved.t)inletcp2=Component.Of_Lang.(module_path(empty())p2)inmatchcanonical_helperenvresolvelang_ofc_mod_posscp2with|None->p2|Some(rp,m)->letm=Component.Delayed.getmin(* Need to check if the module we're going to link to has been expanded.
ModuleTypes are always expanded if possible, but Aliases are only expanded
if they're an alias to a hidden module or if they're self canonical.
Checking if a module is self canonical is a bit tricky, since this function
is itself part of the process of resolving any canonical reference. Hence
what we do here is to look through alias chains looking for one that's marked
with the same _unresolved_ canonical path that we're currently trying to resolve.
This is particularly important because some modules don't know they're canonical!
For example the module Caml in base, which is marked as the canonical path for
all references to the standard library in the file [import0.ml], but is itself just
defined by including [Stdlib].
If a module doesn't know it's canonical, it will fail the self-canonical check, and
therefore not necessarily be expanded. If this happens, we call [process_module_path]
to stick the [`Alias] constructor back on so we'll link to the correct place. *)letexpanded=matchm.type_with|Component.Module.Alias(_,Some_)->true|Alias(p,None)->(matchresolve_module~mark_substituted:false~add_canonical:falseenvpwith|Ok(rp,_)->(* we're an alias - check to see if we're marked as the canonical path.
If not, check for an alias chain with us as canonical in it... *)letreccheckm=matchm.Component.Module.canonicalwith|Somep->p=p2(* The canonical path is the same one we're trying to resolve *)|None->(matchm.type_with|Component.Module.Alias(p,_)->(matchresolve_module~mark_substituted:false~add_canonical:falseenvpwith|Ok(rp,_)->(matchlookup_module~mark_substituted:falseenvrpwith|Error_->false|Okm->letm=Component.Delayed.getmincheckm)|_->false)|_->false)inletself_canonical()=checkminlethidden=Cpath.is_resolved_module_hidden~weak_canonical_test:truerpinhidden||self_canonical()|_->false)|ModuleType_->trueinletcpath=ifexpandedthenrpelseprocess_module_pathenv~add_canonical:falsemrpinLang_of.(Path.module_(empty())(`Resolvedcpath))andhandle_canonical_moduleenvp2=HandleCanonicalModuleMemo.memoizehandle_canonical_module_realenvp2andhandle_canonical_module_typeenvp2=letcp2=Component.Of_Lang.(module_type_path(empty())p2)inletstrip_alias:Cpath.Resolved.module_type->Cpath.Resolved.module_type=function|`AliasModuleType(_,p)->p|p->pinletresolveenvp=resolve_module_typeenv~mark_substituted:false~add_canonical:falsep>>=fun(p,m)->(* Note, we reresolve here in case any parent module has a canonical
constructor to deal with - we know there's no canonicalmoduletype as we've
explicitly asked for it not to be added *)Ok(reresolve_module_typeenv(strip_aliasp),m)inletlang_ofcpath=(Lang_of.(Path.resolved_module_type(empty())cpath):>Odoc_model.Paths.Path.Resolved.t)inmatchcanonical_helperenvresolvelang_ofc_modty_posscp2with|None->p2|Some(rp,_)->`ResolvedLang_of.(Path.resolved_module_type(empty())rp)andhandle_canonical_typeenvp2=letcp2=Component.Of_Lang.(type_path(empty())p2)inletlang_ofcpath=(Lang_of.(Path.resolved_type(empty())cpath):>Odoc_model.Paths.Path.Resolved.t)inletresolveenvp=matchresolve_typeenv~add_canonical:falsepwith|Ok(_,`FType_removed_)->Error`Find_failure|Ok(x,y)->(* See comment in handle_canonical_module_type for why we're reresolving here *)Ok(reresolve_typeenvx,y)|Errory->Erroryinmatchcanonical_helperenvresolvelang_ofc_ty_posscp2with|None->p2|Some(rp,_)->`ResolvedLang_of.(Path.resolved_type(empty())rp)andhandle_canonical_datatypeenvp2=letcp2=Component.Of_Lang.(datatype(empty())p2)inletlang_ofcpath=(Lang_of.(Path.resolved_datatype(empty())cpath):>Odoc_model.Paths.Path.Resolved.t)inletresolveenvp=matchresolve_datatypeenv~add_canonical:falsepwith|Ok(_,`FType_removed_)->Error`Find_failure|Ok(x,y)->(* See comment in handle_canonical_module_type for why we're reresolving here *)Ok(reresolve_datatypeenvx,y)|Errory->Erroryinmatchcanonical_helperenvresolvelang_ofc_daty_posscp2with|None->p2|Some(rp,_)->`ResolvedLang_of.(Path.resolved_datatype(empty())rp)andreresolve_module_type_gpath:Env.t->Odoc_model.Paths.Path.Resolved.ModuleType.t->Odoc_model.Paths.Path.Resolved.ModuleType.t=funenvpath->matchpathwith|`Identifier_->path|`ModuleType(parent,name)->`ModuleType(reresolve_module_gpathenvparent,name)|`CanonicalModuleType(p1,(`Resolved_asp2))->`CanonicalModuleType(reresolve_module_type_gpathenvp1,p2)|`CanonicalModuleType(p1,p2)->`CanonicalModuleType(reresolve_module_type_gpathenvp1,handle_canonical_module_typeenvp2)|`SubstT(p1,p2)->`SubstT(reresolve_module_type_gpathenvp1,reresolve_module_type_gpathenvp2)|`AliasModuleType(p1,p2)->`AliasModuleType(reresolve_module_type_gpathenvp1,reresolve_module_type_gpathenvp2)|`OpaqueModuleTypem->`OpaqueModuleType(reresolve_module_type_gpathenvm)andreresolve_module_type:Env.t->Cpath.Resolved.module_type->Cpath.Resolved.module_type=funenvpath->matchpathwith|`Local_->path|`Gpathg->`Gpath(reresolve_module_type_gpathenvg)|`Substitutedx->`Substituted(reresolve_module_typeenvx)|`ModuleType(parent,name)->`ModuleType(reresolve_parentenvparent,name)|`CanonicalModuleType(p1,(`Resolved_asp2'))->`CanonicalModuleType(reresolve_module_typeenvp1,p2')|`CanonicalModuleType(p1,p2)->`CanonicalModuleType(reresolve_module_typeenvp1,handle_canonical_module_typeenvp2)|`SubstT(p1,p2)->`SubstT(reresolve_module_typeenvp1,reresolve_module_typeenvp2)|`AliasModuleType(p1,p2)->`AliasModuleType(reresolve_module_typeenvp1,reresolve_module_typeenvp2)|`OpaqueModuleTypem->`OpaqueModuleType(reresolve_module_typeenvm)andreresolve_type:Env.t->Cpath.Resolved.type_->Cpath.Resolved.type_=funenvpath->letresult=matchpathwith|`Gpath_|`Local_->path|`Substituteds->`Substituted(reresolve_typeenvs)|`CanonicalType(p1,p2)->`CanonicalType(reresolve_typeenvp1,handle_canonical_typeenvp2)|`Type(p,n)->`Type(reresolve_parentenvp,n)|`Class(p,n)->`Class(reresolve_parentenvp,n)|`ClassType(p,n)->`ClassType(reresolve_parentenvp,n)inresultandreresolve_datatype:Env.t->Cpath.Resolved.datatype->Cpath.Resolved.datatype=funenvpath->letresult=matchpathwith|`Gpath_|`Local_->path|`Substituteds->`Substituted(reresolve_datatypeenvs)|`CanonicalDataType(p1,p2)->`CanonicalDataType(reresolve_datatypeenvp1,handle_canonical_datatypeenvp2)|`Type(p,n)->`Type(reresolve_parentenvp,n)inresultandreresolve_value:Env.t->Cpath.Resolved.value->Cpath.Resolved.value=funenv(`Value(p,n))->`Value(reresolve_parentenvp,n)andreresolve_constructor:Env.t->Cpath.Resolved.constructor->Cpath.Resolved.constructor=funenv(`Constructor(p,n))->`Constructor(reresolve_datatypeenvp,n)andreresolve_class_type:Env.t->Cpath.Resolved.class_type->Cpath.Resolved.class_type=funenvpath->letresult=matchpathwith|`Gpath_|`Local_->path|`Substituteds->`Substituted(reresolve_class_typeenvs)|`Class(p,n)->`Class(reresolve_parentenvp,n)|`ClassType(p,n)->`ClassType(reresolve_parentenvp,n)inresultandreresolve_parent:Env.t->Cpath.Resolved.parent->Cpath.Resolved.parent=funenvpath->matchpathwith|`Modulem->`Module(reresolve_moduleenvm)|`ModuleTypemty->`ModuleType(reresolve_module_typeenvmty)|`FragmentRoot->path(* *)andmodule_type_expr_of_module_decl:Env.t->Component.Module.decl->(Component.ModuleType.expr,simple_module_type_expr_of_module_error)Result.result=funenvdecl->matchdeclwith|Component.Module.Alias(`Resolvedr,_)->lookup_module~mark_substituted:falseenvr|>map_error(fune->`Parent(`Parent_modulee))>>=funm->letm=Component.Delayed.getminmodule_type_expr_of_module_declenvm.type_|Component.Module.Alias(path,_)->(matchresolve_module~mark_substituted:false~add_canonical:trueenvpathwith|Ok(_,m)->letm=Component.Delayed.getminmodule_type_expr_of_moduleenvm|Error_whenCpath.is_module_forwardpath->Error`UnresolvedForwardPath|Errore->Error(`UnresolvedPath(`Module(path,e))))|Component.Module.ModuleTypeexpr->Okexprandmodule_type_expr_of_module:Env.t->Component.Module.t->(Component.ModuleType.expr,simple_module_type_expr_of_module_error)Result.result=funenvm->module_type_expr_of_module_declenvm.type_andexpansion_of_module_path:Env.t->strengthen:bool->Cpath.module_->(expansion,expansion_of_module_error)Result.result=funenv~strengthenpath->matchresolve_module~mark_substituted:true~add_canonical:trueenvpathwith|Ok(p',m)->(letm=Component.Delayed.getmin(* p' is the path to the aliased module *)letstrengthen=strengthen&¬(Cpath.is_resolved_module_hidden~weak_canonical_test:truep')inexpansion_of_module_cachedenvp'm>>=function|Signaturesg->letsg'=matchm.docwith|[]->sg|docs->{sgwithitems=Comment(`Docsdocs)::sg.items}inifstrengthenthenOk(Signature(Strengthen.signature(`Resolvedp')sg'))elseOk(Signaturesg')|Functor_asf->Okf)|Error_whenCpath.is_module_forwardpath->Error`UnresolvedForwardPath|Errore->Error(`UnresolvedPath(`Module(path,e)))andhandle_signature_with_subs:mark_substituted:bool->Env.t->Component.Signature.t->Component.ModuleType.substitutionlist->(Component.Signature.t,expansion_of_module_error)Result.result=fun~mark_substitutedenvsgsubs->letopenResultMonadinList.fold_left(funsg_optsub->sg_opt>>=funsg->fragmap~mark_substitutedenvsubsg)(Oksg)subsandassert_not_functor:typeerr.expansion->(Component.Signature.t,err)Result.result=function|Signaturesg->Oksg|_->assertfalseandunresolve_subssubs=List.map(function|Component.ModuleType.ModuleEq(`Resolvedf,m)->Component.ModuleType.ModuleEq(Cfrag.unresolve_modulef,m)|ModuleSubst(`Resolvedf,m)->ModuleSubst(Cfrag.unresolve_modulef,m)|TypeEq(`Resolvedf,t)->TypeEq(Cfrag.unresolve_typef,t)|TypeSubst(`Resolvedf,t)->TypeSubst(Cfrag.unresolve_typef,t)|x->x)subsandsignature_of_u_module_type_expr:mark_substituted:bool->Env.t->Component.ModuleType.U.expr->(Component.Signature.t,expansion_of_module_error)Result.result=fun~mark_substitutedenvm->matchmwith|Component.ModuleType.U.Pathp->(matchresolve_module_type~mark_substituted~add_canonical:trueenvpwith|Ok(_,mt)->expansion_of_module_typeenvmt>>=assert_not_functor|Errore->Error(`UnresolvedPath(`ModuleType(p,e))))|Signatures->Oks|With(subs,s)->signature_of_u_module_type_expr~mark_substitutedenvs>>=funsg->letsubs=unresolve_subssubsinhandle_signature_with_subs~mark_substitutedenvsgsubs|TypeOf{t_expansion=Some(Signaturesg);_}->Oksg|TypeOf{t_desc;_}->Error(`UnexpandedTypeOft_desc)(* and expansion_of_simple_expansion :
Component.ModuleType.simple_expansion -> expansion =
let rec helper :
Component.ModuleType.simple_expansion -> Component.ModuleType.expr =
function
| Signature sg -> Signature sg
| Functor (arg, e) -> Functor (arg, helper e)
in
function
| Signature sg -> Signature sg
| Functor (arg, e) -> Functor (arg, helper e) *)andexpansion_of_module_type_expr:mark_substituted:bool->Env.t->Component.ModuleType.expr->(expansion,expansion_of_module_error)Result.result=fun~mark_substitutedenvm->matchmwith(* | Component.ModuleType.Path { p_expansion = Some e; _ } ->
Ok (expansion_of_simple_expansion e) *)|Component.ModuleType.Path{p_path;_}->(matchresolve_module_type~mark_substituted~add_canonical:trueenvp_pathwith|Ok(_,mt)->expansion_of_module_typeenvmt|Errore->Error(`UnresolvedPath(`ModuleType(p_path,e))))|Component.ModuleType.Signatures->Ok(Signatures)(* | Component.ModuleType.With { w_expansion = Some e; _ } ->
Ok (signature_of_simple_expansion e)
Recalculate 'With' expressions always, as we need to know which
items have been removed
*)|Component.ModuleType.With{w_substitutions;w_expr;_}->signature_of_u_module_type_expr~mark_substitutedenvw_expr>>=funsg->letsubs=unresolve_subsw_substitutionsinhandle_signature_with_subs~mark_substitutedenvsgsubs>>=funsg->Ok(Signaturesg)|Component.ModuleType.Functor(arg,expr)->Ok(Functor(arg,expr))|Component.ModuleType.TypeOf{t_expansion=Some(Signaturesg);_}->Ok(Signaturesg)|Component.ModuleType.TypeOf{t_desc;_}->Error(`UnexpandedTypeOft_desc)andexpansion_of_module_type:Env.t->Component.ModuleType.t->(expansion,expansion_of_module_error)Result.result=funenvm->matchm.exprwith|None->Error`OpaqueModule|Someexpr->expansion_of_module_type_expr~mark_substituted:falseenvexprandexpansion_of_module_decl:Env.t->Component.Module.decl->(expansion,expansion_of_module_error)Result.result=funenvdecl->matchdeclwith(* | Component.Module.Alias (_, Some e) -> Ok (expansion_of_simple_expansion e) *)|Component.Module.Alias(p,_)->expansion_of_module_pathenv~strengthen:truep|Component.Module.ModuleTypeexpr->expansion_of_module_type_expr~mark_substituted:falseenvexprandexpansion_of_module:Env.t->Component.Module.t->(expansion,expansion_of_module_error)Result.result=funenvm->expansion_of_module_declenvm.type_andexpansion_of_module_cached:Env.t->Cpath.Resolved.module_->Component.Module.t->(expansion,expansion_of_module_error)Result.result=funenv'pathm->letid=pathinletrunenv_id=expansion_of_moduleenvminExpansionOfModuleMemo.memoizerunenv'idandumty_of_mty:Component.ModuleType.expr->Component.ModuleType.U.expr=function|Signaturesg->Signaturesg|Path{p_path;_}->Pathp_path|TypeOft->TypeOft|With{w_substitutions;w_expr;_}->With(w_substitutions,w_expr)|Functor_->assertfalseandfragmap:mark_substituted:bool->Env.t->Component.ModuleType.substitution->Component.Signature.t->(Component.Signature.t,expansion_of_module_error)Result.result=fun~mark_substitutedenvsubsg->(* Used when we haven't finished the substitution. For example, if the
substitution is `M.t = u`, this function is used to map the declaration
of `M` to be `M : ... with type t = u` *)letmap_module_decldeclsubst=letopenComponent.Moduleinmatchdeclwith|Alias(path,_)->expansion_of_module_pathenv~strengthen:truepath>>=assert_not_functor>>=funsg->Ok(ModuleType(With{w_substitutions=[subst];w_expansion=None;w_expr=TypeOf{t_desc=StructIncludepath;t_expansion=Some(Signaturesg);};}))|ModuleTypemty'->Ok(ModuleType(With{w_substitutions=[subst];w_expansion=None;w_expr=umty_of_mtymty';}))inletmap_include_decldeclsubst=letopenComponent.Includeinmatchdeclwith|Aliasp->expansion_of_module_pathenv~strengthen:truep>>=assert_not_functor>>=funsg->fragmap~mark_substitutedenvsubstsg>>=funsg->Ok(ModuleType(Signaturesg))|ModuleTypemty'->Ok(ModuleType(With([subst],mty')))inletmap_modulemnew_subst=letopenComponent.Moduleinmap_module_declm.type_new_subst>>=funtype_->Ok(Left{mwithtype_})inletrecmap_signaturemapitems=List.fold_right(funitemacc->acc>>=fun(items,handled,subbed_modules,removed)->match(item,map)with|Component.Signature.Type(id,r,t),{type_=Some(id',fn);_}whenIdent.Name.type_id=id'->(fn(Component.Delayed.gett)>>=function|Leftx->Ok(Component.Signature.Type(id,r,Component.Delayed.put(fun()->x))::items,true,subbed_modules,removed)|Right(texpr,eq)->Ok(items,true,subbed_modules,Component.Signature.RType(id,texpr,eq)::removed))|Component.Signature.Module(id,r,m),{module_=Some(id',fn);_}whenIdent.Name.module_id=id'->(fn(Component.Delayed.getm)>>=function|Leftx->Ok(Component.Signature.Module(id,r,Component.Delayed.put(fun()->x))::items,true,id::subbed_modules,removed)|Righty->Ok(items,true,subbed_modules,Component.Signature.RModule(id,y)::removed))|Component.Signature.Include({expansion_;_}asi),_->map_signaturemapexpansion_.items>>=fun(items',handled',subbed_modules',removed')->letcomponent=ifhandled'thenmap_include_decli.declsub>>=fundecl->letexpansion_=Component.Signature.{expansion_withitems=items';removed=removed';compiled=false;}inOk(Component.Signature.Include{iwithdecl;expansion_;strengthened=None})elseOkitemincomponent>>=func->Ok(c::items,handled'||handled,subbed_modules'@subbed_modules,removed'@removed)|(Component.Signature.ModuleType(id,mt),{module_type=Some(id',fn);_})whenIdent.Name.module_typeid=id'->(fn(Component.Delayed.getmt)>>=function|Leftx->Ok(Component.Signature.ModuleType(id,Component.Delayed.put(fun()->x))::items,true,subbed_modules,removed)|Righty->Ok(items,true,subbed_modules,Component.Signature.RModuleType(id,y)::removed))|x,_->Ok(x::items,handled,subbed_modules,removed))items(Ok([],false,[],[]))inlethandle_intermediatenamenew_subst=letmodmaps=Some(name,funm->map_modulemnew_subst)inmap_signature{id_mapwithmodule_=modmaps}sg.itemsinletnew_sg=matchsubwith|ModuleEq(frag,type_)->(matchCfrag.module_splitfragwith|name,Somefrag'->letnew_subst=Component.ModuleType.ModuleEq(frag',type_)inhandle_intermediatenamenew_subst|name,None->letmapfnm=lettype_=letopenComponent.Moduleinmatchtype_with|Alias(`Resolvedp,_)->letnew_p=ifmark_substitutedthen`SubstitutedpelsepinAlias(`Resolvednew_p,None)|Alias_|ModuleType_->type_inOk(Left{mwithComponent.Module.type_})inmap_signature{id_mapwithmodule_=Some(name,mapfn)}sg.items)|ModuleSubst(frag,p)->(matchCfrag.module_splitfragwith|name,Somefrag'->letnew_subst=Component.ModuleType.ModuleSubst(frag',p)inhandle_intermediatenamenew_subst|name,None->letmapfn_=matchresolve_module~mark_substituted~add_canonical:falseenvpwith|Ok(p,_)->Ok(Rightp)|Errore->Error(`UnresolvedPath(`Module(p,e)))inmap_signature{id_mapwithmodule_=Some(name,mapfn)}sg.items)|ModuleTypeEq(frag,mtye)->(matchCfrag.module_type_splitfragwith|name,Somefrag'->letnew_subst=Component.ModuleType.ModuleTypeEq(frag',mtye)inhandle_intermediatenamenew_subst|name,None->letmapfnt=Ok(Left{twithComponent.ModuleType.expr=Somemtye})inmap_signature{id_mapwithmodule_type=Some(name,mapfn)}sg.items)|ModuleTypeSubst(frag,mtye)->(matchCfrag.module_type_splitfragwith|name,Somefrag'->letnew_subst=Component.ModuleType.ModuleTypeSubst(frag',mtye)inhandle_intermediatenamenew_subst|name,None->letmapfn_t=Ok(Rightmtye)inmap_signature{id_mapwithmodule_type=Some(name,mapfn)}sg.items)|TypeEq(frag,equation)->(matchCfrag.type_splitfragwith|name,Somefrag'->letnew_subst=Component.ModuleType.TypeEq(frag',equation)inhandle_intermediatenamenew_subst|name,None->letmapfnt=Ok(Left{twithComponent.TypeDecl.equation})inmap_signature{id_mapwithtype_=Some(name,mapfn)}sg.items)|TypeSubst(frag,({Component.TypeDecl.Equation.manifest=Somex;_}asequation))->(matchCfrag.type_splitfragwith|name,Somefrag'->letnew_subst=Component.ModuleType.TypeSubst(frag',equation)inhandle_intermediatenamenew_subst|name,None->letmapfn_t=Ok(Right(x,equation))inmap_signature{id_mapwithtype_=Some(name,mapfn)}sg.items)|TypeSubst(_,{Component.TypeDecl.Equation.manifest=None;_})->failwith"Unhandled condition: TypeSubst with no manifest"innew_sg>>=fun(items,_handled,subbed_modules,removed)->letsub_of_removedremovedsub=matchremovedwith|Component.Signature.RModule(id,p)->Subst.add_module(id:>Ident.path_module)(`Resolvedp)psub|Component.Signature.RType(id,r_texpr,r_eq)->Subst.add_type_replacement(id:>Ident.path_type)r_texprr_eqsub|Component.Signature.RModuleType(id,e)->Subst.add_module_type_replacement(id:>Ident.module_type)esubinletsub=List.fold_rightsub_of_removedremovedSubst.identityinletmap_itemsitems=(* Invalidate resolved paths containing substituted idents - See the `With11`
test for an example of why this is necessary *)letsub_of_substitutedxsub=letx=(x:>Ident.path_module)in(ifmark_substitutedthenSubst.add_module_substitutionxsubelsesub)|>Subst.path_invalidate_modulex|>Subst.mto_invalidate_modulexinletsubstituted_sub=List.fold_rightsub_of_substitutedsubbed_modulesSubst.identityin(* Need to call `apply_sig_map` directly as we're substituting for an item
that's declared within the signature *)letitems,_,_=Subst.apply_sig_mapsubstituted_subitems[]in(* Finished marking substituted stuff *)itemsinletitems=map_itemsitemsinletres=Subst.signaturesub{Component.Signature.items;removed=removed@sg.removed;compiled=false;doc=sg.doc;}inOkresandfind_external_module_path:Cpath.Resolved.module_->Cpath.Resolved.module_option=funp->letopenOptionMonadinmatchpwith|`Subst(x,y)->find_external_module_type_pathx>>=funx->find_external_module_pathy>>=funy->Some(`Subst(x,y))|`Module(p,n)->find_external_parent_pathp>>=funp->Some(`Module(p,n))|`Localx->Some(`Localx)|`Substitutedx->find_external_module_pathx>>=funx->Some(`Substitutedx)|`Canonical(x,y)->find_external_module_pathx>>=funx->Some(`Canonical(x,y))|`Hiddenx->find_external_module_pathx>>=funx->Some(`Hiddenx)|`Alias_->None|`Apply(x,y)->find_external_module_pathx>>=funx->find_external_module_pathy>>=funy->Some(`Apply(x,y))|`Gpathx->Some(`Gpathx)|`OpaqueModulem->find_external_module_pathm>>=funx->Some(`OpaqueModulex)andfind_external_module_type_path:Cpath.Resolved.module_type->Cpath.Resolved.module_typeoption=funp->letopenOptionMonadinmatchpwith|`ModuleType(p,name)->find_external_parent_pathp>>=funp->Some(`ModuleType(p,name))|`Local_->Somep|`SubstT(x,y)->find_external_module_type_pathx>>=funx->find_external_module_type_pathy>>=funy->Some(`SubstT(x,y))|`CanonicalModuleType(x,_)|`Substitutedx->find_external_module_type_pathx>>=funx->Some(`Substitutedx)|`Gpath_->Somep|`AliasModuleType(x,y)->(match(find_external_module_type_pathx,find_external_module_type_pathy)with|Somex,Somey->Some(`AliasModuleType(x,y))|Somex,None->Somex|None,Somex->Somex|None,None->None)|`OpaqueModuleTypem->find_external_module_type_pathm>>=funx->Some(`OpaqueModuleTypex)andfind_external_parent_path:Cpath.Resolved.parent->Cpath.Resolved.parentoption=funp->letopenOptionMonadinmatchpwith|`Modulem->find_external_module_pathm>>=funm->Some(`Modulem)|`ModuleTypem->find_external_module_type_pathm>>=funm->Some(`ModuleTypem)|`FragmentRoot->Noneandfixup_module_cfrag(f:Cfrag.resolved_module):Cfrag.resolved_module=matchfwith|`Subst(path,frag)->(matchfind_external_module_type_pathpathwith|Somep->`Subst(p,frag)|None->frag)|`Alias(path,frag)->(matchfind_external_module_pathpathwith|Somep->`Alias(p,frag)|None->frag)|`Module(parent,name)->`Module(fixup_signature_cfragparent,name)|`OpaqueModulem->`OpaqueModule(fixup_module_cfragm)andfixup_module_type_cfrag(f:Cfrag.resolved_module_type):Cfrag.resolved_module_type=matchfwith|`ModuleType(parent,name)->`ModuleType(fixup_signature_cfragparent,name)andfixup_signature_cfrag(f:Cfrag.resolved_signature)=matchfwith|`Rootx->`Rootx|(`OpaqueModule_|`Subst_|`Alias_|`Module_)asf->(fixup_module_cfragf:>Cfrag.resolved_signature)andfixup_type_cfrag(f:Cfrag.resolved_type):Cfrag.resolved_type=matchfwith|`Type(p,x)->`Type(fixup_signature_cfragp,x)|`Class(p,x)->`Class(fixup_signature_cfragp,x)|`ClassType(p,x)->`ClassType(fixup_signature_cfragp,x)andfind_module_with_replacement:Env.t->Component.Signature.t->string->(Component.Module.tComponent.Delayed.t,simple_module_lookup_error)Result.result=funenvsgname->matchFind.careful_module_in_sigsgnamewith|Some(`FModule(_,m))->Ok(Component.Delayed.put_valm)|Some(`FModule_removedpath)->lookup_module~mark_substituted:falseenvpath|None->Error`Find_failureandfind_module_type_with_replacement:Env.t->Component.Signature.t->string->(Component.ModuleType.tComponent.Delayed.t,simple_module_type_lookup_error)Result.result=fun_envsgname->matchFind.careful_module_type_in_sigsgnamewith|Some(`FModuleType(_,m))->Ok(Component.Delayed.put_valm)|None->Error`Find_failure|Some(`FModuleType_removed_mty)->Error`Find_failureandresolve_signature_fragment:Env.t->Cfrag.root*Component.Signature.t->Cfrag.signature->(Cfrag.resolved_signature*Cpath.Resolved.parent*Component.Signature.t)option=funenv(p,sg)frag->matchfragwith|`Root->letsg=prefix_signature(`FragmentRoot,sg)inSome(`Rootp,`FragmentRoot,sg)|`Resolved_r->None|`Dot(parent,name)->letopenOptionMonadinresolve_signature_fragmentenv(p,sg)parent>>=fun(pfrag,ppath,sg)->of_result(find_module_with_replacementenvsgname)>>=funm'->letmname=ModuleName.make_stdnameinletnew_path=`Module(ppath,mname)inletnew_frag=`Module(pfrag,mname)inletm'=Component.Delayed.getm'inletmodifier=get_module_path_modifiersenv~add_canonical:falsem'inletcp',f'=matchmodifierwith|None->(new_path,new_frag)|Some(`Aliasedp')->(`Alias(p',`Resolvednew_path,None),`Alias(p',new_frag))|Some(`SubstMTp')->(`Subst(p',new_path),`Subst(p',new_frag))in(* Don't use the cached one - `FragmentRoot` is not unique *)of_resultResultMonad.(expansion_of_moduleenvm'>>=assert_not_functor)>>=funparent_sg->letsg=prefix_signature(`Modulecp',parent_sg)inSome(f',`Modulecp',sg)andresolve_module_fragment:Env.t->Cfrag.root*Component.Signature.t->Cfrag.module_->Cfrag.resolved_moduleoption=funenv(p,sg)frag->matchfragwith|`Resolvedr->Somer|`Dot(parent,name)->letopenOptionMonadinresolve_signature_fragmentenv(p,sg)parent>>=fun(pfrag,_ppath,sg)->of_result(find_module_with_replacementenvsgname)>>=funm'->letmname=ModuleName.make_stdnameinletnew_frag=`Module(pfrag,mname)inletm'=Component.Delayed.getm'inletmodifier=get_module_path_modifiersenv~add_canonical:falsem'inletf'=matchmodifierwith|None->new_frag|Some(`Aliasedp')->`Alias(p',new_frag)|Some(`SubstMTp')->`Subst(p',new_frag)inletf''=matchexpansion_of_moduleenvm'with|Ok(_m:expansion)->f'|Error`OpaqueModule->`OpaqueModulef'|Error(`UnresolvedForwardPath|`UnresolvedPath_)->f'|Error(`UnexpandedTypeOf_)->f'inSome(fixup_module_cfragf'')andresolve_module_type_fragment:Env.t->Cfrag.root*Component.Signature.t->Cfrag.module_type->Cfrag.resolved_module_typeoption=funenv(p,sg)frag->matchfragwith|`Resolvedr->Somer|`Dot(parent,name)->letopenOptionMonadinresolve_signature_fragmentenv(p,sg)parent>>=fun(pfrag,_ppath,sg)->of_result(find_module_type_with_replacementenvsgname)>>=funmt'->letmtname=ModuleTypeName.make_stdnameinletf'=`ModuleType(pfrag,mtname)inletm'=Component.Delayed.getmt'inletf''=matchexpansion_of_module_typeenvm'with|Ok(_m:expansion)->f'|Error(`UnresolvedForwardPath|`UnresolvedPath_|`OpaqueModule|`UnexpandedTypeOf_)->f'inSome(fixup_module_type_cfragf'')andresolve_type_fragment:Env.t->Cfrag.root*Component.Signature.t->Cfrag.type_->Cfrag.resolved_typeoption=funenv(p,sg)frag->matchfragwith|`Resolvedr->Somer|`Dot(parent,name)->letopenOptionMonadinresolve_signature_fragmentenv(p,sg)parent>>=fun(pfrag,_ppath,_sg)->letresult=fixup_type_cfrag(`Type(pfrag,TypeName.make_stdname))inSomeresultletrecreresolve_signature_fragment:Env.t->Cfrag.resolved_signature->Cfrag.resolved_signature=funenvm->matchmwith|`Root(`ModuleTypep)->`Root(`ModuleType(reresolve_module_typeenvp))|`Root(`Modulep)->`Root(`Module(reresolve_moduleenvp))|(`OpaqueModule_|`Subst_|`Alias_|`Module_)asx->(reresolve_module_fragmentenvx:>Cfrag.resolved_signature)andreresolve_module_fragment:Env.t->Cfrag.resolved_module->Cfrag.resolved_module=funenvm->matchmwith|`Subst(p,f)->letp'=reresolve_module_typeenvpin`Subst(p',reresolve_module_fragmentenvf)|`Alias(p,f)->letp'=reresolve_moduleenvpin`Alias(p',reresolve_module_fragmentenvf)|`OpaqueModulem->`OpaqueModule(reresolve_module_fragmentenvm)|`Module(sg,m)->`Module(reresolve_signature_fragmentenvsg,m)andreresolve_type_fragment:Env.t->Cfrag.resolved_type->Cfrag.resolved_type=funenvm->matchmwith|`Type(p,n)->`Type(reresolve_signature_fragmentenvp,n)|`ClassType(p,n)->`ClassType(reresolve_signature_fragmentenvp,n)|`Class(p,n)->`Class(reresolve_signature_fragmentenvp,n)andreresolve_module_type_fragment:Env.t->Cfrag.resolved_module_type->Cfrag.resolved_module_type=funenvm->matchmwith|`ModuleType(p,n)->`ModuleType(reresolve_signature_fragmentenvp,n)letrecclass_signature_of_class:Env.t->Component.Class.t->Component.ClassSignature.toption=funenvc->letrecinnerdecl=matchdeclwith|Component.Class.ClassTypee->class_signature_of_class_type_exprenve|Arrow(_,_,d)->innerdininnerc.type_andclass_signature_of_class_type_expr:Env.t->Component.ClassType.expr->Component.ClassSignature.toption=funenve->matchewith|Signatures->Somes|Constr(p,_)->(matchresolve_typeenv~add_canonical:true(p:>Cpath.type_)with|Ok(_,`FClass(_,c))->class_signature_of_classenvc|Ok(_,`FClassType(_,c))->class_signature_of_class_typeenvc|_->None)andclass_signature_of_class_type:Env.t->Component.ClassType.t->Component.ClassSignature.toption=funenvc->class_signature_of_class_type_exprenvc.exprletresolve_module_pathenvp=resolve_module~mark_substituted:true~add_canonical:trueenvp>>=fun(p,m)->matchpwith|`Gpath(`Identifier{iv=`Root_;_})|`Hidden(`Gpath(`Identifier{iv=`Root_;_}))->Okp|_->(letm=Component.Delayed.getminmatchexpansion_of_module_cachedenvpmwith|Ok_->Okp|Error`OpaqueModule->Ok(`OpaqueModulep)|Error(`UnresolvedForwardPath|`UnresolvedPath_)->Okp|Error(`UnexpandedTypeOf_)->Okp)letresolve_module_type_pathenvp=resolve_module_type~mark_substituted:true~add_canonical:trueenvp>>=fun(p,mt)->matchexpansion_of_module_typeenvmtwith|Ok_->Okp|Error`OpaqueModule->Ok(`OpaqueModuleTypep)|Error(`UnresolvedForwardPath|`UnresolvedPath_)|Error(`UnexpandedTypeOf_)->Okpletresolve_type_pathenvp=resolve_typeenv~add_canonical:truep>>=fun(p,_)->Okpletresolve_value_pathenvp=resolve_valueenvp>>=fun(p,_)->Okpletresolve_constructor_pathenvp=resolve_constructorenvp>>=fun(p,_)->Okpletresolve_class_type_pathenvp=resolve_class_typeenvp>>=fun(p,_)->Okp