123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141(************************************************************************)(* * 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) *)(************************************************************************)openUnivtypet=|QEqofSorts.Quality.t*Sorts.Quality.t|QLeqofSorts.Quality.t*Sorts.Quality.t|ULeofSorts.t*Sorts.t|UEqofSorts.t*Sorts.t|ULubofLevel.t*Level.t|UWeakofLevel.t*Level.tletis_trivial=function|QLeq(QConstantQProp,QConstantQType)->true|QLeq(a,b)|QEq(a,b)->Sorts.Quality.equalab|ULe(u,v)|UEq(u,v)->Sorts.equaluv|ULub(u,v)|UWeak(u,v)->Level.equaluvletforce=function|QEq_|QLeq_|ULe_|UEq_|UWeak_ascst->cst|ULub(u,v)->UEq(Sorts.sort_of_univ@@Universe.makeu,Sorts.sort_of_univ@@Universe.makev)letcheck_eq_levelguv=UGraph.check_eq_levelguvmoduleSet=structmoduleS=Set.Make(structtypenonrect=tletcomparexy=matchx,ywith|QEq(a,b),QEq(a',b')->leti=Sorts.Quality.compareaa'inifi<>0thenielseSorts.Quality.comparebb'|QLeq(a,b),QLeq(a',b')->leti=Sorts.Quality.compareaa'inifi<>0thenielseSorts.Quality.comparebb'|ULe(u,v),ULe(u',v')->leti=Sorts.compareuu'inifInt.equali0thenSorts.comparevv'elsei|UEq(u,v),UEq(u',v')->leti=Sorts.compareuu'inifInt.equali0thenSorts.comparevv'elseifSorts.equaluv'&&Sorts.equalvu'then0elsei|ULub(u,v),ULub(u',v')|UWeak(u,v),UWeak(u',v')->leti=Level.compareuu'inifInt.equali0thenLevel.comparevv'elseifLevel.equaluv'&&Level.equalvu'then0elsei|QEq_,_->-1|_,QEq_->1|QLeq_,_->-1|_,QLeq_->1|ULe_,_->-1|_,ULe_->1|UEq_,_->-1|_,UEq_->1|ULub_,_->-1|_,ULub_->1end)includeSletaddcsts=ifis_trivialcstthenselseaddcstsletpr_one=letopenPpinfunction|QEq(a,b)->Sorts.Quality.raw_pra++str" = "++Sorts.Quality.raw_prb|QLeq(a,b)->Sorts.Quality.raw_pra++str" <= "++Sorts.Quality.raw_prb|ULe(u,v)->Sorts.debug_printu++str" <= "++Sorts.debug_printv|UEq(u,v)->Sorts.debug_printu++str" = "++Sorts.debug_printv|ULub(u,v)->Level.raw_pru++str" /\\ "++Level.raw_prv|UWeak(u,v)->Level.raw_pru++str" ~ "++Level.raw_prvletprc=letopenPpinfold(funcstpp_std->pp_std++pr_onecst++fnl())c(str"")letequalxy=x==y||equalxyletforces=mapforcesendtype'aconstraint_function='a->'a->Set.t->Set.tletenforce_eq_instances_univsstrictxyc=letmkUu=Sorts.sort_of_univ@@Universe.makeuinletmkuv=ifstrictthenULub(u,v)elseUEq(mkUu,mkUv)inifnot(UVars.eq_sizes(UVars.Instance.lengthx)(UVars.Instance.lengthy))thenCErrors.anomalyPp.(str"Invalid argument: enforce_eq_instances_univs called with"++str" instances of different lengths.");letxq,xu=UVars.Instance.to_arrayxandyq,yu=UVars.Instance.to_arrayyinletc=CArray.fold_left2(* TODO strict? *)(funcxy->ifSorts.Quality.equalxythencelseSet.add(QEq(x,y))c)cxqyqinletc=CArray.fold_left2(funcxy->Set.add(mkxy)c)cxuyuincletenforce_eq_qualitiesqsqs'cstrs=CArray.fold_left2(funcab->ifSorts.Quality.equalabthencelseSet.add(QEq(a,b))c)cstrsqsqs'letcompare_cumulative_instancescv_pbvariancesuu'cstrs=letmakeu=Sorts.sort_of_univ@@Univ.Universe.makeuinletqs,us=UVars.Instance.to_arrayuandqs',us'=UVars.Instance.to_arrayu'inletcstrs=enforce_eq_qualitiesqsqs'cstrsinCArray.fold_left3(funcstrsvuu'->letopenUVars.Varianceinmatchvwith|Irrelevant->Set.add(UWeak(u,u'))cstrs|Covariant->(matchcv_pbwith|Conversion.CONV->Set.add(UEq(makeu,makeu'))cstrs|Conversion.CUMUL->Set.add(ULe(makeu,makeu'))cstrs)|Invariant->Set.add(UEq(makeu,makeu'))cstrs)cstrsvariancesusus'