123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)openDeclarationsopenLibnamesopenConstrexpropenConstrinterntypemodule_internalization_error=|NotAModuleNorModtypeofqualid|NotAModuleTypeofqualid|NotAModuleofqualid|IncorrectWithInModule|IncorrectModuleApplicationexceptionModuleInternalizationErrorofmodule_internalization_errortypemodule_kind=Module|ModType|ModAnytypemodule_struct_expr=(universe_decl_exproption*constr_expr)Declarations.module_alg_exprleterror_not_a_module_loc~infokindlocqid=lete=matchkindwith|Module->NotAModuleqid|ModType->NotAModuleTypeqid|ModAny->NotAModuleNorModtypeqidinletinfo=Option.cata(Loc.add_locinfo)infolocinExninfo.iraise(ModuleInternalizationErrore,info)leterror_incorrect_with_in_moduleloc=Loc.raise?loc(ModuleInternalizationErrorIncorrectWithInModule)leterror_application_to_module_typeloc=Loc.raise?loc(ModuleInternalizationErrorIncorrectModuleApplication)(** Searching for a module name in the Nametab.
According to the input module kind, modules or module types
or both are searched. The returned kind is never ModAny, and
it is equal to the input kind when this one isn't ModAny. *)letlookup_module_or_modtypekindqid=letloc=qid.CAst.locintryifkind==ModTypethenraiseNot_found;letmp=Nametab.locate_moduleqidinDumpglob.dump_modref?locmp"modtype";(mp,Module)withNot_found->tryifkind==ModulethenraiseNot_found;letmp=Nametab.locate_modtypeqidinDumpglob.dump_modref?locmp"mod";(mp,ModType)withNot_foundasexn->let_,info=Exninfo.captureexninerror_not_a_module_loc~infokindlocqidletlookup_modulelqid=fst(lookup_module_or_modtypeModulelqid)letlookup_polymorphismenvbasekindfqid=letm=matchkindwith|Module->(Environ.lookup_modulebaseenv).mod_type|ModType->(Environ.lookup_modtypebaseenv).mod_type|ModAny->assertfalseinletrecdefunctor=function|NoFunctorm->m|MoreFunctor(_,_,m)->defunctorminletrecauxmfqid=letopenNamesinmatchfqidwith|[]->assertfalse|[id]->lettest(lab,obj)=matchId.equal(Label.to_idlab)id,objwith|false,_|_,(SFBrules_|SFBmodule_|SFBmodtype_)->None|true,SFBmindmind->Some(Declareops.inductive_is_polymorphicmind)|true,SFBconstconst->Some(Declareops.constant_is_polymorphicconst)in(matchCList.find_maptestmwithSomev->v|None->false(* error later *))|id::rem->letnext=function|MoreFunctor_->false(* error later *)|NoFunctorbody->auxbodyreminlettest(lab,obj)=matchId.equal(Label.to_idlab)id,objwith|false,_|_,(SFBrules_|SFBconst_|SFBmind_)->None|true,SFBmodulebody->Some(nextbody.mod_type)|true,SFBmodtypebody->(* XXX is this valid? If not error later *)Some(nextbody.mod_type)in(matchCList.find_maptestmwithSomev->v|None->false(* error later *))inaux(defunctorm)fqidletintern_with_decl=function|CWith_Module({CAst.v=fqid},qid)->WithMod(fqid,lookup_moduleqid)|CWith_Definition({CAst.v=fqid},udecl,c)->WithDef(fqid,(udecl,c))letloc_of_modulel=l.CAst.loc(* Invariant : the returned kind is never ModAny, and it is
equal to the input kind when this one isn't ModAny. *)letrecintern_module_astkindm=matchmwith|{CAst.loc;v=CMidentqid}->let(mp,kind)=lookup_module_or_modtypekindqidin(MEidentmp,mp,kind)|{CAst.loc;v=CMapply(me1,me2)}->letme1',base,kind1=intern_module_astkindme1inletmp2,kind2=lookup_module_or_modtypeModAnyme2inifkind2==ModTypethenerror_application_to_module_type(loc_of_moduleme2);(MEapply(me1',mp2),base,kind1)|{CAst.loc;v=CMwith(me,decl)}->letme,base,kind=intern_module_astkindmeinifkind==Modulethenerror_incorrect_with_in_modulem.CAst.loc;letdecl=intern_with_decldeclin(MEwith(me,decl),base,kind)letinterp_with_declenvbasekind=function|WithMod(fqid,mp)->WithMod(fqid,mp),Univ.ContextSet.empty|WithDef(fqid,(udecl,c))->letsigma,udecl=interp_univ_decl_optenvudeclinletc,ectx=interp_constrenvsigmacinletpoly=lookup_polymorphismenvbasekindfqidinbeginmatchfst(UState.check_univ_decl~polyectxudecl)with|UState.Polymorphic_entryctx->letinst,ctx=UVars.abstract_universesctxinletc=EConstr.Vars.subst_univs_level_constr(UVars.make_instance_substinst)cinletc=EConstr.to_constrsigmacinWithDef(fqid,(c,Somectx)),Univ.ContextSet.empty|UState.Monomorphic_entryctx->letc=EConstr.to_constrsigmacinWithDef(fqid,(c,None)),ctxendletrecinterp_module_astenvkindbasemcst=matchmwith|MEidentmp->MEidentmp,cst|MEapply(me,mp)->letme',cst=interp_module_astenvkindbasemecstinMEapply(me',mp),cst|MEwith(me,decl)->letme,cst=interp_module_astenvkindbasemecstinletdecl,cst'=interp_with_declenvbasekinddeclinletcst=Univ.ContextSet.unioncstcst'inMEwith(me,decl),cstletinterp_module_astenvkindbasem=interp_module_astenvkindbasemUniv.ContextSet.empty