1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105openComponentexceptionInvalidatedexceptionMTOInvalidatedtype('a,'b)or_replaced=Not_replacedof'a|Replacedof'btype'atype_or_replaced=('a,TypeExpr.t*TypeDecl.Equation.t)or_replacedtype'amodule_type_or_replaced=('a,ModuleType.expr)or_replacedletmap_replacedf=function|Not_replacedp->Not_replaced(fp)|Replaced_asr->ropenComponentopenSubstitutiontypenonrect=tletidentity={module_=PathModuleMap.empty;module_type=ModuleTypeMap.empty;module_type_replacement=ModuleTypeMap.empty;type_=PathTypeMap.empty;class_type=PathClassTypeMap.empty;type_replacement=PathTypeMap.empty;path_invalidating_modules=[];module_type_of_invalidating_modules=[];unresolve_opaque_paths=false;}letunresolve_opaque_pathss={swithunresolve_opaque_paths=true}letpath_invalidate_moduleidt={twithpath_invalidating_modules=id::t.path_invalidating_modules}letmto_invalidate_moduleidt={twithmodule_type_of_invalidating_modules=id::t.module_type_of_invalidating_modules;}letadd_moduleidprpt={twithmodule_=PathModuleMap.addid(`Prefixed(p,rp))t.module_}letadd_module_typeidprpt={twithmodule_type=ModuleTypeMap.addid(`Prefixed(p,rp))t.module_type;}letadd_type:Ident.type_->Cpath.type_->Cpath.Resolved.type_->t->t=funidprpt->{twithtype_=PathTypeMap.add(id:>Ident.path_type)(`Prefixed(p,rp))t.type_;}letadd_class:Ident.class_->Cpath.class_type->Cpath.Resolved.class_type->t->t=funidprpt->{twithtype_=PathTypeMap.add(id:>Ident.path_type)(`Prefixed((p:>Cpath.type_),(rp:>Cpath.Resolved.type_)))t.type_;class_type=PathClassTypeMap.add(id:>Ident.path_class_type)(`Prefixed(p,rp))t.class_type;}letadd_class_type:Ident.class_type->Cpath.class_type->Cpath.Resolved.class_type->t->t=funidprpt->{twithtype_=PathTypeMap.add(id:>Ident.path_type)(`Prefixed((p:>Cpath.type_),(rp:>Cpath.Resolved.type_)))t.type_;class_type=PathClassTypeMap.add(id:>Ident.path_class_type)(`Prefixed(p,rp))t.class_type;}letadd_type_replacementidtexpequationt={twithtype_replacement=PathTypeMap.addid(texp,equation)t.type_replacement;}letadd_module_type_replacementpathmtyt={twithmodule_type_replacement=ModuleTypeMap.addpathmtyt.module_type_replacement;}letadd_module_substitution:Ident.path_module->t->t=funidt->{twithmodule_type_of_invalidating_modules=id::t.module_type_of_invalidating_modules;path_invalidating_modules=id::t.path_invalidating_modules;module_=PathModuleMap.addid`Substitutedt.module_;}letrename_module:Ident.path_module->Ident.path_module->t->t=funidid't->{twithmodule_=PathModuleMap.addid(`Renamedid')t.module_}letrename_module_type:Ident.module_type->Ident.module_type->t->t=funidid't->{twithmodule_type=ModuleTypeMap.addid(`Renamedid')t.module_type}letrename_type:Ident.path_type->Ident.path_type->t->t=funidid't->{twithtype_=PathTypeMap.addid(`Renamedid')t.type_}letrename_class_type:Ident.path_class_type->Ident.path_class_type->t->t=funidid't->{twithclass_type=PathClassTypeMap.addid(`Renamedid')t.class_type;type_=PathTypeMap.add(id:>Ident.path_type)(`Renamed(id':>Ident.path_type))t.type_;}letrecsubstitute_varsvarst=letopenTypeExprinmatchtwith|Vars->(tryList.assocsvarswithNot_found->t)|Any->Any|Alias(t,str)->Alias(substitute_varsvarst,str)|Arrow(lbl,t1,t2)->Arrow(lbl,substitute_varsvarst1,substitute_varsvarst2)|Tuplets->Tuple(List.map(substitute_varsvars)ts)|Constr(p,ts)->Constr(p,List.map(substitute_varsvars)ts)|Polymorphic_variantv->Polymorphic_variant(substitute_vars_poly_variantvarsv)|Objecto->Object(substitute_vars_type_objectvarso)|Class(p,ts)->Class(p,List.map(substitute_varsvars)ts)|Poly(strs,ts)->Poly(strs,substitute_varsvarsts)|Packagep->Package(substitute_vars_packagevarsp)andsubstitute_vars_packagevarsp=letopenTypeExpr.Packageinletsubst_subst(p,t)=(p,substitute_varsvarst)in{pwithsubstitutions=List.mapsubst_substp.substitutions}andsubstitute_vars_type_objectvarso=letopenTypeExpr.Objectinletsubst_field=function|Methodm->Method{mwithtype_=substitute_varsvarsm.type_}|Inheritt->Inherit(substitute_varsvarst)in{owithfields=List.mapsubst_fieldo.fields}andsubstitute_vars_poly_variantvarsv=letopenTypeExpr.Polymorphic_variantinletsubst_element=function|Typet->Type(substitute_varsvarst)|Constructorc->letarguments=List.map(substitute_varsvars)c.Constructor.argumentsinConstructor{cwitharguments}in{vwithelements=List.mapsubst_elementv.elements}letrecresolved_module_path:t->Cpath.Resolved.module_->Cpath.Resolved.module_=funsp->matchpwith|`Localid->(ifList.memids.path_invalidating_modulesthenraiseInvalidated;matchtrySome(PathModuleMap.find(id:>Ident.path_module)s.module_)with_->Nonewith|Some(`Renamedx)->`Localx|Some(`Prefixed(_p,rp))->rp|Some`Substituted->`Substitutedp|None->p)|`Identifier_->p|`Apply(p1,p2)->`Apply(resolved_module_pathsp1,resolved_module_pathsp2)|`Substitutedp->`Substituted(resolved_module_pathsp)|`Module(p,n)->`Module(resolved_parent_pathsp,n)|`Alias(p1,p2)->`Alias(resolved_module_pathsp1,resolved_module_pathsp2)|`Subst(p1,p2)->letp1=matchresolved_module_type_pathsp1with|Replaced_->(* the left hand side of Subst is a named module type inside a module,
it cannot be substituted away *)assertfalse|Not_replacedp1->p1in`Subst(p1,resolved_module_pathsp2)|`Hiddenp1->`Hidden(resolved_module_pathsp1)|`Canonical(p1,p2)->`Canonical(resolved_module_pathsp1,module_pathsp2)|`OpaqueModulem->ifs.unresolve_opaque_pathsthenraiseInvalidatedelse`OpaqueModule(resolved_module_pathsm)andresolved_parent_paths=function|`Modulem->`Module(resolved_module_pathsm)|`ModuleTypem->letp=matchresolved_module_type_pathsmwith|Replaced_->assertfalse|Not_replacedp1->p1in`ModuleTypep|`FragmentRootasx->xandmodule_path:t->Cpath.module_->Cpath.module_=funsp->matchpwith|`Resolvedp'->(try`Resolved(resolved_module_pathsp')withInvalidated->letpath'=Cpath.unresolve_resolved_module_pathp'inmodule_pathspath')|`Dot(p',str)->`Dot(module_pathsp',str)|`Module(p',str)->`Module(resolved_parent_pathsp',str)|`Apply(p1,p2)->`Apply(module_pathsp1,module_pathsp2)|`Local(id,b)->(matchtrySome(PathModuleMap.find(id:>Ident.path_module)s.module_)with_->Nonewith|Some(`Prefixed(p,_rp))->p|Some(`Renamedx)->`Local(x,b)|Some`Substituted->`Substitutedp|None->`Local(id,b))|`Identifier_->p|`Substitutedp->`Substituted(module_pathsp)|`Forward_->p|`Root_->pandresolved_module_type_path:t->Cpath.Resolved.module_type->(Cpath.Resolved.module_type,ModuleType.expr)or_replaced=funsp->matchpwith|`Localid->(ifModuleTypeMap.memids.module_type_replacementthenReplaced(ModuleTypeMap.findids.module_type_replacement)elsematchModuleTypeMap.findids.module_typewith|`Prefixed(_p,rp)->Not_replacedrp|`Renamedx->Not_replaced(`Localx)|exceptionNot_found->Not_replaced(`Localid))|`Identifier_->Not_replacedp|`Substitutedp->resolved_module_type_pathsp|>map_replaced(funp->`Substitutedp)|`ModuleType(p,n)->Not_replaced(`ModuleType(resolved_parent_pathsp,n))|`CanonicalModuleType(mt1,mt2)->(match(resolved_module_type_pathsmt1,module_type_pathsmt2)with|Not_replacedmt1',Not_replacedmt2'->Not_replaced(`CanonicalModuleType(mt1',mt2'))|x,_->x)|`OpaqueModuleTypem->ifs.unresolve_opaque_pathsthenraiseInvalidatedelseresolved_module_type_pathsm|>map_replaced(funx->`OpaqueModuleTypex)|`SubstT(p1,p2)->(match(resolved_module_type_pathsp1,resolved_module_type_pathsp2)with|Not_replacedp1,Not_replacedp2->Not_replaced(`SubstT(p1,p2))|Replacedmt,_|_,Replacedmt->Replacedmt)|`AliasModuleType(p1,p2)->(match(resolved_module_type_pathsp1,resolved_module_type_pathsp2)with|Not_replacedp1,Not_replacedp2->Not_replaced(`AliasModuleType(p1,p2))|Replacedmt,_|_,Replacedmt->Replacedmt)andmodule_type_path:t->Cpath.module_type->Cpath.module_typemodule_type_or_replaced=funsp->matchpwith|`Resolvedr->(tryresolved_module_type_pathsr|>map_replaced(funr->`Resolvedr)withInvalidated->letpath'=Cpath.unresolve_resolved_module_type_pathrinmodule_type_pathspath')|`Substitutedp->module_type_pathsp|>map_replaced(funr->`Substitutedr)|`Local(id,b)->ifModuleTypeMap.memids.module_type_replacementthenReplaced(ModuleTypeMap.findids.module_type_replacement)elseletr=matchtrySome(ModuleTypeMap.findids.module_type)with_->Nonewith|Some(`Prefixed(p,_rp))->p|Some(`Renamedx)->`Local(x,b)|None->`Local(id,b)inNot_replacedr|`Identifier_->Not_replacedp|`Dot(p,n)->Not_replaced(`Dot(module_pathsp,n))|`ModuleType(p',str)->Not_replaced(`ModuleType(resolved_parent_pathsp',str))andresolved_type_path:t->Cpath.Resolved.type_->(Cpath.Resolved.type_,TypeExpr.t*TypeDecl.Equation.t)or_replaced=funsp->matchpwith|`Localid->(ifPathTypeMap.memids.type_replacementthenReplaced(PathTypeMap.findids.type_replacement)elsematchtrySome(PathTypeMap.findids.type_)withNot_found->Nonewith|Some(`Prefixed(_p,rp))->Not_replacedrp|Some(`Renamedx)->Not_replaced(`Localx)|None->Not_replaced(`Localid))|`CanonicalType(t1,t2)->(match(resolved_type_pathst1,type_pathst2)with|Not_replacedt1',Not_replacedt2'->Not_replaced(`CanonicalType(t1',t2'))|x,_->x)|`Identifier_->Not_replacedp|`Substitutedp->resolved_type_pathsp|>map_replaced(funp->`Substitutedp)|`Type(p,n)->Not_replaced(`Type(resolved_parent_pathsp,n))|`ClassType(p,n)->Not_replaced(`ClassType(resolved_parent_pathsp,n))|`Class(p,n)->Not_replaced(`Class(resolved_parent_pathsp,n))andtype_path:t->Cpath.type_->Cpath.type_type_or_replaced=funsp->matchpwith|`Resolvedr->(tryresolved_type_pathsr|>map_replaced(funr->`Resolvedr)withInvalidated->letpath'=Cpath.unresolve_resolved_type_pathrintype_pathspath')|`Substitutedp->type_pathsp|>map_replaced(funr->`Substitutedr)|`Local(id,b)->(ifPathTypeMap.memids.type_replacementthenReplaced(PathTypeMap.findids.type_replacement)elsematchtrySome(PathTypeMap.findids.type_)withNot_found->Nonewith|Some(`Prefixed(p,_rp))->Not_replacedp|Some(`Renamedx)->Not_replaced(`Local(x,b))|None->Not_replaced(`Local(id,b)))|`Identifier_->Not_replacedp|`Dot(p,n)->Not_replaced(`Dot(module_pathsp,n))|`Type(p,n)->Not_replaced(`Type(resolved_parent_pathsp,n))|`Class(p,n)->Not_replaced(`Class(resolved_parent_pathsp,n))|`ClassType(p,n)->Not_replaced(`ClassType(resolved_parent_pathsp,n))andresolved_class_type_path:t->Cpath.Resolved.class_type->Cpath.Resolved.class_type=funsp->matchpwith|`Localid->(matchtrySome(PathClassTypeMap.findids.class_type)with_->Nonewith|Some(`Prefixed(_p,rp))->rp|Some(`Renamedx)->`Localx|None->`Localid)|`Identifier_->p|`Substitutedp->`Substituted(resolved_class_type_pathsp)|`ClassType(p,n)->`ClassType(resolved_parent_pathsp,n)|`Class(p,n)->`Class(resolved_parent_pathsp,n)andclass_type_path:t->Cpath.class_type->Cpath.class_type=funsp->matchpwith|`Resolvedr->(try`Resolved(resolved_class_type_pathsr)withInvalidated->letpath'=Cpath.unresolve_resolved_class_type_pathrinclass_type_pathspath')|`Local(id,b)->(matchtrySome(PathClassTypeMap.findids.class_type)with_->Nonewith|Some(`Prefixed(p,_rp))->p|Some(`Renamedx)->`Local(x,b)|None->`Local(id,b))|`Identifier_->p|`Substitutedp->`Substituted(class_type_pathsp)|`Dot(p,n)->`Dot(module_pathsp,n)|`Class(p,n)->`Class(resolved_parent_pathsp,n)|`ClassType(p,n)->`ClassType(resolved_parent_pathsp,n)letrecresolved_signature_fragment:t->Cfrag.resolved_signature->Cfrag.resolved_signature=funtr->matchrwith|`Root(`ModuleTypep)->letp=matchresolved_module_type_pathtpwith|Not_replacedp->p|Replaced_->assertfalsein`Root(`ModuleTypep)|`Root(`Modulep)->`Root(`Module(resolved_module_pathtp))|(`Subst_|`Alias_|`OpaqueModule_|`Module_)asx->(resolved_module_fragmenttx:>Cfrag.resolved_signature)andresolved_module_fragment:t->Cfrag.resolved_module->Cfrag.resolved_module=funtr->matchrwith|`Subst(mty,f)->letp=matchresolved_module_type_pathtmtywith|Not_replacedp->p|Replaced_->(* the left hand side of subst is a named module type inside a module,
it cannot be substituted *)assertfalsein`Subst(p,resolved_module_fragmenttf)|`Alias(m,f)->`Alias(resolved_module_pathtm,resolved_module_fragmenttf)|`Module(sg,n)->`Module(resolved_signature_fragmenttsg,n)|`OpaqueModulem->`OpaqueModule(resolved_module_fragmenttm)andresolved_module_type_fragment:t->Cfrag.resolved_module_type->Cfrag.resolved_module_type=funtr->matchrwith|`ModuleType(s,n)->`ModuleType(resolved_signature_fragmentts,n)andresolved_type_fragment:t->Cfrag.resolved_type->Cfrag.resolved_type=funtr->matchrwith|`Type(s,n)->`Type(resolved_signature_fragmentts,n)|`ClassType(s,n)->`ClassType(resolved_signature_fragmentts,n)|`Class(s,n)->`Class(resolved_signature_fragmentts,n)letrecsignature_fragment:t->Cfrag.signature->Cfrag.signature=funtr->matchrwith|`Resolvedf->`Resolved(resolved_signature_fragmenttf)|`Dot(sg,n)->`Dot(signature_fragmenttsg,n)|`Root->`Rootletrecmodule_fragment:t->Cfrag.module_->Cfrag.module_=funtr->matchrwith|`Resolvedr->(try`Resolved(resolved_module_fragmenttr)withInvalidated->letfrag'=Cfrag.unresolve_modulerinmodule_fragmenttfrag')|`Dot(sg,n)->`Dot(signature_fragmenttsg,n)letrecmodule_type_fragment:t->Cfrag.module_type->Cfrag.module_type=funtr->matchrwith|`Resolvedr->(try`Resolved(resolved_module_type_fragmenttr)withInvalidated->letfrag'=Cfrag.unresolve_module_typerinmodule_type_fragmenttfrag')|`Dot(sg,n)->`Dot(signature_fragmenttsg,n)letrectype_fragment:t->Cfrag.type_->Cfrag.type_=funtr->matchrwith|`Resolvedr->(try`Resolved(resolved_type_fragmenttr)withInvalidated->letfrag'=Cfrag.unresolve_typerintype_fragmenttfrag')|`Dot(sg,n)->`Dot(signature_fragmenttsg,n)letoption_convsx=matchxwithSomex->Some(convsx)|None->Noneletoption_bindconvsx=matchxwithSomex->convsx|None->Noneletlistconvsxs=List.map(convs)xsletrectype_st=letopenComponent.TypeDeclinletrepresentation=option_type_decl_representationst.representationinletcanonical=matcht.canonicalwith|Somep->(matchtype_pathspwith|Not_replacedp'->Somep'|Replaced_->None)|None->Nonein{equation=type_decl_equationst.equation;representation;doc=t.doc;canonical;}andtype_decl_representationst=letopenComponent.TypeDecl.Representationinmatchtwith|Variantcs->Variant(List.map(type_decl_constructors)cs)|Recordfs->Record(List.map(type_decl_fields)fs)|Extensible->tandtype_decl_constructorst=letopenComponent.TypeDecl.Constructorinletargs=type_decl_constructor_argst.argsinletres=option_type_exprst.resin{twithargs;res}andtype_poly_varsv=letopenComponent.TypeExpr.Polymorphic_variantinletmap_constrc=letopenConstructorin{name=c.name;constant=c.constant;arguments=List.map(type_exprs)c.arguments;doc=c.doc;}inletmap_element=function|Typet->(matchtype_exprstwith|Polymorphic_variantv->v.elements|x->[Typex])|Constructorc->[Constructor(map_constrc)]in{kind=v.kind;elements=List.flatten(List.mapmap_elementv.elements)}andtype_objectso=letopenComponent.TypeExpr.Objectinletmap_field=function|Methodm->Method{mwithtype_=type_exprsm.type_}|Inheritt->Inherit(type_exprst)in{fields=List.mapmap_fieldo.fields;open_=o.open_}andtype_packagesp=letopenComponent.TypeExpr.Packageinletsub(x,y)=(type_fragmentsx,type_exprsy)in{path=(matchmodule_type_pathsp.pathwith|Not_replacedp->p|Replaced(Pathp)->p.p_path|Replaced_->(* substituting away a packed module type by a non-path module type is a type error *)assertfalse);substitutions=List.mapsubp.substitutions;}andtype_exprst=letopenComponent.TypeExprinmatchtwith|Vars->Vars|Any->Any|Alias(t,str)->Alias(type_exprst,str)|Arrow(lbl,t1,t2)->Arrow(lbl,type_exprst1,type_exprst2)|Tuplets->Tuple(List.map(type_exprs)ts)|Constr(p,ts)->(matchtype_pathspwith|Replaced(t,eq)->letmk_varaccpexprparam=matchparam.Odoc_model.Lang.TypeDecl.descwith|Any->acc|Varn->(n,type_exprspexpr)::accinletvars=List.fold_left2mk_var[]tseq.paramsinsubstitute_varsvarst|Not_replacedp->Constr(p,List.map(type_exprs)ts))|Polymorphic_variantv->Polymorphic_variant(type_poly_varsv)|Objecto->Object(type_objectso)|Class(p,ts)->Class(class_type_pathsp,List.map(type_exprs)ts)|Poly(strs,ts)->Poly(strs,type_exprsts)|Packagep->Package(type_packagesp)andsimple_expansion:t->Component.ModuleType.simple_expansion->Component.ModuleType.simple_expansion=funst->letopenComponent.ModuleTypeinmatchtwith|Signaturesg->Signature(signaturessg)|Functor(arg,sg)->Functor(functor_parametersarg,simple_expansionssg)andmodule_typest=letopenComponent.ModuleTypeinletexpr=matcht.exprwithSomem->Some(module_type_exprsm)|None->Noneinletmaybe_pathst=matchmodule_type_pathstwith|Not_replacedp->Somep|Replaced(Pathp)->Somep.p_path|Replaced_->Nonein{expr;doc=t.doc;canonical=option_bindmaybe_pathst.canonical}andmodule_type_substitutionst=letopenComponent.ModuleTypeSubstitutioninletmanifest=module_type_exprst.manifestin{manifest;doc=t.doc}andfunctor_parameterst=letopenComponent.FunctorParameterinmatchtwith|Namedarg->Named{argwithexpr=module_type_exprsarg.expr}|Unit->Unitandmodule_type_type_of_descst=letopenComponent.ModuleTypeinmatchtwith|ModPathp->ifmto_module_path_invalidatedspthenraiseMTOInvalidatedelseModPath(module_pathsp)|StructIncludep->ifmto_module_path_invalidatedspthenraiseMTOInvalidatedelseStructInclude(module_pathsp)andmodule_type_type_of_desc_noexnst=letopenComponent.ModuleTypeinmatchtwith|ModPathp->ModPath(module_pathsp)|StructIncludep->StructInclude(module_pathsp)andmto_module_path_invalidated:t->Cpath.module_->bool=funsp->matchpwith|`Resolvedp'->mto_resolved_module_path_invalidatedsp'|`Substitutedp'|`Dot(p',_)->mto_module_path_invalidatedsp'|`Module(`Modulep',_)->mto_resolved_module_path_invalidatedsp'|`Module(_,_)->false|`Apply(p1,p2)->mto_module_path_invalidatedsp1||mto_module_path_invalidatedsp2|`Local(id,_)->List.memids.module_type_of_invalidating_modules|`Identifier_->false|`Forward_->false|`Root_->falseandmto_resolved_module_path_invalidatedsp=matchpwith|`Localid->List.memids.module_type_of_invalidating_modules|`Identifier_->false|`Apply(p1,p2)->mto_resolved_module_path_invalidatedsp1||mto_resolved_module_path_invalidatedsp2|`Module(`Modulep,_)|`Substitutedp->mto_resolved_module_path_invalidatedsp|`Module(_,_)->false|`Alias(p1,_p2)->mto_resolved_module_path_invalidatedsp1|`Subst(_p1,p2)->mto_resolved_module_path_invalidatedsp2|`Hiddenp->mto_resolved_module_path_invalidatedsp|`Canonical(p1,_p2)->mto_resolved_module_path_invalidatedsp1|`OpaqueModulep->mto_resolved_module_path_invalidatedspandu_module_type_exprst=letopenComponent.ModuleType.Uinmatchtwith|Pathp->(matchmodule_type_pathspwith|Not_replacedp->Pathp|Replacedeqn->(matcheqnwith|Pathp->Pathp.p_path|Signatures->Signatures|TypeOft->TypeOft|Withw->With(w.w_substitutions,w.w_expr)|Functor_->(* non functor cannot be substituted away to a functor *)assertfalse))|Signaturesg->Signature(signaturessg)|With(subs,e)->With(List.map(with_module_type_substitutions)subs,u_module_type_exprse)|TypeOf{t_desc;t_expansion=Some(Signaturee)}->(tryTypeOf{t_desc=module_type_type_of_descst_desc;t_expansion=Some(Signature(apply_sig_map_sgse));}withMTOInvalidated->u_module_type_exprs(Signaturee))|TypeOf{t_expansion=Some(Functor_);_}->assertfalse|TypeOf{t_desc;t_expansion=None}->TypeOf{t_desc=module_type_type_of_desc_noexnst_desc;t_expansion=None}andmodule_type_of_simple_expansion:Component.ModuleType.simple_expansion->Component.ModuleType.expr=function|Signaturesg->Signaturesg|Functor(arg,e)->Functor(arg,module_type_of_simple_expansione)andmodule_type_exprst=letopenComponent.ModuleTypeinmatchtwith|Path{p_path;p_expansion}->(matchmodule_type_pathsp_pathwith|Not_replacedp_path->Path{p_path;p_expansion=option_simple_expansionsp_expansion}|Replaceds->s)|Signaturesg->Signature(signaturessg)|Functor(arg,expr)->Functor(functor_parametersarg,module_type_exprsexpr)|With{w_substitutions;w_expansion;w_expr}->With{w_substitutions=List.map(with_module_type_substitutions)w_substitutions;w_expansion=option_simple_expansionsw_expansion;w_expr=u_module_type_exprsw_expr;}|TypeOf{t_desc;t_expansion=Somee}->(tryTypeOf{t_desc=module_type_type_of_descst_desc;t_expansion=Some(simple_expansionse);}withMTOInvalidated->module_type_exprs(module_type_of_simple_expansione))|TypeOf{t_desc;t_expansion=None}->TypeOf{t_desc=module_type_type_of_desc_noexnst_desc;t_expansion=None}andwith_module_type_substitutionssub=letopenComponent.ModuleTypeinmatchsubwith|ModuleEq(f,m)->ModuleEq(module_fragmentsf,module_declsm)|ModuleSubst(f,p)->ModuleSubst(module_fragmentsf,module_pathsp)|TypeEq(f,eq)->TypeEq(type_fragmentsf,type_decl_equationseq)|TypeSubst(f,eq)->TypeSubst(type_fragmentsf,type_decl_equationseq)|ModuleTypeEq(f,eq)->ModuleTypeEq(module_type_fragmentsf,module_type_exprseq)|ModuleTypeSubst(f,eq)->ModuleTypeSubst(module_type_fragmentsf,module_type_exprseq)andmodule_declst=matchtwith|Alias(p,e)->Alias(module_pathsp,option_simple_expansionse)|ModuleTypet->ModuleType(module_type_exprst)andinclude_declst=matchtwith|Include.Aliasp->Include.Alias(module_pathsp)|ModuleTypet->ModuleType(u_module_type_exprst)andmodule_st=letopenComponent.Moduleinlettype_=module_declst.type_inletcanonical=option_(funsm1->module_pathsm1)st.canonicalin{twithtype_;canonical}andmodule_substitutionsm=letopenComponent.ModuleSubstitutioninletmanifest=module_pathsm.manifestin{manifest;doc=m.doc}andtype_decl_fieldsf=letopenComponent.TypeDecl.Fieldin{fwithtype_=type_exprsf.type_}andtype_decl_constructor_argsa=letopenComponent.TypeDecl.Constructorinmatchawith|Tuplets->Tuple(listtype_exprsts)|Recordfs->Record(listtype_decl_fieldsfs)andtype_decl_equationst=letopenComponent.TypeDecl.Equationin{twithmanifest=option_type_exprst.manifest;constraints=List.map(fun(x,y)->(type_exprsx,type_exprsy))t.constraints;}andexception_se=letopenComponent.Exceptioninletres=option_type_exprse.resinletargs=type_decl_constructor_argse.argsin{args;res;doc=e.doc}andextension_constructorsc=letopenComponent.Extension.Constructorin{cwithargs=type_decl_constructor_argsc.args;res=option_type_exprsc.res;}andextensionse=letopenComponent.Extensioninlettype_path=matchtype_pathse.type_pathwith|Not_replacedp->p|Replaced(TypeExpr.Constr(p,_),_)->p|Replaced_->(* What else is possible ? *)assertfalseandconstructors=List.map(extension_constructors)e.constructorsin{ewithtype_path;constructors}andinclude_si=letopenComponent.Includein{iwithdecl=include_declsi.decl;strengthened=option_module_pathsi.strengthened;expansion_=apply_sig_map_sgsi.expansion_;}andopen_so=letopenComponent.Openin{expansion=apply_sig_map_sgso.expansion;doc=o.doc}andvaluesv=letopenComponent.Valuein{vwithtype_=type_exprsv.type_}andclass_sc=letopenComponent.Classinletexpansion=option_class_signaturesc.expansionin{cwithtype_=class_declsc.type_;expansion}andclass_decls=letopenComponent.Classinfunction|ClassTypee->ClassType(class_type_exprse)|Arrow(lbl,t,d)->Arrow(lbl,type_exprst,class_declsd)andclass_type_exprs=letopenComponent.ClassTypeinfunction|Constr(p,ts)->Constr(class_type_pathsp,List.map(type_exprs)ts)|Signaturesg->Signature(class_signaturessg)andclass_typesc=letopenComponent.ClassTypeinletexpansion=option_class_signaturesc.expansionin{cwithexpr=class_type_exprsc.expr;expansion}andclass_signature_items=letopenComponent.ClassSignatureinfunction|Method(id,m)->Method(id,method_sm)|InstanceVariable(id,i)->InstanceVariable(id,instance_variablesi)|Constraint(t1,t2)->Constraint(type_exprst1,type_exprst2)|Inherite->Inherit(class_type_exprse)|Comment_asy->yandclass_signaturessg=letopenComponent.ClassSignaturein{sgwithself=option_type_exprssg.self;items=List.map(class_signature_items)sg.items;}andmethod_sm=letopenComponent.Methodin{mwithtype_=type_exprsm.type_}andinstance_variablesi=letopenComponent.InstanceVariablein{iwithtype_=type_exprsi.type_}andrename_bound_identsssg=letopenComponent.Signatureinletnew_module_idid=trymatchPathModuleMap.find(id:>Ident.path_module)s.module_with|`Renamed(`LModule_asx)->x|`Prefixed(_,_)->(* This is unusual but can happen when we have TypeOf expressions. It means
we're already prefixing this module path, hence we can essentially rename
it to whatever we like because it's never going to be referred to. *)Ident.Rename.module_id|_->failwith"Error"withNot_found->Ident.Rename.module_idinletnew_module_type_idid=trymatchModuleTypeMap.findids.module_typewith|`Renamedx->x|`Prefixed(_,_)->Ident.Rename.module_typeidwithNot_found->Ident.Rename.module_typeidinletnew_type_idid=trymatchPathTypeMap.find(id:>Ident.path_type)s.type_with|`Renamed(`LType_asx)->x|`Prefixed(_,_)->Ident.Rename.type_id|_->failwith"Error"withNot_found->Ident.Rename.type_idinletnew_class_idid=trymatchPathClassTypeMap.find(id:>Ident.path_class_type)s.class_typewith|`Renamed(`LClass_asx)->x|`Prefixed(_,_)->Ident.Rename.class_id|_->failwith"Error"withNot_found->Ident.Rename.class_idinletnew_class_type_idid=trymatchPathClassTypeMap.find(id:>Ident.path_class_type)s.class_typewith|`Renamed(`LClassType_asx)->x|`Prefixed(_,_)->Ident.Rename.class_typeid|_->failwith"Error!"withNot_found->Ident.Rename.class_typeidinfunction|[]->(s,List.revsg)|Module(id,r,m)::rest->letid'=new_module_ididinrename_bound_idents(rename_module(id:>Ident.path_module)(id':>Ident.path_module)s)(Module(id',r,m)::sg)rest|ModuleSubstitution(id,m)::rest->letid'=new_module_ididinrename_bound_idents(rename_module(id:>Ident.path_module)(id':>Ident.path_module)s)(ModuleSubstitution(id',m)::sg)rest|ModuleType(id,mt)::rest->letid'=new_module_type_ididinrename_bound_idents(rename_module_typeidid's)(ModuleType(id',mt)::sg)rest|ModuleTypeSubstitution(id,mt)::rest->letid'=new_module_type_ididinrename_bound_idents(rename_module_typeidid's)(ModuleTypeSubstitution(id',mt)::sg)rest|Type(id,r,t)::rest->letid'=new_type_ididinrename_bound_idents(rename_type(id:>Ident.path_type)(id':>Ident.path_type)s)(Type(id',r,t)::sg)rest|TypeSubstitution(id,t)::rest->letid'=new_type_ididinrename_bound_idents(rename_type(id:>Ident.path_type)(id':>Ident.path_type)s)(TypeSubstitution(id',t)::sg)rest|Exception(id,e)::rest->letid'=Ident.Rename.exception_idinrename_bound_identss(Exception(id',e)::sg)rest|TypExte::rest->rename_bound_identss(TypExte::sg)rest|Value(id,v)::rest->letid'=Ident.Rename.valueidinrename_bound_identss(Value(id',v)::sg)rest|Class(id,r,c)::rest->letid'=new_class_ididinrename_bound_idents(rename_class_type(id:>Ident.path_class_type)(id':>Ident.path_class_type)s)(Class(id',r,c)::sg)rest|ClassType(id,r,c)::rest->letid'=new_class_type_ididinrename_bound_idents(rename_class_type(id:>Ident.path_class_type)(id':>Ident.path_class_type)s)(ClassType(id',r,c)::sg)rest|Include({expansion_;_}asi)::rest->lets,items=rename_bound_identss[]expansion_.itemsinrename_bound_identss(Include{iwithexpansion_={expansion_withitems;removed=[]}}::sg)rest|Open{expansion;doc}::rest->lets,items=rename_bound_identss[]expansion.itemsinrename_bound_identss(Open{expansion={expansionwithitems;removed=[]};doc}::sg)rest|(Comment_asitem)::rest->rename_bound_identss(item::sg)restandremoved_itemssitems=letopenComponent.SignatureinList.map(function|RModule(id,_)asx->(trymatchPathModuleMap.find(id:>Ident.path_module)s.module_with|`Prefixed(_,x)->RModule(id,x)|_->xwithNot_found->x)|x->x)itemsandsignaturessg=lets,items=rename_bound_identss[]sg.itemsinletitems,removed,dont_recompile=apply_sig_mapsitemssg.removedin{sgwithitems;removed;compiled=sg.compiled&&dont_recompile}andapply_sig_map_sgs(sg:Component.Signature.t)=letitems,removed,dont_recompile=apply_sig_mapssg.itemssg.removedin{sgwithitems;removed;compiled=sg.compiled&&dont_recompile}andapply_sig_mapsitemsremoved=letopenComponent.Signatureinletrecinneritemsacc=matchitemswith|[]->List.revacc|Module(id,r,m)::rest->innerrest(Module(id,r,Component.Delayed.put(fun()->module_s(Component.Delayed.getm)))::acc)|ModuleSubstitution(id,m)::rest->innerrest(ModuleSubstitution(id,module_substitutionsm)::acc)|ModuleType(id,mt)::rest->innerrest(ModuleType(id,Component.Delayed.put(fun()->module_types(Component.Delayed.getmt)))::acc)|ModuleTypeSubstitution(id,mt)::rest->innerrest(ModuleTypeSubstitution(id,module_type_substitutionsmt)::acc)|Type(id,r,t)::rest->innerrest(Type(id,r,Component.Delayed.put(fun()->type_s(Component.Delayed.gett)))::acc)|TypeSubstitution(id,t)::rest->innerrest(TypeSubstitution(id,type_st)::acc)|Exception(id,e)::rest->innerrest(Exception(id,exception_se)::acc)|TypExte::rest->innerrest(TypExt(extensionse)::acc)|Value(id,v)::rest->innerrest(Value(id,Component.Delayed.put(fun()->values(Component.Delayed.getv)))::acc)|Class(id,r,c)::rest->innerrest(Class(id,r,class_sc)::acc)|ClassType(id,r,c)::rest->innerrest(ClassType(id,r,class_typesc)::acc)|Includei::rest->innerrest(Include(include_si)::acc)|Openo::rest->innerrest(Open(open_so)::acc)|Commentc::rest->innerrest(Commentc::acc)inletdont_recompile=List.lengths.path_invalidating_modules=0&&List.lengths.module_type_of_invalidating_modules=0in(inneritems[],removed_itemssremoved,dont_recompile)