123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501(************************************************************************)(* * The Rocq Prover / The Rocq 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) *)(************************************************************************)openUnivtypefamily=InSProp|InProp|InSet|InType|InQSortletall_families=[InSProp;InProp;InSet;InType;InQSort]moduleQVar=structtyperepr=|Varofint|Unifofstring*inttypet=reprletmake_varn=Varnletmake_unifsn=Unif(s,n)letvar_index=function|Varq->Someq|Unif_->Nonelethash=function|Varq->Hashset.Combine.combinesmall1q|Unif(s,q)->Hashset.Combine.(combinesmall2(combine(CString.hashs)q))moduleHstruct=structtypenonrect=ttypeu=unitlethashcons()=function|Var_asq->q|Unif(s,i)asq->lets'=CString.hconssinifs==s'thenqelseUnif(s',i)leteqab=matcha,bwith|Vara,Varb->Int.equalab|Unif(sa,ia),Unif(sb,ib)->sa==sb&&Int.equaliaib|(Var_|Unif_),_->falselethash=hashendmoduleHasher=Hashcons.Make(Hstruct)lethcons=Hashcons.simple_hconsHasher.generateHasher.hcons()letcompareab=matcha,bwith|Vara,Varb->Int.compareab|Unif(s1,i1),Unif(s2,i2)->letc=Int.comparei1i2inifc<>0thencelseCString.compares1s2|Var_,Unif_->-1|Unif_,Var_->1letequalab=matcha,bwith|Vara,Varb->Int.equalab|Unif(s1,i1),Unif(s2,i2)->Int.equali1i2&&CString.equals1s2|Var_,Unif_|Unif_,Var_->falseletto_string=function|Varq->Printf.sprintf"β%d"q|Unif(s,q)->lets=ifCString.is_emptysthen""elses^"."inPrintf.sprintf"%sα%d"sqletraw_prq=Pp.str(to_stringq)letreprx=xletof_reprx=xmoduleSelf=structtypenonrect=tletcompare=compareendmoduleSet=CSet.Make(Self)moduleMap=CMap.Make(Self)endmoduleQuality=structtypeconstant=QProp|QSProp|QTypetypet=QVarofQVar.t|QConstantofconstantletvari=QVar(QVar.make_vari)letvar_index=function|QVarq->QVar.var_indexq|QConstant_->NonemoduleConstants=structletequalab=matcha,bwith|QProp,QProp|QSProp,QSProp|QType,QType->true|(QProp|QSProp|QType),_->falseletcompareab=matcha,bwith|QProp,QProp->0|QProp,_->-1|_,QProp->1|QSProp,QSProp->0|QSProp,_->-1|_,QSProp->1|QType,QType->0letpr=function|QProp->Pp.str"Prop"|QSProp->Pp.str"SProp"|QType->Pp.str"Type"lethash=function|QSProp->0|QProp->1|QType->2endletequalab=matcha,bwith|QVara,QVarb->QVar.equalab|QConstanta,QConstantb->Constants.equalab|(QVar_|QConstant_),_->falseletcompareab=matcha,bwith|QVara,QVarb->QVar.compareab|QVar_,_->-1|_,QVar_->1|QConstanta,QConstantb->Constants.compareabletprprv=function|QVarv->prvv|QConstantq->Constants.prqletraw_prq=prQVar.raw_prqlethash=letopenHashset.Combineinfunction|QConstantq->Constants.hashq|QVarq->combinesmall3(QVar.hashq)letsubstf=function|QConstant_asq->q|QVarqvasq->matchfqvwith|QConstant_asq->q|QVarqv'asq'->ifqv==qv'thenqelseq'letsubst_fnmv=matchQVar.Map.find_optvmwith|Somev->v|None->QVarvmoduleHstruct=structtypenonrect=ttypeu=QVar.t->QVar.tlethashconshv=function|QConstant_asq->q|QVarqvasq->letqv'=hvqvinifqv==qv'thenqelseQVarqv'leteqab=matcha,bwith|QVara,QVarb->a==b|QVar_,_->false|(QConstant_),_->equalablethash=hashendmoduleHasher=Hashcons.Make(Hstruct)lethcons=Hashcons.simple_hconsHasher.generateHasher.hconsQVar.hconsletqsprop=hcons(QConstantQSProp)letqprop=hcons(QConstantQProp)letqtype=hcons(QConstantQType)moduleSelf=structtypenonrect=tletcompare=compareendmoduleSet=CSet.Make(Self)moduleMap=CMap.Make(Self)typepattern=|PQVarofintoption|PQConstantofconstantletpattern_matchpssqusubst=matchps,swith|PQConstantqc,QConstantqc'->ifConstants.equalqcqc'thenSomequsubstelseNone|PQVarqio,q->Some(Partial_subst.maybe_add_qualityqioqqusubst)|PQConstant_,QVar_->NoneendmoduleQConstraint=structtypekind=Equal|Leqleteq_kind:kind->kind->bool=(=)letcompare_kind:kind->kind->int=compareletpr_kind=function|Equal->Pp.str"="|Leq->Pp.str"<="typet=Quality.t*kind*Quality.tletequal(a,k,b)(a',k',b')=eq_kindkk'&&Quality.equalaa'&&Quality.equalbb'letcompare(a,k,b)(a',k',b')=letc=compare_kindkk'inifc<>0thencelseletc=Quality.compareaa'inifc<>0thencelseQuality.comparebb'lettrivial(a,(Equal|Leq),b)=Quality.equalabletprprq(a,k,b)=letopenPpinhov1(Quality.prprqa++spc()++pr_kindk++spc()++Quality.prprqb)letraw_prx=prQVar.raw_prxendmoduleQConstraints=structincludeCSet.Make(QConstraint)lettrivial=for_allQConstraint.trivialletprprqc=letopenPpinv0(prlist_with_sepspc(fun(u1,op,u2)->hov0(Quality.prprqu1++QConstraint.pr_kindop++Quality.prprqu2))(elementsc))endletenforce_eq_qualityabcsts=ifQuality.equalabthencstselseQConstraints.add(a,QConstraint.Equal,b)cstsletenforce_leq_qualityabcsts=ifQuality.equalabthencstselsematcha,bwith|Quality.(QConstantQProp),Quality.(QConstantQType)->csts|_->QConstraints.add(a,QConstraint.Leq,b)cstsmoduleQUConstraints=structtypet=QConstraints.t*Univ.Constraints.tletempty=QConstraints.empty,Univ.Constraints.emptyletunion(qcsts,ucsts)(qcsts',ucsts')=QConstraints.unionqcstsqcsts',Constraints.unionucstsucsts'endtypet=|SProp|Prop|Set|TypeofUniverse.t|QSortofQVar.t*Universe.tletsprop=SPropletprop=Propletset=Setlettype1=TypeUniverse.type1letqsortqu=QSort(q,u)letsort_of_univu=ifUniverse.is_type0uthensetelseTypeuletmakequ=letopenQualityinmatchqwith|QVarq->qsortqu|QConstantQSProp->sprop|QConstantQProp->prop|QConstantQType->sort_of_univuletcompares1s2=ifs1==s2then0elsematchs1,s2with|SProp,SProp->0|SProp,(Prop|Set|Type_|QSort_)->-1|(Prop|Set|Type_|QSort_),SProp->1|Prop,Prop->0|Prop,(Set|Type_|QSort_)->-1|Set,Prop->1|Set,Set->0|Set,(Type_|QSort_)->-1|Type_,QSort_->-1|Typeu1,Typeu2->Universe.compareu1u2|Type_,(Prop|Set)->1|QSort(q1,u1),QSort(q2,u2)->letc=QVar.compareq1q2inifInt.equalc0thenUniverse.compareu1u2elsec|QSort_,(Prop|Set|Type_)->1letequals1s2=Int.equal(compares1s2)0letsuper=function|SProp|Prop|Set->Type(Universe.type1)|Typeu|QSort(_,u)->Type(Universe.superu)letis_sprop=function|SProp->true|Prop|Set|Type_|QSort_->falseletis_prop=function|Prop->true|SProp|Set|Type_|QSort_->falseletis_set=function|Set->true|SProp|Prop|Type_|QSort_->falseletis_small=function|SProp|Prop|Set->true|Type_|QSort_->falseletlevelss=matchswith|SProp|Prop->Level.Set.empty|Set->Level.Set.singletonLevel.set|Typeu|QSort(_,u)->Universe.levelsuletsubst_fn(fq,fu)=function|SProp|Prop|Setass->s|Typevass->letv'=fuvinifv'==vthenselsesort_of_univv'|QSort(q,v)ass->letopenQualityinmatchfqqwith|QVarq'->letv'=fuvinifq'==q&&v'==vthenselseqsortq'v'|QConstantQSProp->sprop|QConstantQProp->prop|QConstantQType->sort_of_univ(fuv)letfamily=function|SProp->InSProp|Prop->InProp|Set->InSet|Type_->InType|QSort_->InQSortletquality=letopenQualityinfunction|Set|Type_->QConstantQType|Prop->QConstantQProp|SProp->QConstantQSProp|QSort(q,_)->QVarqletfamily_compareab=matcha,bwith|InSProp,InSProp->0|InSProp,_->-1|_,InSProp->1|InProp,InProp->0|InProp,_->-1|_,InProp->1|InSet,InSet->0|InSet,_->-1|_,InSet->1|InType,InType->0|InType,_->-1|_,InType->1|InQSort,InQSort->0letfamily_equalab=matcha,bwith|InSProp,InSProp|InProp,InProp|InSet,InSet|InType,InType->true|InQSort,InQSort->true|(InSProp|InProp|InSet|InType|InQSort),_->falseletfamily_leqab=family_equalab||matcha,bwith|InSProp,_->true|InProp,InSet->true|_,InType->true|_->falseopenHashset.Combinelethash=function|SProp->combinesmall10|Prop->combinesmall11|Set->combinesmall12|Typeu->leth=Univ.Universe.hashuincombinesmall2h|QSort(q,u)->leth=Univ.Universe.hashuinleth'=QVar.hashqincombinesmall3(combinehh')moduleHsorts=Hashcons.Make(structtype_t=ttypet=_ttypeu=Universe.t->Universe.tlethashconshuniv=function|Typeuasc->letu'=hunivuinifu'==uthencelseTypeu'|QSort(q,u)asc->letu'=hunivuinifu'==uthencelseQSort(q,u)|SProp|Prop|Setass->sleteqs1s2=match(s1,s2)with|SProp,SProp|Prop,Prop|Set,Set->true|(Typeu1,Typeu2)->u1==u2|QSort(q1,u1),QSort(q2,u2)->q1==q2&&u1==u2|(SProp|Prop|Set|Type_|QSort_),_->falselethash=hashend)lethcons=Hashcons.simple_hconsHsorts.generateHsorts.hconshcons_univ(** On binders: is this variable proof relevant *)typerelevance=Relevant|Irrelevant|RelevanceVarofQVar.tletrelevance_equalr1r2=matchr1,r2with|Relevant,Relevant|Irrelevant,Irrelevant->true|RelevanceVarq1,RelevanceVarq2->QVar.equalq1q2|(Relevant|Irrelevant|RelevanceVar_),_->falseletrelevance_of_sort_family=function|InSProp->Irrelevant|_->Relevantletrelevance_hash=function|Relevant->0|Irrelevant->1|RelevanceVarq->Hashset.Combine.combinesmall2(QVar.hashq)letrelevance_subst_fnf=function|Relevant|Irrelevantasr->r|RelevanceVarqvasr->letopenQualityinmatchfqvwith|QConstantQSProp->Irrelevant|QConstant(QProp|QType)->Relevant|QVarqv'->ifqv'==qvthenrelseRelevanceVarqv'letrelevance_of_sort=function|SProp->Irrelevant|Prop|Set|Type_->Relevant|QSort(q,_)->RelevanceVarqletdebug_print=function|SProp->Pp.(str"SProp")|Prop->Pp.(str"Prop")|Set->Pp.(str"Set")|Typeu->Pp.(str"Type("++Univ.Universe.raw_pru++str")")|QSort(q,u)->Pp.(str"QSort("++QVar.raw_prq++str","++spc()++Univ.Universe.raw_pru++str")")letpr_sort_family=function|InSProp->Pp.(str"SProp")|InProp->Pp.(str"Prop")|InSet->Pp.(str"Set")|InType->Pp.(str"Type")|InQSort->Pp.(str"Type")(* FIXME? *)typepattern=|PSProp|PSSProp|PSSet|PSTypeofintoption|PSQSortofintoption*intoptionletextract_levelu=matchUniverse.leveluwith|Somel->l|None->CErrors.anomalyPp.(str"Tried to extract level of an algebraic universe")letextract_sort_level=function|Typeu|QSort(_,u)->extract_levelu|Prop|SProp|Set->Univ.Level.setletpattern_matchpssqusubst=matchps,swith|PSProp,Prop->Somequsubst|PSSProp,SProp->Somequsubst|PSSet,Set->Somequsubst|PSTypeuio,Set->Some(Partial_subst.maybe_add_univuioUniv.Level.setqusubst)|PSTypeuio,Typeu->Some(Partial_subst.maybe_add_univuio(extract_levelu)qusubst)|PSQSort(qio,uio),s->Some(qusubst|>Partial_subst.maybe_add_qualityqio(qualitys)|>Partial_subst.maybe_add_univuio(extract_sort_levels))|(PSProp|PSSProp|PSSet|PSType_),_->None