| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Pp |
| 12 |
open Util |
| 13 |
open Names |
| 14 |
open Environ |
| 15 |
open EConstr |
| 16 |
open Evd |
| 17 |
open Tactypes |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
exception IntroAlreadyDeclared of Id.t |
| 24 |
exception ClearDependency of env * evar_map * Id.t option * Evarutil.clear_dependency_error * GlobRef.t option |
| 25 |
exception ReplacingDependency of env * evar_map * Id.t * Evarutil.clear_dependency_error * GlobRef.t option |
| 26 |
exception AlreadyUsed of Id.t |
| 27 |
exception UsedTwice of Id.t |
| 28 |
exception VariableHasNoValue of Id.t |
| 29 |
exception ConvertIncompatibleTypes of env * evar_map * constr * constr |
| 30 |
exception ConvertNotAType |
| 31 |
exception NotConvertible |
| 32 |
exception NotUnfoldable |
| 33 |
exception NoQuantifiedHypothesis of quantified_hypothesis * bool |
| 34 |
exception CannotFindInstance of Id.t |
| 35 |
exception NothingToRewrite of Id.t |
| 36 |
exception IllFormedEliminationType |
| 37 |
exception UnableToApplyLemma of env * evar_map * constr * constr |
| 38 |
exception DependsOnBody of Id.t list * Id.Set.t * Id.t option |
| 39 |
exception NotRightNumberConstructors of int |
| 40 |
exception NotEnoughConstructors |
| 41 |
exception ConstructorNumberedFromOne |
| 42 |
exception NoConstructors |
| 43 |
exception UnexpectedExtraPattern of int option * delayed_open_constr intro_pattern_expr |
| 44 |
exception CannotFindInductiveArgument |
| 45 |
exception OneIntroPatternExpected |
| 46 |
exception KeepAndClearModifierOnlyForHypotheses |
| 47 |
exception FixpointOnNonInductiveType |
| 48 |
exception NotEnoughProducts |
| 49 |
exception AllMethodsInCoinductiveType |
| 50 |
exception ReplacementIllTyped of exn |
| 51 |
exception NotEnoughPremises |
| 52 |
exception NeedDependentProduct |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
let clear_in_global_msg = function |
| 59 |
| None -> mt () |
| 60 |
| Some ref -> str " implicitly in " ++ Printer.pr_global ref |
| 61 |
|
| 62 |
let clear_dependency_msg env sigma id err inglobal = |
| 63 |
let ppidupper = function Some id -> Id.print id | None -> str "This variable" in |
| 64 |
let ppid = function Some id -> Id.print id | None -> str "this variable" in |
| 65 |
let pp = clear_in_global_msg inglobal in |
| 66 |
match err with |
| 67 |
| Evarutil.OccurHypInSimpleClause None -> |
| 68 |
ppidupper id ++ str " is used" ++ pp ++ str " in conclusion." |
| 69 |
| Evarutil.OccurHypInSimpleClause (Some id') -> |
| 70 |
ppidupper id ++ strbrk " is used" ++ pp ++ str " in hypothesis " ++ Id.print id' ++ str"." |
| 71 |
| Evarutil.EvarTypingBreak ev -> |
| 72 |
str "Cannot remove " ++ ppid id ++ |
| 73 |
strbrk " without breaking the typing of " ++ |
| 74 |
Printer.pr_leconstr_env env sigma (mkEvar ev) ++ str"." |
| 75 |
| Evarutil.NoCandidatesLeft ev -> |
| 76 |
str "Cannot remove " ++ ppid id ++ str " as it would leave the existential " ++ |
| 77 |
Printer.pr_existential_key env sigma ev ++ str" without candidates." |
| 78 |
|
| 79 |
let replacing_dependency_msg env sigma id err inglobal = |
| 80 |
let pp = clear_in_global_msg inglobal in |
| 81 |
match err with |
| 82 |
| Evarutil.OccurHypInSimpleClause None -> |
| 83 |
str "Cannot change " ++ Id.print id ++ str ", it is used" ++ pp ++ str " in conclusion." |
| 84 |
| Evarutil.OccurHypInSimpleClause (Some id') -> |
| 85 |
str "Cannot change " ++ Id.print id ++ |
| 86 |
strbrk ", it is used" ++ pp ++ str " in hypothesis " ++ Id.print id' ++ str"." |
| 87 |
| Evarutil.EvarTypingBreak ev -> |
| 88 |
str "Cannot change " ++ Id.print id ++ |
| 89 |
strbrk " without breaking the typing of " ++ |
| 90 |
Printer.pr_leconstr_env env sigma (mkEvar ev) ++ str"." |
| 91 |
| Evarutil.NoCandidatesLeft ev -> |
| 92 |
str "Cannot change " ++ Id.print id ++ str " as it would leave the existential " ++ |
| 93 |
Printer.pr_existential_key env sigma ev ++ str" without candidates." |
| 94 |
|
| 95 |
let msg_quantified_hypothesis = function |
| 96 |
| NamedHyp id -> |
| 97 |
str "quantified hypothesis named " ++ Id.print id.CAst.v |
| 98 |
| AnonHyp n -> |
| 99 |
pr_nth n ++ |
| 100 |
str " non dependent hypothesis" |
| 101 |
|
| 102 |
let explain_unexpected_extra_pattern bound pat = |
| 103 |
let nb = Option.get bound in |
| 104 |
let s1,s2,s3 = match pat with |
| 105 |
| IntroNaming (IntroIdentifier _) -> |
| 106 |
"name", (String.plural nb " introduction pattern"), "no" |
| 107 |
| _ -> "introduction pattern", "", "none" in |
| 108 |
str "Unexpected " ++ str s1 ++ str " (" ++ |
| 109 |
(if Int.equal nb 0 then (str s3 ++ str s2) else |
| 110 |
(str "at most " ++ int nb ++ str s2)) ++ spc () ++ |
| 111 |
str (if Int.equal nb 1 then "was" else "were") ++ |
| 112 |
strbrk " expected in the branch)." |
| 113 |
|
| 114 |
|
| 115 |
exception Unhandled |
| 116 |
|
| 117 |
|
| 118 |
let tactic_interp_error_handler = function |
| 119 |
| IntroAlreadyDeclared id -> |
| 120 |
Id.print id ++ str " is already declared." |
| 121 |
| ClearDependency (env,sigma,id,err,inglobal) -> |
| 122 |
clear_dependency_msg env sigma id err inglobal |
| 123 |
| ReplacingDependency (env,sigma,id,err,inglobal) -> |
| 124 |
replacing_dependency_msg env sigma id err inglobal |
| 125 |
| AlreadyUsed id -> |
| 126 |
Id.print id ++ str " is already used." |
| 127 |
| UsedTwice id -> |
| 128 |
Id.print id ++ str" is used twice." |
| 129 |
| VariableHasNoValue id -> |
| 130 |
Id.print id ++ str" is not a defined hypothesis." |
| 131 |
| ConvertIncompatibleTypes (env,sigma,t1,t2) -> |
| 132 |
str "The first term has type" ++ spc () ++ |
| 133 |
quote (Termops.Internal.print_constr_env env sigma t1) ++ spc () ++ |
| 134 |
strbrk "while the second term has incompatible type" ++ spc () ++ |
| 135 |
quote (Termops.Internal.print_constr_env env sigma t2) ++ str "." |
| 136 |
| ConvertNotAType -> |
| 137 |
str "Not a type." |
| 138 |
| NotConvertible -> |
| 139 |
str "Not convertible." |
| 140 |
| NotUnfoldable -> |
| 141 |
str "Cannot unfold a non-constant." |
| 142 |
| NoQuantifiedHypothesis (id,red) -> |
| 143 |
str "No " ++ msg_quantified_hypothesis id ++ |
| 144 |
strbrk " in current goal" ++ |
| 145 |
(if red then strbrk " even after head-reduction" else mt ()) ++ str"." |
| 146 |
| CannotFindInstance id -> |
| 147 |
str "Cannot find an instance for " ++ Id.print id ++ str"." |
| 148 |
| NothingToRewrite id -> |
| 149 |
str "Nothing to rewrite in " ++ Id.print id ++ str"." |
| 150 |
| IllFormedEliminationType -> |
| 151 |
str "The type of elimination clause is not well-formed." |
| 152 |
| UnableToApplyLemma (env,sigma,thm,t) -> |
| 153 |
str "Unable to apply lemma of type" ++ brk(1,1) ++ |
| 154 |
quote (Printer.pr_leconstr_env env sigma thm) ++ spc() ++ |
| 155 |
str "on hypothesis of type" ++ brk(1,1) ++ |
| 156 |
quote (Printer.pr_leconstr_env env sigma t) ++ |
| 157 |
str "." |
| 158 |
| DependsOnBody (idl,ids,where) -> |
| 159 |
let idl = List.filter (fun id -> Id.Set.mem id ids) idl in |
| 160 |
let on_the_bodies = function |
| 161 |
| [] -> assert false |
| 162 |
| [id] -> str " depends on the body of " ++ Id.print id |
| 163 |
| l -> str " depends on the bodies of " ++ pr_sequence Id.print l |
| 164 |
in |
| 165 |
(match where with |
| 166 |
| None -> str "Conclusion" ++ on_the_bodies idl |
| 167 |
| Some id -> str "Hypothesis " ++ Id.print id ++ on_the_bodies idl) |
| 168 |
| NotRightNumberConstructors n -> |
| 169 |
str "Not an inductive goal with " ++ int n ++ str (String.plural n " constructor") ++ str "." |
| 170 |
| NotEnoughConstructors -> |
| 171 |
str "Not enough constructors." |
| 172 |
| ConstructorNumberedFromOne -> |
| 173 |
str "The constructors are numbered starting from 1." |
| 174 |
| NoConstructors -> |
| 175 |
str "The type has no constructors." |
| 176 |
| UnexpectedExtraPattern (bound,pat) -> |
| 177 |
explain_unexpected_extra_pattern bound pat |
| 178 |
| CannotFindInductiveArgument -> |
| 179 |
str "Cannot find inductive argument of elimination scheme." |
| 180 |
| OneIntroPatternExpected -> |
| 181 |
str "Introduction pattern for one hypothesis expected." |
| 182 |
| KeepAndClearModifierOnlyForHypotheses -> |
| 183 |
str "keep/clear modifiers apply only to hypothesis names." |
| 184 |
| FixpointOnNonInductiveType -> |
| 185 |
str "Cannot do a fixpoint on a non inductive type." |
| 186 |
| NotEnoughProducts -> |
| 187 |
str "Not enough products." |
| 188 |
| AllMethodsInCoinductiveType -> |
| 189 |
str "All methods must construct elements in coinductive types." |
| 190 |
| ReplacementIllTyped e -> |
| 191 |
str "Replacement would lead to an ill-typed term:" ++ spc () ++ CErrors.print e |
| 192 |
| NotEnoughPremises -> |
| 193 |
str "Applied theorem does not have enough premises." |
| 194 |
| NeedDependentProduct -> |
| 195 |
str "Needs a non-dependent product." |
| 196 |
| _ -> raise Unhandled |
| 197 |
|
| 198 |
let wrap_unhandled f e = |
| 199 |
try Some (f e) |
| 200 |
with Unhandled -> None |
| 201 |
|
| 202 |
|
| 203 |
let _ = CErrors.register_handler (wrap_unhandled tactic_interp_error_handler) |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
let intro_already_declared ?loc id = |
| 210 |
Loc.raise ?loc (IntroAlreadyDeclared id) |
| 211 |
|
| 212 |
let clear_dependency ?loc env sigma id dep_err gref = |
| 213 |
Loc.raise ?loc (ClearDependency (env, sigma, id, dep_err, gref)) |
| 214 |
|
| 215 |
let replacing_dependency ?loc env sigma id dep_err gref = |
| 216 |
Loc.raise ?loc (ReplacingDependency (env, sigma, id, dep_err, gref)) |
| 217 |
|
| 218 |
let already_used ?loc id = |
| 219 |
Loc.raise ?loc (AlreadyUsed id) |
| 220 |
|
| 221 |
let used_twice ?loc id = |
| 222 |
Loc.raise ?loc (UsedTwice id) |
| 223 |
|
| 224 |
let variable_has_no_value ?loc id = |
| 225 |
Loc.raise ?loc (VariableHasNoValue id) |
| 226 |
|
| 227 |
let convert_incompatible_types ?loc env sigma x y = |
| 228 |
Loc.raise ?loc (ConvertIncompatibleTypes (env, sigma, x, y)) |
| 229 |
|
| 230 |
let convert_not_a_type ?loc () = |
| 231 |
Loc.raise ?loc ConvertNotAType |
| 232 |
|
| 233 |
let not_convertible ?loc () = |
| 234 |
Loc.raise ?loc NotConvertible |
| 235 |
|
| 236 |
let not_unfoldable ?loc () = |
| 237 |
Loc.raise ?loc NotUnfoldable |
| 238 |
|
| 239 |
let no_quantified_hypothesis ?loc hyp b = |
| 240 |
Loc.raise ?loc (NoQuantifiedHypothesis (hyp, b)) |
| 241 |
|
| 242 |
let cannot_find_instance ?loc id = |
| 243 |
Loc.raise ?loc (CannotFindInstance id) |
| 244 |
|
| 245 |
let nothing_to_rewrite ?loc id = |
| 246 |
Loc.raise ?loc (NothingToRewrite id) |
| 247 |
|
| 248 |
let ill_formed_elimination_type ?loc () = |
| 249 |
Loc.raise ?loc IllFormedEliminationType |
| 250 |
|
| 251 |
let unable_to_apply_lemma ?loc env sigma x y = |
| 252 |
Loc.raise ?loc (UnableToApplyLemma (env, sigma, x, y)) |
| 253 |
|
| 254 |
let depends_on_body ?loc id ids id_opt = |
| 255 |
Loc.raise ?loc (DependsOnBody (id, ids, id_opt)) |
| 256 |
|
| 257 |
let not_right_number_constructors ?loc n = |
| 258 |
Loc.raise ?loc (NotRightNumberConstructors n) |
| 259 |
|
| 260 |
let not_enough_constructors ?loc () = |
| 261 |
Loc.raise ?loc NotEnoughConstructors |
| 262 |
|
| 263 |
let constructors_numbered_from_one ?loc () = |
| 264 |
Loc.raise ?loc ConstructorNumberedFromOne |
| 265 |
|
| 266 |
let no_constructors ?loc () = |
| 267 |
Loc.raise ?loc NoConstructors |
| 268 |
|
| 269 |
let unexpected_extra_pattern ?loc n patt = |
| 270 |
Loc.raise ?loc (UnexpectedExtraPattern (n, patt)) |
| 271 |
|
| 272 |
let cannot_find_inductive_argument ?loc () = |
| 273 |
Loc.raise ?loc CannotFindInductiveArgument |
| 274 |
|
| 275 |
let one_intro_pattern_expected ?loc () = |
| 276 |
Loc.raise ?loc OneIntroPatternExpected |
| 277 |
|
| 278 |
let keep_and_clear_modifier_only_for_hypotheses ?loc () = |
| 279 |
Loc.raise ?loc KeepAndClearModifierOnlyForHypotheses |
| 280 |
|
| 281 |
let fixpoint_on_non_inductive_type ?loc () = |
| 282 |
Loc.raise ?loc FixpointOnNonInductiveType |
| 283 |
|
| 284 |
let not_enough_products ?loc () = |
| 285 |
Loc.raise ?loc NotEnoughProducts |
| 286 |
|
| 287 |
let all_methods_in_coinductive_type ?loc () = |
| 288 |
Loc.raise ?loc AllMethodsInCoinductiveType |
| 289 |
|
| 290 |
let replacement_ill_typed ?loc exn = |
| 291 |
Loc.raise ?loc (ReplacementIllTyped exn) |
| 292 |
|
| 293 |
let not_enough_premises ?loc () = |
| 294 |
Loc.raise ?loc NotEnoughPremises |
| 295 |
|
| 296 |
let need_dependent_product ?loc () = |
| 297 |
Loc.raise ?loc NeedDependentProduct |