@@ -1667,31 +1667,32 @@ let inductive_of_mutfix ?evars env ((nvect, bodynum), (names, types, bodies as r
16671667 else anomaly ~label: " check_one_fix" (Pp. str " Bad occurrence of recursive call." )
16681668 | _ -> raise_err env i (NotEnoughAbstractionInFixBody k)
16691669 in
1670- let ((ind, inst), bs) = check_occur fixenv 1 def in
1671- (* recursive sprop means non record with projections -> squashed *)
1672- let sorts_opt =
1673- if Environ. is_type_in_type env (GlobRef. IndRef ind) then None
1674- else
1670+ check_occur fixenv 1 def
1671+ in
1672+ (* Do it on every fixpoint *)
1673+ let rv = Array. map2_i find_ind nvect bodies in
1674+ (Array. map fst rv, Array. map snd rv)
1675+
1676+ (* Returns the pairs of (inductive sort * output sort) or None if Type in Type *)
1677+ let sorts_of_mutfix env minds names =
1678+ let check_type_in_type (ind , _ ) = Environ. is_type_in_type env (GlobRef. IndRef ind) in
1679+ (* recursive sprop means non record with projections -> squashed *)
1680+ if Array. exists check_type_in_type minds then None
1681+ else
1682+ Some (Array. fold_left_i (fun i sorts (ind , inst ) ->
16751683 let _, mip = lookup_mind_specif env ind in
1676- let sind = UVars. subst_instance_sort inst mip.mind_sort in
1677- let u = Sorts. univ_of_sort sind in
1684+ let ind_sort = UVars. subst_instance_sort inst mip.mind_sort in
1685+ let u = Sorts. univ_of_sort ind_sort in
16781686 (* This is an approximation: a [Relevant] variable might be of sort [Prop]
16791687 or [Type]. As we only care about the quality, we have to be conservative
16801688 here, i.e., every relevant sort (so, [Prop] or above) can be eliminated
16811689 into any other relevant sort. *)
1682- let bsort = match names.(i).Context. binder_relevance with
1690+ let out_sort = match names.(i).Context. binder_relevance with
16831691 | Irrelevant -> Sorts. sprop
16841692 | Relevant -> Sorts. prop
16851693 | RelevanceVar q -> Sorts. qsort q u in
1686- Some (sind, bsort)
1687- in
1688- ind, bs, sorts_opt
1689- in
1690- (* Do it on every fixpoint *)
1691- let rv = Array. map2_i find_ind nvect bodies in
1692- (Array. map (fun (minds , _ , _ ) -> minds) rv,
1693- Array. map (fun (_ , rdef , _ ) -> rdef) rv,
1694- Array. map (fun (_ , _ , sorts_opt ) -> sorts_opt) rv)
1694+ (ind_sort, out_sort) :: sorts
1695+ ) [] minds)
16951696
16961697
16971698let check_fix_pre_sorts ?evars env ((nvect , _ ), (names , _ , bodies as recdef ) as fix ) =
@@ -1700,38 +1701,35 @@ let check_fix_pre_sorts ?evars env ((nvect, _), (names, _, bodies as recdef) as
17001701 the possibly new constraints (see e.g. [esearch_guard] (Pretyping)). We expose this
17011702 function to be used for this purpose, while check_fix performs the normal check,
17021703 failing when elimination constraints are not satisfied. *)
1703- let (minds, rdef, sorts_opt) = inductive_of_mutfix ?evars env fix in
1704+ let minds, rdef = inductive_of_mutfix ?evars env fix in
1705+ let sorts_opt = sorts_of_mutfix env minds names in
1706+ let inds = Array. map fst minds in
17041707 let flags = Environ. typing_flags env in
17051708 let raise_err = raise_fix_guard_err_fn env recdef names in
1706- if flags.check_guarded then
1707- let get_tree ( kn , i ) =
1708- let mib = Environ. lookup_mind kn env in
1709- mib.mind_packets.(i).mind_recargs
1710- in
1711- let trees = Array. map get_tree minds in
1712- let () =
1709+ let () =
1710+ if flags.check_guarded then
1711+ let get_tree ( kn , i ) =
1712+ let mib = Environ. lookup_mind kn env in
1713+ mib.mind_packets.(i).mind_recargs
1714+ in
1715+ let trees = Array. map get_tree inds in
17131716 for i = 0 to Array. length bodies - 1 do
17141717 let (fenv, body) = rdef.(i) in
17151718 let renv = make_renv fenv nvect.(i) trees.(i) in
17161719 try check_one_fix cache ?evars renv nvect trees body
17171720 with FixGuardError (err_env , err ) -> raise_err err_env i err
17181721 done
1719- in
1720- sorts_opt
1721- else
1722- sorts_opt
1722+ in
1723+ sorts_opt
17231724
17241725let check_fix ?evars env (_ , (names , _ , _ as recdef ) as fix ) =
17251726 let sorts_opts = check_fix_pre_sorts ?evars env fix in
17261727 let raise_err = raise_fix_guard_err_fn env recdef names in
17271728 let elim_to = eliminates_to (Environ. qualities env) in
1728- Array. iteri (fun i sort_opt ->
1729- match sort_opt with
1730- | None -> ()
1731- | Some (ind_sort , binder_sort ) ->
1732- if not (is_allowed_fixpoint elim_to ind_sort binder_sort) then
1733- raise_err env i @@ FixpointOnNonEliminable (ind_sort, binder_sort)
1734- ) sorts_opts
1729+ Option. iter (List. iteri (fun i (ind_sort , out_sort ) ->
1730+ if not (is_allowed_fixpoint elim_to ind_sort out_sort) then
1731+ raise_err env i @@ FixpointOnNonEliminable (ind_sort, out_sort)
1732+ )) sorts_opts
17351733
17361734(* ***********************************************************************)
17371735(* Co-fixpoints. *)
0 commit comments