123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107(************************************************************************)(* * 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) *)(************************************************************************)openSortsopenNamesopenConstropenUniv(* Generator of levels *)letnew_univ_id=letcnt=ref0infun()->incrcnt;!cntletnew_univ_global()=lets=ifFlags.async_proofs_is_worker()then!Flags.async_proofs_worker_idelse""inUniv.Level.UGlobal.make(Global.current_dirpath())s(new_univ_id())letfresh_level()=Univ.Level.make(new_univ_global())letfresh_instanceauctx=letinst=Array.init(AUContext.sizeauctx)(fun_->fresh_level())inletctx=Array.fold_rightLSet.addinstLSet.emptyinletinst=Instance.of_arrayinstininst,(ctx,AUContext.instantiateinstauctx)letexisting_instance?locauctxinst=let()=letlen1=Array.length(Instance.to_arrayinst)andlen2=AUContext.sizeauctxinifnot(len1==len2)thenCErrors.user_err?loc~hdr:"Universes"Pp.(str"Universe instance should have length "++intlen2++str".")else()ininst,(LSet.empty,AUContext.instantiateinstauctx)letfresh_instance_from?locctx=function|Someinst->existing_instance?locctxinst|None->fresh_instancectx(** Fresh universe polymorphic construction *)letfresh_global_instance?loc?namesenvgr=letauctx=Environ.universes_of_globalenvgrinletu,ctx=fresh_instance_from?locauctxnamesinu,ctxletfresh_constant_instanceenvc=letu,ctx=fresh_global_instanceenv(GlobRef.ConstRefc)in(c,u),ctxletfresh_inductive_instanceenvind=letu,ctx=fresh_global_instanceenv(GlobRef.IndRefind)in(ind,u),ctxletfresh_constructor_instanceenvc=letu,ctx=fresh_global_instanceenv(GlobRef.ConstructRefc)in(c,u),ctxletfresh_array_instanceenv=letauctx=CPrimitives.typ_univsCPrimitives.PT_arrayinletu,ctx=fresh_instance_fromauctxNoneinu,ctxletfresh_global_instance?loc?namesenvgr=letu,ctx=fresh_global_instance?loc?namesenvgrinmkRef(gr,u),ctxletconstr_of_monomorphic_globalgr=ifnot(Global.is_polymorphicgr)thenfst(fresh_global_instance(Global.env())gr)elseCErrors.user_err~hdr:"constr_of_global"Pp.(str"globalization of polymorphic reference "++Nametab.pr_global_envId.Set.emptygr++str" would forget universes.")letfresh_sort_in_family=function|InSProp->Sorts.sprop,ContextSet.empty|InProp->Sorts.prop,ContextSet.empty|InSet->Sorts.set,ContextSet.empty|InType->letu=fresh_level()insort_of_univ(Univ.Universe.makeu),ContextSet.singletonuletnew_global_univ()=letu=fresh_level()in(Univ.Universe.makeu,ContextSet.singletonu)letfresh_universe_context_set_instancectx=ifContextSet.is_emptyctxthenLMap.empty,ctxelselet(univs,cst)=ContextSet.levelsctx,ContextSet.constraintsctxinletunivs',subst=LSet.fold(funu(univs',subst)->letu'=fresh_level()in(LSet.addu'univs',LMap.adduu'subst))univs(LSet.empty,LMap.empty)inletcst'=subst_univs_level_constraintssubstcstinsubst,(univs',cst')