~ubuntu-branches/ubuntu/wily/coq-doc/wily

« back to all changes in this revision

Viewing changes to toplevel/himsg.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu, Stéphane Glondu, Samuel Mimram
  • Date: 2010-01-07 22:50:39 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100107225039-n3cq82589u0qt0s2
Tags: 8.2pl1-1
[ Stéphane Glondu ]
* New upstream release (Closes: #563669)
  - remove patches
* Packaging overhaul:
  - use git, advertise it in Vcs-* fields of debian/control
  - use debhelper 7 and dh with override
  - use source format 3.0 (quilt)
* debian/control:
  - set Maintainer to d-o-m, set Uploaders to Sam and myself
  - add Homepage field
  - bump Standards-Version to 3.8.3
* Register PDF documentation into doc-base
* Add debian/watch
* Update debian/copyright

[ Samuel Mimram ]
* Change coq-doc's description to mention that it provides documentation in
  pdf format, not postscript, closes: #543545.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
(************************************************************************)
 
8
 
 
9
(* $Id: himsg.ml 11986 2009-03-17 11:44:20Z herbelin $ *)
 
10
 
 
11
open Pp
 
12
open Util
 
13
open Flags
 
14
open Names
 
15
open Nameops
 
16
open Term
 
17
open Termops
 
18
open Inductive
 
19
open Indtypes
 
20
open Sign
 
21
open Environ
 
22
open Pretype_errors
 
23
open Type_errors
 
24
open Typeclasses_errors
 
25
open Indrec
 
26
open Reduction
 
27
open Cases
 
28
open Logic
 
29
open Printer
 
30
open Rawterm
 
31
open Evd
 
32
 
 
33
let pr_lconstr c = quote (pr_lconstr c)
 
34
let pr_lconstr_env e c = quote (pr_lconstr_env e c)
 
35
let pr_lconstr_env_at_top e c = quote (pr_lconstr_env_at_top e c)
 
36
let pr_ljudge_env e c = let v,t = pr_ljudge_env e c in (quote v,quote t)
 
37
 
 
38
let pr_db env i =
 
39
  try
 
40
    match lookup_rel i env with
 
41
        Name id, _, _ -> pr_id id
 
42
      | Anonymous, _, _ -> str "<>"
 
43
  with Not_found -> str "UNBOUND_REL_" ++ int i
 
44
 
 
45
let explain_unbound_rel env n =
 
46
  let pe = pr_ne_context_of (str "In environment") env in
 
47
  str "Unbound reference: " ++ pe ++
 
48
  str "The reference " ++ int n ++ str " is free."
 
49
 
 
50
let explain_unbound_var env v =
 
51
  let var = pr_id v in
 
52
  str "No such section variable or assumption: " ++ var ++ str "."
 
53
 
 
54
let explain_not_type env j =
 
55
  let pe = pr_ne_context_of (str "In environment") env in
 
56
  let pc,pt = pr_ljudge_env env j in
 
57
  pe ++ str "The term" ++ brk(1,1) ++ pc ++ spc () ++
 
58
  str "has type" ++ spc () ++ pt ++ spc () ++
 
59
  str "which should be Set, Prop or Type."
 
60
 
 
61
let explain_bad_assumption env j =
 
62
  let pe = pr_ne_context_of (str "In environment") env in
 
63
  let pc,pt = pr_ljudge_env env j in
 
64
  pe ++ str "Cannot declare a variable or hypothesis over the term" ++
 
65
  brk(1,1) ++ pc ++ spc () ++ str "of type" ++ spc () ++ pt ++ spc () ++
 
66
  str "because this term is not a type."
 
67
 
 
68
let explain_reference_variables c =
 
69
  let pc = pr_lconstr c in
 
70
  str "The constant" ++ spc () ++ pc ++ spc () ++
 
71
  str "refers to variables which are not in the context."
 
72
 
 
73
let rec pr_disjunction pr = function
 
74
  | [a] -> pr  a
 
75
  | [a;b] -> pr a ++ str " or" ++ spc () ++ pr b
 
76
  | a::l -> pr a ++ str "," ++ spc () ++ pr_disjunction pr l
 
77
  | [] -> assert false
 
78
 
 
79
let explain_elim_arity env ind sorts c pj okinds =
 
80
  let env = make_all_name_different env in
 
81
  let pi = pr_inductive env ind in
 
82
  let pc = pr_lconstr_env env c in
 
83
  let msg = match okinds with
 
84
  | Some(kp,ki,explanation) ->
 
85
      let pki = pr_sort_family ki in
 
86
      let pkp = pr_sort_family kp in
 
87
      let explanation = match explanation with
 
88
        | NonInformativeToInformative ->
 
89
          "proofs can be eliminated only to build proofs"
 
90
        | StrongEliminationOnNonSmallType ->
 
91
          "strong elimination on non-small inductive types leads to paradoxes"
 
92
        | WrongArity ->
 
93
          "wrong arity" in
 
94
      let ppar = pr_disjunction (fun s -> quote (pr_sort_family s)) sorts in
 
95
      let ppt = pr_lconstr_env env (snd (decompose_prod_assum pj.uj_type)) in
 
96
      hov 0
 
97
        (str "the return type has sort" ++ spc () ++ ppt ++ spc () ++
 
98
         str "while it" ++ spc () ++ str "should be " ++ ppar ++ str ".") ++
 
99
      fnl () ++
 
100
      hov 0
 
101
        (str "Elimination of an inductive object of sort " ++
 
102
         pki ++ brk(1,0) ++
 
103
         str "is not allowed on a predicate in sort " ++ pkp ++ fnl () ++
 
104
         str "because" ++ spc () ++ str explanation ++ str ".")
 
105
  | None ->
 
106
      str "ill-formed elimination predicate."
 
107
  in
 
108
  hov 0 (
 
109
    str "Incorrect elimination of" ++ spc () ++ pc ++ spc () ++
 
110
    str "in the inductive type" ++ spc () ++ quote pi ++ str ":") ++
 
111
  fnl () ++ msg
 
112
 
 
113
let explain_case_not_inductive env cj =
 
114
  let env = make_all_name_different env in
 
115
  let pc = pr_lconstr_env env cj.uj_val in
 
116
  let pct = pr_lconstr_env env cj.uj_type in
 
117
    match kind_of_term cj.uj_type with
 
118
      | Evar _ ->
 
119
          str "Cannot infer a type for this expression."
 
120
      | _ ->
 
121
          str "The term" ++ brk(1,1) ++ pc ++ spc () ++
 
122
          str "has type" ++ brk(1,1) ++ pct ++ spc () ++
 
123
          str "which is not a (co-)inductive type."
 
124
 
 
125
let explain_number_branches env cj expn =
 
126
  let env = make_all_name_different env in
 
127
  let pc = pr_lconstr_env env cj.uj_val in
 
128
  let pct = pr_lconstr_env env cj.uj_type in
 
129
  str "Matching on term" ++ brk(1,1) ++ pc ++ spc () ++
 
130
  str "of type" ++ brk(1,1) ++ pct ++ spc () ++
 
131
  str "expects " ++  int expn ++ str " branches."
 
132
 
 
133
let explain_ill_formed_branch env c i actty expty =
 
134
  let env = make_all_name_different env in
 
135
  let pc = pr_lconstr_env env c in
 
136
  let pa = pr_lconstr_env env actty in
 
137
  let pe = pr_lconstr_env env expty in
 
138
  str "In pattern-matching on term" ++ brk(1,1) ++ pc ++
 
139
  spc () ++ str "the " ++ nth (i+1) ++ str " branch has type" ++
 
140
  brk(1,1) ++ pa ++ spc () ++
 
141
  str "which should be" ++ brk(1,1) ++ pe ++ str "."
 
142
 
 
143
let explain_generalization env (name,var) j =
 
144
  let pe = pr_ne_context_of (str "In environment") env in
 
145
  let pv = pr_ltype_env env var in
 
146
  let (pc,pt) = pr_ljudge_env (push_rel_assum (name,var) env) j in
 
147
  pe ++ str "Cannot generalize" ++ brk(1,1) ++ pv ++ spc () ++
 
148
  str "over" ++ brk(1,1) ++ pc ++ str "," ++ spc () ++
 
149
  str "it has type" ++ spc () ++ pt ++
 
150
  spc () ++ str "which should be Set, Prop or Type."
 
151
 
 
152
let explain_actual_type env j pt =
 
153
  let pe = pr_ne_context_of (str "In environment") env in
 
154
  let (pc,pct) = pr_ljudge_env env j in
 
155
  let pt = pr_lconstr_env env pt in
 
156
  pe ++
 
157
  str "The term" ++ brk(1,1) ++ pc ++ spc () ++
 
158
  str "has type" ++ brk(1,1) ++ pct ++ brk(1,1) ++
 
159
  str "while it is expected to have type" ++ brk(1,1) ++ pt ++ str "."
 
160
 
 
161
let explain_cant_apply_bad_type env (n,exptyp,actualtyp) rator randl =
 
162
  let env = make_all_name_different env in
 
163
  let nargs = Array.length randl in
 
164
(*  let pe = pr_ne_context_of (str "in environment") env in*)
 
165
  let pr,prt = pr_ljudge_env env rator in
 
166
  let term_string1 = str (plural nargs "term") in
 
167
  let term_string2 =
 
168
    if nargs>1 then str "The " ++ nth n ++ str " term" else str "This term" in
 
169
  let appl = prvect_with_sep pr_fnl
 
170
               (fun c ->
 
171
                  let pc,pct = pr_ljudge_env env c in
 
172
                  hov 2 (pc ++ spc () ++ str ": " ++ pct)) randl
 
173
  in
 
174
  str "Illegal application (Type Error): " ++ (* pe ++ *) fnl () ++
 
175
  str "The term" ++ brk(1,1) ++ pr ++ spc () ++
 
176
  str "of type" ++ brk(1,1) ++ prt ++ spc () ++
 
177
  str "cannot be applied to the " ++ term_string1 ++ fnl () ++
 
178
  str " " ++ v 0 appl ++ fnl () ++ term_string2 ++ str " has type" ++
 
179
  brk(1,1) ++ pr_lconstr_env env actualtyp ++ spc () ++
 
180
  str "which should be coercible to" ++ brk(1,1) ++
 
181
  pr_lconstr_env env exptyp ++ str "."
 
182
 
 
183
let explain_cant_apply_not_functional env rator randl =
 
184
  let env = make_all_name_different env in
 
185
  let nargs = Array.length randl in
 
186
(*  let pe = pr_ne_context_of (str "in environment") env in*)
 
187
  let pr = pr_lconstr_env env rator.uj_val in
 
188
  let prt = pr_lconstr_env env rator.uj_type in
 
189
  let appl = prvect_with_sep pr_fnl
 
190
               (fun c ->
 
191
                  let pc = pr_lconstr_env env c.uj_val in
 
192
                  let pct = pr_lconstr_env env c.uj_type in
 
193
                  hov 2 (pc ++ spc () ++ str ": " ++ pct)) randl
 
194
  in
 
195
  str "Illegal application (Non-functional construction): " ++
 
196
  (* pe ++ *) fnl () ++
 
197
  str "The expression" ++ brk(1,1) ++ pr ++ spc () ++
 
198
  str "of type" ++ brk(1,1) ++ prt ++ spc () ++
 
199
  str "cannot be applied to the " ++ str (plural nargs "term") ++ fnl () ++
 
200
  str " " ++ v 0 appl
 
201
 
 
202
let explain_unexpected_type env actual_type expected_type =
 
203
  let pract = pr_lconstr_env env actual_type in
 
204
  let prexp = pr_lconstr_env env expected_type in
 
205
  str "This type is" ++ spc () ++ pract ++ spc () ++
 
206
  str "but is expected to be" ++
 
207
  spc () ++ prexp ++ str "."
 
208
 
 
209
let explain_not_product env c =
 
210
  let pr = pr_lconstr_env env c in
 
211
  str "The type of this term is a product" ++ spc () ++
 
212
  str "while it is expected to be" ++
 
213
  (if is_Type c then str " a sort" else (brk(1,1) ++ pr)) ++ str "."
 
214
 
 
215
(* TODO: use the names *)
 
216
(* (co)fixpoints *)
 
217
let explain_ill_formed_rec_body env err names i fixenv vdefj =
 
218
  let prt_name i =
 
219
    match names.(i) with
 
220
        Name id -> str "Recursive definition of " ++ pr_id id
 
221
      | Anonymous -> str "The " ++ nth i ++ str " definition" in
 
222
 
 
223
  let st = match err with
 
224
 
 
225
  (* Fixpoint guard errors *)
 
226
  | NotEnoughAbstractionInFixBody ->
 
227
      str "Not enough abstractions in the definition"
 
228
  | RecursionNotOnInductiveType c ->
 
229
      str "Recursive definition on" ++ spc () ++ pr_lconstr_env env c ++ spc () ++
 
230
      str "which should be an inductive type"
 
231
  | RecursionOnIllegalTerm(j,arg,le,lt) ->
 
232
      let called =
 
233
        match names.(j) with
 
234
            Name id -> pr_id id
 
235
          | Anonymous -> str "the " ++ nth i ++ str " definition" in
 
236
      let vars =
 
237
        match (lt,le) with
 
238
            ([],[]) -> assert false
 
239
          | ([],[x]) ->
 
240
              str "a subterm of " ++ pr_db env x
 
241
          | ([],_) ->
 
242
              str "a subterm of the following variables: " ++
 
243
              prlist_with_sep pr_spc (pr_db env) le
 
244
          | ([x],_) -> pr_db env x
 
245
          | _ ->
 
246
              str "one of the following variables: " ++
 
247
              prlist_with_sep pr_spc (pr_db env) lt in
 
248
      str "Recursive call to " ++ called ++ spc () ++
 
249
      str "has principal argument equal to" ++ spc () ++
 
250
      pr_lconstr_env env arg ++ fnl () ++ str "instead of " ++ vars
 
251
 
 
252
  | NotEnoughArgumentsForFixCall j ->
 
253
      let called =
 
254
        match names.(j) with
 
255
            Name id -> pr_id id
 
256
          | Anonymous -> str "the " ++ nth i ++ str " definition" in
 
257
     str "Recursive call to " ++ called ++ str " has not enough arguments"
 
258
 
 
259
  (* CoFixpoint guard errors *)
 
260
  | CodomainNotInductiveType c ->
 
261
      str "The codomain is" ++ spc () ++ pr_lconstr_env env c ++ spc () ++
 
262
      str "which should be a coinductive type"
 
263
  | NestedRecursiveOccurrences ->
 
264
      str "Nested recursive occurrences"
 
265
  | UnguardedRecursiveCall c ->
 
266
      str "Unguarded recursive call in" ++ spc () ++ pr_lconstr_env env c
 
267
  | RecCallInTypeOfAbstraction c ->
 
268
      str "Recursive call forbidden in the domain of an abstraction:" ++
 
269
      spc () ++ pr_lconstr_env env c
 
270
  | RecCallInNonRecArgOfConstructor c ->
 
271
      str "Recursive call on a non-recursive argument of constructor" ++
 
272
      spc () ++ pr_lconstr_env env c
 
273
  | RecCallInTypeOfDef c ->
 
274
      str "Recursive call forbidden in the type of a recursive definition" ++
 
275
      spc () ++ pr_lconstr_env env c
 
276
  | RecCallInCaseFun c ->
 
277
      str "Recursive call in a branch of" ++ spc () ++ pr_lconstr_env env c
 
278
  | RecCallInCaseArg c ->
 
279
      str "Recursive call in the argument of cases in" ++ spc () ++
 
280
      pr_lconstr_env env c
 
281
  | RecCallInCasePred c ->
 
282
      str "Recursive call in the type of cases in" ++  spc () ++
 
283
      pr_lconstr_env env c
 
284
  | NotGuardedForm c ->
 
285
      str "Sub-expression " ++ pr_lconstr_env env c ++
 
286
      strbrk " not in guarded form (should be a constructor," ++
 
287
      strbrk " an abstraction, a match, a cofix or a recursive call)"
 
288
  in
 
289
  prt_name i ++ str " is ill-formed." ++ fnl () ++
 
290
  pr_ne_context_of (str "In environment") env ++
 
291
  st ++ str "."
 
292
 
 
293
let explain_ill_typed_rec_body env i names vdefj vargs =
 
294
  let env = make_all_name_different env in
 
295
  let pvd,pvdt = pr_ljudge_env env (vdefj.(i)) in
 
296
  let pv = pr_lconstr_env env vargs.(i) in
 
297
  str "The " ++
 
298
  (if Array.length vdefj = 1 then mt () else nth (i+1) ++ spc ()) ++
 
299
  str "recursive definition" ++ spc () ++ pvd ++ spc () ++
 
300
  str "has type" ++ spc () ++ pvdt ++ spc () ++
 
301
  str "while it should be" ++ spc () ++ pv ++ str "."
 
302
 
 
303
let explain_cant_find_case_type env c =
 
304
  let env = make_all_name_different env in
 
305
  let pe = pr_lconstr_env env c in
 
306
  str "Cannot infer type of pattern-matching on" ++ ws 1 ++ pe ++ str "."
 
307
 
 
308
let explain_occur_check env ev rhs =
 
309
  let env = make_all_name_different env in
 
310
  let id = Evd.string_of_existential ev in
 
311
  let pt = pr_lconstr_env env rhs in
 
312
  str "Cannot define " ++ str id ++ str " with term" ++ brk(1,1) ++
 
313
  pt ++ spc () ++ str "that would depend on itself."
 
314
 
 
315
let pr_ne_context_of header footer env =
 
316
  if Environ.rel_context env = empty_rel_context &
 
317
    Environ.named_context env = empty_named_context
 
318
  then footer
 
319
  else pr_ne_context_of header env
 
320
 
 
321
let explain_hole_kind env evi = function
 
322
  | QuestionMark _ -> str "this placeholder"
 
323
  | CasesType ->
 
324
      str "the type of this pattern-matching problem"
 
325
  | BinderType (Name id) ->
 
326
      str "the type of " ++ Nameops.pr_id id
 
327
  | BinderType Anonymous ->
 
328
      str "the type of this anonymous binder"
 
329
  | ImplicitArg (c,(n,ido)) ->
 
330
      let id = Option.get ido in
 
331
      str "the implicit parameter " ++
 
332
      pr_id id ++ spc () ++ str "of" ++
 
333
      spc () ++ Nametab.pr_global_env Idset.empty c
 
334
  | InternalHole ->
 
335
      str "an internal placeholder" ++
 
336
        Option.cata (fun evi ->
 
337
          let env = Evd.evar_env evi in
 
338
            str " of type "  ++ pr_lconstr_env env evi.evar_concl ++
 
339
              pr_ne_context_of (str " in environment:"++ fnl ()) (mt ()) env)
 
340
        (mt ()) evi
 
341
  | TomatchTypeParameter (tyi,n) ->
 
342
      str "the " ++ nth n ++
 
343
      str " argument of the inductive type (" ++ pr_inductive env tyi ++
 
344
      str ") of this term"
 
345
  | GoalEvar ->
 
346
      str "an existential variable"
 
347
  | ImpossibleCase ->
 
348
      str "the type of an impossible pattern-matching clause"
 
349
 
 
350
let explain_not_clean env ev t k =
 
351
  let env = make_all_name_different env in
 
352
  let id = Evd.string_of_existential ev in
 
353
  let var = pr_lconstr_env env t in
 
354
  str "Tried to instantiate " ++ explain_hole_kind env None k ++
 
355
  str " (" ++ str id ++ str ")" ++ spc () ++
 
356
  str "with a term using variable " ++ var ++ spc () ++
 
357
  str "which is not in its scope."
 
358
 
 
359
let explain_unsolvability = function
 
360
  | None -> mt()
 
361
  | Some (SeveralInstancesFound n) ->
 
362
      strbrk " (several distinct possible instances found)"
 
363
 
 
364
let explain_typeclass_resolution env evi k =
 
365
  match k with
 
366
  | GoalEvar | InternalHole | ImplicitArg _ ->
 
367
      (match Typeclasses.class_of_constr evi.evar_concl with
 
368
      | Some c -> 
 
369
          let env = Evd.evar_env evi in
 
370
            fnl () ++ str "Could not find an instance for " ++ 
 
371
              pr_lconstr_env env evi.evar_concl ++ 
 
372
              pr_ne_context_of (str " in environment:"++ fnl ()) (str ".") env
 
373
      | None -> mt())
 
374
  | _ -> mt()
 
375
      
 
376
let explain_unsolvable_implicit env evi k explain =
 
377
  str "Cannot infer " ++ explain_hole_kind env (Some evi) k ++ 
 
378
  explain_unsolvability explain ++ str "." ++ 
 
379
  explain_typeclass_resolution env evi k
 
380
 
 
381
let explain_var_not_found env id =
 
382
  str "The variable" ++ spc () ++ pr_id id ++
 
383
  spc () ++ str "was not found" ++
 
384
  spc () ++ str "in the current" ++ spc () ++ str "environment" ++ str "."
 
385
 
 
386
let explain_wrong_case_info env ind ci =
 
387
  let pi = pr_inductive (Global.env()) ind in
 
388
  if ci.ci_ind = ind then
 
389
    str "Pattern-matching expression on an object of inductive type" ++
 
390
    spc () ++ pi ++ spc () ++ str "has invalid information."
 
391
  else
 
392
    let pc = pr_inductive (Global.env()) ci.ci_ind in
 
393
    str "A term of inductive type" ++ spc () ++ pi ++ spc () ++
 
394
    str "was given to a pattern-matching expression on the inductive type" ++
 
395
    spc () ++ pc ++ str "."
 
396
 
 
397
let explain_cannot_unify env m n =
 
398
  let pm = pr_lconstr_env env m in
 
399
  let pn = pr_lconstr_env env n in
 
400
  str "Impossible to unify" ++ brk(1,1) ++ pm ++ spc () ++
 
401
  str "with" ++ brk(1,1) ++ pn ++ str "."
 
402
 
 
403
let explain_cannot_unify_local env m n subn =
 
404
  let pm = pr_lconstr_env env m in
 
405
  let pn = pr_lconstr_env env n in
 
406
  let psubn = pr_lconstr_env env subn in
 
407
    str "Impossible to unify" ++ brk(1,1) ++ pm ++ spc () ++
 
408
      str "with" ++ brk(1,1) ++ pn ++ spc () ++ str "as" ++ brk(1,1) ++
 
409
      psubn ++ str " contains local variables."
 
410
 
 
411
let explain_refiner_cannot_generalize env ty =
 
412
  str "Cannot find a well-typed generalisation of the goal with type: " ++
 
413
  pr_lconstr_env env ty ++ str "."
 
414
 
 
415
let explain_no_occurrence_found env c id =
 
416
  str "Found no subterm matching " ++ pr_lconstr_env env c ++
 
417
  str " in " ++ 
 
418
    (match id with
 
419
      | Some id -> pr_id id
 
420
      | None -> str"the current goal") ++ str "."
 
421
 
 
422
let explain_cannot_unify_binding_type env m n =
 
423
  let pm = pr_lconstr_env env m in
 
424
  let pn = pr_lconstr_env env n in
 
425
  str "This binding has type" ++ brk(1,1) ++ pm ++ spc () ++
 
426
  str "which should be unifiable with" ++ brk(1,1) ++ pn ++ str "."
 
427
 
 
428
let explain_cannot_find_well_typed_abstraction env p l =
 
429
  str "Abstracting over the " ++
 
430
  str (plural (List.length l) "term") ++ spc () ++ 
 
431
  hov 0 (pr_enum (pr_lconstr_env env) l) ++ spc () ++
 
432
  str "leads to a term" ++ spc () ++ pr_lconstr_env env p ++ spc () ++ 
 
433
  str "which is ill-typed."
 
434
 
 
435
let explain_type_error env err =
 
436
  let env = make_all_name_different env in
 
437
  match err with
 
438
  | UnboundRel n ->
 
439
      explain_unbound_rel env n
 
440
  | UnboundVar v ->
 
441
      explain_unbound_var env v
 
442
  | NotAType j ->
 
443
      explain_not_type env j
 
444
  | BadAssumption c ->
 
445
      explain_bad_assumption env c
 
446
  | ReferenceVariables id ->
 
447
      explain_reference_variables id
 
448
  | ElimArity (ind, aritylst, c, pj, okinds) ->
 
449
      explain_elim_arity env ind aritylst c pj okinds
 
450
  | CaseNotInductive cj ->
 
451
      explain_case_not_inductive env cj
 
452
  | NumberBranches (cj, n) ->
 
453
      explain_number_branches env cj n
 
454
  | IllFormedBranch (c, i, actty, expty) ->
 
455
      explain_ill_formed_branch env c i actty expty
 
456
  | Generalization (nvar, c) ->
 
457
      explain_generalization env nvar c
 
458
  | ActualType (j, pt) ->
 
459
      explain_actual_type env j pt
 
460
  | CantApplyBadType (t, rator, randl) ->
 
461
      explain_cant_apply_bad_type env t rator randl
 
462
  | CantApplyNonFunctional (rator, randl) ->
 
463
      explain_cant_apply_not_functional env rator randl
 
464
  | IllFormedRecBody (err, lna, i, fixenv, vdefj) ->
 
465
      explain_ill_formed_rec_body env err lna i fixenv vdefj
 
466
  | IllTypedRecBody (i, lna, vdefj, vargs) ->
 
467
     explain_ill_typed_rec_body env i lna vdefj vargs
 
468
  | WrongCaseInfo (ind,ci) ->
 
469
      explain_wrong_case_info env ind ci
 
470
 
 
471
let explain_pretype_error env err =
 
472
  let env = make_all_name_different env in
 
473
  match err with
 
474
  | CantFindCaseType c -> explain_cant_find_case_type env c
 
475
  | OccurCheck (n,c) -> explain_occur_check env n c
 
476
  | NotClean (n,c,k) -> explain_not_clean env n c k
 
477
  | UnsolvableImplicit (evi,k,exp) -> explain_unsolvable_implicit env evi k exp
 
478
  | VarNotFound id -> explain_var_not_found env id
 
479
  | UnexpectedType (actual,expect) -> explain_unexpected_type env actual expect
 
480
  | NotProduct c -> explain_not_product env c
 
481
  | CannotUnify (m,n) -> explain_cannot_unify env m n
 
482
  | CannotUnifyLocal (m,n,sn) -> explain_cannot_unify_local env m n sn
 
483
  | CannotGeneralize ty -> explain_refiner_cannot_generalize env ty
 
484
  | NoOccurrenceFound (c, id) -> explain_no_occurrence_found env c id
 
485
  | CannotUnifyBindingType (m,n) -> explain_cannot_unify_binding_type env m n
 
486
  | CannotFindWellTypedAbstraction (p,l) ->
 
487
      explain_cannot_find_well_typed_abstraction env p l
 
488
 
 
489
      
 
490
(* Typeclass errors *)
 
491
 
 
492
let explain_not_a_class env c =
 
493
  pr_constr_env env c ++ str" is not a declared type class."
 
494
 
 
495
let explain_unbound_method env cid id =
 
496
  str "Unbound method name " ++ Nameops.pr_id (snd id) ++ spc () ++ str"of class" ++ spc () ++ 
 
497
    pr_global cid ++ str "."
 
498
 
 
499
let pr_constr_exprs exprs = 
 
500
  hv 0 (List.fold_right 
 
501
         (fun d pps -> ws 2 ++ Ppconstr.pr_constr_expr d ++ pps)
 
502
         exprs (mt ()))
 
503
 
 
504
let explain_no_instance env (_,id) l =
 
505
  str "No instance found for class " ++ Nameops.pr_id id ++ spc () ++
 
506
  str "applied to arguments" ++ spc () ++ 
 
507
    prlist_with_sep pr_spc (pr_lconstr_env env) l
 
508
 
 
509
let pr_constraints printenv env evm =
 
510
  let l = Evd.to_list evm in
 
511
  let (ev, evi) = List.hd l in
 
512
    if List.for_all (fun (ev', evi') ->
 
513
      eq_named_context_val evi.evar_hyps evi'.evar_hyps) l
 
514
    then
 
515
      let pe = pr_ne_context_of (str "In environment:") (mt ()) 
 
516
        (reset_with_named_context evi.evar_hyps env) in
 
517
        (if printenv then pe ++ fnl () else mt ()) ++
 
518
          prlist_with_sep (fun () -> fnl ()) 
 
519
          (fun (ev, evi) -> str(string_of_existential ev)++ str " == " ++ pr_constr evi.evar_concl) l
 
520
    else
 
521
      pr_evar_map evm
 
522
      
 
523
let explain_unsatisfiable_constraints env evd constr =
 
524
  let evm = Evd.evars_of evd in
 
525
  match constr with
 
526
  | None ->
 
527
      str"Unable to satisfy the following constraints:" ++ fnl() ++
 
528
        pr_constraints true env evm
 
529
  | Some (evi, k) -> 
 
530
      explain_unsolvable_implicit env evi k None ++ fnl () ++
 
531
        if List.length (Evd.to_list evm) > 1 then
 
532
          str"With the following constraints:" ++ fnl() ++ 
 
533
            pr_constraints false env evm
 
534
        else mt ()
 
535
        
 
536
let explain_mismatched_contexts env c i j = 
 
537
  str"Mismatched contexts while declaring instance: " ++ brk (1,1) ++
 
538
    hov 1 (str"Expected:" ++ brk (1, 1) ++ pr_rel_context env j) ++ fnl () ++ brk (1,1) ++ 
 
539
    hov 1 (str"Found:" ++ brk (1, 1) ++ pr_constr_exprs i)
 
540
 
 
541
let explain_typeclass_error env err = 
 
542
  match err with
 
543
    | NotAClass c -> explain_not_a_class env c
 
544
    | UnboundMethod (cid, id) -> explain_unbound_method env cid id
 
545
    | NoInstance (id, l) -> explain_no_instance env id l
 
546
    | UnsatisfiableConstraints (evd, c) -> explain_unsatisfiable_constraints env evd c
 
547
    | MismatchedContextInstance (c, i, j) -> explain_mismatched_contexts env c i j
 
548
        
 
549
(* Refiner errors *)
 
550
 
 
551
let explain_refiner_bad_type arg ty conclty =
 
552
  str "Refiner was given an argument" ++ brk(1,1) ++
 
553
  pr_lconstr arg ++ spc () ++
 
554
  str "of type" ++ brk(1,1) ++ pr_lconstr ty ++ spc () ++
 
555
  str "instead of" ++ brk(1,1) ++ pr_lconstr conclty ++ str "."
 
556
 
 
557
let explain_refiner_unresolved_bindings l =
 
558
  str "Unable to find an instance for the " ++ 
 
559
  str (plural (List.length l) "variable") ++ spc () ++
 
560
  prlist_with_sep pr_coma pr_name l ++ str"."
 
561
 
 
562
let explain_refiner_cannot_apply t harg =
 
563
  str "In refiner, a term of type" ++ brk(1,1) ++
 
564
  pr_lconstr t ++ spc () ++ str "could not be applied to" ++ brk(1,1) ++
 
565
  pr_lconstr harg ++ str "."
 
566
 
 
567
let explain_refiner_not_well_typed c =
 
568
  str "The term " ++ pr_lconstr c ++ str " is not well-typed."
 
569
 
 
570
let explain_intro_needs_product () =
 
571
  str "Introduction tactics needs products."
 
572
 
 
573
let explain_does_not_occur_in c hyp =
 
574
  str "The term" ++ spc () ++ pr_lconstr c ++ spc () ++
 
575
  str "does not occur in" ++ spc () ++ pr_id hyp ++ str "."
 
576
 
 
577
let explain_non_linear_proof c =
 
578
  str "Cannot refine with term" ++ brk(1,1) ++ pr_lconstr c ++
 
579
  spc () ++ str "because a metavariable has several occurrences."
 
580
 
 
581
let explain_meta_in_type c =
 
582
  str "In refiner, a meta appears in the type " ++ brk(1,1) ++ pr_lconstr c ++ 
 
583
  str " of another meta"
 
584
    
 
585
let explain_refiner_error = function
 
586
  | BadType (arg,ty,conclty) -> explain_refiner_bad_type arg ty conclty
 
587
  | UnresolvedBindings t -> explain_refiner_unresolved_bindings t
 
588
  | CannotApply (t,harg) -> explain_refiner_cannot_apply t harg
 
589
  | NotWellTyped c -> explain_refiner_not_well_typed c
 
590
  | IntroNeedsProduct -> explain_intro_needs_product ()
 
591
  | DoesNotOccurIn (c,hyp) -> explain_does_not_occur_in c hyp
 
592
  | NonLinearProof c -> explain_non_linear_proof c
 
593
  | MetaInType c -> explain_meta_in_type c
 
594
 
 
595
(* Inductive errors *)
 
596
 
 
597
let error_non_strictly_positive env c v  =
 
598
  let pc = pr_lconstr_env env c in
 
599
  let pv = pr_lconstr_env env v in
 
600
  str "Non strictly positive occurrence of " ++ pv ++ str " in" ++
 
601
  brk(1,1) ++ pc ++ str "."
 
602
 
 
603
let error_ill_formed_inductive env c v =
 
604
  let pc = pr_lconstr_env env c in
 
605
  let pv = pr_lconstr_env env v in
 
606
  str "Not enough arguments applied to the " ++ pv ++
 
607
  str " in" ++ brk(1,1) ++ pc ++ str "."
 
608
 
 
609
let error_ill_formed_constructor env id c v nparams nargs =
 
610
  let pv = pr_lconstr_env env v in
 
611
  let atomic = (nb_prod c = 0) in
 
612
  str "The type of constructor" ++ brk(1,1) ++ pr_id id ++ brk(1,1) ++
 
613
  str "is not valid;" ++ brk(1,1) ++ 
 
614
  strbrk (if atomic then "it must be " else "its conclusion must be ") ++ 
 
615
  pv ++ 
 
616
  (* warning: because of implicit arguments it is difficult to say which
 
617
     parameters must be explicitly given *)
 
618
  (if nparams<>0 then
 
619
    strbrk " applied to its " ++ str (plural nparams "parameter")
 
620
  else
 
621
    mt()) ++
 
622
  (if nargs<>0 then
 
623
     str (if nparams<>0 then " and" else " applied") ++
 
624
     strbrk " to some " ++ str (plural nargs "argument")
 
625
   else
 
626
     mt()) ++ str "."
 
627
 
 
628
let error_bad_ind_parameters env c n v1 v2  =
 
629
  let pc = pr_lconstr_env_at_top env c in
 
630
  let pv1 = pr_lconstr_env env v1 in
 
631
  let pv2 = pr_lconstr_env env v2 in
 
632
  str "Last occurrence of " ++ pv2 ++ str " must have " ++ pv1 ++
 
633
  str " as " ++ nth n ++ str " argument in " ++ brk(1,1) ++ pc ++ str "."
 
634
 
 
635
let error_same_names_types id =
 
636
  str "The name" ++ spc () ++ pr_id id ++ spc () ++
 
637
  str "is used more than once."
 
638
 
 
639
let error_same_names_constructors id =
 
640
  str "The constructor name" ++ spc () ++ pr_id id ++ spc () ++
 
641
  str "is used more than once."
 
642
 
 
643
let error_same_names_overlap idl =
 
644
  strbrk "The following names are used both as type names and constructor " ++
 
645
  str "names:" ++ spc () ++
 
646
  prlist_with_sep pr_coma pr_id idl ++ str "."
 
647
 
 
648
let error_not_an_arity id =
 
649
  str "The type of" ++ spc () ++ pr_id id ++ spc () ++ str "is not an arity."
 
650
 
 
651
let error_bad_entry () =
 
652
  str "Bad inductive definition."
 
653
 
 
654
let error_large_non_prop_inductive_not_in_type () =
 
655
  str "Large non-propositional inductive types must be in Type."
 
656
 
 
657
(* Recursion schemes errors *)
 
658
 
 
659
let error_not_allowed_case_analysis isrec kind i =
 
660
  str (if isrec then "Induction" else "Case analysis") ++
 
661
  strbrk " on sort " ++ pr_sort kind ++ 
 
662
  strbrk " is not allowed for inductive definition " ++
 
663
  pr_inductive (Global.env()) i ++ str "."
 
664
 
 
665
let error_not_mutual_in_scheme ind ind' =
 
666
  if ind = ind' then
 
667
    str "The inductive type " ++ pr_inductive (Global.env()) ind ++
 
668
    str "occurs twice."
 
669
  else
 
670
    str "The inductive types " ++ pr_inductive (Global.env()) ind ++ spc () ++
 
671
    str "and" ++ spc () ++ pr_inductive (Global.env()) ind' ++ spc () ++
 
672
    str "are not mutually defined."
 
673
 
 
674
(* Inductive constructions errors *)
 
675
 
 
676
let explain_inductive_error = function
 
677
  | NonPos (env,c,v) -> error_non_strictly_positive env c v
 
678
  | NotEnoughArgs (env,c,v) -> error_ill_formed_inductive env c v
 
679
  | NotConstructor (env,id,c,v,n,m) ->
 
680
      error_ill_formed_constructor env id c v n m
 
681
  | NonPar (env,c,n,v1,v2) -> error_bad_ind_parameters env c n v1 v2
 
682
  | SameNamesTypes id -> error_same_names_types id
 
683
  | SameNamesConstructors id -> error_same_names_constructors id
 
684
  | SameNamesOverlap idl -> error_same_names_overlap idl
 
685
  | NotAnArity id -> error_not_an_arity id
 
686
  | BadEntry -> error_bad_entry ()
 
687
  | LargeNonPropInductiveNotInType -> error_large_non_prop_inductive_not_in_type ()
 
688
 
 
689
(* Recursion schemes errors *)
 
690
 
 
691
let explain_recursion_scheme_error = function
 
692
  | NotAllowedCaseAnalysis (isrec,k,i) ->
 
693
      error_not_allowed_case_analysis isrec k i
 
694
  | NotMutualInScheme (ind,ind')-> error_not_mutual_in_scheme ind ind'
 
695
 
 
696
(* Pattern-matching errors *)
 
697
 
 
698
let explain_bad_pattern env cstr ty =
 
699
  let env = make_all_name_different env in
 
700
  let pt = pr_lconstr_env env ty in
 
701
  let pc = pr_constructor env cstr in
 
702
  str "Found the constructor " ++ pc ++ brk(1,1) ++
 
703
  str "while matching a term of type " ++ pt ++ brk(1,1) ++
 
704
  str "which is not an inductive type."
 
705
 
 
706
let explain_bad_constructor env cstr ind =
 
707
  let pi = pr_inductive env ind in
 
708
(*  let pc = pr_constructor env cstr in*)
 
709
  let pt = pr_inductive env (inductive_of_constructor cstr) in
 
710
  str "Found a constructor of inductive type " ++ pt ++ brk(1,1) ++
 
711
  str "while a constructor of " ++ pi ++ brk(1,1) ++
 
712
  str "is expected."
 
713
 
 
714
let decline_string n s =
 
715
  if n = 0 then "no "^s^"s"
 
716
  else if n = 1 then "1 "^s
 
717
  else (string_of_int n^" "^s^"s")
 
718
 
 
719
let explain_wrong_numarg_constructor env cstr n =
 
720
  str "The constructor " ++ pr_constructor env cstr ++
 
721
  str " expects " ++ str (decline_string n "argument") ++ str "."
 
722
 
 
723
let explain_wrong_numarg_inductive env ind n =
 
724
  str "The inductive type " ++ pr_inductive env ind ++
 
725
  str " expects " ++ str (decline_string n "argument") ++ str "."
 
726
 
 
727
let explain_wrong_predicate_arity env pred nondep_arity dep_arity=
 
728
  let env = make_all_name_different env in
 
729
  let pp = pr_lconstr_env env pred in
 
730
  str "The elimination predicate " ++ spc () ++ pp ++ fnl () ++
 
731
  str "should be of arity" ++ spc () ++
 
732
  pr_lconstr_env env nondep_arity ++ spc () ++
 
733
  str "(for non dependent case) or" ++
 
734
  spc () ++ pr_lconstr_env env dep_arity ++ spc () ++ str "(for dependent case)."
 
735
 
 
736
let explain_needs_inversion env x t =
 
737
  let env = make_all_name_different env in
 
738
  let px = pr_lconstr_env env x in
 
739
  let pt = pr_lconstr_env env t in
 
740
  str "Sorry, I need inversion to compile pattern matching on term " ++
 
741
  px ++ str " of type: " ++ pt ++ str "."
 
742
 
 
743
let explain_unused_clause env pats =
 
744
(* Without localisation
 
745
  let s = if List.length pats > 1 then "s" else "" in
 
746
  (str ("Unused clause with pattern"^s) ++ spc () ++
 
747
    hov 0 (prlist_with_sep pr_spc pr_cases_pattern pats) ++ str ")")
 
748
*)
 
749
  str "This clause is redundant."
 
750
 
 
751
let explain_non_exhaustive env pats =
 
752
  str "Non exhaustive pattern-matching: no clause found for " ++
 
753
  str (plural (List.length pats) "pattern") ++
 
754
  spc () ++ hov 0 (prlist_with_sep pr_spc pr_cases_pattern pats)
 
755
 
 
756
let explain_cannot_infer_predicate env typs =
 
757
  let env = make_all_name_different env in
 
758
  let pr_branch (cstr,typ) =
 
759
    let cstr,_ = decompose_app cstr in
 
760
    str "For " ++ pr_lconstr_env env cstr ++ str ": " ++ pr_lconstr_env env typ
 
761
  in
 
762
  str "Unable to unify the types found in the branches:" ++
 
763
  spc () ++ hov 0 (prlist_with_sep pr_fnl pr_branch (Array.to_list typs))
 
764
 
 
765
let explain_pattern_matching_error env = function
 
766
  | BadPattern (c,t) ->
 
767
      explain_bad_pattern env c t
 
768
  | BadConstructor (c,ind) ->
 
769
      explain_bad_constructor env c ind
 
770
  | WrongNumargConstructor (c,n) ->
 
771
      explain_wrong_numarg_constructor env c n
 
772
  | WrongNumargInductive (c,n) ->
 
773
      explain_wrong_numarg_inductive env c n
 
774
  | WrongPredicateArity (pred,n,dep) ->
 
775
      explain_wrong_predicate_arity env pred n dep
 
776
  | NeedsInversion (x,t) ->
 
777
      explain_needs_inversion env x t
 
778
  | UnusedClause tms ->
 
779
      explain_unused_clause env tms
 
780
  | NonExhaustive tms ->
 
781
      explain_non_exhaustive env tms
 
782
  | CannotInferPredicate typs ->
 
783
      explain_cannot_infer_predicate env typs
 
784
 
 
785
let explain_reduction_tactic_error = function
 
786
  | Tacred.InvalidAbstraction (env,c,(env',e)) ->
 
787
      str "The abstracted term" ++ spc () ++ pr_lconstr_env_at_top env c ++
 
788
      spc () ++ str "is not well typed." ++ fnl () ++
 
789
      explain_type_error env' e
 
790
 
 
791
let explain_ltac_call_trace (last,trace,loc) =
 
792
  let calls = last :: List.rev (List.map snd trace) in
 
793
  let pr_call = function
 
794
  | Proof_type.LtacNotationCall s -> quote (str s)
 
795
  | Proof_type.LtacNameCall cst -> quote (Pptactic.pr_ltac_constant cst)
 
796
  | Proof_type.LtacVarCall (id,t) ->
 
797
      quote (Nameops.pr_id id) ++ strbrk " (bound to " ++ 
 
798
      Pptactic.pr_glob_tactic (Global.env()) t ++ str ")"
 
799
  | Proof_type.LtacAtomCall (te,otac) -> quote
 
800
      (Pptactic.pr_glob_tactic (Global.env())
 
801
        (Tacexpr.TacAtom (dummy_loc,te)))
 
802
      ++ (match !otac with
 
803
      | Some te' when (Obj.magic te' <> te) ->
 
804
          strbrk " (expanded to " ++ quote
 
805
          (Pptactic.pr_tactic (Global.env())
 
806
            (Tacexpr.TacAtom (dummy_loc,te')))
 
807
        ++ str ")"
 
808
      | _ -> mt ())
 
809
  | Proof_type.LtacConstrInterp (c,(vars,unboundvars)) ->
 
810
      let filter =
 
811
        function (id,None) -> None | (id,Some id') -> Some(id,mkVar id') in
 
812
      let unboundvars = list_map_filter filter unboundvars in
 
813
      quote (pr_rawconstr_env (Global.env()) c) ++
 
814
      (if unboundvars <> [] or vars <> [] then
 
815
        strbrk " (with " ++ prlist_with_sep pr_coma (fun (id,c) -> 
 
816
        pr_id id ++ str ":=" ++ Printer.pr_lconstr c)
 
817
          (List.rev vars @ unboundvars) ++ str ")"
 
818
       else mt()) in
 
819
  if calls <> [] then
 
820
    let kind_of_last_call = match list_last calls with
 
821
    | Proof_type.LtacConstrInterp _ -> ", last term evaluation failed."
 
822
    | _ -> ", last call failed." in
 
823
    hov 0 (str "In nested Ltac calls to " ++ 
 
824
           pr_enum pr_call calls ++ strbrk kind_of_last_call)
 
825
  else
 
826
    mt ()