123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083openComponentexceptionInvalidatedexceptionMTOInvalidatedtype('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)|`Gpath_->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,p3opt)->letp2'=module_pathsp2inletup2'=tryCpath.unresolve_module_pathp2'with_->p2'inletp3opt'=matchp3optwith|Somep3->Some(resolved_module_pathsp3)|None->Nonein`Alias(resolved_module_pathsp1,up2',p3opt')|`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,p2)|`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))|`Gpath_->Not_replacedp|`Substitutedp->resolved_module_type_pathsp|>map_replaced(funp->`Substitutedp)|`ModuleType(p,n)->Not_replaced(`ModuleType(resolved_parent_pathsp,n))|`CanonicalModuleType(mt1,mt2)->(matchresolved_module_type_pathsmt1with|Not_replacedmt1'->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)->(matchresolved_type_pathst1with|Not_replacedt1'->Not_replaced(`CanonicalType(t1',t2))|x->x)|`Gpath_->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)|`Gpath_->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->Noneletlistconvsxs=List.map(convs)xsletrectype_st=letopenComponent.TypeDeclinletrepresentation=option_type_decl_representationst.representationin{twithequation=type_decl_equationst.equation;representation}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->Nonein{expr;source_loc=t.source_loc;doc=t.doc;canonical=t.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|`Gpath_->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=t.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{ewithargs;res}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)|Constraintcst->Constraint(class_constraintscst)|Inherite->Inherit(inherit_se)|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_}andclass_constraintscst=letopenComponent.ClassSignature.Constraintin{cstwithleft=type_exprscst.left;right=type_exprscst.right}andinherit_sih=letopenComponent.ClassSignature.Inheritin{ihwithexpr=class_type_exprsih.expr}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_map_itemsitem=letopenComponent.Signatureinmatchitemwith|Module(id,r,m)->Module(id,r,Component.Delayed.put(fun()->module_s(Component.Delayed.getm)))|ModuleSubstitution(id,m)->ModuleSubstitution(id,module_substitutionsm)|ModuleType(id,mt)->ModuleType(id,Component.Delayed.put(fun()->module_types(Component.Delayed.getmt)))|ModuleTypeSubstitution(id,mt)->ModuleTypeSubstitution(id,module_type_substitutionsmt)|Type(id,r,t)->Type(id,r,Component.Delayed.put(fun()->type_s(Component.Delayed.gett)))|TypeSubstitution(id,t)->TypeSubstitution(id,type_st)|Exception(id,e)->Exception(id,exception_se)|TypExte->TypExt(extensionse)|Value(id,v)->Value(id,Component.Delayed.put(fun()->values(Component.Delayed.getv)))|Class(id,r,c)->Class(id,r,class_sc)|ClassType(id,r,c)->ClassType(id,r,class_typesc)|Includei->Include(include_si)|Openo->Open(open_so)|Commentc->Commentcandapply_sig_map_itemssitems=List.rev_map(apply_sig_map_items)items|>List.revandapply_sig_mapsitemsremoved=letdont_recompile=List.lengths.path_invalidating_modules=0&&List.lengths.module_type_of_invalidating_modules=0in(apply_sig_map_itemssitems,removed_itemssremoved,dont_recompile)