summaryrefslogtreecommitdiff
path: root/pretyping/pretyping.ml
diff options
context:
space:
mode:
Diffstat (limited to 'pretyping/pretyping.ml')
-rw-r--r--pretyping/pretyping.ml66
1 files changed, 40 insertions, 26 deletions
diff --git a/pretyping/pretyping.ml b/pretyping/pretyping.ml
index d354a6c3..ac0104d9 100644
--- a/pretyping/pretyping.ml
+++ b/pretyping/pretyping.ml
@@ -1,6 +1,6 @@
(************************************************************************)
(* v * The Coq Proof Assistant / The Coq Development Team *)
-(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *)
+(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2016 *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
@@ -183,22 +183,26 @@ type inference_flags = {
expand_evars : bool
}
+let frozen_holes (sigma, sigma') =
+ let fold evk _ accu = Evar.Set.add evk accu in
+ Evd.fold_undefined fold sigma Evar.Set.empty
+
let pending_holes (sigma, sigma') =
let fold evk _ accu =
if not (Evd.mem sigma evk) then Evar.Set.add evk accu else accu
in
Evd.fold_undefined fold sigma' Evar.Set.empty
-let apply_typeclasses env evdref pending fail_evar =
- let filter_pending evk = Evar.Set.mem evk pending in
+let apply_typeclasses env evdref frozen fail_evar =
+ let filter_frozen evk = Evar.Set.mem evk frozen in
evdref := Typeclasses.resolve_typeclasses
~filter:(if Flags.is_program_mode ()
- then (fun evk evi -> Typeclasses.no_goals_or_obligations evk evi && filter_pending evk)
- else (fun evk evi -> Typeclasses.no_goals evk evi && filter_pending evk))
+ then (fun evk evi -> Typeclasses.no_goals_or_obligations evk evi && not (filter_frozen evk))
+ else (fun evk evi -> Typeclasses.no_goals evk evi && not (filter_frozen evk)))
~split:true ~fail:fail_evar env !evdref;
if Flags.is_program_mode () then (* Try optionally solving the obligations *)
evdref := Typeclasses.resolve_typeclasses
- ~filter:(fun evk evi -> Typeclasses.all_evars evk evi && filter_pending evk) ~split:true ~fail:false env !evdref
+ ~filter:(fun evk evi -> Typeclasses.all_evars evk evi && not (filter_frozen evk)) ~split:true ~fail:false env !evdref
let apply_inference_hook hook evdref pending =
evdref := Evar.Set.fold (fun evk sigma ->
@@ -219,9 +223,9 @@ let apply_heuristics env evdref fail_evar =
with e when Errors.noncritical e ->
let e = Errors.push e in if fail_evar then iraise e
-let check_typeclasses_instances_are_solved env current_sigma pending =
+let check_typeclasses_instances_are_solved env current_sigma frozen =
(* Naive way, call resolution again with failure flag *)
- apply_typeclasses env (ref current_sigma) pending true
+ apply_typeclasses env (ref current_sigma) frozen true
let check_extra_evars_are_solved env current_sigma pending =
Evar.Set.iter
@@ -233,26 +237,28 @@ let check_extra_evars_are_solved env current_sigma pending =
| _ ->
error_unsolvable_implicit loc env current_sigma evk None) pending
-let check_evars_are_solved env current_sigma pending =
- check_typeclasses_instances_are_solved env current_sigma pending;
+let check_evars_are_solved env current_sigma frozen pending =
+ check_typeclasses_instances_are_solved env current_sigma frozen;
check_problems_are_solved env current_sigma;
check_extra_evars_are_solved env current_sigma pending
(* Try typeclasses, hooks, unification heuristics ... *)
let solve_remaining_evars flags env current_sigma pending =
+ let frozen = frozen_holes pending in
let pending = pending_holes pending in
let evdref = ref current_sigma in
- if flags.use_typeclasses then apply_typeclasses env evdref pending false;
+ if flags.use_typeclasses then apply_typeclasses env evdref frozen false;
if Option.has_some flags.use_hook then
apply_inference_hook (Option.get flags.use_hook env) evdref pending;
if flags.use_unif_heuristics then apply_heuristics env evdref false;
- if flags.fail_evar then check_evars_are_solved env !evdref pending;
+ if flags.fail_evar then check_evars_are_solved env !evdref frozen pending;
!evdref
let check_evars_are_solved env current_sigma pending =
+ let frozen = frozen_holes pending in
let pending = pending_holes pending in
- check_evars_are_solved env current_sigma pending
+ check_evars_are_solved env current_sigma frozen pending
let process_inference_flags flags env initial_sigma (sigma,c) =
let sigma = solve_remaining_evars flags env sigma (initial_sigma, sigma) in
@@ -394,18 +400,22 @@ let pretype_global loc rigid env evd gr us =
match us with
| None -> evd, None
| Some l ->
- let _, ctx = Universes.unsafe_constr_of_global gr in
- let arr = Univ.Instance.to_array (Univ.UContext.instance ctx) in
- let len = Array.length arr in
- if len != List.length l then
- user_err_loc (loc, "pretype",
- str "Universe instance should have length " ++ int len)
- else
- let evd, l' = List.fold_left (fun (evd, univs) l ->
+ let _, ctx = Universes.unsafe_constr_of_global gr in
+ let arr = Univ.Instance.to_array (Univ.UContext.instance ctx) in
+ let len = Array.length arr in
+ if len != List.length l then
+ user_err_loc (loc, "pretype",
+ str "Universe instance should have length " ++ int len)
+ else
+ let evd, l' = List.fold_left (fun (evd, univs) l ->
let evd, l = interp_universe_level_name evd l in
(evd, l :: univs)) (evd, []) l
- in
- evd, Some (Univ.Instance.of_array (Array.of_list (List.rev l')))
+ in
+ if List.exists (fun l -> Univ.Level.is_prop l) l' then
+ user_err_loc (loc, "pretype",
+ str "Universe instances cannot contain Prop, polymorphic" ++
+ str " universe instances must be greater or equal to Set.");
+ evd, Some (Univ.Instance.of_array (Array.of_list (List.rev l')))
in
Evd.fresh_global ~rigid ?names:instance env evd gr
@@ -440,13 +450,15 @@ let pretype_sort evdref = function
let new_type_evar env evdref loc =
let e, s =
- evd_comb0 (fun evd -> Evarutil.new_type_evar env evd univ_flexible_alg ~src:(loc,Evar_kinds.InternalHole)) evdref
+ evd_comb0 (fun evd -> Evarutil.new_type_evar env evd
+ univ_flexible_alg ~src:(loc,Evar_kinds.InternalHole)) evdref
in e
let get_projection env cst =
let cb = lookup_constant cst env in
match cb.Declarations.const_proj with
- | Some {Declarations.proj_ind = mind; proj_npars = n; proj_arg = m; proj_type = ty} ->
+ | Some {Declarations.proj_ind = mind; proj_npars = n;
+ proj_arg = m; proj_type = ty} ->
(cst,mind,n,m,ty)
| None -> raise Not_found
@@ -739,7 +751,9 @@ let rec pretype k0 resolve_tc (tycon : type_constraint) env evdref (lvar : ltac_
pretype (mk_tycon tj.utj_val) env evdref lvar c
| _ -> pretype empty_tycon env evdref lvar c1
in
- let t = j.uj_type in
+ let t = evd_comb1 (Evarsolve.refresh_universes
+ ~onlyalg:true ~status:Evd.univ_flexible (Some false) env)
+ evdref j.uj_type in
(* The name specified by ltac is used also to create bindings. So
the substitution must also be applied on variables before they are
looked up in the rel context. *)