1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(* $Id: subtac.ml 12194 2009-06-17 16:38:09Z msozeau $ *)
42
let require_library dirpath =
43
let qualid = (dummy_loc, qualid_of_dirpath (dirpath_of_string dirpath)) in
44
Library.require_library [qualid] None
52
let solve_tccs_in_type env id isevars evm c typ =
53
if not (evm = Evd.empty) then
54
let stmt_id = Nameops.add_suffix id "_stmt" in
55
let obls, c', t' = eterm_obligations env stmt_id !isevars evm 0 ~status:Expand c typ in
56
match Subtac_obligations.add_definition stmt_id c' typ obls with
57
Subtac_obligations.Defined cst -> constant_value (Global.env())
58
(match cst with ConstRef kn -> kn | _ -> assert false)
60
errorlabstrm "start_proof"
61
(str "The statement obligations could not be resolved automatically, " ++ spc () ++
62
str "write a statement definition first.")
64
let _ = Typeops.infer_type env c in c
67
let start_proof_com env isevars sopt kind (bl,t) hook =
68
let id = match sopt with
70
(* We check existence here: it's a bit late at Qed time *)
71
if Nametab.exists_cci (Lib.make_path id) or is_section_variable id then
72
user_err_loc (loc,"start_proof",pr_id id ++ str " already exists");
75
next_global_ident_away false (id_of_string "Unnamed_thm")
76
(Pfedit.get_all_proof_names ())
78
let evm, c, typ, _imps =
79
Subtac_pretyping.subtac_process env isevars id [] (Command.generalize_constr_expr t bl) None
81
let c = solve_tccs_in_type env id isevars evm c typ in
82
Command.start_proof id kind c hook
84
let print_subgoals () = Flags.if_verbose (fun () -> msg (Printer.pr_open_subgoals ())) ()
86
let start_proof_and_print env isevars idopt k t hook =
87
start_proof_com env isevars idopt k t hook;
90
let _ = Detyping.set_detype_anonymous (fun loc n -> RVar (loc, id_of_string ("Anonymous_REL_" ^ string_of_int n)))
92
let assumption_message id =
93
Flags.if_verbose message ((string_of_id id) ^ " is assumed")
95
let declare_assumption env isevars idl is_coe k bl c nl =
96
if not (Pfedit.refining ()) then
97
let id = snd (List.hd idl) in
98
let evm, c, typ, imps =
99
Subtac_pretyping.subtac_process env isevars id [] (Command.generalize_constr_expr c bl) None
101
let c = solve_tccs_in_type env id isevars evm c typ in
102
List.iter (Command.declare_one_assumption is_coe k c imps false [] nl) idl
104
errorlabstrm "Command.Assumption"
105
(str "Cannot declare an assumption while in proof editing mode.")
107
let dump_constraint ty ((loc, n), _, _) =
109
| Name id -> Dumpglob.dump_definition (loc, id) false ty
112
let dump_variable lid = ()
114
let vernac_assumption env isevars kind l nl =
115
let global = fst kind = Global in
116
List.iter (fun (is_coe,(idl,c)) ->
117
if Dumpglob.dump () then
118
List.iter (fun lid ->
119
if global then Dumpglob.dump_definition lid (not global) "ax"
120
else dump_variable lid) idl;
121
declare_assumption env isevars idl is_coe kind [] c nl) l
123
let check_fresh (loc,id) =
124
if Nametab.exists_cci (Lib.make_path id) or is_section_variable id then
125
user_err_loc (loc,"",pr_id id ++ str " already exists")
127
let subtac (loc, command) =
128
check_required_library ["Coq";"Init";"Datatypes"];
129
check_required_library ["Coq";"Init";"Specif"];
130
let env = Global.env () in
131
let isevars = ref (create_evar_defs Evd.empty) in
134
| VernacDefinition (defkind, (_, id as lid), expr, hook) ->
136
Dumpglob.dump_definition lid false "def";
138
| ProveBody (bl, t) ->
139
if Lib.is_modtype () then
140
errorlabstrm "Subtac_command.StartProof"
141
(str "Proof editing mode not supported in module types");
142
start_proof_and_print env isevars (Some lid) (Global, DefinitionBody Definition) (bl,t)
144
| DefineBody (bl, _, c, tycon) ->
145
ignore(Subtac_pretyping.subtac_proof defkind hook env isevars id bl c tycon))
146
| VernacFixpoint (l, b) ->
147
List.iter (fun ((lid, _, _, _, _), _) ->
149
Dumpglob.dump_definition lid false "fix") l;
150
let _ = trace (str "Building fixpoint") in
151
ignore(Subtac_command.build_recursive l b)
153
| VernacStartTheoremProof (thkind, [Some id, (bl, t)], lettop, hook) ->
154
Dumpglob.dump_definition id false "prf";
155
if not(Pfedit.refining ()) then
157
errorlabstrm "Subtac_command.StartProof"
158
(str "Let declarations can only be used in proof editing mode");
159
if Lib.is_modtype () then
160
errorlabstrm "Subtac_command.StartProof"
161
(str "Proof editing mode not supported in module types");
163
start_proof_and_print env isevars (Some id) (Global, Proof thkind) (bl,t) hook
165
| VernacAssumption (stre,nl,l) ->
166
vernac_assumption env isevars stre l nl
168
| VernacInstance (glob, sup, is, props, pri) ->
169
dump_constraint "inst" is;
170
ignore(Subtac_classes.new_instance ~global:glob sup is props pri)
172
| VernacCoFixpoint (l, b) ->
173
if Dumpglob.dump () then
174
List.iter (fun ((lid, _, _, _), _) -> Dumpglob.dump_definition lid false "cofix") l;
175
ignore(Subtac_command.build_corecursive l b)
177
(*| VernacEndProof e ->
180
| _ -> user_err_loc (loc,"", str ("Invalid Program command"))
183
msg_warning (str "Type error in Program tactic:");
186
| NonFunctionalApp (loc, x, mux, e) ->
187
str "non functional application of term " ++
188
e ++ str " to function " ++ x ++ str " of (mu) type " ++ mux
189
| NonSigma (loc, t) ->
190
str "Term is not of Sigma type: " ++ t
191
| NonConvertible (loc, x, y) ->
192
str "Unconvertible terms:" ++ spc () ++
193
x ++ spc () ++ str "and" ++ spc () ++ y
194
| IllSorted (loc, t) ->
195
str "Term is ill-sorted:" ++ spc () ++ t
199
| Subtyping_error e ->
200
msg_warning (str "(Program tactic) Subtyping error:");
203
| UncoercibleInferType (loc, x, y) ->
204
str "Uncoercible terms:" ++ spc ()
205
++ x ++ spc () ++ str "and" ++ spc () ++ y
206
| UncoercibleInferTerm (loc, x, y, tx, ty) ->
207
str "Uncoercible terms:" ++ spc ()
208
++ tx ++ spc () ++ str "of" ++ spc () ++ str "type" ++ spc () ++ x
209
++ str "and" ++ spc() ++ ty ++ spc () ++ str "of" ++ spc () ++ str "type" ++ spc () ++ y
210
| UncoercibleRewrite (x, y) ->
211
str "Uncoercible terms:" ++ spc ()
212
++ x ++ spc () ++ str "and" ++ spc () ++ y
215
| Cases.PatternMatchingError (env, exn) as e ->
216
debug 2 (Himsg.explain_pattern_matching_error env exn);
219
| Type_errors.TypeError (env, exn) as e ->
220
debug 2 (Himsg.explain_type_error env exn);
223
| Pretype_errors.PretypeError (env, exn) as e ->
224
debug 2 (Himsg.explain_pretype_error env exn);
227
| (Stdpp.Exc_located (loc, Proof_type.LtacLocated (_,e')) |
228
Stdpp.Exc_located (loc, e') as e) ->
229
debug 2 (str "Parsing exception: ");
231
| Type_errors.TypeError (env, exn) ->
232
debug 2 (Himsg.explain_type_error env exn);
235
| Pretype_errors.PretypeError (env, exn) ->
236
debug 2 (Himsg.explain_pretype_error env exn);