diff options
Diffstat (limited to 'proofs/evar_refiner.ml')
-rw-r--r-- | proofs/evar_refiner.ml | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/proofs/evar_refiner.ml b/proofs/evar_refiner.ml index 6548a1dd..c8cb1d1c 100644 --- a/proofs/evar_refiner.ml +++ b/proofs/evar_refiner.ml @@ -1,61 +1,71 @@ (************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) -(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2014 *) +(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) +open Errors open Util open Names -open Term open Evd open Evarutil -open Sign -open Refiner +open Evarsolve (******************************************) (* Instantiation of existential variables *) (******************************************) let depends_on_evar evk _ (pbty,_,t1,t2) = - try head_evar t1 = evk + try Evar.equal (head_evar t1) evk with NoHeadEvar -> - try head_evar t2 = evk + try Evar.equal (head_evar t2) evk with NoHeadEvar -> false -let define_and_solve_constraints evk c evd = - try - let evd = define evk c evd in - let (evd,pbs) = extract_changed_conv_pbs evd (depends_on_evar evk) in - fst (List.fold_left - (fun (evd,b as p) (pbty,env,t1,t2) -> - if b then Evarconv.evar_conv_x full_transparent_state env evd pbty t1 t2 else p) (evd,true) - pbs) - with e when Pretype_errors.precatchable_exception e -> - error "Instance does not satisfy constraints." +let define_and_solve_constraints evk c env evd = + if Termops.occur_evar evk c then + Pretype_errors.error_occur_check env evd evk c; + let evd = define evk c evd in + let (evd,pbs) = extract_changed_conv_pbs evd (depends_on_evar evk) in + match + List.fold_left + (fun p (pbty,env,t1,t2) -> match p with + | Success evd -> Evarconv.evar_conv_x full_transparent_state env evd pbty t1 t2 + | UnifFailure _ as x -> x) (Success evd) + pbs + with + | Success evd -> evd + | UnifFailure _ -> error "Instance does not satisfy the constraints." let w_refine (evk,evi) (ltac_var,rawc) sigma = if Evd.is_defined sigma evk then error "Instantiate called on already-defined evar"; - let env = Evd.evar_env evi in + let env = Evd.evar_filtered_env evi in let sigma',typed_c = - try Pretyping.Default.understand_ltac ~resolve_classes:true true sigma env ltac_var - (Pretyping.OfType (Some evi.evar_concl)) rawc + let flags = { + Pretyping.use_typeclasses = true; + Pretyping.use_unif_heuristics = true; + Pretyping.use_hook = None; + Pretyping.fail_evar = false; + Pretyping.expand_evars = true } in + try Pretyping.understand_ltac flags + env sigma ltac_var (Pretyping.OfType evi.evar_concl) rawc with e when Errors.noncritical e -> - let loc = Glob_term.loc_of_glob_constr rawc in + let loc = Glob_ops.loc_of_glob_constr rawc in user_err_loc (loc,"",Pp.str ("Instance is not well-typed in the environment of " ^ string_of_existential evk)) in - define_and_solve_constraints evk typed_c (evars_reset_evd sigma' sigma) + define_and_solve_constraints evk typed_c env (evars_reset_evd sigma' sigma) (* vernac command Existential *) (* Main component of vernac command Existential *) let instantiate_pf_com evk com sigma = let evi = Evd.find sigma evk in - let env = Evd.evar_env evi in - let rawc = Constrintern.intern_constr sigma env com in - let sigma' = w_refine (evk,evi) (([],[]),rawc) sigma in + let env = Evd.evar_filtered_env evi in + let rawc = Constrintern.intern_constr env com in + let ltac_vars = Pretyping.empty_lvar in + let sigma' = w_refine (evk, evi) (ltac_vars, rawc) sigma in sigma' |