@@ -149,28 +149,28 @@ type conv_pb =
149149 | CUMUL
150150
151151type ('a, 'err) universe_compare = {
152- compare_sorts : env -> conv_pb -> Sorts .t -> Sorts .t -> 'a -> ('a , 'err option ) result ;
153- compare_instances : env -> flex :bool -> UVars.Instance .t -> UVars.Instance .t -> 'a -> ('a , 'err option ) result ;
154- compare_cumul_instances : env -> conv_pb -> UVars.Variance .t array ->
152+ compare_sorts : conv_pb -> Sorts .t -> Sorts .t -> 'a -> ('a , 'err option ) result ;
153+ compare_instances : flex :bool -> UVars.Instance .t -> UVars.Instance .t -> 'a -> ('a , 'err option ) result ;
154+ compare_cumul_instances : conv_pb -> UVars.Variance .t array ->
155155 UVars.Instance .t -> UVars.Instance .t -> 'a -> ('a , 'err option ) result ;
156156}
157157
158158type ('a, 'err) universe_state = 'a * ('a , 'err ) universe_compare
159159
160160type ('a, 'err) generic_conversion_function = ('a , 'err ) universe_state -> constr -> constr -> ('a , 'err option ) result
161161
162- let sort_cmp_universes env pb s0 s1 (u , check ) =
163- (check.compare_sorts env pb s0 s1 u, check)
162+ let sort_cmp_universes pb s0 s1 (u , check ) =
163+ (check.compare_sorts pb s0 s1 u, check)
164164
165165(* [flex] should be true for constants, false for inductive types and
166166 constructors. *)
167- let convert_instances env ~flex u u' (s , check ) =
168- (check.compare_instances env ~flex u u' s, check)
167+ let convert_instances ~flex u u' (s , check ) =
168+ (check.compare_instances ~flex u u' s, check)
169169
170170exception MustExpand
171171
172- let convert_instances_cumul env pb var u u' (s , check ) =
173- (check.compare_cumul_instances env pb var u u' s, check)
172+ let convert_instances_cumul pb var u u' (s , check ) =
173+ (check.compare_cumul_instances pb var u u' s, check)
174174
175175let get_cumulativity_constraints cv_pb variance u u' =
176176 match cv_pb with
@@ -209,8 +209,8 @@ let fail_check (infos : 'err conv_tab) (state, check) = match state with
209209| Result. Error None -> raise NotConvertible
210210| Result. Error (Some err ) -> raise (NotConvertibleTrace (infos.err_ret err))
211211
212- let convert_inductives env cv_pb ind nargs u1 u2 (s , check ) =
213- convert_inductives_gen (check.compare_instances env ~flex: false ) ( check.compare_cumul_instances env)
212+ let convert_inductives cv_pb ind nargs u1 u2 (s , check ) =
213+ convert_inductives_gen (check.compare_instances ~flex: false ) check.compare_cumul_instances
214214 cv_pb ind nargs u1 u2 s, check
215215
216216let constructor_cumulativity_arguments (mind , ind , ctor ) =
@@ -231,8 +231,8 @@ let convert_constructors_gen cmp_instances cmp_cumul (mind, ind, cns) nargs u1 u
231231 let variance = Array. make (snd (UVars.Instance. length u1)) UVars.Variance. Irrelevant in
232232 cmp_cumul CONV variance u1 u2 s
233233
234- let convert_constructors env ctor nargs u1 u2 (s , check ) =
235- convert_constructors_gen (check.compare_instances env ~flex: false ) ( check.compare_cumul_instances env)
234+ let convert_constructors ctor nargs u1 u2 (s , check ) =
235+ convert_constructors_gen (check.compare_instances ~flex: false ) check.compare_cumul_instances
236236 ctor nargs u1 u2 s, check
237237
238238let conv_table_key infos ~nargs k1 k2 cuniv =
@@ -244,7 +244,7 @@ let conv_table_key infos ~nargs k1 k2 cuniv =
244244 else
245245 let flex = evaluable_constant cst (info_env infos.cnv_inf)
246246 && RedFlags. red_set (info_flags infos.cnv_inf) (RedFlags. fCONST cst)
247- in fail_check infos @@ convert_instances (info_env infos.cnv_inf) ~flex u u' cuniv
247+ in fail_check infos @@ convert_instances ~flex u u' cuniv
248248 | VarKey id , VarKey id' when Id. equal id id' -> cuniv
249249 | RelKey n , RelKey n' when Int. equal n n' -> cuniv
250250 | _ -> raise NotConvertible
@@ -404,7 +404,7 @@ and eqwhnf cv_pb l2r infos (lft1, (hd1, v1) as appr1) (lft2, (hd2, v2) as appr2)
404404 if not (is_empty_stack v1 && is_empty_stack v2) then
405405 (* May happen because we convert application right to left *)
406406 raise NotConvertible ;
407- fail_check infos @@ sort_cmp_universes (info_env infos.cnv_inf) cv_pb s1 s2 cuniv
407+ fail_check infos @@ sort_cmp_universes cv_pb s1 s2 cuniv
408408 | (Meta n , Meta m ) ->
409409 if Int. equal n m
410410 then convert_stacks l2r infos lft1 lft2 v1 v2 cuniv
@@ -625,12 +625,12 @@ and eqwhnf cv_pb l2r infos (lft1, (hd1, v1) as appr1) (lft2, (hd2, v2) as appr2)
625625 | (FInd (ind1 ,u1 as pind1 ), FInd (ind2 ,u2 as pind2 )) ->
626626 if Ind.CanOrd. equal ind1 ind2 then
627627 if UVars.Instance. is_empty u1 || UVars.Instance. is_empty u2 then
628- let cuniv = fail_check infos @@ convert_instances (info_env infos.cnv_inf) ~flex: false u1 u2 cuniv in
628+ let cuniv = fail_check infos @@ convert_instances ~flex: false u1 u2 cuniv in
629629 convert_stacks l2r infos lft1 lft2 v1 v2 cuniv
630630 else
631631 let mind = Environ. lookup_mind (fst ind1) (info_env infos.cnv_inf) in
632632 let nargs = same_args_size v1 v2 in
633- match fail_check infos @@ convert_inductives (info_env infos.cnv_inf) cv_pb (mind, snd ind1) nargs u1 u2 cuniv with
633+ match fail_check infos @@ convert_inductives cv_pb (mind, snd ind1) nargs u1 u2 cuniv with
634634 | cuniv -> convert_stacks l2r infos lft1 lft2 v1 v2 cuniv
635635 | exception MustExpand ->
636636 let env = info_env infos.cnv_inf in
@@ -648,11 +648,11 @@ and eqwhnf cv_pb l2r infos (lft1, (hd1, v1) as appr1) (lft2, (hd2, v2) as appr2)
648648 let v2 = append_stack args2 v2 in
649649 if Int. equal j1 j2 && Ind.CanOrd. equal ind1 ind2 then
650650 if UVars.Instance. is_empty u1 || UVars.Instance. is_empty u2 then
651- let cuniv = fail_check infos @@ convert_instances (info_env infos.cnv_inf) ~flex: false u1 u2 cuniv in
651+ let cuniv = fail_check infos @@ convert_instances ~flex: false u1 u2 cuniv in
652652 convert_stacks l2r infos lft1 lft2 v1 v2 cuniv
653653 else
654654 let mind = Environ. lookup_mind (fst ind1) (info_env infos.cnv_inf) in
655- match fail_check infos @@ convert_constructors (info_env infos.cnv_inf) ( mind, snd ind1, j1) nargs u1 u2 cuniv with
655+ match fail_check infos @@ convert_constructors (mind, snd ind1, j1) nargs u1 u2 cuniv with
656656 | cuniv -> convert_stacks l2r infos lft1 lft2 v1 v2 cuniv
657657 | exception MustExpand ->
658658 let env = info_env infos.cnv_inf in
@@ -746,7 +746,7 @@ and eqwhnf cv_pb l2r infos (lft1, (hd1, v1) as appr1) (lft2, (hd2, v2) as appr2)
746746 let nargs = inductive_cumulativity_arguments ind in
747747 let u1 = CClosure. usubst_instance e1 u1 in
748748 let u2 = CClosure. usubst_instance e2 u2 in
749- fail_check infos @@ convert_inductives (info_env infos.cnv_inf) CONV ind nargs u1 u2 cuniv
749+ fail_check infos @@ convert_inductives CONV ind nargs u1 u2 cuniv
750750 in
751751 let pms1 = mk_clos_vect e1 pms1 in
752752 let pms2 = mk_clos_vect e2 pms2 in
@@ -758,7 +758,7 @@ and eqwhnf cv_pb l2r infos (lft1, (hd1, v1) as appr1) (lft2, (hd2, v2) as appr2)
758758 | FArray (u1 ,t1 ,ty1 ), FArray (u2 ,t2 ,ty2 ) ->
759759 let len = Parray. length_int t1 in
760760 if not (Int. equal len (Parray. length_int t2)) then raise NotConvertible ;
761- let cuniv = fail_check infos @@ convert_instances_cumul (info_env infos.cnv_inf) CONV [|UVars.Variance. Irrelevant |] u1 u2 cuniv in
761+ let cuniv = fail_check infos @@ convert_instances_cumul CONV [|UVars.Variance. Irrelevant |] u1 u2 cuniv in
762762 let el1 = el_stack lft1 v1 in
763763 let el2 = el_stack lft2 v2 in
764764 let cuniv = ccnv CONV l2r infos el1 el2 ty1 ty2 cuniv in
@@ -834,13 +834,13 @@ and convert_stacks ?(mask = [||]) l2r infos lft1 lft2 stk1 stk2 cuniv =
834834 let mip = mind.Declarations. mind_packets.(snd ci1.ci_ind) in
835835 let cu =
836836 if UVars.Instance. is_empty u1 || UVars.Instance. is_empty u2 then
837- convert_instances (info_env infos.cnv_inf) ~flex: false u1 u2 cu
837+ convert_instances ~flex: false u1 u2 cu
838838 else
839839 let u1 = CClosure. usubst_instance e1 u1 in
840840 let u2 = CClosure. usubst_instance e2 u2 in
841841 match mind.Declarations. mind_variance with
842- | None -> convert_instances (info_env infos.cnv_inf) ~flex: false u1 u2 cu
843- | Some variances -> convert_instances_cumul (info_env infos.cnv_inf) CONV variances u1 u2 cu
842+ | None -> convert_instances ~flex: false u1 u2 cu
843+ | Some variances -> convert_instances_cumul CONV variances u1 u2 cu
844844 in
845845 let cu = fail_check infos cu in
846846 let pms1 = mk_clos_vect e1 pms1 in
@@ -951,30 +951,30 @@ let clos_gen_conv (type err) ~typed trans cv_pb l2r evars env graph univs t1 t2
951951 | NotConvertibleTrace _ -> assert false
952952 end ()
953953
954- let check_eq univs elims u u' =
954+ let check_eq ( elims , univs as state ) u u' =
955955 if UGraph. check_eq_sort elims univs u u'
956- then Result. Ok univs
956+ then Result. Ok state
957957 else Result. Error None
958958
959- let check_leq univs elims u u' =
959+ let check_leq ( elims , univs as state ) u u' =
960960 if UGraph. check_leq_sort elims univs u u'
961- then Result. Ok univs
961+ then Result. Ok state
962962 else Result. Error None
963963
964- let checked_sort_cmp_universes env pb s0 s1 univs =
964+ let checked_sort_cmp_universes pb s0 s1 state =
965965 match pb with
966- | CUMUL -> check_leq univs ( Environ. qualities env) s0 s1
967- | CONV -> check_eq univs ( Environ. qualities env) s0 s1
966+ | CUMUL -> check_leq state s0 s1
967+ | CONV -> check_eq state s0 s1
968968
969- let check_convert_instances env ~flex :_ u u' univs =
970- if UGraph. check_eq_instances ( Environ. qualities env) univs u u' then Result. Ok univs
969+ let check_convert_instances ~flex :_ u u' ( elims , univs as state ) =
970+ if UGraph. check_eq_instances elims univs u u' then Result. Ok state
971971 else Result. Error None
972972
973973(* general conversion and inference functions *)
974- let check_inductive_instances env cv_pb variance u1 u2 univs =
974+ let check_inductive_instances cv_pb variance u1 u2 ( elims , univs as state ) =
975975 let qcsts, ucsts = get_cumulativity_constraints cv_pb variance u1 u2 in
976- if QGraph. check_constraints (Sorts.QCumulConstraints. to_elims qcsts) ( Environ. qualities env) && UGraph. check_constraints ucsts univs
977- then Result. Ok univs
976+ if QGraph. check_constraints (Sorts.QCumulConstraints. to_elims qcsts) elims && UGraph. check_constraints ucsts univs
977+ then Result. Ok state
978978 else Result. Error None
979979
980980let checked_universes =
@@ -986,12 +986,12 @@ let () =
986986 let conv infos tab a b =
987987 try
988988 let box = Empty. abort in
989- let univs = info_univs infos in
989+ let state = info_elims infos, info_univs infos in
990990 let infos = { cnv_inf = infos; cnv_typ = true ; lft_tab = tab; rgt_tab = tab; err_ret = box } in
991- let univs ', _ = ccnv CONV false infos el_id el_id a b
992- (univs , checked_universes)
991+ let state ', _ = ccnv CONV false infos el_id el_id a b
992+ (state , checked_universes)
993993 in
994- assert (univs == univs ');
994+ assert (state == state ');
995995 true
996996 with
997997 | NotConvertible -> false
@@ -1002,22 +1002,23 @@ let () =
10021002let gen_conv ~typed cv_pb ?(l2r =false ) ?(reds =TransparentState. full) env ?(evars =default_evar_handler env) t1 t2 =
10031003 let univs = Environ. universes env in
10041004 let elims = Environ. qualities env in
1005+ let state = elims, univs in
10051006 let b =
10061007 if cv_pb = CUMUL then leq_constr_univs elims univs t1 t2
10071008 else eq_constr_univs elims univs t1 t2
10081009 in
10091010 if b then Result. Ok ()
1010- else match clos_gen_conv ~typed reds cv_pb l2r evars env univs (univs , checked_universes) t1 t2 with
1011- | Result. Ok (_ : UGraph.t * (UGraph.t , Empty.t) universe_compare )-> Result. Ok ()
1011+ else match clos_gen_conv ~typed reds cv_pb l2r evars env univs (state , checked_universes) t1 t2 with
1012+ | Result. Ok (_ : 'a * ('a , Empty.t) universe_compare )-> Result. Ok ()
10121013 | Result. Error None -> Result. Error ()
10131014 | Result. Error (Some e ) -> Empty. abort e
10141015
10151016let conv = gen_conv ~typed: false CONV
10161017let conv_leq = gen_conv ~typed: false CUMUL
10171018
1018- let generic_conv cv_pb ~l2r reds env ?(evars =default_evar_handler env) univs t1 t2 =
1019+ let generic_conv cv_pb ~l2r reds env ?(evars =default_evar_handler env) state t1 t2 =
10191020 let graph = Environ. universes env in
1020- match clos_gen_conv ~typed: false reds cv_pb l2r evars env graph univs t1 t2 with
1021+ match clos_gen_conv ~typed: false reds cv_pb l2r evars env graph state t1 t2 with
10211022 | Result. Ok (s , _ ) -> Result. Ok s
10221023 | Result. Error e -> Result. Error e
10231024
0 commit comments