123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170(************************************************************************)(* * 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) *)(************************************************************************)(** Keys for unification and indexing *)openNamesopenConstropenLibobjectopenGlobnamestypekey=|KGlobofGlobRef.t|KLam|KLet|KProd|KSort|KCase|KFix|KCoFix|KRel|KInt|KFloat|KArraymoduleKeyOrdered=structtypet=keylethashgr=matchgrwith|KGlobgr->9+GlobRef.CanOrd.hashgr|KLam->0|KLet->1|KProd->2|KSort->3|KCase->4|KFix->5|KCoFix->6|KRel->7|KInt->8|KFloat->9|KArray->10letcomparegr1gr2=matchgr1,gr2with|KGlobgr1,KGlobgr2->GlobRef.CanOrd.comparegr1gr2|_,KGlob_->-1|KGlob_,_->1|k,k'->Int.compare(hashk)(hashk')letequalk1k2=matchk1,k2with|KGlobgr1,KGlobgr2->GlobRef.CanOrd.equalgr1gr2|_,KGlob_->false|KGlob_,_->false|k,k'->k==k'endmoduleKeymap=HMap.Make(KeyOrdered)moduleKeyset=Keymap.Set(* Mapping structure for references to be considered equivalent *)letkeys=Summary.refKeymap.empty~name:"Keys_decl"letadd_kvkvm=tryKeymap.modifyk(funk'vs->Keyset.addvvs)mwithNot_found->Keymap.addk(Keyset.singletonv)mletadd_keyskv=keys:=add_kvkv(add_kvvk!keys)letequiv_keyskk'=k==k'||KeyOrdered.equalkk'||tryKeyset.memk'(Keymap.findk!keys)withNot_found->false(** Registration of keys as an object *)letload_keys_(ref,ref')=add_keysrefref'letcache_keyso=load_keys1oletsubst_keysubstk=matchkwith|KGlobgr->KGlob(subst_global_referencesubstgr)|_->kletsubst_keys(subst,(k,k'))=(subst_keysubstk,subst_keysubstk')letdischarge_key=function|KGlob(GlobRef.VarRef_asg)whenLib.is_in_sectiong->None|x->Somexletdischarge_keys(k,k')=matchdischarge_keyk,discharge_keyk'with|Somex,Somey->Some(x,y)|_->Nonetypekey_obj=key*keyletinKeys:key_obj->obj=declare_object@@superglobal_object"KEYS"~cache:cache_keys~subst:(Somesubst_keys)~discharge:discharge_keysletdeclare_equiv_keysrefref'=Lib.add_leaf(inKeys(ref,ref'))letconstr_keykindc=tryletrecauxk=matchkindkwith|Const(c,_)->KGlob(GlobRef.ConstRefc)|Ind(i,u)->KGlob(GlobRef.IndRefi)|Construct(c,u)->KGlob(GlobRef.ConstructRefc)|Varid->KGlob(GlobRef.VarRefid)|App(f,_)->auxf|Proj(p,_)->KGlob(GlobRef.ConstRef(Projection.constantp))|Cast(p,_,_)->auxp|Lambda_->KLam|Prod_->KProd|Case_->KCase|Fix_->KFix|CoFix_->KCoFix|Rel_->KRel|Meta_->raiseNot_found|Evar_->raiseNot_found|Sort_->KSort|LetIn_->KLet|Int_->KInt|Float_->KFloat|Array_->KArrayinSome(auxc)withNot_found->NoneopenPpletpr_keypr_global=function|KGlobgr->pr_globalgr|KLam->str"Lambda"|KLet->str"Let"|KProd->str"Product"|KSort->str"Sort"|KCase->str"Case"|KFix->str"Fix"|KCoFix->str"CoFix"|KRel->str"Rel"|KInt->str"Int"|KFloat->str"Float"|KArray->str"Array"letpr_keysetpr_globalv=prlist_with_sepspc(pr_keypr_global)(Keyset.elementsv)letpr_mappingpr_globalkv=pr_keypr_globalk++str" <-> "++pr_keysetpr_globalvletpr_keyspr_global=Keymap.fold(funkvacc->pr_mappingpr_globalkv++fnl()++acc)!keys(mt())