123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791(* Phase 1 - compilation *)(* First round of resolving only attempts to resolve paths and fragments, and then only those
that don't contain forward paths *)openOdoc_modelopenLangmoduleId=Paths.IdentifiermoduleOpt=structletmapf=functionSomex->Some(fx)|None->Noneendlettype_path:Env.t->Paths.Path.Type.t->Paths.Path.Type.t=funenvp->matchpwith|`Resolved_->p|_->(letcp=Component.Of_Lang.(type_path(empty())p)inmatchTools.resolve_type_pathenvcpwith|Okp'->`ResolvedLang_of.(Path.resolved_type(empty())p')|Error_->p)andmodule_type_path:Env.t->Paths.Path.ModuleType.t->Paths.Path.ModuleType.t=funenvp->matchpwith|`Resolved_->p|_->(letcp=Component.Of_Lang.(module_type_path(empty())p)inmatchTools.resolve_module_type_pathenvcpwith|Okp'->`ResolvedLang_of.(Path.resolved_module_type(empty())p')|Error_->p)andmodule_path:Env.t->Paths.Path.Module.t->Paths.Path.Module.t=funenvp->matchpwith|`Resolved_->p|_->(letcp=Component.Of_Lang.(module_path(empty())p)inmatchTools.resolve_module_pathenvcpwith|Okp'->`ResolvedLang_of.(Path.resolved_module(empty())p')|Error_->p)andclass_type_path:Env.t->Paths.Path.ClassType.t->Paths.Path.ClassType.t=funenvp->matchpwith|`Resolved_->p|_->(letcp=Component.Of_Lang.(class_type_path(empty())p)inmatchTools.resolve_class_type_pathenvcpwith|Okp'->`ResolvedLang_of.(Path.resolved_class_type(empty())p')|Error_->p)letrecunitenvt=letopenCompilation_unitin{twithcontent=contentenvt.idt.content}andcontentenvid=letopenCompilation_unitinfunction|Modulem->letsg=Type_of.signatureenvminletsg=signatureenv(id:>Id.Signature.t)sginModulesg|Packp->Packpandvalue_envparentt=letopenValueinletcontainer=(parent:>Id.Parent.t)intry{twithtype_=type_expressionenvcontainert.type_}with_->Errors.report~what:(`Valuet.id)`Compile;tandexception_envparente=letopenExceptioninletcontainer=(parent:>Id.Parent.t)inletres=Opt.map(type_expressionenvcontainer)e.resinletargs=type_decl_constructor_argumentenvcontainere.argsin{ewithres;args}andextensionenvparentt=letopenExtensioninletcontainer=(parent:>Id.Parent.t)inletconstructorc=letopenConstructorin{cwithargs=type_decl_constructor_argumentenvcontainerc.args;res=Opt.map(type_expressionenvcontainer)c.res;}inlettype_path=type_pathenvt.type_pathinletconstructors=List.mapconstructort.constructorsin{twithtype_path;constructors}andclass_type_exprenvparent=letopenClassTypeinletcontainer=(parent:>Id.Parent.t)infunction|Constr(path,texps)->Constr(class_type_pathenvpath,List.map(type_expressionenvcontainer)texps)|Signatures->Signature(class_signatureenvparents)andclass_typeenvc=letopenClassTypeinletexpansion=matchletopenUtils.OptionMonadinEnv.(lookup_by_ids_class_type)c.idenv>>=fun(`ClassType(_,c'))->Tools.class_signature_of_class_typeenvc'>>=funsg->letcs=Lang_of.class_signature(Lang_of.empty())(c.id:>Paths.Identifier.Path.ClassType.t)sginletcompiled=class_signatureenv(c.id:>Id.ClassSignature.t)csinSomecompiledwith|Some_asexp->exp|None->Errors.report~what:(`Class_typec.id)`Expand;c.expansionin{cwithexpr=class_type_exprenv(c.id:>Id.ClassSignature.t)c.expr;expansion;}andclass_signatureenvparentc=letopenClassSignatureinletcontainer=(parent:Id.ClassSignature.t:>Id.Parent.t)inletenv=Env.open_class_signaturecenvinletmap_item=function|Methodm->Method(method_envparentm)|InstanceVariablei->InstanceVariable(instance_variableenvparenti)|Constraint(t1,t2)->Constraint(type_expressionenvcontainert1,type_expressionenvcontainert2)|Inheritc->Inherit(class_type_exprenvparentc)|Commentc->Commentcin{cwithself=Opt.map(type_expressionenvcontainer)c.self;items=List.mapmap_itemc.items;}andmethod_envparentm=letopenMethodinletcontainer=(parent:>Id.Parent.t)in{mwithtype_=type_expressionenvcontainerm.type_}andinstance_variableenvparenti=letopenInstanceVariableinletcontainer=(parent:>Id.Parent.t)in{iwithtype_=type_expressionenvcontaineri.type_}andclass_envparentc=letopenClassinletcontainer=(parent:>Id.Parent.t)inletexpansion=matchletopenUtils.OptionMonadinEnv.(lookup_by_ids_class)c.idenv>>=fun(`Class(_,c'))->Tools.class_signature_of_classenvc'>>=funsg->letcs=Lang_of.class_signature(Lang_of.empty())(c.id:>Paths.Identifier.Path.ClassType.t)sginSome(class_signatureenv(c.id:>Id.ClassSignature.t)cs)with|Some_asexp->exp|None->Errors.report~what:(`Classc.id)`Expand;c.expansioninletrecmap_decl=function|ClassTypeexpr->ClassType(class_type_exprenv(c.id:>Id.ClassSignature.t)expr)|Arrow(lbl,expr,decl)->Arrow(lbl,type_expressionenvcontainerexpr,map_decldecl)in{cwithtype_=map_declc.type_;expansion}andmodule_substitutionenvm=letopenModuleSubstitutionin{mwithmanifest=module_pathenvm.manifest}andsignature_items:Env.t->Id.Signature.t->Signature.itemlist->_=funenvids->letopenSignatureinletitems,_=List.fold_left(fun(items,env)item->letstdi=(i::items,env)inmatchitemwith|Module(r,m)->letm'=module_envminifm==m'then(item::items,env)elseletty=Component.Delayed.(put(fun()->Component.Of_Lang.(module_(empty())m')))inletdocs=[]inletenv'=Env.update_module(m.id:>Paths.Identifier.Path.Module.t)tydocsenvin(Module(r,m')::items,env')|ModuleSubstitutionm->letenv'=Env.open_module_substitutionmenvin(ModuleSubstitution(module_substitutionenvm)::items,env')|Type(r,t)->std@@Type(r,type_declenvt)|TypeSubstitutiont->letenv'=Env.open_type_substitutiontenvin(TypeSubstitution(type_declenvt)::items,env')|ModuleTypemt->letm'=module_typeenvmtinletty=Component.Of_Lang.(module_type(empty())m')inletenv'=Env.update_module_typemt.idtyenvin(ModuleType(module_typeenvmt)::items,env')|ModuleTypeSubstitutionmt->letenv'=Env.open_module_type_substitutionmtenvin(ModuleTypeSubstitution(module_type_substitutionenvmt)::items,env')|Valuev->std@@Value(value_envidv)|Commentc->std@@Commentc|TypExtt->std@@TypExt(extensionenvidt)|Exceptione->std@@Exception(exception_envide)|Class(r,c)->std@@Class(r,class_envidc)|ClassType(r,c)->std@@ClassType(r,class_typeenvc)|Includei->leti'=include_enviinifi'.expansion==i.expansionthenstd@@Includei'else(* Expansion has changed, let's put the content into the environment *)letenv'=Env.close_signaturei.Include.expansion.contentenvinletenv''=Env.open_signaturei'.Include.expansion.contentenv'in(Includei'::items,env'')|Openo->std@@Openo)([],env)sinList.revitemsandmodule_type_substitutionenvmt=letopenModuleTypeSubstitutionin{mtwithmanifest=module_type_exprenv(mt.id:>Id.Signature.t)mt.manifest;}andsignature:Env.t->Id.Signature.t->Signature.t->_=funenvids->ifs.compiledthenselseletsg=letenv=Env.open_signaturesenvinletitems=signature_itemsenvids.itemsin{Signature.items;compiled=true;doc=s.doc(* comments are ignored while compiling *);}inletsg'=Component.Of_Lang.(signature(empty())sg)inLang_of.(signature(id:>Id.Signature.t)(empty())sg')andmodule_:Env.t->Module.t->Module.t=funenvm->letopenModuleinifm.hiddenthenmelse{mwithtype_=module_declenv(m.id:>Id.Signature.t)m.type_}andmodule_decl:Env.t->Id.Signature.t->Module.decl->Module.decl=funenviddecl->letopenModuleinmatchdeclwith|ModuleTypeexpr->ModuleType(module_type_exprenvidexpr)|Alias(p,expn)->Alias(module_pathenvp,expn)andinclude_decl:Env.t->Id.Signature.t->Include.decl->Include.decl=funenviddecl->letopenIncludeinmatchdeclwith|ModuleTypeexpr->ModuleType(u_module_type_exprenvidexpr)|Aliasp->Alias(module_pathenvp)andmodule_type:Env.t->ModuleType.t->ModuleType.t=funenvm->letopenModuleTypeinletsg_id=(m.id:>Id.Signature.t)inletexpr=matchm.exprwith|None->None|Somee->Some(module_type_exprenvsg_id~expand_paths:falsee)in{mwithexpr}andinclude_:Env.t->Include.t->Include.t=funenvi->letopenIncludeinletdecl=Component.Of_Lang.(include_decl(empty())i.decl)inletget_expansion()=matchletopenUtils.ResultMonadinmatchdeclwith|Aliasp->Expand_tools.aux_expansion_of_module_aliasenv~strengthen:truep>>=Expand_tools.assert_not_functor|ModuleTypemty->Expand_tools.aux_expansion_of_u_module_type_exprenvmtywith|Errore->Errors.report~what:(`Includedecl)~tools_error:e`Expand;i.expansion|Oksg->letmap=Lang_of.with_shadowedi.expansion.shadowedinletsg'=matchi.strengthenedwith|Somep->letcp=Component.Of_Lang.(module_path(empty())p)inStrengthen.signaturecpsg|None->sginlete=Lang_of.(simple_expansionmapi.parent(Signaturesg'))inletexpansion_sg=matchewith|ModuleType.Signaturesg->sg|_->failwith"Expansion shouldn't be anything other than a signature"inletcontent=letenv=Env.close_signaturei.expansion.contentenvinsignatureenvi.parentexpansion_sgin{shadowed=i.expansion.shadowed;content}inletexpansion=ifi.expansion.content.compiledtheni.expansionelseget_expansion()in{iwithdecl=include_declenvi.parenti.decl;expansion}andsimple_expansion:Env.t->Id.Signature.t->ModuleType.simple_expansion->ModuleType.simple_expansion=funenvide->matchewith|Signaturesg->Signature(signatureenvidsg)|Functor(param,sg)->letenv'=Env.add_functor_parameterparamenvinFunctor(functor_parameterenvparam,simple_expansionenv'(`Resultid)sg)andfunctor_parameter:Env.t->FunctorParameter.t->FunctorParameter.t=funenvparam->matchparamwith|Unit->Unit|Namedarg->Named(functor_parameter_parameterenvarg)andfunctor_parameter_parameter:Env.t->FunctorParameter.parameter->FunctorParameter.parameter=funenva->{awithexpr=module_type_exprenv(a.id:>Id.Signature.t)a.expr}andmodule_type_expr_subid~fragment_root(sg_res,env,subs)lsub=letopenUtils.ResultMonadinmatchsg_reswith|Error_->(sg_res,env,lsub::subs)|Oksg->(letlang_of_map=Lang_of.with_fragment_rootfragment_rootinletenv=Env.add_fragment_rootsgenvinletsg_and_sub=matchlsubwith|Odoc_model.Lang.ModuleType.ModuleEq(frag,decl)->letcfrag=Component.Of_Lang.(module_fragment(empty())frag)inletcfrag',frag'=matchTools.resolve_module_fragmentenv(fragment_root,sg)cfragwith|Somecfrag'->(`Resolvedcfrag',`Resolved(Lang_of.Path.resolved_module_fragmentlang_of_mapcfrag'))|None->Errors.report~what:(`With_modulecfrag)`Resolve;(cfrag,frag)inletdecl'=module_declenviddeclinletcdecl'=Component.Of_Lang.(module_decl(empty())decl')inletresolved_csub=Component.ModuleType.ModuleEq(cfrag',cdecl')inTools.fragmap~mark_substituted:trueenvresolved_csubsg>>=funsg'->Ok(sg',Odoc_model.Lang.ModuleType.ModuleEq(frag',decl'))|TypeEq(frag,eqn)->letcfrag=Component.Of_Lang.(type_fragment(empty())frag)inletcfrag',frag'=matchTools.resolve_type_fragmentenv(fragment_root,sg)cfragwith|Somecfrag'->(`Resolvedcfrag',`Resolved(Lang_of.Path.resolved_type_fragmentlang_of_mapcfrag'))|None->Errors.report~what:(`With_typecfrag)`Compile;(cfrag,frag)inleteqn'=type_decl_equationenv(id:>Id.Parent.t)eqninletceqn'=Component.Of_Lang.(type_equation(empty())eqn')inTools.fragmap~mark_substituted:trueenv(Component.ModuleType.TypeEq(cfrag',ceqn'))sg>>=funsg'->Ok(sg',Odoc_model.Lang.ModuleType.TypeEq(frag',eqn'))|ModuleSubst(frag,mpath)->letcfrag=Component.Of_Lang.(module_fragment(empty())frag)inletcfrag',frag'=matchTools.resolve_module_fragmentenv(fragment_root,sg)cfragwith|Somecfrag->(`Resolvedcfrag,`Resolved(Lang_of.Path.resolved_module_fragmentlang_of_mapcfrag))|None->Errors.report~what:(`With_modulecfrag)`Resolve;(cfrag,frag)inletmpath'=module_pathenvmpathinletcmpath'=Component.Of_Lang.(module_path(empty())mpath')inTools.fragmap~mark_substituted:trueenv(Component.ModuleType.ModuleSubst(cfrag',cmpath'))sg>>=funsg'->Ok(sg',Odoc_model.Lang.ModuleType.ModuleSubst(frag',mpath'))|TypeSubst(frag,eqn)->letcfrag=Component.Of_Lang.(type_fragment(empty())frag)inletcfrag',frag'=matchTools.resolve_type_fragmentenv(fragment_root,sg)cfragwith|Somecfrag->(`Resolvedcfrag,`Resolved(Lang_of.Path.resolved_type_fragmentlang_of_mapcfrag))|None->Errors.report~what:(`With_typecfrag)`Compile;(cfrag,frag)inleteqn'=type_decl_equationenv(id:>Id.Parent.t)eqninletceqn'=Component.Of_Lang.(type_equation(empty())eqn')inTools.fragmap~mark_substituted:trueenv(Component.ModuleType.TypeSubst(cfrag',ceqn'))sg>>=funsg'->Ok(sg',Odoc_model.Lang.ModuleType.TypeSubst(frag',eqn'))|ModuleTypeEq(frag,mty)->letcfrag=Component.Of_Lang.(module_type_fragment(empty())frag)inletcfrag',frag'=matchTools.resolve_module_type_fragmentenv(fragment_root,sg)cfragwith|Somecfrag'->(`Resolvedcfrag',`Resolved(Lang_of.Path.resolved_module_type_fragmentlang_of_mapcfrag'))|None->Errors.report~what:(`With_module_typecfrag)`Resolve;(cfrag,frag)inletmty=module_type_exprenvidmtyinletmty'=Component.Of_Lang.(module_type_expr(empty())mty)inletresolved_csub=Component.ModuleType.ModuleTypeEq(cfrag',mty')inTools.fragmap~mark_substituted:trueenvresolved_csubsg>>=funsg'->Ok(sg',Odoc_model.Lang.ModuleType.ModuleTypeEq(frag',mty))|Odoc_model.Lang.ModuleType.ModuleTypeSubst(frag,mty)->letcfrag=Component.Of_Lang.(module_type_fragment(empty())frag)inletcfrag',frag'=matchTools.resolve_module_type_fragmentenv(fragment_root,sg)cfragwith|Somecfrag'->(`Resolvedcfrag',`Resolved(Lang_of.Path.resolved_module_type_fragmentlang_of_mapcfrag'))|None->Errors.report~what:(`With_module_typecfrag)`Resolve;(cfrag,frag)inletmty=module_type_exprenvidmtyinletmty'=Component.Of_Lang.(module_type_expr(empty())mty)inletresolved_csub=Component.ModuleType.ModuleTypeSubst(cfrag',mty')inTools.fragmap~mark_substituted:trueenvresolved_csubsg>>=funsg'->Ok(sg',Odoc_model.Lang.ModuleType.ModuleTypeSubst(frag',mty))inmatchsg_and_subwith|Ok(sg',sub')->(Oksg',env,sub'::subs)|Error_->(sg_res,env,lsub::subs))andmodule_type_map_subsenvidcexprsubs=letrecfind_parent:Component.ModuleType.U.expr->Cfrag.rootoption=funexpr->matchexprwith|Component.ModuleType.U.Signature_->None|Path(`Resolvedp)->Some(`ModuleTypep)|Path_->None|With(_,e)->find_parente|TypeOf{t_desc=ModPath(`Resolvedp);_}|TypeOf{t_desc=StructInclude(`Resolvedp);_}->Some(`Modulep)|TypeOf_->Noneinmatchfind_parentcexprwith|None->None|Someparent->(matchTools.signature_of_u_module_type_expr~mark_substituted:trueenvcexprwith|Errore->Errors.report~what:(`Module_typeid)~tools_error:e`Lookup;None|Oksg->letfragment_root=matchparentwith(`ModuleType_|`Module_)asx->xinlet_,_,subs=List.fold_left(module_type_expr_sub(id:>Id.Signature.t)~fragment_root)(Oksg,env,[])subsinletsubs=List.revsubsinSomesubs)andu_module_type_expr:Env.t->Id.Signature.t->ModuleType.U.expr->ModuleType.U.expr=funenvidexpr->letopenModuleTypeinletrecinner:U.expr->U.expr=function|Signatures->Signatures|Pathp->Path(module_type_pathenvp)|With(subs,expr)->letexpr'=innerexprinletcexpr=Component.Of_Lang.(u_module_type_expr(empty())expr')inletsubs'=matchmodule_type_map_subsenvidcexprsubswith|Somes->s|None->subsinletresult:ModuleType.U.expr=With(subs',expr')inresult|TypeOf{t_desc;t_expansion}->lett_desc=matcht_descwith|ModPathp->ModPath(module_pathenvp)|StructIncludep->StructInclude(module_pathenvp)inTypeOf{t_desc;t_expansion}ininnerexprandmodule_type_expr:Env.t->Id.Signature.t->?expand_paths:bool->ModuleType.expr->ModuleType.expr=funenvid?(expand_paths=true)expr->letget_expansioncure=matchcurwith|Somee->Some(simple_expansionenvide)|None->(letce=Component.Of_Lang.(module_type_expr(empty())e)inmatchExpand_tools.expansion_of_module_type_exprenvidcewith|Ok(_,_,ce)->lete=Lang_of.simple_expansion(Lang_of.empty())idceinSome(simple_expansionenvide)|Error`OpaqueModule->None|Errore->Errors.report~what:(`Module_type_exprce)~tools_error:e`Expand;None)inmatchexprwith|Signatures->Signature(signatureenvids)|Path{p_path;p_expansion}ase->letp_expansion=ifexpand_pathsthenget_expansionp_expansioneelsep_expansioninPath{p_path=module_type_pathenvp_path;p_expansion}|With{w_substitutions;w_expansion;w_expr}ase->(letw_expansion=get_expansionw_expansioneinletw_expr=u_module_type_exprenvidw_exprinletcexpr=Component.Of_Lang.(u_module_type_expr(empty())w_expr)inletsubs'=module_type_map_subsenvidcexprw_substitutionsinmatchsubs'with|None->With{w_substitutions;w_expansion;w_expr}|Somes->With{w_substitutions=s;w_expansion;w_expr})|Functor(param,res)->letparam'=functor_parameterenvparaminletenv'=Env.add_functor_parameterparamenvinletres'=module_type_exprenv'(`Resultid)resinFunctor(param',res')|TypeOf{t_desc;t_expansion}ase->lett_expansion=get_expansiont_expansioneinlett_desc=matcht_descwith|ModPathp->ModuleType.ModPath(module_pathenvp)|StructIncludep->StructInclude(module_pathenvp)inTypeOf{t_desc;t_expansion}andtype_decl:Env.t->TypeDecl.t->TypeDecl.t=funenvt->letopenTypeDeclinletcontainer=matcht.idwith|`Type(parent,_)->(parent:>Id.Parent.t)|`CoreType_->assertfalseinletequation=type_decl_equationenvcontainert.equationinletrepresentation=Opt.map(type_decl_representationenvcontainer)t.representationin{twithequation;representation}andtype_decl_equation:Env.t->Id.Parent.t->TypeDecl.Equation.t->TypeDecl.Equation.t=funenvparentt->letopenTypeDecl.Equationinletmanifest=Opt.map(type_expressionenvparent)t.manifestinletconstraints=List.map(fun(tex1,tex2)->(type_expressionenvparenttex1,type_expressionenvparenttex2))t.constraintsin{twithmanifest;constraints}andtype_decl_representation:Env.t->Id.Parent.t->TypeDecl.Representation.t->TypeDecl.Representation.t=funenvparentr->letopenTypeDecl.Representationinmatchrwith|Variantcs->Variant(List.map(type_decl_constructorenvparent)cs)|Recordfs->Record(List.map(type_decl_fieldenvparent)fs)|Extensible->Extensibleandtype_decl_fieldenvparentf=letopenTypeDecl.Fieldin{fwithtype_=type_expressionenvparentf.type_}andtype_decl_constructor_argumentenvparentc=letopenTypeDecl.Constructorinmatchcwith|Tuplets->Tuple(List.map(type_expressionenvparent)ts)|Recordfs->Record(List.map(type_decl_fieldenvparent)fs)andtype_decl_constructor:Env.t->Id.Parent.t->TypeDecl.Constructor.t->TypeDecl.Constructor.t=funenvparentc->letopenTypeDecl.Constructorinletargs=type_decl_constructor_argumentenvparentc.argsinletres=Opt.map(type_expressionenvparent)c.resin{cwithargs;res}andtype_expression_polyvarenvparentv=letopenTypeExpr.Polymorphic_variantinletconstructorc=letopenConstructorin{cwitharguments=List.map(type_expressionenvparent)c.arguments}inletelement=function|Typet->Type(type_expressionenvparentt)|Constructorc->Constructor(constructorc)in{vwithelements=List.mapelementv.elements}andtype_expression_objectenvparento=letopenTypeExpr.Objectinletmethod_m={mwithtype_=type_expressionenvparentm.type_}inletfield=function|Methodm->Method(method_m)|Inheritt->Inherit(type_expressionenvparentt)in{owithfields=List.mapfieldo.fields}andtype_expression_packageenvparentp=letopenTypeExpr.Packageinletcp=Component.Of_Lang.(module_type_path(empty())p.path)inmatchTools.resolve_module_type~mark_substituted:true~add_canonical:trueenvcpwith|Ok(path,mt)->(matchTools.signature_of_module_typeenvmtwith|Errore->Errors.report~what:(`Packagecp)~tools_error:e`Lookup;p|Oksg->letsubstitution(frag,t)=letcfrag=Component.Of_Lang.(type_fragment(empty())frag)inletfrag'=matchTools.resolve_type_fragmentenv(`ModuleTypepath,sg)cfragwith|Somecfrag'->`Resolved(Lang_of.(Path.resolved_type_fragment(empty()))cfrag')|None->Errors.report~what:(`Typecfrag)`Compile;fragin(frag',type_expressionenvparentt)in{path=module_type_pathenvp.path;substitutions=List.mapsubstitutionp.substitutions;})|Error_->{pwithpath=Lang_of.(Path.module_type(empty())cp)}andtype_expression:Env.t->Id.Parent.t->_->_=funenvparenttexpr->letopenTypeExprinmatchtexprwith|Var_|Any->texpr|Alias(t,str)->Alias(type_expressionenvparentt,str)|Arrow(lbl,t1,t2)->Arrow(lbl,type_expressionenvparentt1,type_expressionenvparentt2)|Tuplets->Tuple(List.map(type_expressionenvparent)ts)|Constr(path,ts')->(letcp=Component.Of_Lang.(type_path(empty())path)inletts=List.map(type_expressionenvparent)ts'inmatchTools.resolve_typeenv~add_canonical:truecpwith|Ok(cp,(`FType_|`FClass_|`FClassType_))->letp=Lang_of.(Path.resolved_type(empty())cp)inConstr(`Resolvedp,ts)|Ok(_cp,`FType_removed(_,x,_eq))->(* Substitute type variables ? *)Lang_of.(type_expr(empty())parentx)|Error_->Constr(Lang_of.(Path.type_(empty())cp),ts))|Polymorphic_variantv->Polymorphic_variant(type_expression_polyvarenvparentv)|Objecto->Object(type_expression_objectenvparento)|Class(path,ts)->(letts'=List.map(type_expressionenvparent)tsinletcp=Component.Of_Lang.(class_type_path(empty())path)inmatchTools.resolve_class_typeenvcpwith|Ok(cp,(`FClass_|`FClassType_))->letp=Lang_of.(Path.resolved_class_type(empty())cp)inClass(`Resolvedp,ts')|_->Class(path,ts'))|Poly(strs,t)->Poly(strs,type_expressionenvparentt)|Packagep->Package(type_expression_packageenvparentp)letcompile~filenameenvcompilation_unit=Lookup_failures.catch_failures~filename(fun()->unitenvcompilation_unit)letresolve_page_resolvery=y