123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144(************************************************************************)(* * 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) *)(************************************************************************)openNamesopenUniv(* object_kind , id *)exceptionAlreadyDeclaredof(stringoption*Id.t)let_=CErrors.register_handler(function|AlreadyDeclared(kind,id)->SomePp.(seq[Pp.pr_opt_no_spc(funs->strs++spc())kind;Id.printid;str" already exists."])|_->None)typeuniverse_source=|BoundUniv(* polymorphic universe, bound in a function (this will go away someday) *)|QualifiedUnivofId.t(* global universe introduced by some global value *)|UnqualifiedUniv(* other global universe *)typeuniverse_name_decl=universe_source*(Id.t*Univ.UGlobal.t)listletcheck_exists_universesp=ifNametab.exists_universespthenraise(AlreadyDeclared(Some"Universe",Libnames.basenamesp))else()letqualify_unividpsrcid=matchsrcwith|BoundUniv|UnqualifiedUniv->i,Libnames.make_pathdpid|QualifiedUnivl->letdp=DirPath.reprdpinNametab.map_visibilitysucci,Libnames.make_path(DirPath.make(l::dp))idletdo_univ_name~checkidpsrc(id,univ)=leti,sp=qualify_unividpsrcidinifcheckthencheck_exists_universesp;Nametab.push_universeispunivletcache_univ_names(prefix,(src,univs))=letdepth=Lib.sections_depth()inletdp=Libnames.pop_dirpath_ndepthprefix.Nametab.obj_dirinList.iter(do_univ_name~check:true(Nametab.Until1)dpsrc)univsletload_univ_namesi(prefix,(src,univs))=List.iter(do_univ_name~check:false(Nametab.Untili)prefix.Nametab.obj_dirsrc)univsletopen_univ_namesi(prefix,(src,univs))=List.iter(do_univ_name~check:false(Nametab.Exactlyi)prefix.Nametab.obj_dirsrc)univsletdischarge_univ_names=function|BoundUniv,_->None|(QualifiedUniv_|UnqualifiedUniv),_asx->Somexletinput_univ_names:universe_name_decl->Libobject.obj=letopenLibobjectindeclare_named_object_gen{(default_object"Global universe name state")withcache_function=cache_univ_names;load_function=load_univ_names;open_function=simple_openopen_univ_names;discharge_function=discharge_univ_names;subst_function=(fun(subst,a)->(* Actually the name is generated once and for all. *)a);classify_function=(funa->Substitute)}letinput_univ_names(src,l)=ifCList.is_emptylthen()elseLib.add_leaf(input_univ_names(src,l))letinvent_name(named,cnt)u=letrecauxi=letna=Id.of_string("u"^(string_of_inti))inifId.Map.memnanamedthenaux(i+1)elsena,(Id.Map.addnaunamed,i+1)inauxcntletlabel_of=letopenGlobRefinfunction|ConstRefc->Label.to_id@@Constant.labelc|IndRef(c,_)->Label.to_id@@MutInd.labelc|VarRefid->id|ConstructRef_->CErrors.anomaly~label:"declare_univ_binders"Pp.(str"declare_univ_binders on a constructor reference")letdeclare_univ_bindersgr(univs,pl)=letl=label_ofgrinmatchunivswith|UState.Polymorphic_entry_->()|UState.Monomorphic_entry(levels,_)->(* First the explicitly named universes *)letnamed,univs=Id.Map.fold(funiduniv(named,univs)->letunivs=matchUniv.Level.nameunivwith|None->assertfalse(* having Prop/Set/Var as binders is nonsense *)|Someuniv->(id,univ)::univsinletnamed=Level.Set.addunivnamedinnamed,univs)pl(Level.Set.empty,[])in(* then invent names for the rest *)let_,univs=Level.Set.fold(fununiv(aux,univs)->letid,aux=invent_nameauxunivinletuniv=Option.get(Level.nameuniv)inaux,(id,univ)::univs)(Level.Set.difflevelsnamed)((pl,0),univs)ininput_univ_names(QualifiedUnivl,univs)letdo_universe~polyl=letin_section=Lib.sections_are_opened()inlet()=ifpoly&¬in_sectionthenCErrors.user_err(Pp.str"Cannot declare polymorphic universes outside sections.")inletl=List.map(fun{CAst.v=id}->(id,UnivGen.new_univ_global()))linletctx=List.fold_left(functx(_,qid)->Univ.Level.Set.add(Univ.Level.makeqid)ctx)Univ.Level.Set.emptyl,Univ.Constraints.emptyinletsrc=ifpolythenBoundUnivelseUnqualifiedUnivinlet()=input_univ_names(src,l)inDeclareUctx.declare_universe_context~polyctxletdo_constraint~polyl=letopenUnivinletevd=Evd.from_env(Global.env())inletconstraints=List.fold_left(funacccst->letcst=Constrintern.interp_univ_constraintevdcstinConstraints.addcstacc)Constraints.emptylinletuctx=ContextSet.add_constraintsconstraintsContextSet.emptyinDeclareUctx.declare_universe_context~polyuctx