| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Pp |
| 12 |
open Util |
| 13 |
open Names |
| 14 |
open Nameops |
| 15 |
open Namegen |
| 16 |
open Constr |
| 17 |
open Context |
| 18 |
open Termops |
| 19 |
open Environ |
| 20 |
open Pretype_errors |
| 21 |
open Type_errors |
| 22 |
open Typeclasses_errors |
| 23 |
open Indrec |
| 24 |
open Cases |
| 25 |
open Logic |
| 26 |
open Printer |
| 27 |
open Evd |
| 28 |
open Context.Rel.Declaration |
| 29 |
|
| 30 |
module RelDecl = Context.Rel.Declaration |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
let contract env sigma lc = |
| 35 |
let open EConstr in |
| 36 |
let l = ref [] in |
| 37 |
let contract_context decl env = |
| 38 |
match decl with |
| 39 |
| LocalDef (_,c',_) when isRel sigma c' -> |
| 40 |
l := (Vars.substl !l c') :: !l; |
| 41 |
env |
| 42 |
| _ -> |
| 43 |
let t = Vars.substl !l (RelDecl.get_type decl) in |
| 44 |
let decl = decl |> RelDecl.map_name (named_hd env sigma t) |> RelDecl.map_value (Vars.substl !l) |> RelDecl.set_type t in |
| 45 |
l := (mkRel 1) :: List.map (Vars.lift 1) !l; |
| 46 |
push_rel decl env |
| 47 |
in |
| 48 |
let env = process_rel_context contract_context env in |
| 49 |
(env, List.map (Vars.substl !l) lc) |
| 50 |
|
| 51 |
let contract2 env sigma a b = match contract env sigma [a;b] with |
| 52 |
| env, [a;b] -> env,a,b | _ -> assert false |
| 53 |
|
| 54 |
let contract3 env sigma a b c = match contract env sigma [a;b;c] with |
| 55 |
| env, [a;b;c] -> env,a,b,c | _ -> assert false |
| 56 |
|
| 57 |
let contract4 env sigma a b c d = match contract env sigma [a;b;c;d] with |
| 58 |
| env, [a;b;c;d] -> (env,a,b,c),d | _ -> assert false |
| 59 |
|
| 60 |
let contract1 env sigma a v = |
| 61 |
match contract env sigma (a :: v) with |
| 62 |
| env, a::l -> env,a,l |
| 63 |
| _ -> assert false |
| 64 |
|
| 65 |
let rec contract3' env sigma a b c = function |
| 66 |
| OccurCheck (evk,d) -> |
| 67 |
let x,d = contract4 env sigma a b c d in x,OccurCheck(evk, d) |
| 68 |
| NotClean ((evk,args),env',d) -> |
| 69 |
let args = Evd.expand_existential sigma (evk, args) in |
| 70 |
let env',d,args = contract1 env' sigma d args in |
| 71 |
let args = SList.of_full_list args in |
| 72 |
contract3 env sigma a b c,NotClean((evk,args),env',d) |
| 73 |
| ConversionFailed (env',t1,t2) -> |
| 74 |
let (env',t1,t2) = contract2 env' sigma t1 t2 in |
| 75 |
contract3 env sigma a b c, ConversionFailed (env',t1,t2) |
| 76 |
| IncompatibleInstances (env',ev,t1,t2) -> |
| 77 |
let (env',ev,t1,t2) = contract3 env' sigma (EConstr.mkEvar ev) t1 t2 in |
| 78 |
contract3 env sigma a b c, IncompatibleInstances (env',EConstr.destEvar sigma ev,t1,t2) |
| 79 |
| NotSameArgSize | NotSameHead | NoCanonicalStructure | MetaOccurInBody _ |
| 80 |
| InstanceNotSameType _ | InstanceNotFunctionalType _ | ProblemBeyondCapabilities |
| 81 |
| UnifUnivInconsistency _ as x -> contract3 env sigma a b c, x |
| 82 |
| CannotSolveConstraint ((pb,env',t,u),x) -> |
| 83 |
let env',t,u = contract2 env' sigma t u in |
| 84 |
let y,x = contract3' env sigma a b c x in |
| 85 |
y,CannotSolveConstraint ((pb,env',t,u),x) |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
let j_nf_betaiotaevar env sigma j = |
| 90 |
{ uj_val = j.uj_val; |
| 91 |
uj_type = Reductionops.nf_betaiota env sigma j.uj_type } |
| 92 |
|
| 93 |
let jv_nf_betaiotaevar env sigma jl = |
| 94 |
Array.Smart.map (fun j -> j_nf_betaiotaevar env sigma j) jl |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
let pr_lconstr_env e s c = quote (pr_lconstr_env e s c) |
| 99 |
let pr_leconstr_env e s c = quote (pr_leconstr_env e s c) |
| 100 |
let pr_ljudge_env e s c = let v,t = pr_ljudge_env e s c in (quote v,quote t) |
| 101 |
|
| 102 |
|
| 103 |
let pr_global gr = |
| 104 |
try pr_global gr |
| 105 |
with Not_found -> GlobRef.print gr |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
let canonize_constr sigma c = |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
let open EConstr in |
| 114 |
let dn = Name.Anonymous in |
| 115 |
let rec canonize_binders c = |
| 116 |
match EConstr.kind sigma c with |
| 117 |
| Prod (x,t,b) -> mkProd({x with binder_name=dn},t,b) |
| 118 |
| Lambda (x,t,b) -> mkLambda({x with binder_name=dn},t,b) |
| 119 |
| LetIn (x,u,t,b) -> mkLetIn({x with binder_name=dn},u,t,b) |
| 120 |
| _ -> EConstr.map sigma canonize_binders c |
| 121 |
in |
| 122 |
canonize_binders c |
| 123 |
|
| 124 |
let rec display_expr_eq c1 c2 = |
| 125 |
let open Constrexpr in |
| 126 |
match CAst.(c1.v, c2.v) with |
| 127 |
| (CHole _ | CEvar _), _ | _, (CEvar _ | CHole _) -> true |
| 128 |
| _ -> |
| 129 |
Constrexpr_ops.constr_expr_eq_gen display_expr_eq c1 c2 |
| 130 |
|
| 131 |
let safe_extern_constr ~flags env sigma t = |
| 132 |
Printer.safe_extern_wrapper begin fun env sigma () -> |
| 133 |
Constrextern.extern_constr ~flags env sigma t |
| 134 |
end env sigma () |
| 135 |
|
| 136 |
|
| 137 |
let display_eq ~flags env sigma t1 t2 = |
| 138 |
|
| 139 |
let t1 = canonize_constr sigma t1 in |
| 140 |
let t2 = canonize_constr sigma t2 in |
| 141 |
let ct1 = safe_extern_constr ~flags env sigma t1 in |
| 142 |
let ct2 = safe_extern_constr ~flags env sigma t2 in |
| 143 |
match ct1, ct2 with |
| 144 |
| None, None -> false |
| 145 |
| Some _, None | None, Some _ -> false |
| 146 |
| Some ct1, Some ct2 -> display_expr_eq ct1 ct2 |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
let rec pr_explicit_aux env sigma t1 t2 = function |
| 151 |
| [] -> |
| 152 |
|
| 153 |
Printer.pr_leconstr_env env sigma t1, Printer.pr_leconstr_env env sigma t2 |
| 154 |
| flags :: rem -> |
| 155 |
let equal = display_eq ~flags env sigma t1 t2 in |
| 156 |
if equal then |
| 157 |
|
| 158 |
pr_explicit_aux env sigma t1 t2 rem |
| 159 |
else |
| 160 |
let ct1 = safe_extern_constr ~flags env sigma t1 in |
| 161 |
let ct2 = safe_extern_constr ~flags env sigma t2 in |
| 162 |
let pr = function |
| 163 |
| None -> str "??" |
| 164 |
| Some c -> Ppconstr.pr_lconstr_expr ~flags:(Ppconstr.of_printing_flags flags) env sigma c |
| 165 |
in |
| 166 |
pr ct1, pr ct2 |
| 167 |
|
| 168 |
let explicit_flags () = |
| 169 |
let open PrintingFlags in |
| 170 |
let with_implicits flags = { flags with extern = { flags.extern with implicits = true } } in |
| 171 |
let with_universes flags = { flags with detype = { flags.detype with universes = true } } in |
| 172 |
let with_coe_nosymb flags = { flags with extern = { flags.extern with coercions = true; notations = false } } in |
| 173 |
let flags = PrintingFlags.current() in |
| 174 |
[ flags; |
| 175 |
with_implicits flags; |
| 176 |
with_universes flags; |
| 177 |
with_universes @@ with_implicits flags; |
| 178 |
with_implicits @@ with_coe_nosymb flags; |
| 179 |
with_universes @@ with_implicits @@ with_coe_nosymb flags ] |
| 180 |
|
| 181 |
let with_diffs pm pn = |
| 182 |
if not (Proof_diffs.show_diffs ()) then pm, pn else |
| 183 |
try |
| 184 |
let tokenize_string = Proof_diffs.tokenize_string in |
| 185 |
Pp_diff.diff_pp ~tokenize_string pm pn |
| 186 |
with Pp_diff.Diff_Failure msg -> |
| 187 |
begin |
| 188 |
try ignore(Sys.getenv("HIDEDIFFFAILUREMSG")) |
| 189 |
with Not_found -> Proof_diffs.notify_proof_diff_failure msg |
| 190 |
end; |
| 191 |
pm, pn |
| 192 |
|
| 193 |
let pr_explicit env sigma t1 t2 = |
| 194 |
let p1, p2 = pr_explicit_aux env sigma t1 t2 (explicit_flags()) in |
| 195 |
let p1, p2 = with_diffs p1 p2 in |
| 196 |
quote p1, quote p2 |
| 197 |
|
| 198 |
let pr_db env i = |
| 199 |
try |
| 200 |
match env |> lookup_rel i |> get_name with |
| 201 |
| Name id -> Id.print id |
| 202 |
| Anonymous -> str "<>" |
| 203 |
with Not_found -> str "UNBOUND_REL_" ++ int i |
| 204 |
|
| 205 |
let explain_unbound_rel env sigma n = |
| 206 |
if n > 0 then |
| 207 |
let pe = pr_ne_context_of (str "In environment") env sigma in |
| 208 |
str "Unbound reference: " ++ pe ++ |
| 209 |
str "The reference " ++ int n ++ str " is free." |
| 210 |
else |
| 211 |
str "Invalid Rel " ++ int n ++ |
| 212 |
(if n = 0 then str ": local references are 1-indexed" else mt()) |
| 213 |
++ str " (bugged tactic?)." |
| 214 |
|
| 215 |
let explain_unbound_var env v = |
| 216 |
let var = Id.print v in |
| 217 |
str "No such section variable or assumption: " ++ var ++ str "." |
| 218 |
|
| 219 |
let explain_not_type env sigma j = |
| 220 |
let pe = pr_ne_context_of (str "In environment") env sigma in |
| 221 |
let pc,pt = pr_ljudge_env env sigma j in |
| 222 |
pe ++ str "The term" ++ brk(1,1) ++ pc ++ spc () ++ |
| 223 |
str "has type" ++ spc () ++ pt ++ spc () ++ |
| 224 |
str "which should be Set, Prop or Type." |
| 225 |
|
| 226 |
let explain_bad_assumption env sigma j = |
| 227 |
let pe = pr_ne_context_of (str "In environment") env sigma in |
| 228 |
let pc,pt = pr_ljudge_env env sigma j in |
| 229 |
pe ++ str "Cannot declare a variable or hypothesis over the term" ++ |
| 230 |
brk(1,1) ++ pc ++ spc () ++ str "of type" ++ spc () ++ pt ++ spc () ++ |
| 231 |
str "because this term is not a type." |
| 232 |
|
| 233 |
let explain_reference_variables sigma id c = |
| 234 |
pr_global c ++ strbrk " depends on the variable " ++ Id.print id ++ |
| 235 |
strbrk " which is not declared in the context." |
| 236 |
|
| 237 |
let explain_elim_arity env sigma ind c okinds = |
| 238 |
let open EConstr in |
| 239 |
let env = make_all_name_different env sigma in |
| 240 |
let mib, mip as specif = Inductive.lookup_mind_specif env (fst ind) in |
| 241 |
let pi = |
| 242 |
let pp () = pr_pinductive env sigma ind in |
| 243 |
match mip.mind_squashed with |
| 244 |
| None | Some AlwaysSquashed -> pp () |
| 245 |
| Some (SometimesSquashed _) -> |
| 246 |
|
| 247 |
Flags.with_option PrintingFlags.print_universes pp () |
| 248 |
in |
| 249 |
let pc = Option.map (pr_leconstr_env env sigma) c in |
| 250 |
let msg = match okinds with |
| 251 |
| None -> str "ill-formed elimination predicate." |
| 252 |
| Some sp -> |
| 253 |
let ppt ?(ppunivs=false) () = |
| 254 |
let pp () = pr_leconstr_env env sigma (mkSort (ESorts.make sp)) in |
| 255 |
if ppunivs then Flags.with_option PrintingFlags.print_universes pp () |
| 256 |
else pp () |
| 257 |
in |
| 258 |
let g = QGraph.merge (Environ.qualities env) (Evd.elim_graph sigma) in |
| 259 |
let env = Environ.set_qualities g env in |
| 260 |
let squash = Option.get (Inductive.is_squashed env (specif, snd ind)) in |
| 261 |
match squash with |
| 262 |
| SquashToSet -> |
| 263 |
let ppt = ppt () in |
| 264 |
hov 0 |
| 265 |
(str "the return type has sort" ++ spc () ++ ppt ++ spc () ++ |
| 266 |
str "while it should be SProp, Prop or Set.") ++ |
| 267 |
fnl () ++ |
| 268 |
hov 0 |
| 269 |
(str "Elimination of an inductive object of sort Set" ++ spc() ++ |
| 270 |
str "is not allowed on a predicate in sort " ++ ppt ++ fnl () ++ |
| 271 |
str "because" ++ spc () ++ |
| 272 |
str "strong elimination on non-small inductive types leads to paradoxes.") |
| 273 |
| SquashToQuality (QConstant (QSProp | QProp as squashq)) -> |
| 274 |
let ppt = ppt () in |
| 275 |
let inds, sorts, explain = match squashq with |
| 276 |
| QSProp -> "SProp", "SProp", "strict proofs can be eliminated only to build strict proofs" |
| 277 |
| QProp -> "Prop", "SProp or Prop", "proofs can be eliminated only to build proofs" |
| 278 |
| QType -> assert false |
| 279 |
in |
| 280 |
hov 0 |
| 281 |
(str "the return type has sort" ++ spc () ++ ppt ++ spc () ++ |
| 282 |
str "while it should be " ++ str sorts ++ str ".") ++ |
| 283 |
fnl () ++ |
| 284 |
hov 0 |
| 285 |
(str "Elimination of an inductive object of sort " ++ str inds ++ spc() ++ |
| 286 |
str "is not allowed on a predicate in sort " ++ ppt ++ fnl () ++ |
| 287 |
str "because" ++ spc () ++ |
| 288 |
str explain ++ str ".") |
| 289 |
| SquashToQuality (QConstant QType) -> |
| 290 |
let ppt = ppt ~ppunivs:true () in |
| 291 |
hov 0 |
| 292 |
(str "the return type has sort" ++ spc () ++ ppt ++ spc () ++ |
| 293 |
str "while it may not be of a variable sort quality.") ++ |
| 294 |
fnl () ++ |
| 295 |
hov 0 |
| 296 |
(str "Elimination of a sort polymorphic inductive object instantiated to sort Type" ++ spc() ++ |
| 297 |
|
| 298 |
str "is not allowed on a predicate in a variable sort quality.") |
| 299 |
| SquashToQuality (QVar squashq) -> |
| 300 |
let ppt = ppt ~ppunivs:true () in |
| 301 |
hov 0 |
| 302 |
(str "the return type has sort" ++ spc () ++ ppt ++ spc () ++ |
| 303 |
str "while it should be in a sort " ++ pr_evd_qvar sigma squashq ++ str " eliminates to.") ++ |
| 304 |
fnl () ++ |
| 305 |
hov 0 |
| 306 |
(str "Elimination of a sort polymorphic inductive object instantiated to a variable sort quality" ++ spc() ++ |
| 307 |
str "is only allowed on itself or with an explicit elimination constraint to the target sort.") |
| 308 |
in |
| 309 |
hov 0 ( |
| 310 |
str "Incorrect elimination" ++ |
| 311 |
(match pc with None -> mt() | Some pc -> str " of" ++ spc () ++ pc) ++ spc () ++ |
| 312 |
str "in the inductive type" ++ spc () ++ quote pi ++ str ":") ++ |
| 313 |
fnl () ++ msg |
| 314 |
|
| 315 |
let explain_case_not_inductive env sigma cj = |
| 316 |
let env = make_all_name_different env sigma in |
| 317 |
let pc = pr_leconstr_env env sigma cj.uj_val in |
| 318 |
let pct = pr_leconstr_env env sigma cj.uj_type in |
| 319 |
match EConstr.kind sigma cj.uj_type with |
| 320 |
| Evar _ -> |
| 321 |
str "Cannot infer a type for this expression." |
| 322 |
| _ -> |
| 323 |
str "The term" ++ brk(1,1) ++ pc ++ spc () ++ |
| 324 |
str "has type" ++ brk(1,1) ++ pct ++ spc () ++ |
| 325 |
str "which is not a (co-)inductive type." |
| 326 |
|
| 327 |
let explain_case_on_private_ind env sigma ind = |
| 328 |
str "Case analysis on private inductive "++ pr_inductive env ind |
| 329 |
++ str " is not allowed." |
| 330 |
|
| 331 |
let explain_number_branches env sigma cj expn = |
| 332 |
let env = make_all_name_different env sigma in |
| 333 |
let pc = pr_leconstr_env env sigma cj.uj_val in |
| 334 |
let pct = pr_leconstr_env env sigma cj.uj_type in |
| 335 |
str "Matching on term" ++ brk(1,1) ++ pc ++ spc () ++ |
| 336 |
str "of type" ++ brk(1,1) ++ pct ++ spc () ++ |
| 337 |
str "expects " ++ int expn ++ str " branches." |
| 338 |
|
| 339 |
let explain_ill_formed_case_params env sigma = |
| 340 |
str "Ill formed case parameters (bugged tactic?)." |
| 341 |
|
| 342 |
let explain_ill_formed_branch env sigma c ci actty expty = |
| 343 |
let simp t = Reductionops.nf_betaiota env sigma t in |
| 344 |
let env = make_all_name_different env sigma in |
| 345 |
let pc = pr_leconstr_env env sigma c in |
| 346 |
let pa, pe = pr_explicit env sigma (simp actty) (simp expty) in |
| 347 |
strbrk "In pattern-matching on term" ++ brk(1,1) ++ pc ++ |
| 348 |
spc () ++ strbrk "the branch for constructor" ++ spc () ++ |
| 349 |
quote (pr_pconstructor env sigma ci) ++ |
| 350 |
spc () ++ str "has type" ++ brk(1,1) ++ pa ++ spc () ++ |
| 351 |
str "which should be" ++ brk(1,1) ++ pe ++ str "." |
| 352 |
|
| 353 |
let explain_bad_proj_type env sigma cj p = |
| 354 |
let pc = pr_leconstr_env env sigma cj.uj_val in |
| 355 |
let pct = pr_leconstr_env env sigma cj.uj_type in |
| 356 |
let rcd = pr_global (GlobRef.IndRef (Projection.inductive p)) in |
| 357 |
str "The term" ++ brk(1,1) ++ pc ++ spc () ++ |
| 358 |
str "has type" ++ brk(1,1) ++ pct ++ spc () ++ |
| 359 |
str "which is not an instance of record type " ++ rcd ++ str "." |
| 360 |
|
| 361 |
let explain_generalization env sigma (name,var) j = |
| 362 |
let pe = pr_ne_context_of (str "In environment") env sigma in |
| 363 |
let pv = pr_letype_env env sigma var in |
| 364 |
let (pc,pt) = pr_ljudge_env (push_rel_assum (make_annot name EConstr.ERelevance.relevant,var) env) sigma j in |
| 365 |
pe ++ str "Cannot generalize" ++ brk(1,1) ++ pv ++ spc () ++ |
| 366 |
str "over" ++ brk(1,1) ++ pc ++ str "," ++ spc () ++ |
| 367 |
str "it has type" ++ spc () ++ pt ++ |
| 368 |
spc () ++ str "which should be Set, Prop or Type." |
| 369 |
|
| 370 |
let explain_unification_error env sigma p1 p2 = function |
| 371 |
| None -> mt() |
| 372 |
| Some e -> |
| 373 |
let rec aux p1 p2 = function |
| 374 |
| OccurCheck (evk,rhs) -> |
| 375 |
[str "cannot define " ++ quote (pr_existential_key env sigma evk) ++ |
| 376 |
strbrk " with term " ++ pr_leconstr_env env sigma rhs ++ |
| 377 |
strbrk " that would depend on itself"] |
| 378 |
| NotClean ((evk,args),env,c) -> |
| 379 |
let args = Evd.expand_existential sigma (evk, args) in |
| 380 |
let env = make_all_name_different env sigma in |
| 381 |
[str "cannot instantiate " ++ quote (pr_existential_key env sigma evk) |
| 382 |
++ strbrk " because " ++ pr_leconstr_env env sigma c ++ |
| 383 |
strbrk " is not in its scope" ++ |
| 384 |
(if List.is_empty args then mt() else |
| 385 |
strbrk ": available arguments are " ++ |
| 386 |
pr_sequence (pr_leconstr_env env sigma) (List.rev args))] |
| 387 |
| NotSameArgSize | NotSameHead | NoCanonicalStructure -> |
| 388 |
[] |
| 389 |
| ConversionFailed (env,t1,t2) -> |
| 390 |
let t1 = Reductionops.nf_betaiota env sigma t1 in |
| 391 |
let t2 = Reductionops.nf_betaiota env sigma t2 in |
| 392 |
if EConstr.eq_constr sigma t1 p1 && EConstr.eq_constr sigma t2 p2 then [] else |
| 393 |
let env = make_all_name_different env sigma in |
| 394 |
if not (EConstr.eq_constr sigma t1 p1) || not (EConstr.eq_constr sigma t2 p2) then |
| 395 |
let t1, t2 = pr_explicit env sigma t1 t2 in |
| 396 |
[str "cannot unify " ++ t1 ++ strbrk " and " ++ t2] |
| 397 |
else [] |
| 398 |
| IncompatibleInstances (env,ev,t1,t2) -> |
| 399 |
let env = make_all_name_different env sigma in |
| 400 |
let ev = pr_leconstr_env env sigma (EConstr.mkEvar ev) in |
| 401 |
let t1 = Reductionops.nf_betaiota env sigma t1 in |
| 402 |
let t2 = Reductionops.nf_betaiota env sigma t2 in |
| 403 |
let t1, t2 = pr_explicit env sigma t1 t2 in |
| 404 |
[ev ++ strbrk " has otherwise to unify with " ++ t1 ++ str " which is incompatible with " ++ t2] |
| 405 |
| MetaOccurInBody evk -> |
| 406 |
[str "instance for " ++ quote (pr_existential_key env sigma evk) ++ |
| 407 |
strbrk " refers to a metavariable - please report your example" ++ |
| 408 |
strbrk "at " ++ str Coq_config.wwwbugtracker ++ str "."] |
| 409 |
| InstanceNotSameType (evk,env,Some t,u) -> |
| 410 |
let t, u = pr_explicit env sigma t u in |
| 411 |
[str "unable to find a well-typed instantiation for " ++ |
| 412 |
quote (pr_existential_key env sigma evk) ++ |
| 413 |
strbrk ": cannot ensure that " ++ |
| 414 |
t ++ strbrk " is a subtype of " ++ u] |
| 415 |
| InstanceNotSameType (evk,env,None,u) -> |
| 416 |
let u = pr_leconstr_env env sigma u in |
| 417 |
[str "unable to find a well-typed instantiation for " ++ |
| 418 |
quote (pr_existential_key env sigma evk) ++ |
| 419 |
strbrk " of type " ++ u] |
| 420 |
| InstanceNotFunctionalType (evk,env,f,u) -> |
| 421 |
let env = make_all_name_different env sigma in |
| 422 |
let f = pr_leconstr_env env sigma f in |
| 423 |
let u = pr_leconstr_env env sigma u in |
| 424 |
[str "unable to find a well-typed instantiation for " ++ |
| 425 |
quote (pr_existential_key env sigma evk) ++ |
| 426 |
strbrk ": " ++ f ++ |
| 427 |
strbrk " is expected to have a functional type but it has type " ++ u] |
| 428 |
| UnifUnivInconsistency p -> |
| 429 |
[str "universe inconsistency: " ++ |
| 430 |
UGraph.explain_universe_inconsistency |
| 431 |
(Termops.pr_evd_qvar sigma) |
| 432 |
(Termops.pr_evd_level sigma) |
| 433 |
p] |
| 434 |
| CannotSolveConstraint ((pb,env,t,u),e) -> |
| 435 |
let env = make_all_name_different env sigma in |
| 436 |
(strbrk "cannot satisfy constraint " ++ pr_leconstr_env env sigma t ++ |
| 437 |
str " == " ++ pr_leconstr_env env sigma u) |
| 438 |
:: aux t u e |
| 439 |
| ProblemBeyondCapabilities -> |
| 440 |
[] |
| 441 |
in |
| 442 |
match aux p1 p2 e with |
| 443 |
| [] -> mt () |
| 444 |
| l -> spc () ++ str "(" ++ |
| 445 |
prlist_with_sep pr_semicolon (fun x -> x) l ++ str ")" |
| 446 |
|
| 447 |
let explain_actual_type env sigma j t reason = |
| 448 |
let env = make_all_name_different env sigma in |
| 449 |
let j = j_nf_betaiotaevar env sigma j in |
| 450 |
let t = Reductionops.nf_betaiota env sigma t in |
| 451 |
|
| 452 |
let pe = pr_ne_context_of (str "In environment") env sigma in |
| 453 |
let pc = pr_leconstr_env env sigma (Environ.j_val j) in |
| 454 |
let (pt, pct) = pr_explicit env sigma t (Environ.j_type j) in |
| 455 |
let ppreason = explain_unification_error env sigma j.uj_type t reason in |
| 456 |
pe ++ |
| 457 |
hov 0 ( |
| 458 |
str "The term" ++ brk(1,1) ++ pc ++ spc () ++ |
| 459 |
str "has type" ++ brk(1,1) ++ pct ++ spc () ++ |
| 460 |
str "while it is expected to have type" ++ brk(1,1) ++ pt ++ |
| 461 |
ppreason ++ str ".") |
| 462 |
|
| 463 |
let explain_incorrect_primitive env sigma j exp = |
| 464 |
let env = make_all_name_different env sigma in |
| 465 |
let {uj_val=p;uj_type=t} = j in |
| 466 |
let t = Reductionops.nf_betaiota env sigma t in |
| 467 |
let exp = Reductionops.nf_betaiota env sigma exp in |
| 468 |
|
| 469 |
let pe = pr_ne_context_of (str "In environment") env sigma in |
| 470 |
let (pt, pct) = pr_explicit env sigma exp t in |
| 471 |
pe ++ |
| 472 |
hov 0 ( |
| 473 |
str "The primitive" ++ brk(1,1) ++ str (CPrimitives.op_or_type_to_string p) ++ spc () ++ |
| 474 |
str "has type" ++ brk(1,1) ++ pct ++ spc () ++ |
| 475 |
str "while it is expected to have type" ++ brk(1,1) ++ pt ++ str ".") |
| 476 |
|
| 477 |
let explain_cant_apply_bad_type env sigma ?error (n,exptyp,actualtyp) rator randl = |
| 478 |
let randl = jv_nf_betaiotaevar env sigma randl in |
| 479 |
let actualtyp = Reductionops.nf_betaiota env sigma actualtyp in |
| 480 |
let env = make_all_name_different env sigma in |
| 481 |
let error = explain_unification_error env sigma actualtyp exptyp error in |
| 482 |
let actualtyp, exptyp = pr_explicit env sigma actualtyp exptyp in |
| 483 |
let nargs = Array.length randl in |
| 484 |
|
| 485 |
let pr,prt = pr_ljudge_env env sigma rator in |
| 486 |
let term_string1 = str (String.plural nargs "term") in |
| 487 |
let term_string2 = |
| 488 |
if nargs>1 then str "The " ++ pr_nth n ++ str " term" else str "This term" |
| 489 |
in |
| 490 |
let appl = prvect_with_sep fnl |
| 491 |
(fun c -> |
| 492 |
let pc,pct = pr_ljudge_env env sigma c in |
| 493 |
hov 2 (pc ++ spc () ++ str ": " ++ pct)) randl |
| 494 |
in |
| 495 |
str "Illegal application: " ++ fnl () ++ |
| 496 |
str "The term" ++ brk(1,1) ++ pr ++ spc () ++ |
| 497 |
str "of type" ++ brk(1,1) ++ prt ++ spc () ++ |
| 498 |
str "cannot be applied to the " ++ term_string1 ++ fnl () ++ |
| 499 |
str " " ++ v 0 appl ++ fnl () ++ term_string2 ++ str " has type" ++ |
| 500 |
brk(1,1) ++ actualtyp ++ spc () ++ |
| 501 |
str "which should be a subtype of" ++ brk(1,1) ++ |
| 502 |
exptyp ++ str "." ++ error |
| 503 |
|
| 504 |
let explain_cant_apply_not_functional env sigma rator randl = |
| 505 |
let env = make_all_name_different env sigma in |
| 506 |
let nargs = Array.length randl in |
| 507 |
|
| 508 |
let pr = pr_leconstr_env env sigma rator.uj_val in |
| 509 |
let prt = pr_leconstr_env env sigma rator.uj_type in |
| 510 |
let appl = prvect_with_sep fnl |
| 511 |
(fun c -> |
| 512 |
let pc = pr_leconstr_env env sigma c.uj_val in |
| 513 |
let pct = pr_leconstr_env env sigma c.uj_type in |
| 514 |
hov 2 (pc ++ spc () ++ str ": " ++ pct)) randl |
| 515 |
in |
| 516 |
str "Illegal application (Non-functional construction): " ++ |
| 517 |
fnl () ++ |
| 518 |
str "The expression" ++ brk(1,1) ++ pr ++ spc () ++ |
| 519 |
str "of type" ++ brk(1,1) ++ prt ++ spc () ++ |
| 520 |
str "cannot be applied to the " ++ str (String.plural nargs "term") ++ |
| 521 |
fnl () ++ str " " ++ v 0 appl |
| 522 |
|
| 523 |
let explain_unexpected_type env sigma actual_type expected_type e = |
| 524 |
let pract, prexp = pr_explicit env sigma actual_type expected_type in |
| 525 |
str "Found type" ++ spc () ++ pract ++ spc () ++ |
| 526 |
str "where" ++ spc () ++ prexp ++ str " was expected" ++ |
| 527 |
explain_unification_error env sigma actual_type expected_type (Some e) ++ str"." |
| 528 |
|
| 529 |
let explain_not_product env sigma c = |
| 530 |
let pr = pr_econstr_env env sigma c in |
| 531 |
str "The type of this term is a product" ++ spc () ++ |
| 532 |
str "while it is expected to be" ++ |
| 533 |
(if EConstr.isType sigma c then str " a sort" else (brk(1,1) ++ pr)) ++ str "." |
| 534 |
|
| 535 |
let explain_ill_formed_fix_body env sigma names i = function |
| 536 |
|
| 537 |
| NotEnoughAbstractionInFixBody k -> |
| 538 |
fmt "Not enough abstractions in the definition:@ expected at least %d according to the \"struct\" annotation" (k+1) |
| 539 |
| RecursionNotOnInductiveType c -> |
| 540 |
str "Recursive definition on" ++ spc () ++ pr_leconstr_env env sigma c ++ |
| 541 |
spc () ++ str "which should be a recursive inductive type" |
| 542 |
| RecursionOnIllegalTerm(j,(arg_env, arg),le_lt) -> |
| 543 |
let arg_env = make_all_name_different arg_env sigma in |
| 544 |
let called = |
| 545 |
match names.(j).binder_name with |
| 546 |
Name id -> Id.print id |
| 547 |
| Anonymous -> str "the " ++ pr_nth i ++ str " definition" in |
| 548 |
let pr_db x = quote (pr_db env x) in |
| 549 |
let vars = |
| 550 |
match Lazy.force le_lt with |
| 551 |
([],[]) -> assert false |
| 552 |
| ([x],[]) -> str "a subterm of " ++ pr_db x |
| 553 |
| (le,[]) -> str "a subterm of the following variables: " ++ |
| 554 |
pr_sequence pr_db le |
| 555 |
| (_,[x]) -> pr_db x |
| 556 |
| (_,lt) -> |
| 557 |
str "one of the following variables: " ++ |
| 558 |
pr_sequence pr_db lt in |
| 559 |
str "Recursive call to " ++ called ++ spc () ++ |
| 560 |
strbrk "has principal argument equal to" ++ spc () ++ |
| 561 |
pr_leconstr_env arg_env sigma arg ++ strbrk " instead of " ++ vars |
| 562 |
| NotEnoughArgumentsForFixCall j -> |
| 563 |
let called = |
| 564 |
match names.(j).binder_name with |
| 565 |
Name id -> Id.print id |
| 566 |
| Anonymous -> str "the " ++ pr_nth i ++ str " definition" in |
| 567 |
str "Recursive call to " ++ called ++ str " has not enough arguments" |
| 568 |
| FixpointOnNonEliminable (s, s') -> |
| 569 |
let pr_sort u = quote @@ Flags.with_option PrintingFlags.print_universes (Printer.pr_sort sigma) u in |
| 570 |
fmt "Cannot define a fixpoint@ with principal argument living in sort %t@ \ |
| 571 |
to produce a value in sort %t@ because %t does not eliminate to %t" |
| 572 |
(fun () -> pr_sort s) |
| 573 |
(fun () -> pr_sort s') |
| 574 |
(fun () -> pr_sort s) |
| 575 |
(fun () -> pr_sort s') |
| 576 |
|
| 577 |
let explain_ill_formed_cofix_body env sigma = function |
| 578 |
|
| 579 |
| CodomainNotInductiveType c -> |
| 580 |
str "The codomain is" ++ spc () ++ pr_leconstr_env env sigma c ++ spc () ++ |
| 581 |
str "which should be a coinductive type" |
| 582 |
| NestedRecursiveOccurrences -> |
| 583 |
str "Nested recursive occurrences" |
| 584 |
| UnguardedRecursiveCall c -> |
| 585 |
str "Unguarded recursive call in" ++ spc () ++ pr_leconstr_env env sigma c |
| 586 |
| RecCallInTypeOfAbstraction c -> |
| 587 |
str "Recursive call forbidden in the domain of an abstraction:" ++ |
| 588 |
spc () ++ pr_leconstr_env env sigma c |
| 589 |
| RecCallInNonRecArgOfConstructor c -> |
| 590 |
str "Recursive call on a non-recursive argument of constructor" ++ |
| 591 |
spc () ++ pr_leconstr_env env sigma c |
| 592 |
| RecCallInTypeOfDef c -> |
| 593 |
str "Recursive call forbidden in the type of a recursive definition" ++ |
| 594 |
spc () ++ pr_leconstr_env env sigma c |
| 595 |
| RecCallInCaseFun c -> |
| 596 |
str "Invalid recursive call in a branch of" ++ |
| 597 |
spc () ++ pr_leconstr_env env sigma c |
| 598 |
| RecCallInCaseArg c -> |
| 599 |
str "Invalid recursive call in the argument of \"match\" in" ++ spc () ++ |
| 600 |
pr_leconstr_env env sigma c |
| 601 |
| RecCallInCasePred c -> |
| 602 |
str "Invalid recursive call in the \"return\" clause of \"match\" in" ++ |
| 603 |
spc () ++ pr_leconstr_env env sigma c |
| 604 |
| NotGuardedForm c -> |
| 605 |
str "Sub-expression " ++ pr_leconstr_env env sigma c ++ |
| 606 |
strbrk " not in guarded form (should be a constructor," ++ |
| 607 |
strbrk " an abstraction, a match, a cofix or a recursive call)" |
| 608 |
| ReturnPredicateNotCoInductive c -> |
| 609 |
str "The return clause of the following pattern matching should be" ++ |
| 610 |
strbrk " a coinductive type:" ++ |
| 611 |
spc () ++ pr_leconstr_env env sigma c |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
let explain_ill_formed_rec_body env sigma err names i fixenv vdefj = |
| 616 |
let prt_name i = |
| 617 |
match names.(i).binder_name with |
| 618 |
Name id -> str "Recursive definition of " ++ Id.print id |
| 619 |
| Anonymous -> str "The " ++ pr_nth i ++ str " definition" in |
| 620 |
let st = match err with |
| 621 |
| FixGuardError err -> explain_ill_formed_fix_body env sigma names i err |
| 622 |
| CoFixGuardError err -> explain_ill_formed_cofix_body env sigma err |
| 623 |
in |
| 624 |
prt_name i ++ str " is ill-formed." ++ fnl () ++ |
| 625 |
pr_ne_context_of (str "In environment") env sigma ++ |
| 626 |
st ++ str "." ++ fnl () ++ |
| 627 |
(try |
| 628 |
let fixenv = make_all_name_different fixenv sigma in |
| 629 |
let pvd = pr_leconstr_env fixenv sigma vdefj.(i).uj_val in |
| 630 |
str"Recursive definition is:" ++ spc () ++ pvd ++ str "." |
| 631 |
with e when CErrors.noncritical e -> mt ()) |
| 632 |
|
| 633 |
let explain_not_guarded env sigma cofix_err fix_errs (names, typs, defs as recdef) = |
| 634 |
let nfix = Array.length names in |
| 635 |
let lnames = Array.map_to_list binder_name names in |
| 636 |
let prt_names = |
| 637 |
hov 0 (str "Recursive definition of " ++ pr_enum Name.print lnames) |
| 638 |
in |
| 639 |
let st = |
| 640 |
(match cofix_err with |
| 641 |
| None -> mt () |
| 642 |
| Some (env, i, err) -> |
| 643 |
(if nfix > 1 then str "As a mutual co-fixpoint:" else str "As a co-fixpoint:") |
| 644 |
++ fnl() ++ explain_ill_formed_cofix_body env sigma err) |
| 645 |
in |
| 646 |
let stl = |
| 647 |
if List.exists (fun (env, i, nv, err) -> match err with RecursionOnIllegalTerm _ -> true | _ -> false) fix_errs then |
| 648 |
List.map (fun (env, i, nv, err) -> |
| 649 |
hov 0 ((if nfix > 1 then str "As a mutual fixpoint" else str "As a fixpoint") |
| 650 |
++ str " decreasing on the " ++ pr_enum (fun (n,na) -> pr_nth (n+1) ++ str " argument of " ++ Name.print na) (List.combine nv lnames) ++ str ":") ++ |
| 651 |
fnl() ++ explain_ill_formed_fix_body env sigma names i err ++ str "." ++ fnl ()) |
| 652 |
fix_errs |
| 653 |
else |
| 654 |
match fix_errs with |
| 655 |
| [] -> [] |
| 656 |
| (env, i, nv, err) :: _ -> |
| 657 |
[hov 0 ((if nfix > 1 then str "As a mutual fixpoint" else str "As a fixpoint") ++ str ":") ++ |
| 658 |
fnl() ++ explain_ill_formed_fix_body env sigma names i err ++ str "." ++ fnl ()] |
| 659 |
|
| 660 |
|
| 661 |
in |
| 662 |
let fixenv = EConstr.push_rec_types recdef env in |
| 663 |
let st = prlist (fun x -> x) (st::stl) in |
| 664 |
prt_names ++ str " is ill-formed." ++ fnl () ++ |
| 665 |
pr_ne_context_of (str "In environment") env sigma ++ |
| 666 |
st ++ |
| 667 |
prvecti_with_sep fnl (fun i v -> |
| 668 |
try |
| 669 |
let fixenv = make_all_name_different fixenv sigma in |
| 670 |
let pvd = pr_leconstr_env fixenv sigma v in |
| 671 |
if nfix = 1 then |
| 672 |
str "Recursive definition is:" ++ spc () ++ pvd ++ str "." |
| 673 |
else |
| 674 |
str "The " ++ pr_nth (i+1) ++ str " recursive definition is:" ++ spc () ++ pvd ++ str "." |
| 675 |
with e when CErrors.noncritical e -> mt ()) |
| 676 |
defs |
| 677 |
|
| 678 |
let explain_ill_typed_rec_body env sigma i names vdefj vargs = |
| 679 |
let env = make_all_name_different env sigma in |
| 680 |
let pvd = pr_leconstr_env env sigma vdefj.(i).uj_val in |
| 681 |
let pvdt, pv = pr_explicit env sigma vdefj.(i).uj_type vargs.(i) in |
| 682 |
str "The " ++ |
| 683 |
(match vdefj with [|_|] -> mt () | _ -> pr_nth (i+1) ++ spc ()) ++ |
| 684 |
str "recursive definition" ++ spc () ++ pvd ++ spc () ++ |
| 685 |
str "has type" ++ spc () ++ pvdt ++ spc () ++ |
| 686 |
str "while it should be" ++ spc () ++ pv ++ str "." |
| 687 |
|
| 688 |
let explain_cant_find_case_type env sigma c = |
| 689 |
let env = make_all_name_different env sigma in |
| 690 |
let pe = pr_leconstr_env env sigma c in |
| 691 |
str "Cannot infer the return type of pattern-matching on" ++ ws 1 ++ |
| 692 |
pe ++ str "." |
| 693 |
|
| 694 |
let explain_occur_check env sigma ev rhs = |
| 695 |
let env = make_all_name_different env sigma in |
| 696 |
let pt = pr_leconstr_env env sigma rhs in |
| 697 |
str "Cannot define " ++ pr_existential_key env sigma ev ++ str " with term" ++ |
| 698 |
brk(1,1) ++ pt ++ spc () ++ str "that would depend on itself." |
| 699 |
|
| 700 |
let pr_trailing_ne_context_of env sigma = |
| 701 |
if List.is_empty (Environ.rel_context env) && |
| 702 |
List.is_empty (Environ.named_context env) |
| 703 |
then str "." |
| 704 |
else (strbrk " in environment:" ++ pr_context_unlimited env sigma) |
| 705 |
|
| 706 |
let rec explain_evar_kind env sigma evk ty = |
| 707 |
let open Evar_kinds in |
| 708 |
function |
| 709 |
| Evar_kinds.NamedHole id -> |
| 710 |
strbrk "the existential variable named " ++ Id.print id |
| 711 |
| Evar_kinds.QuestionMark {qm_record_field=None} -> |
| 712 |
strbrk "this placeholder of type " ++ ty |
| 713 |
| Evar_kinds.QuestionMark {qm_record_field=Some {fieldname; recordname}} -> |
| 714 |
str "field " ++ (Printer.pr_constant env fieldname) ++ str " of record " ++ (Printer.pr_inductive env recordname) |
| 715 |
| Evar_kinds.CasesType false -> |
| 716 |
strbrk "the type of this pattern-matching problem" |
| 717 |
| Evar_kinds.CasesType true -> |
| 718 |
strbrk "a subterm of type " ++ ty ++ |
| 719 |
strbrk " in the type of this pattern-matching problem" |
| 720 |
| Evar_kinds.BinderType (Name id) -> |
| 721 |
strbrk "the type of " ++ Id.print id |
| 722 |
| Evar_kinds.BinderType Anonymous -> |
| 723 |
strbrk "the type of this anonymous binder" |
| 724 |
| Evar_kinds.EvarType (ido,evk) -> |
| 725 |
let pp = match ido with |
| 726 |
| Some id -> str "?" ++ Id.print id |
| 727 |
| None -> |
| 728 |
try pr_existential_key env sigma evk |
| 729 |
with Not_found -> strbrk "an internal placeholder" in |
| 730 |
strbrk "the type of " ++ pp |
| 731 |
| Evar_kinds.ImplicitArg (c,(n,id),b) -> |
| 732 |
strbrk "the implicit parameter " ++ Id.print id ++ spc () ++ str "of" ++ |
| 733 |
spc () ++ Nametab.pr_global_env Id.Set.empty c ++ |
| 734 |
strbrk " whose type is " ++ ty |
| 735 |
| Evar_kinds.InternalHole -> strbrk "an internal placeholder of type " ++ ty |
| 736 |
| Evar_kinds.TomatchTypeParameter (tyi,n) -> |
| 737 |
strbrk "the " ++ pr_nth n ++ |
| 738 |
strbrk " argument of the inductive type (" ++ pr_inductive env tyi ++ |
| 739 |
strbrk ") of this term" |
| 740 |
| Evar_kinds.GoalEvar -> |
| 741 |
strbrk "an existential variable of type " ++ ty |
| 742 |
| Evar_kinds.ImpossibleCase -> |
| 743 |
strbrk "the type of an impossible pattern-matching clause" |
| 744 |
| Evar_kinds.MatchingVar _ -> |
| 745 |
assert false |
| 746 |
| Evar_kinds.VarInstance id -> |
| 747 |
strbrk "an instance of type " ++ ty ++ |
| 748 |
str " for the variable " ++ Id.print id |
| 749 |
| Evar_kinds.SubEvar (where,evk') -> |
| 750 |
let rec find_source evk = |
| 751 |
let EvarInfo evi = Evd.find sigma evk in |
| 752 |
match snd (Evd.evar_source evi) with |
| 753 |
| Evar_kinds.SubEvar (_,evk) -> find_source evk |
| 754 |
| src -> EvarInfo evi, src in |
| 755 |
let EvarInfo evi, src = find_source evk' in |
| 756 |
let pc = match Evd.evar_body evi with |
| 757 |
| Evar_defined c -> pr_leconstr_env env sigma c |
| 758 |
| Evar_empty -> assert false in |
| 759 |
let ty' = match Evd.evar_body evi with |
| 760 |
| Evar_empty -> Evd.evar_concl evi |
| 761 |
| Evar_defined b -> Retyping.get_type_of env sigma b |
| 762 |
in |
| 763 |
pr_existential_key env sigma evk ++ |
| 764 |
strbrk " in the partial instance " ++ pc ++ |
| 765 |
strbrk " found for " ++ |
| 766 |
explain_evar_kind env sigma evk |
| 767 |
(pr_leconstr_env env sigma ty') src |
| 768 |
| Evar_kinds.RewriteRulePattern Anonymous -> |
| 769 |
strbrk "an anonymous pattern variable of type " ++ ty |
| 770 |
| Evar_kinds.RewriteRulePattern Name id -> |
| 771 |
strbrk "the pattern variable named " ++ Id.print id |
| 772 |
|
| 773 |
let explain_typeclass_resolution env sigma evi k = |
| 774 |
match Typeclasses.class_of_constr env sigma (Evd.evar_concl evi) with |
| 775 |
| Some _ -> |
| 776 |
let env = Evd.evar_filtered_env env evi in |
| 777 |
str "Could not find an instance for " ++ |
| 778 |
pr_leconstr_env env sigma (Evd.evar_concl evi) ++ |
| 779 |
pr_trailing_ne_context_of env sigma |
| 780 |
| _ -> mt() |
| 781 |
|
| 782 |
let explain_placeholder_kind env sigma c e = |
| 783 |
match e with |
| 784 |
| Some (SeveralInstancesFound n) -> |
| 785 |
strbrk " (several distinct possible type class instances found)" |
| 786 |
| None -> |
| 787 |
match Typeclasses.class_of_constr env sigma c with |
| 788 |
| Some _ -> strbrk " (no type class instance found)" |
| 789 |
| _ -> mt () |
| 790 |
|
| 791 |
let explain_unsolvable_implicit env sigma evk explain = |
| 792 |
let evi = Evarutil.nf_evar_info sigma (Evd.find_undefined sigma evk) in |
| 793 |
let env = Evd.evar_filtered_env env evi in |
| 794 |
let type_of_hole = pr_leconstr_env env sigma (Evd.evar_concl evi) in |
| 795 |
let pe = pr_trailing_ne_context_of env sigma in |
| 796 |
strbrk "Cannot infer " ++ |
| 797 |
explain_evar_kind env sigma evk type_of_hole (snd (Evd.evar_source evi)) ++ |
| 798 |
explain_placeholder_kind env sigma (Evd.evar_concl evi) explain ++ pe |
| 799 |
|
| 800 |
let explain_var_not_found env id = |
| 801 |
str "The variable" ++ spc () ++ Id.print id ++ |
| 802 |
spc () ++ str "was not found" ++ |
| 803 |
spc () ++ str "in the current" ++ spc () ++ str "environment" ++ str "." |
| 804 |
|
| 805 |
|
| 806 |
let explain_evar_not_found env sigma id = |
| 807 |
let undef = Evar.Map.domain (Evd.undefined_map sigma) in |
| 808 |
let all_undef_evars = Evar.Set.elements undef in |
| 809 |
let f ev = Id.equal id (Termops.evar_suggested_name (Global.env ()) sigma ev) in |
| 810 |
if List.exists f all_undef_evars then |
| 811 |
|
| 812 |
str "?" ++ Id.print id ++ |
| 813 |
strbrk " is a generated name. Only user-given names for existential variables" ++ |
| 814 |
strbrk " can be referenced. To give a user name to an existential variable," ++ |
| 815 |
strbrk " introduce it with the ?[name] syntax." |
| 816 |
else |
| 817 |
str "Unknown existential variable." |
| 818 |
|
| 819 |
let explain_wrong_case_info env (ind,u) ci = |
| 820 |
let pi = pr_inductive env ind in |
| 821 |
if QInd.equal env ci.ci_ind ind then |
| 822 |
str "Pattern-matching expression on an object of inductive type" ++ |
| 823 |
spc () ++ pi ++ spc () ++ str "has invalid information." |
| 824 |
else |
| 825 |
let pc = pr_inductive env ci.ci_ind in |
| 826 |
str "A term of inductive type" ++ spc () ++ pi ++ spc () ++ |
| 827 |
str "was given to a pattern-matching expression on the inductive type" ++ |
| 828 |
spc () ++ pc ++ str "." |
| 829 |
|
| 830 |
let explain_cannot_unify env sigma m n e = |
| 831 |
let env = make_all_name_different env sigma in |
| 832 |
let pm, pn = pr_explicit env sigma m n in |
| 833 |
let ppreason = explain_unification_error env sigma m n e in |
| 834 |
let pe = pr_ne_context_of (str "In environment") env sigma in |
| 835 |
pe ++ str "Unable to unify" ++ brk(1,1) ++ pm ++ spc () ++ |
| 836 |
str "with" ++ brk(1,1) ++ pn ++ ppreason ++ str "." |
| 837 |
|
| 838 |
let explain_cannot_unify_local env sigma m n subn = |
| 839 |
let pm = pr_leconstr_env env sigma m in |
| 840 |
let pn = pr_leconstr_env env sigma n in |
| 841 |
let psubn = pr_leconstr_env env sigma subn in |
| 842 |
str "Unable to unify" ++ brk(1,1) ++ pm ++ spc () ++ |
| 843 |
str "with" ++ brk(1,1) ++ pn ++ spc () ++ str "as" ++ brk(1,1) ++ |
| 844 |
psubn ++ str " contains local variables." |
| 845 |
|
| 846 |
let explain_refiner_cannot_generalize env sigma ty = |
| 847 |
str "Cannot find a well-typed generalisation of the goal with type: " ++ |
| 848 |
pr_leconstr_env env sigma ty ++ str "." |
| 849 |
|
| 850 |
let explain_no_occurrence_found env sigma c id = |
| 851 |
str "Found no subterm matching" ++ spc() ++ pr_leconstr_env env sigma c ++ |
| 852 |
spc() ++ str "in " ++ |
| 853 |
(match id with |
| 854 |
| Some id -> Id.print id |
| 855 |
| None -> str"the current goal") ++ str "." |
| 856 |
|
| 857 |
let explain_cannot_unify_binding_type env sigma m n = |
| 858 |
let pm = pr_leconstr_env env sigma m in |
| 859 |
let pn = pr_leconstr_env env sigma n in |
| 860 |
str "This binding has type" ++ brk(1,1) ++ pm ++ spc () ++ |
| 861 |
str "which should be unifiable with" ++ brk(1,1) ++ pn ++ str "." |
| 862 |
|
| 863 |
let explain_cannot_find_well_typed_abstraction env sigma p l e = |
| 864 |
str "Abstracting over the " ++ |
| 865 |
str (String.plural (List.length l) "term") ++ spc () ++ |
| 866 |
hov 0 (pr_enum (fun c -> pr_leconstr_env env sigma c) l) ++ spc () ++ |
| 867 |
str "leads to a term" ++ spc () ++ pr_letype_env ~goal_concl_style:true env sigma p ++ |
| 868 |
spc () ++ str "which is ill-typed." ++ |
| 869 |
(match e with None -> mt () | Some e -> fnl () ++ str "Reason is: " ++ e) |
| 870 |
|
| 871 |
let explain_wrong_abstraction_type env sigma na abs expected result = |
| 872 |
let ppname = match na with Name id -> Id.print id ++ spc () | _ -> mt () in |
| 873 |
str "Cannot instantiate metavariable " ++ ppname ++ strbrk "of type " ++ |
| 874 |
pr_leconstr_env env sigma expected ++ strbrk " with abstraction " ++ |
| 875 |
pr_leconstr_env env sigma abs ++ strbrk " of incompatible type " ++ |
| 876 |
pr_leconstr_env env sigma result ++ str "." |
| 877 |
|
| 878 |
let explain_abstraction_over_meta _ m n = |
| 879 |
strbrk "Too complex unification problem: cannot find a solution for both " ++ |
| 880 |
Name.print m ++ spc () ++ str "and " ++ Name.print n ++ str "." |
| 881 |
|
| 882 |
let explain_non_linear_unification env sigma m t = |
| 883 |
strbrk "Cannot unambiguously instantiate " ++ |
| 884 |
Name.print m ++ str ":" ++ |
| 885 |
strbrk " which would require to abstract twice on " ++ |
| 886 |
pr_leconstr_env env sigma t ++ str "." |
| 887 |
|
| 888 |
let explain_unsatisfied_poly_constraints env sigma (elim_csts,univ_csts) = |
| 889 |
let univ_csts = Univ.UnivConstraints.filter (fun cst -> not @@ UGraph.check_constraint (Evd.universes sigma) cst) univ_csts in |
| 890 |
let elim_csts = Sorts.ElimConstraints.filter (fun cst -> not @@ QGraph.check_constraint (Evd.elim_graph sigma) cst) elim_csts in |
| 891 |
let univ_str = if Univ.UnivConstraints.is_empty univ_csts |
| 892 |
then mt() |
| 893 |
else spc() ++ Univ.UnivConstraints.pr (Termops.pr_evd_level sigma) univ_csts in |
| 894 |
let elim_str = if Sorts.ElimConstraints.is_empty elim_csts |
| 895 |
then mt() |
| 896 |
else spc() ++ Sorts.ElimConstraints.pr (Termops.pr_evd_qvar sigma) elim_csts in |
| 897 |
strbrk "Unsatisfied constraints:" ++ univ_str ++ elim_str ++ |
| 898 |
spc () ++ str "(maybe a bugged tactic)." |
| 899 |
|
| 900 |
let explain_unsatisfied_univ_constraints env sigma cst = |
| 901 |
let cst = Univ.UnivConstraints.filter (fun cst -> not @@ UGraph.check_constraint (Evd.universes sigma) cst) cst in |
| 902 |
strbrk "Unsatisfied constraints: " ++ |
| 903 |
Univ.UnivConstraints.pr (Termops.pr_evd_level sigma) cst ++ |
| 904 |
spc () ++ str "(maybe a bugged tactic)." |
| 905 |
|
| 906 |
let explain_undeclared_universes env sigma l = |
| 907 |
let l = Univ.Level.Set.elements l in |
| 908 |
strbrk "Undeclared " ++ str (CString.lplural l "universe") ++ strbrk ": " ++ |
| 909 |
prlist_with_sep spc (Termops.pr_evd_level sigma) l ++ |
| 910 |
spc () ++ str "(maybe a bugged tactic)." |
| 911 |
|
| 912 |
let explain_undeclared_qualities env sigma l = |
| 913 |
let n = Sorts.QVar.Set.cardinal l in |
| 914 |
strbrk "Undeclared " ++ str (if n = 1 then "quality" else "qualities") ++ strbrk": " ++ |
| 915 |
prlist_with_sep spc (Termops.pr_evd_qvar sigma) (Sorts.QVar.Set.elements l) ++ |
| 916 |
spc () ++ str "(maybe a bugged tactic)." |
| 917 |
|
| 918 |
let explain_not_allowed_sprop () = |
| 919 |
Pp.(strbrk "SProp is not allowed because the " |
| 920 |
++ str "\"Allow StrictProp\"" |
| 921 |
++ strbrk " flag is off.") |
| 922 |
|
| 923 |
let explain_not_allowed_dependent_eliminitation env isrec i = |
| 924 |
let open Pp in |
| 925 |
str "Dependent " ++ str (if isrec then "induction" else "case analysis") ++ |
| 926 |
strbrk " is not allowed for " ++ Termops.pr_global_env env (IndRef i) ++ str "." ++ |
| 927 |
str "Primitive records must have eta conversion to allow dependent elimination." |
| 928 |
|
| 929 |
let pr_relevance sigma r = |
| 930 |
let r = EConstr.ERelevance.kind sigma r in |
| 931 |
match r with |
| 932 |
| Sorts.Relevant -> str "relevant" |
| 933 |
| Sorts.Irrelevant -> str "irrelevant" |
| 934 |
| Sorts.RelevanceVar q -> str "a variable " ++ Sorts.QVar.raw_pr q |
| 935 |
|
| 936 |
let pr_binder env sigma = function |
| 937 |
| LocalAssum (na, t) -> |
| 938 |
Pp.hov 2 (str "(" ++ (Name.print @@ na.binder_name) ++ str " : " ++ |
| 939 |
pr_leconstr_env env sigma t ++ str ")") |
| 940 |
| LocalDef (na, b, t) -> |
| 941 |
Pp.hov 2 (str "(" ++ (Name.print @@ na.binder_name) ++ str " : " ++ |
| 942 |
pr_leconstr_env env sigma t ++ str " := " ++ pr_leconstr_env env sigma b ++ str ")") |
| 943 |
|
| 944 |
let explain_bad_binder_relevance env sigma rlv decl = |
| 945 |
strbrk "Binder" ++ spc () ++ pr_binder env sigma decl ++ |
| 946 |
strbrk " has relevance mark set to " ++ pr_relevance sigma (RelDecl.get_relevance decl) ++ |
| 947 |
strbrk " but was expected to be " ++ pr_relevance sigma rlv ++ |
| 948 |
spc () ++ str "(maybe a bugged tactic)." |
| 949 |
|
| 950 |
let explain_bad_case_relevance env sigma rlv case = |
| 951 |
let (_, _, _, (_,badr), _, _, _) = EConstr.destCase sigma case in |
| 952 |
strbrk "Pattern-matching" ++ spc () ++ pr_leconstr_env env sigma case ++ |
| 953 |
strbrk " has relevance mark set to " ++ pr_relevance sigma badr ++ |
| 954 |
strbrk " but was expected to be " ++ pr_relevance sigma rlv ++ |
| 955 |
spc () ++ str "(maybe a bugged tactic)." |
| 956 |
|
| 957 |
let explain_bad_relevance env sigma = function |
| 958 |
| Typing.BadRelevanceCase (r,c) -> explain_bad_case_relevance env sigma r c |
| 959 |
| BadRelevanceBinder (r,d) -> explain_bad_binder_relevance env sigma r d |
| 960 |
|
| 961 |
let () = CWarnings.register_printer Typing.bad_relevance_msg |
| 962 |
(fun (env, sigma, b) -> explain_bad_relevance env sigma b) |
| 963 |
|
| 964 |
let explain_bad_invert env = |
| 965 |
strbrk "Bad case inversion (maybe a bugged tactic)." |
| 966 |
|
| 967 |
let explain_bad_variance env sigma ~lev ~expected ~actual = |
| 968 |
fmt "Incorrect variance for universe %t:@ expected %t@ but cannot be less restrictive than %t." |
| 969 |
(fun () -> Termops.pr_evd_level sigma lev) |
| 970 |
(fun () -> UVars.Variance.pr expected) |
| 971 |
(fun () -> UVars.Variance.pr actual) |
| 972 |
|
| 973 |
let explain_undeclared_used_variables env sigma ~declared_vars ~inferred_vars = |
| 974 |
let l = Id.Set.elements (Id.Set.diff inferred_vars declared_vars) in |
| 975 |
let n = List.length l in |
| 976 |
let declared_vars = Pp.pr_sequence Id.print (Id.Set.elements declared_vars) in |
| 977 |
let inferred_vars = Pp.pr_sequence Id.print (Id.Set.elements inferred_vars) in |
| 978 |
let missing_vars = Pp.pr_sequence Id.print (List.rev l) in |
| 979 |
Pp.(prlist str |
| 980 |
["The following section "; (String.plural n "variable"); " "; |
| 981 |
(String.conjugate_verb_to_be n); " used but not declared:"] ++ fnl () ++ |
| 982 |
missing_vars ++ str "." ++ fnl () ++ fnl () ++ |
| 983 |
str "You can either update your proof to not depend on " ++ missing_vars ++ |
| 984 |
str ", or you can update your Proof line from" ++ fnl () ++ |
| 985 |
str "Proof using " ++ declared_vars ++ fnl () ++ |
| 986 |
str "to" ++ fnl () ++ |
| 987 |
str "Proof using " ++ inferred_vars) |
| 988 |
|
| 989 |
let explain_ill_formed_constant env sigma cst kn = |
| 990 |
strbrk "Ill-formed constant" ++ spc () ++ pr_constant env cst ++ str ":" ++ spc () ++ |
| 991 |
strbrk "expected canonical name" ++ spc () ++ KerName.print kn ++ spc () ++ |
| 992 |
strbrk "but found" ++ spc () ++ KerName.print (Constant.canonical cst) |
| 993 |
|
| 994 |
let explain_ill_formed_inductive env sigma mind kn = |
| 995 |
strbrk "Ill-formed inductive" ++ spc () ++ pr_inductive env (mind, 0) ++ str ":" ++ spc () ++ |
| 996 |
strbrk "expected canonical name" ++ spc () ++ KerName.print kn ++ spc () ++ |
| 997 |
strbrk "but found" ++ spc () ++ KerName.print (MutInd.canonical mind) |
| 998 |
|
| 999 |
let explain_type_error env sigma err = |
| 1000 |
let env = make_all_name_different env sigma in |
| 1001 |
match err with |
| 1002 |
| UnboundRel n -> |
| 1003 |
explain_unbound_rel env sigma n |
| 1004 |
| UnboundVar v -> |
| 1005 |
explain_unbound_var env v |
| 1006 |
| NotAType j -> |
| 1007 |
explain_not_type env sigma j |
| 1008 |
| BadAssumption c -> |
| 1009 |
explain_bad_assumption env sigma c |
| 1010 |
| ReferenceVariables (id,c) -> |
| 1011 |
explain_reference_variables sigma id c |
| 1012 |
| ElimArity (ind, c, okinds) -> |
| 1013 |
explain_elim_arity env sigma ind (Some c) okinds |
| 1014 |
| CaseNotInductive cj -> |
| 1015 |
explain_case_not_inductive env sigma cj |
| 1016 |
| CaseOnPrivateInd ind -> explain_case_on_private_ind env sigma ind |
| 1017 |
| NumberBranches (cj, n) -> |
| 1018 |
explain_number_branches env sigma cj n |
| 1019 |
| IllFormedCaseParams -> explain_ill_formed_case_params env sigma |
| 1020 |
| IllFormedBranch (c, i, actty, expty) -> |
| 1021 |
explain_ill_formed_branch env sigma c i actty expty |
| 1022 |
| BadProjType (cj, p) -> |
| 1023 |
explain_bad_proj_type env sigma cj p |
| 1024 |
| Generalization (nvar, c) -> |
| 1025 |
explain_generalization env sigma nvar c |
| 1026 |
| ActualType (j, pt) -> |
| 1027 |
explain_actual_type env sigma j pt None |
| 1028 |
| IncorrectPrimitive (j, t) -> |
| 1029 |
explain_incorrect_primitive env sigma j t |
| 1030 |
| CantApplyBadType (t, rator, randl) -> |
| 1031 |
explain_cant_apply_bad_type env sigma t rator randl |
| 1032 |
| CantApplyNonFunctional (rator, randl) -> |
| 1033 |
explain_cant_apply_not_functional env sigma rator randl |
| 1034 |
| IllFormedRecBody (err, lna, i, fixenv, vdefj) -> |
| 1035 |
explain_ill_formed_rec_body env sigma err lna i fixenv vdefj |
| 1036 |
| IllTypedRecBody (i, lna, vdefj, vargs) -> |
| 1037 |
explain_ill_typed_rec_body env sigma i lna vdefj vargs |
| 1038 |
| WrongCaseInfo (ind,ci) -> |
| 1039 |
explain_wrong_case_info env ind ci |
| 1040 |
| UnsatisfiedPConstraints cst -> |
| 1041 |
explain_unsatisfied_poly_constraints env sigma cst |
| 1042 |
| UnsatisfiedUnivConstraints cst -> |
| 1043 |
explain_unsatisfied_univ_constraints env sigma cst |
| 1044 |
| UndeclaredUniverses l -> |
| 1045 |
explain_undeclared_universes env sigma l |
| 1046 |
| UndeclaredQualities l -> |
| 1047 |
explain_undeclared_qualities env sigma l |
| 1048 |
| NotAllowedSProp -> explain_not_allowed_sprop () |
| 1049 |
| BadBinderRelevance (rlv, decl) -> explain_bad_binder_relevance env sigma rlv decl |
| 1050 |
| BadCaseRelevance (rlv, case) -> explain_bad_case_relevance env sigma rlv case |
| 1051 |
| BadInvert -> explain_bad_invert env |
| 1052 |
| BadVariance {lev;expected;actual} -> explain_bad_variance env sigma ~lev ~expected ~actual |
| 1053 |
| UndeclaredUsedVariables {declared_vars;inferred_vars} -> |
| 1054 |
explain_undeclared_used_variables env sigma ~declared_vars ~inferred_vars |
| 1055 |
| IllFormedConstant (cst, kn) -> |
| 1056 |
explain_ill_formed_constant env sigma cst kn |
| 1057 |
| IllFormedInductive (mind, kn) -> |
| 1058 |
explain_ill_formed_inductive env sigma mind kn |
| 1059 |
|
| 1060 |
let pr_position (cl,pos) = |
| 1061 |
let clpos = match cl with |
| 1062 |
| None -> str " of the goal" |
| 1063 |
| Some (id,Locus.InHyp) -> str " of hypothesis " ++ Id.print id |
| 1064 |
| Some (id,Locus.InHypTypeOnly) -> str " of the type of hypothesis " ++ Id.print id |
| 1065 |
| Some (id,Locus.InHypValueOnly) -> str " of the body of hypothesis " ++ Id.print id in |
| 1066 |
int pos ++ clpos |
| 1067 |
|
| 1068 |
let explain_cannot_unify_occurrences env sigma nested ((cl2,pos2),t2) ((cl1,pos1),t1) = |
| 1069 |
if nested then |
| 1070 |
str "Found nested occurrences of the pattern at positions " ++ |
| 1071 |
int pos1 ++ strbrk " and " ++ pr_position (cl2,pos2) ++ str "." |
| 1072 |
else |
| 1073 |
str "Found incompatible occurrences of the pattern" ++ str ":" ++ |
| 1074 |
spc () ++ str "Matched term " ++ pr_leconstr_env env sigma t2 ++ |
| 1075 |
strbrk " at position " ++ pr_position (cl2,pos2) ++ |
| 1076 |
strbrk " is not compatible with matched term " ++ |
| 1077 |
pr_leconstr_env env sigma t1 ++ strbrk " at position " ++ |
| 1078 |
pr_position (cl1,pos1) ++ str "." |
| 1079 |
|
| 1080 |
let pr_constraints printenv msg env sigma evars cstrs = |
| 1081 |
let (ev, evi) = Evar.Map.choose evars in |
| 1082 |
if Evar.Map.for_all (fun ev' evi' -> |
| 1083 |
eq_named_context_val (Evd.evar_hyps evi) (Evd.evar_hyps evi')) evars |
| 1084 |
then |
| 1085 |
let l = Evar.Map.bindings evars in |
| 1086 |
let env' = Evd.evar_env env evi in |
| 1087 |
let pe = |
| 1088 |
if printenv then |
| 1089 |
pr_ne_context_of (str "In environment:") env' sigma |
| 1090 |
else mt () |
| 1091 |
in |
| 1092 |
let env = Global.env () in |
| 1093 |
let evs = |
| 1094 |
prlist_with_sep (fun () -> fnl () ++ fnl ()) |
| 1095 |
(fun (ev, evi) -> hov 2 (pr_existential_key env sigma ev ++ |
| 1096 |
str " :" ++ spc () ++ Printer.pr_leconstr_env env' sigma (Evd.evar_concl evi))) l |
| 1097 |
in |
| 1098 |
h (pe ++ str msg ++ fnl () ++ evs ++ pr_evar_constraints sigma cstrs) |
| 1099 |
else |
| 1100 |
let filter evk _ = Evar.Map.mem evk evars in |
| 1101 |
pr_evar_map_filter ~with_univs:false filter env sigma |
| 1102 |
|
| 1103 |
let explain_unsatisfiable_constraints env sigma constr comp = |
| 1104 |
let (_, constraints) = Evd.extract_all_conv_pbs sigma in |
| 1105 |
let tcs = Evd.get_typeclass_evars sigma in |
| 1106 |
let undef = Evd.undefined_map sigma in |
| 1107 |
|
| 1108 |
|
| 1109 |
let is_kept evk _ = Evar.Set.mem evk tcs && Evar.Set.mem evk comp in |
| 1110 |
let undef = |
| 1111 |
let m = Evar.Map.filter is_kept undef in |
| 1112 |
if Evar.Map.is_empty m then undef |
| 1113 |
else m |
| 1114 |
in |
| 1115 |
match constr with |
| 1116 |
| None -> |
| 1117 |
if List.is_empty constraints then |
| 1118 |
let msg = "Could not find an instance for the following existential variables:" in |
| 1119 |
pr_constraints true msg env sigma undef constraints |
| 1120 |
else |
| 1121 |
let msg = "Unable to satisfy the following constraints:" in |
| 1122 |
pr_constraints true msg env sigma undef constraints |
| 1123 |
| Some (ev, k) -> |
| 1124 |
let cstr = |
| 1125 |
let remaining = Evar.Map.remove ev undef in |
| 1126 |
if not (Evar.Map.is_empty remaining) then |
| 1127 |
let msg = "With the following constraints:" in |
| 1128 |
pr_constraints false msg env sigma remaining constraints |
| 1129 |
else mt () |
| 1130 |
in |
| 1131 |
let info = Evar.Map.find ev undef in |
| 1132 |
explain_typeclass_resolution env sigma info k ++ fnl () ++ cstr |
| 1133 |
|
| 1134 |
let rec explain_pretype_error env sigma err = |
| 1135 |
let env = Evardefine.env_nf_betaiotaevar sigma env in |
| 1136 |
let env = make_all_name_different env sigma in |
| 1137 |
match err with |
| 1138 |
| CantFindCaseType c -> explain_cant_find_case_type env sigma c |
| 1139 |
| ActualTypeNotCoercible (j,t,e) -> |
| 1140 |
let {uj_val = c; uj_type = actty} = j in |
| 1141 |
let (env, c, actty, expty), e = contract3' env sigma c actty t e in |
| 1142 |
let j = {uj_val = c; uj_type = actty} in |
| 1143 |
explain_actual_type env sigma j expty (Some e) |
| 1144 |
| UnifOccurCheck (ev,rhs) -> explain_occur_check env sigma ev rhs |
| 1145 |
| UnsolvableImplicit (evk,exp) -> explain_unsolvable_implicit env sigma evk exp |
| 1146 |
| VarNotFound id -> explain_var_not_found env id |
| 1147 |
| EvarNotFound id -> explain_evar_not_found env sigma id |
| 1148 |
| UnexpectedType (actual,expect,e) -> |
| 1149 |
let env, actual, expect = contract2 env sigma actual expect in |
| 1150 |
explain_unexpected_type env sigma actual expect e |
| 1151 |
| NotProduct c -> explain_not_product env sigma c |
| 1152 |
| CannotUnify (m,n,e) -> |
| 1153 |
let env, m, n = contract2 env sigma m n in |
| 1154 |
explain_cannot_unify env sigma m n e |
| 1155 |
| CannotUnifyLocal (m,n,sn) -> explain_cannot_unify_local env sigma m n sn |
| 1156 |
| CannotGeneralize ty -> explain_refiner_cannot_generalize env sigma ty |
| 1157 |
| NoOccurrenceFound (c, id) -> explain_no_occurrence_found env sigma c id |
| 1158 |
| CannotUnifyBindingType (m,n) -> explain_cannot_unify_binding_type env sigma m n |
| 1159 |
| CannotFindWellTypedAbstraction (p,l,e) -> |
| 1160 |
explain_cannot_find_well_typed_abstraction env sigma p l |
| 1161 |
(Option.map (fun (env',e) -> explain_pretype_error env' sigma e) e) |
| 1162 |
| WrongAbstractionType (n,a,t,u) -> |
| 1163 |
explain_wrong_abstraction_type env sigma n a t u |
| 1164 |
| AbstractionOverMeta (m,n) -> explain_abstraction_over_meta env m n |
| 1165 |
| NonLinearUnification (m,c) -> explain_non_linear_unification env sigma m c |
| 1166 |
| TypingError t -> explain_type_error env sigma t |
| 1167 |
| CantApplyBadTypeExplained ((t, rator, randl),error) -> |
| 1168 |
explain_cant_apply_bad_type env sigma ~error t rator randl |
| 1169 |
| CannotUnifyOccurrences (b,c1,c2) -> explain_cannot_unify_occurrences env sigma b c1 c2 |
| 1170 |
| UnsatisfiableConstraints (c,comp) -> explain_unsatisfiable_constraints env sigma c comp |
| 1171 |
| NotAllowedSProp -> explain_not_allowed_sprop () |
| 1172 |
| NotAllowedElimination (isrec, k, (ind,u)) -> |
| 1173 |
explain_elim_arity env sigma (ind, (EConstr.EInstance.kind sigma u)) |
| 1174 |
None (Some (EConstr.ESorts.kind sigma k)) |
| 1175 |
| NotAllowedDependentElimination (isrec, i) -> explain_not_allowed_dependent_eliminitation env isrec i |
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
let pr_modpath mp = |
| 1180 |
Libnames.pr_qualid (Nametab.shortest_qualid_of_module mp) |
| 1181 |
|
| 1182 |
let pr_modtype_subpath upper mp = |
| 1183 |
let rec aux mp = |
| 1184 |
try |
| 1185 |
let (dir,id) = Libnames.repr_qualid (Nametab.shortest_qualid_of_modtype mp) in |
| 1186 |
Libnames.add_dirpath_suffix dir id, [] |
| 1187 |
with Not_found -> |
| 1188 |
match mp with |
| 1189 |
| MPdot (mp',id) -> let mp, suff = aux mp' in mp, id::suff |
| 1190 |
| _ -> assert false |
| 1191 |
in |
| 1192 |
let mp, suff = aux mp in |
| 1193 |
(if suff = [] then mt () |
| 1194 |
else strbrk (if upper then "Module " else "module ") ++ DirPath.print (DirPath.make suff) ++ strbrk " of ") ++ |
| 1195 |
DirPath.print mp |
| 1196 |
|
| 1197 |
let pr_module_or_modtype_subpath mp = match Nametab.shortest_qualid_of_module mp with |
| 1198 |
| qid -> |
| 1199 |
|
| 1200 |
strbrk "module " ++ Libnames.pr_qualid qid |
| 1201 |
| exception Not_found -> |
| 1202 |
|
| 1203 |
pr_modtype_subpath false mp |
| 1204 |
|
| 1205 |
open Modops |
| 1206 |
|
| 1207 |
let explain_not_match_error = function |
| 1208 |
| InductiveFieldExpected _ -> |
| 1209 |
strbrk "an inductive definition is expected" |
| 1210 |
| DefinitionFieldExpected -> |
| 1211 |
strbrk "a definition is expected. Hint: you can rename the \ |
| 1212 |
inductive or constructor and add a definition mapping the \ |
| 1213 |
old name to the new name" |
| 1214 |
| ModuleFieldExpected -> |
| 1215 |
strbrk "a module is expected" |
| 1216 |
| ModuleTypeFieldExpected -> |
| 1217 |
strbrk "a module type is expected" |
| 1218 |
| NotConvertibleInductiveField (id, None) -> |
| 1219 |
str "types given to " ++ Id.print id ++ str " differ" |
| 1220 |
| NotConvertibleInductiveField (id, Some (env, typ1, typ2)) -> |
| 1221 |
let typ1, typ2 = pr_explicit env (Evd.from_env env) (EConstr.of_constr typ1) (EConstr.of_constr typ2) in |
| 1222 |
str "types given to " ++ Id.print id ++ str " differ:" ++ spc () ++ |
| 1223 |
str "expected" ++ spc () ++ typ2 ++ spc () ++ |
| 1224 |
str "but found" ++ spc () ++ typ1 |
| 1225 |
| NotConvertibleConstructorField (id, None) -> |
| 1226 |
str "types given to constructor " ++ Id.print id ++ str " differ" |
| 1227 |
| NotConvertibleConstructorField (id, Some (env, typ1, typ2)) -> |
| 1228 |
let typ1, typ2 = pr_explicit env (Evd.from_env env) (EConstr.of_constr typ1) (EConstr.of_constr typ2) in |
| 1229 |
str "types given to constructor " ++ Id.print id ++ str " differ:" ++ spc () ++ |
| 1230 |
str "expected" ++ spc () ++ typ2 ++ spc () ++ |
| 1231 |
str "but found" ++ spc () ++ typ1 |
| 1232 |
| NotConvertibleBodyField None -> |
| 1233 |
str "the body of definitions differs" |
| 1234 |
| NotConvertibleBodyField (Some (env, c1, c2)) -> |
| 1235 |
let sigma = Evd.from_env env in |
| 1236 |
let c1, c2 = pr_explicit env sigma (EConstr.of_constr c1) (EConstr.of_constr c2) in |
| 1237 |
str "the body of definitions differs:" ++ spc () ++ |
| 1238 |
str "expected" ++ spc () ++ c2 ++ spc () ++ |
| 1239 |
str "but found" ++ spc () ++ c1 |
| 1240 |
| NotConvertibleTypeField (env, typ1, typ2) -> |
| 1241 |
let typ1, typ2 = pr_explicit env (Evd.from_env env) (EConstr.of_constr typ1) (EConstr.of_constr typ2) in |
| 1242 |
str "expected type" ++ spc () ++ |
| 1243 |
typ2 ++ spc () ++ |
| 1244 |
str "but found type" ++ spc () ++ |
| 1245 |
typ1 |
| 1246 |
| NotSameConstructorNamesField (got, expected) -> |
| 1247 |
let pr_names arr = prlist_with_sep pr_comma Id.print (Array.to_list arr) in |
| 1248 |
str "constructor names differ:" ++ spc () ++ |
| 1249 |
str "expected" ++ spc () ++ pr_names expected ++ spc () ++ |
| 1250 |
str "but found" ++ spc () ++ pr_names got |
| 1251 |
| NotSameInductiveNameInBlockField (got, expected) -> |
| 1252 |
str "inductive type names differ:" ++ spc () ++ |
| 1253 |
str "expected" ++ spc () ++ Id.print expected ++ spc () ++ |
| 1254 |
str "but found" ++ spc () ++ Id.print got |
| 1255 |
| FiniteInductiveFieldExpected isfinite -> |
| 1256 |
str "type is expected to be " ++ |
| 1257 |
str (if isfinite then "coinductive" else "inductive") |
| 1258 |
| InductiveNumbersFieldExpected { got; expected } -> |
| 1259 |
str "number of inductive types differs:" ++ spc () ++ |
| 1260 |
str "expected" ++ spc () ++ int expected ++ spc () ++ |
| 1261 |
str "but found" ++ spc () ++ int got |
| 1262 |
| InductiveParamsNumberField { got; expected } -> |
| 1263 |
str "number of parameters differs:" ++ spc () ++ |
| 1264 |
str "expected" ++ spc () ++ int expected ++ spc () ++ |
| 1265 |
str "but found" ++ spc () ++ int got |
| 1266 |
| RecordFieldExpected isrecord -> |
| 1267 |
str "type is expected " ++ str (if isrecord then "" else "not ") ++ |
| 1268 |
str "to be a record" |
| 1269 |
| RecordProjectionsExpected { expected; got } -> |
| 1270 |
let pr_names nal = pr_enum (function Name id -> Id.print id | _ -> str "_") nal in |
| 1271 |
str "projection names differ:" ++ spc () ++ |
| 1272 |
str "expected" ++ spc () ++ pr_names expected ++ spc () ++ |
| 1273 |
str "but found" ++ spc () ++ pr_names got |
| 1274 |
| NotEqualInductiveAliases (got, expected) -> |
| 1275 |
str "aliases to inductive types do not match:" ++ spc () ++ |
| 1276 |
str "expected" ++ spc () ++ MutInd.print expected ++ spc () ++ |
| 1277 |
str "but found" ++ spc () ++ MutInd.print got |
| 1278 |
| CumulativeStatusExpected b -> |
| 1279 |
let status b = if b then str"cumulative" else str"non-cumulative" in |
| 1280 |
str "a " ++ status b ++ str" declaration was expected, but a " ++ |
| 1281 |
status (not b) ++ str" declaration was found" |
| 1282 |
| PolymorphicStatusExpected b -> |
| 1283 |
let status b = if b then str"polymorphic" else str"monomorphic" in |
| 1284 |
str "a " ++ status b ++ str" declaration was expected, but a " ++ |
| 1285 |
status (not b) ++ str" declaration was found" |
| 1286 |
| IncompatibleUniverses { err; env; t1; t2 } -> |
| 1287 |
let sigma = Evd.from_env env in |
| 1288 |
let t1, t2 = pr_explicit env sigma (EConstr.of_constr t1) (EConstr.of_constr t2) in |
| 1289 |
str"the universe constraints are inconsistent:" ++ spc () ++ |
| 1290 |
UGraph.explain_universe_inconsistency |
| 1291 |
Sorts.QVar.raw_pr |
| 1292 |
UnivNames.pr_level_with_global_universes |
| 1293 |
err ++ spc () ++ |
| 1294 |
str "when comparing" ++ spc () ++ t1 ++ spc () ++ |
| 1295 |
str "and" ++ spc () ++ t2 |
| 1296 |
| IncompatibleQualities { err; env; t1; t2 } -> |
| 1297 |
let sigma = Evd.from_env env in |
| 1298 |
let t1, t2 = pr_explicit env sigma (EConstr.of_constr t1) (EConstr.of_constr t2) in |
| 1299 |
QGraph.explain_elimination_error Sorts.QVar.raw_pr err ++ spc () ++ |
| 1300 |
str "when comparing" ++ spc () ++ t1 ++ spc () ++ |
| 1301 |
str "and" ++ spc () ++ t2 |
| 1302 |
| IncompatiblePolymorphism (env, t1, t2) -> |
| 1303 |
let t1, t2 = pr_explicit env (Evd.from_env env) (EConstr.of_constr t1) (EConstr.of_constr t2) in |
| 1304 |
str "conversion of polymorphic values generates additional constraints: " ++ |
| 1305 |
quote t1 ++ spc () ++ |
| 1306 |
str "compared to " ++ spc () ++ |
| 1307 |
quote t2 |
| 1308 |
| IncompatibleUnivConstraints { got; expect } -> |
| 1309 |
let open UVars in |
| 1310 |
let pr_auctx auctx = |
| 1311 |
let sigma = Evd.from_ctx |
| 1312 |
(UState.of_names |
| 1313 |
(Printer.universe_binders_with_opt_names auctx None)) |
| 1314 |
in |
| 1315 |
let uctx = AbstractContext.repr auctx in |
| 1316 |
Printer.pr_universe_instance_binder sigma |
| 1317 |
(UContext.instance uctx) |
| 1318 |
(UContext.univ_constraints uctx) |
| 1319 |
in |
| 1320 |
str "incompatible polymorphic binders: got" ++ spc () ++ h (pr_auctx got) ++ spc() ++ |
| 1321 |
str "but expected" ++ spc() ++ h (pr_auctx expect) ++ |
| 1322 |
(if not (UVars.eq_sizes (AbstractContext.size got) (AbstractContext.size expect)) then mt() else |
| 1323 |
fnl() ++ str "(incompatible constraints)") |
| 1324 |
| IncompatibleVariance -> |
| 1325 |
str "incompatible variance information" |
| 1326 |
| NoRewriteRulesSubtyping -> |
| 1327 |
strbrk "subtyping for rewrite rule blocks is not supported" |
| 1328 |
|
| 1329 |
let rec get_submodules acc = function |
| 1330 |
| [] -> acc, [] |
| 1331 |
| Submodule l :: trace -> get_submodules (l::acc) trace |
| 1332 |
| (FunctorArgument _ :: _) as trace -> acc, trace |
| 1333 |
|
| 1334 |
let get_submodules trace = |
| 1335 |
let submodules, trace = get_submodules [] trace in |
| 1336 |
(String.concat "." (List.map Id.to_string submodules)), trace |
| 1337 |
|
| 1338 |
let rec print_trace = function |
| 1339 |
| [] -> assert false |
| 1340 |
| (Submodule _ :: _) as trace -> |
| 1341 |
let submodules, trace = get_submodules trace in |
| 1342 |
str submodules ++ |
| 1343 |
(if List.is_empty trace then mt() else spc() ++ str "in " ++ print_trace trace) |
| 1344 |
| FunctorArgument n :: trace -> |
| 1345 |
str "the " ++ str (CString.ordinal n) ++ str " functor argument" ++ |
| 1346 |
(if List.is_empty trace then mt() else spc() ++ str "of " ++ print_trace trace) |
| 1347 |
|
| 1348 |
let explain_signature_mismatch trace l why = |
| 1349 |
let submodules, trace = get_submodules trace in |
| 1350 |
let l = if String.is_empty submodules then Id.print l |
| 1351 |
else str submodules ++ str"." ++ Id.print l |
| 1352 |
in |
| 1353 |
str "Signature components for field " ++ l ++ |
| 1354 |
(if List.is_empty trace then mt() else str " in " ++ print_trace trace) ++ |
| 1355 |
str " do not match:" ++ spc () ++ explain_not_match_error why ++ str "." |
| 1356 |
|
| 1357 |
let explain_label_already_declared l = |
| 1358 |
str "The label " ++ Id.print l ++ str " is already declared." |
| 1359 |
|
| 1360 |
let explain_not_a_functor () = |
| 1361 |
str "Application of a non-functor." |
| 1362 |
|
| 1363 |
let explain_is_a_functor mp = |
| 1364 |
pr_modtype_subpath true mp ++ str " not expected to be a functor." |
| 1365 |
|
| 1366 |
let explain_incompatible_module_types mexpr1 mexpr2 = |
| 1367 |
let open Declarations in |
| 1368 |
let open Mod_declarations in |
| 1369 |
let rec get_arg = function |
| 1370 |
| NoFunctor _ -> 0 |
| 1371 |
| MoreFunctor (_, _, ty) -> succ (get_arg ty) |
| 1372 |
in |
| 1373 |
let len1 = get_arg @@ mod_type mexpr1 in |
| 1374 |
let len2 = get_arg @@ mod_type mexpr2 in |
| 1375 |
if len1 <> len2 then |
| 1376 |
str "Incompatible module types: module expects " ++ int len2 ++ |
| 1377 |
str " arguments, found " ++ int len1 ++ str "." |
| 1378 |
else str "Incompatible module types." |
| 1379 |
|
| 1380 |
let explain_not_equal_module_paths mp1 mp2 = |
| 1381 |
str "Module " ++ pr_modpath mp1 ++ strbrk " is not equal to " ++ pr_module_or_modtype_subpath mp2 ++ str "." |
| 1382 |
|
| 1383 |
let explain_no_such_label l mp = |
| 1384 |
str "No field named " ++ Id.print l ++ str " in " ++ pr_modtype_subpath false mp ++ str "." |
| 1385 |
|
| 1386 |
let explain_not_a_module_label l = |
| 1387 |
Id.print l ++ str " is not the name of a module field." |
| 1388 |
|
| 1389 |
let explain_not_a_constant l = |
| 1390 |
quote (Id.print l) ++ str " is not a constant." |
| 1391 |
|
| 1392 |
let explain_with_constraint_error = function |
| 1393 |
| WithSignatureMismatch sig_err -> explain_not_match_error sig_err |
| 1394 |
| WithCannotConstrainPrimitive -> |
| 1395 |
str "cannot constrain a primitive" |
| 1396 |
| WithCannotConstrainSymbol -> |
| 1397 |
str "cannot constrain a symbol" |
| 1398 |
|
| 1399 |
let explain_incorrect_with_constraint l err = |
| 1400 |
str "Incorrect constraint for label " ++ quote (Id.print l) ++ str ": " ++ |
| 1401 |
explain_with_constraint_error err |
| 1402 |
|
| 1403 |
let explain_generative_module_expected l = |
| 1404 |
str "The module " ++ Id.print l ++ str " is not generative." ++ |
| 1405 |
strbrk " Only components of generative modules can be changed" ++ |
| 1406 |
strbrk " using the \"with\" construct." |
| 1407 |
|
| 1408 |
let explain_label_missing l s = |
| 1409 |
str "The field " ++ Id.print l ++ str " is missing in " |
| 1410 |
++ str s ++ str "." |
| 1411 |
|
| 1412 |
let explain_include_restricted_functor mp = |
| 1413 |
str "Cannot include the functor " ++ pr_modpath mp ++ |
| 1414 |
strbrk " since it has a restricted signature. " ++ |
| 1415 |
strbrk "You may name first an instance of this functor, and include it." |
| 1416 |
|
| 1417 |
let explain_module_error = function |
| 1418 |
| SignatureMismatch (trace,l,err) -> explain_signature_mismatch trace l err |
| 1419 |
| LabelAlreadyDeclared l -> explain_label_already_declared l |
| 1420 |
| NotAFunctor -> explain_not_a_functor () |
| 1421 |
| IsAFunctor mp -> explain_is_a_functor mp |
| 1422 |
| IncompatibleModuleTypes (m1,m2) -> explain_incompatible_module_types m1 m2 |
| 1423 |
| NotEqualModulePaths (mp1,mp2) -> explain_not_equal_module_paths mp1 mp2 |
| 1424 |
| NoSuchLabel (l,mp) -> explain_no_such_label l mp |
| 1425 |
| NotAModuleLabel l -> explain_not_a_module_label l |
| 1426 |
| NotAConstant l -> explain_not_a_constant l |
| 1427 |
| IncorrectWithConstraint (l, err) -> explain_incorrect_with_constraint l err |
| 1428 |
| GenerativeModuleExpected l -> explain_generative_module_expected l |
| 1429 |
| LabelMissing (l,s) -> explain_label_missing l s |
| 1430 |
| IncludeRestrictedFunctor mp -> explain_include_restricted_functor mp |
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
let explain_not_module_nor_modtype qid = |
| 1441 |
Libnames.pr_qualid qid ++ str " is not a module or module type." |
| 1442 |
|
| 1443 |
let explain_not_a_module qid = |
| 1444 |
Libnames.pr_qualid qid ++ str " is not a module." |
| 1445 |
|
| 1446 |
let explain_not_a_module_type qid = |
| 1447 |
Libnames.pr_qualid qid ++ str " is not a module type." |
| 1448 |
|
| 1449 |
let explain_incorrect_with_in_module () = |
| 1450 |
str "The syntax \"with\" is not allowed for modules." |
| 1451 |
|
| 1452 |
let explain_incorrect_module_application () = |
| 1453 |
str "Illegal application to a module type." |
| 1454 |
|
| 1455 |
let explain_module_internalization_error = let open Modintern in function |
| 1456 |
| NotAModuleNorModtype qid -> explain_not_module_nor_modtype qid |
| 1457 |
| NotAModule qid -> explain_not_a_module qid |
| 1458 |
| NotAModuleType qid -> explain_not_a_module_type qid |
| 1459 |
| IncorrectWithInModule -> explain_incorrect_with_in_module () |
| 1460 |
| IncorrectModuleApplication -> explain_incorrect_module_application () |
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
let explain_not_a_class env sigma c = |
| 1465 |
pr_econstr_env env sigma c ++ str" is not a declared type class." |
| 1466 |
|
| 1467 |
let explain_unbound_method env sigma cid { CAst.v = id } = |
| 1468 |
str "Unbound method name " ++ Id.print (id) ++ spc () ++ |
| 1469 |
str"of class" ++ spc () ++ pr_global cid ++ str "." |
| 1470 |
|
| 1471 |
let explain_typeclass_error env sigma = function |
| 1472 |
| NotAClass c -> explain_not_a_class env sigma c |
| 1473 |
| UnboundMethod (cid, id) -> explain_unbound_method env sigma cid id |
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
let explain_refiner_unresolved_bindings l = |
| 1478 |
str "Unable to find an instance for the " ++ |
| 1479 |
str (String.plural (List.length l) "variable") ++ spc () ++ |
| 1480 |
prlist_with_sep pr_comma Name.print l ++ str"." |
| 1481 |
|
| 1482 |
let explain_refiner_cannot_apply env sigma t harg = |
| 1483 |
str "In refiner, a term of type" ++ brk(1,1) ++ |
| 1484 |
pr_leconstr_env env sigma t ++ spc () ++ str "could not be applied to" ++ brk(1,1) ++ |
| 1485 |
pr_leconstr_env env sigma harg ++ str "." |
| 1486 |
|
| 1487 |
let explain_intro_needs_product () = |
| 1488 |
str "Introduction tactics needs products." |
| 1489 |
|
| 1490 |
let explain_non_linear_proof env sigma c = |
| 1491 |
str "Cannot refine with term" ++ brk(1,1) ++ pr_leconstr_env env sigma c ++ |
| 1492 |
spc () ++ str "because a metavariable has several occurrences." |
| 1493 |
|
| 1494 |
let explain_no_such_hyp id = |
| 1495 |
str "No such hypothesis: " ++ Id.print id |
| 1496 |
|
| 1497 |
let explain_refiner_error env sigma = function |
| 1498 |
| UnresolvedBindings t -> explain_refiner_unresolved_bindings t |
| 1499 |
| CannotApply (t,harg) -> explain_refiner_cannot_apply env sigma t harg |
| 1500 |
| IntroNeedsProduct -> explain_intro_needs_product () |
| 1501 |
| NonLinearProof c -> explain_non_linear_proof env sigma c |
| 1502 |
| NoSuchHyp id -> explain_no_such_hyp id |
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
let error_non_strictly_positive env c v = |
| 1507 |
let pc = pr_lconstr_env env (Evd.from_env env) c in |
| 1508 |
let pv = pr_lconstr_env env (Evd.from_env env) v in |
| 1509 |
str "Non strictly positive occurrence of " ++ pv ++ str " in" ++ |
| 1510 |
brk(1,1) ++ pc ++ str "." |
| 1511 |
|
| 1512 |
let error_ill_formed_inductive env c v = |
| 1513 |
let pc = pr_lconstr_env env (Evd.from_env env) c in |
| 1514 |
let pv = pr_lconstr_env env (Evd.from_env env) v in |
| 1515 |
str "Not enough arguments applied to the " ++ pv ++ |
| 1516 |
str " in" ++ brk(1,1) ++ pc ++ str "." |
| 1517 |
|
| 1518 |
let error_ill_formed_constructor env id c v nparams nargs = |
| 1519 |
let pv = pr_lconstr_env env (Evd.from_env env) v in |
| 1520 |
let atomic = Int.equal (nb_prod Evd.empty (EConstr.of_constr c)) 0 in |
| 1521 |
str "The type of constructor" ++ brk(1,1) ++ Id.print id ++ brk(1,1) ++ |
| 1522 |
str "is not valid;" ++ brk(1,1) ++ |
| 1523 |
strbrk (if atomic then "it must be " else "its conclusion must be ") ++ |
| 1524 |
pv ++ |
| 1525 |
|
| 1526 |
|
| 1527 |
(if not (Int.equal nparams 0) then |
| 1528 |
strbrk " applied to its " ++ str (String.plural nparams "parameter") |
| 1529 |
else |
| 1530 |
mt()) ++ |
| 1531 |
(if not (Int.equal nargs 0) then |
| 1532 |
str (if not (Int.equal nparams 0) then " and" else " applied") ++ |
| 1533 |
strbrk " to some " ++ str (String.plural nargs "argument") |
| 1534 |
else |
| 1535 |
mt()) ++ str "." |
| 1536 |
|
| 1537 |
let pr_ltype_using_barendregt_convention_env env c = |
| 1538 |
|
| 1539 |
quote (pr_ltype_env ~goal_concl_style:true env (Evd.from_env env) c) |
| 1540 |
|
| 1541 |
let error_bad_ind_parameters env c n v1 v2 = |
| 1542 |
let pc = pr_ltype_using_barendregt_convention_env env c in |
| 1543 |
let pv1 = pr_lconstr_env env (Evd.from_env env) v1 in |
| 1544 |
let pv2 = pr_lconstr_env env (Evd.from_env env) v2 in |
| 1545 |
str "Last occurrence of " ++ pv2 ++ str " must have " ++ pv1 ++ |
| 1546 |
str " as " ++ pr_nth n ++ str " argument in" ++ brk(1,1) ++ pc ++ str "." |
| 1547 |
|
| 1548 |
let error_same_names_types id = |
| 1549 |
str "The name" ++ spc () ++ Id.print id ++ spc () ++ |
| 1550 |
str "is used more than once." |
| 1551 |
|
| 1552 |
let error_same_names_constructors id = |
| 1553 |
str "The constructor name" ++ spc () ++ Id.print id ++ spc () ++ |
| 1554 |
str "is used more than once." |
| 1555 |
|
| 1556 |
let error_same_names_overlap idl = |
| 1557 |
strbrk "The following names are used both as type names and constructor " ++ |
| 1558 |
str "names:" ++ spc () ++ |
| 1559 |
prlist_with_sep pr_comma Id.print idl ++ str "." |
| 1560 |
|
| 1561 |
let error_not_an_arity env c = |
| 1562 |
str "The type" ++ spc () ++ pr_lconstr_env env (Evd.from_env env) c ++ spc () ++ |
| 1563 |
str "is not an arity." |
| 1564 |
|
| 1565 |
let error_bad_entry () = |
| 1566 |
str "Bad inductive definition." |
| 1567 |
|
| 1568 |
let error_large_non_prop_inductive_not_in_type () = |
| 1569 |
str "Large non-propositional inductive types must be in Type." |
| 1570 |
|
| 1571 |
let error_inductive_missing_constraints env (us,ind_univ) = |
| 1572 |
let sigma = Evd.from_env env in |
| 1573 |
let pr_sort u = Flags.with_option PrintingFlags.print_universes (Printer.pr_sort sigma) u in |
| 1574 |
str "Missing universe constraint declared for inductive type:" ++ spc() |
| 1575 |
++ v 0 (prlist_with_sep spc (fun u -> |
| 1576 |
hov 0 (pr_sort u ++ str " <= " ++ pr_sort ind_univ)) |
| 1577 |
us) |
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
let explain_inductive_error env = function |
| 1582 |
| NonPos (c,v) -> error_non_strictly_positive env c v |
| 1583 |
| NotEnoughArgs (c,v) -> error_ill_formed_inductive env c v |
| 1584 |
| NotConstructor (id,c,v,n,m) -> |
| 1585 |
error_ill_formed_constructor env id c v n m |
| 1586 |
| NonPar (c,n,v1,v2) -> error_bad_ind_parameters env c n v1 v2 |
| 1587 |
| SameNamesTypes id -> error_same_names_types id |
| 1588 |
| SameNamesConstructors id -> error_same_names_constructors id |
| 1589 |
| SameNamesOverlap idl -> error_same_names_overlap idl |
| 1590 |
| NotAnArity c -> error_not_an_arity env c |
| 1591 |
| BadEntry -> error_bad_entry () |
| 1592 |
| LargeNonPropInductiveNotInType -> |
| 1593 |
error_large_non_prop_inductive_not_in_type () |
| 1594 |
| MissingUnivConstraints csts -> error_inductive_missing_constraints env csts |
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
let explain_incompatible_prim_declarations (type a) (act:a Primred.action_kind) (x:a) (y:a) = |
| 1599 |
let open Primred in |
| 1600 |
let env = Global.env() in |
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
match act with |
| 1610 |
| IncompatTypes typ -> |
| 1611 |
let px = try pr_constant env x with Not_found -> Constant.print x in |
| 1612 |
str "Cannot declare " ++ px ++ str " as primitive " ++ str (CPrimitives.prim_type_to_string typ) ++ |
| 1613 |
str ": " ++ pr_constant env y ++ str " is already declared." |
| 1614 |
| IncompatInd ind -> |
| 1615 |
let px = try pr_inductive env x with Not_found -> MutInd.print (fst x) in |
| 1616 |
str "Cannot declare " ++ px ++ str " as primitive " ++ str (CPrimitives.prim_ind_to_string ind) ++ |
| 1617 |
str ": " ++ pr_inductive env y ++ str " is already declared." |
| 1618 |
|
| 1619 |
|
| 1620 |
let error_not_mutual_in_scheme env ind ind' = |
| 1621 |
str "The inductive types " ++ pr_inductive env ind ++ spc () ++ |
| 1622 |
str "and" ++ spc () ++ pr_inductive env ind' ++ spc () ++ |
| 1623 |
str "are not mutually defined." |
| 1624 |
|
| 1625 |
let error_twice_in_scheme env ind = |
| 1626 |
str "The inductive type " ++ pr_inductive env ind ++ str " occurs twice." |
| 1627 |
|
| 1628 |
let explain_recursion_scheme_error env = function |
| 1629 |
| NotMutualInScheme (ind,ind')-> error_not_mutual_in_scheme env ind ind' |
| 1630 |
| DuplicateInductiveBlock ind -> error_twice_in_scheme env ind |
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
let explain_bad_pattern env sigma cstr ty = |
| 1635 |
let env = make_all_name_different env sigma in |
| 1636 |
let pt = pr_leconstr_env env sigma ty in |
| 1637 |
let pc = pr_constructor env cstr in |
| 1638 |
str "Found the constructor " ++ pc ++ brk(1,1) ++ |
| 1639 |
str "while matching a term of type " ++ pt ++ brk(1,1) ++ |
| 1640 |
str "which is not an inductive type." |
| 1641 |
|
| 1642 |
let explain_bad_constructor env cstr ind = |
| 1643 |
let pi = pr_inductive env ind in |
| 1644 |
|
| 1645 |
let pt = pr_inductive env (inductive_of_constructor cstr) in |
| 1646 |
str "Found a constructor of inductive type " ++ pt ++ brk(1,1) ++ |
| 1647 |
str "while a constructor of " ++ pi ++ brk(1,1) ++ |
| 1648 |
str "is expected." |
| 1649 |
|
| 1650 |
let decline_string n s = |
| 1651 |
if Int.equal n 0 then str "no " ++ str s ++ str "s" |
| 1652 |
else if Int.equal n 1 then str "1 " ++ str s |
| 1653 |
else (int n ++ str " " ++ str s ++ str "s") |
| 1654 |
|
| 1655 |
let explain_wrong_numarg_pattern expanded nargs expected_nassums expected_ndecls pp = |
| 1656 |
(if expanded then |
| 1657 |
strbrk "Once notations are expanded, the resulting " |
| 1658 |
else |
| 1659 |
strbrk "The ") ++ pp ++ |
| 1660 |
strbrk " is expected to be applied to " ++ decline_string expected_nassums "argument" ++ |
| 1661 |
(if expected_nassums = expected_ndecls then mt () else |
| 1662 |
strbrk " (or " ++ decline_string expected_ndecls "argument" ++ |
| 1663 |
strbrk " when including variables for local definitions)") ++ |
| 1664 |
strbrk " while it is actually applied to " ++ |
| 1665 |
decline_string nargs "argument" ++ str "." |
| 1666 |
|
| 1667 |
let explain_wrong_numarg_constructor env cstr expanded nargs expected_nassums expected_ndecls = |
| 1668 |
let pp = |
| 1669 |
strbrk "constructor " ++ pr_constructor env cstr ++ |
| 1670 |
strbrk " (in type " ++ pr_inductive env (inductive_of_constructor cstr) ++ |
| 1671 |
strbrk ")" in |
| 1672 |
explain_wrong_numarg_pattern expanded nargs expected_nassums expected_ndecls pp |
| 1673 |
|
| 1674 |
let explain_wrong_numarg_inductive env ind expanded nargs expected_nassums expected_ndecls = |
| 1675 |
let pp = strbrk "inductive type " ++ pr_inductive env ind in |
| 1676 |
explain_wrong_numarg_pattern expanded nargs expected_nassums expected_ndecls pp |
| 1677 |
|
| 1678 |
let explain_unused_clause env pats = |
| 1679 |
str "Pattern \"" ++ hov 0 (prlist_with_sep pr_comma pr_cases_pattern pats) ++ strbrk "\" is redundant in this clause." |
| 1680 |
|
| 1681 |
let explain_non_exhaustive env pats = |
| 1682 |
str "Non exhaustive pattern-matching: no clause found for " ++ |
| 1683 |
str (String.plural (List.length pats) "pattern") ++ |
| 1684 |
spc () ++ hov 0 (prlist_with_sep pr_comma pr_cases_pattern pats) |
| 1685 |
|
| 1686 |
let explain_cannot_infer_predicate env sigma typs = |
| 1687 |
let typs = Array.to_list typs in |
| 1688 |
let env = make_all_name_different env sigma in |
| 1689 |
let pr_branch (cstr,typ) = |
| 1690 |
let cstr,_ = EConstr.decompose_app sigma cstr in |
| 1691 |
str "For " ++ pr_leconstr_env env sigma cstr ++ str ": " ++ pr_leconstr_env env sigma typ |
| 1692 |
in |
| 1693 |
str "Unable to unify the types found in the branches:" ++ |
| 1694 |
spc () ++ hov 0 (prlist_with_sep fnl pr_branch typs) |
| 1695 |
|
| 1696 |
let explain_pattern_matching_error env sigma = function |
| 1697 |
| BadPattern (c,t) -> |
| 1698 |
explain_bad_pattern env sigma c t |
| 1699 |
| BadConstructor (c,ind) -> |
| 1700 |
explain_bad_constructor env c ind |
| 1701 |
| WrongNumargConstructor {cstr; expanded; nargs; expected_nassums; expected_ndecls} -> |
| 1702 |
explain_wrong_numarg_constructor env cstr expanded nargs expected_nassums expected_ndecls |
| 1703 |
| WrongNumargInductive {ind; expanded; nargs; expected_nassums; expected_ndecls} -> |
| 1704 |
explain_wrong_numarg_inductive env ind expanded nargs expected_nassums expected_ndecls |
| 1705 |
| UnusedClause tms -> |
| 1706 |
explain_unused_clause env tms |
| 1707 |
| NonExhaustive tms -> |
| 1708 |
explain_non_exhaustive env tms |
| 1709 |
| CannotInferPredicate typs -> |
| 1710 |
explain_cannot_infer_predicate env sigma typs |
| 1711 |
|
| 1712 |
let explain_reduction_tactic_error = function |
| 1713 |
| Tacred.InvalidAbstraction (env,sigma,c,(env',e)) -> |
| 1714 |
let e = of_type_error e in |
| 1715 |
str "The abstracted term" ++ spc () ++ |
| 1716 |
quote (pr_letype_env ~goal_concl_style:true env sigma c) ++ |
| 1717 |
spc () ++ str "is not well typed." ++ fnl () ++ |
| 1718 |
explain_type_error env' (Evd.from_env env') e |
| 1719 |
|
| 1720 |
let explain_prim_token_notation_error kind env sigma = function |
| 1721 |
| PrimNotations.UnexpectedTerm c -> |
| 1722 |
(strbrk "Unexpected term " ++ |
| 1723 |
pr_constr_env env sigma c ++ |
| 1724 |
strbrk (" while parsing a "^kind^" notation.")) |
| 1725 |
| PrimNotations.UnexpectedNonOptionTerm c -> |
| 1726 |
(strbrk "Unexpected non-option term " ++ |
| 1727 |
pr_constr_env env sigma c ++ |
| 1728 |
strbrk (" while parsing a "^kind^" notation.")) |
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
let error_not_allowed_rewrite_rules symb_or_rule = |
| 1733 |
str (match symb_or_rule with Rule -> "Rewrite rule" | Symb -> "Symbol") ++ spc () ++ |
| 1734 |
strbrk "declaration requires passing the flag " ++ |
| 1735 |
strbrk "\"-allow-rewrite-rules\"." |
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
exception Unhandled |
| 1743 |
|
| 1744 |
let wrap_unhandled f e = |
| 1745 |
try Some (f e) |
| 1746 |
with Unhandled -> None |
| 1747 |
|
| 1748 |
let explain_exn_default = function |
| 1749 |
|
| 1750 |
| Gramlib.Grammar.ParseError txt -> hov 0 (str "Syntax error: " ++ str txt ++ str ".") |
| 1751 |
| CLexer.Error.E err -> hov 0 (str (CLexer.Error.to_string err)) |
| 1752 |
| Sys_error msg -> hov 0 (str "System error: " ++ quote (str msg)) |
| 1753 |
| Out_of_memory -> hov 0 (str "Out of memory.") |
| 1754 |
| Stack_overflow -> hov 0 (str "Stack overflow.") |
| 1755 |
| Sys.Break -> hov 0 (str "User interrupt.") |
| 1756 |
|
| 1757 |
| _ -> raise Unhandled |
| 1758 |
|
| 1759 |
let _ = CErrors.register_handler (wrap_unhandled explain_exn_default) |
| 1760 |
|
| 1761 |
let rec vernac_interp_error_handler = function |
| 1762 |
| UGraph.UniverseInconsistency i -> |
| 1763 |
str "Universe inconsistency." ++ spc() ++ |
| 1764 |
UGraph.explain_universe_inconsistency |
| 1765 |
UnivNames.pr_quality_with_global_universes |
| 1766 |
UnivNames.pr_level_with_global_universes |
| 1767 |
i ++ str "." |
| 1768 |
| QGraph.EliminationError i -> |
| 1769 |
QGraph.explain_elimination_error |
| 1770 |
UnivNames.pr_quality_with_global_universes i |
| 1771 |
| TypeError(env,te) -> |
| 1772 |
let te = of_type_error te in |
| 1773 |
explain_type_error env (Evd.from_env env) te |
| 1774 |
| PretypeError(ctx,sigma,te) -> |
| 1775 |
explain_pretype_error ctx sigma te |
| 1776 |
| Clenv.ClenvCannotUnify (env, sigma, clenv, t1, t2, reason) -> |
| 1777 |
let sigma, f = Clenv.replace_clenv_metas env sigma clenv in |
| 1778 |
explain_pretype_error env sigma (CannotUnify (f t1, f t2, reason)) |
| 1779 |
| PrimNotations.PrimTokenNotationError(kind,ctx,sigma,te) -> |
| 1780 |
explain_prim_token_notation_error kind ctx sigma te |
| 1781 |
| Typeclasses_errors.TypeClassError(env, sigma, te) -> |
| 1782 |
explain_typeclass_error env sigma te |
| 1783 |
| InductiveError (env,e) -> |
| 1784 |
explain_inductive_error env e |
| 1785 |
| Primred.IncompatibleDeclarations (act,x,y) -> |
| 1786 |
explain_incompatible_prim_declarations act x y |
| 1787 |
| Modops.ModuleTypingError e -> |
| 1788 |
explain_module_error e |
| 1789 |
| Modintern.ModuleInternalizationError e -> |
| 1790 |
explain_module_internalization_error e |
| 1791 |
| RecursionSchemeError (env,e) -> |
| 1792 |
explain_recursion_scheme_error env e |
| 1793 |
| Cases.PatternMatchingError (env,sigma,e) -> |
| 1794 |
explain_pattern_matching_error env sigma e |
| 1795 |
| Tacred.ReductionTacticError e -> |
| 1796 |
explain_reduction_tactic_error e |
| 1797 |
| Logic.RefinerError (env, sigma, e) -> |
| 1798 |
explain_refiner_error env sigma e |
| 1799 |
| Nametab.GlobalizationError q -> |
| 1800 |
|
| 1801 |
let ppq = Libnames.string_of_qualid q in |
| 1802 |
let others = |
| 1803 |
|
| 1804 |
if String.length ppq <= 2 then [] |
| 1805 |
else |
| 1806 |
|
| 1807 |
Nametab.XRefs.locate_upto ~limit:(max 1 (String.length ppq / 3)) q |
| 1808 |
in |
| 1809 |
let ppothers = if CList.is_empty others then mt() |
| 1810 |
else spc() ++ str "Did you mean" ++ spc() ++ pr_choice (fun (q',_) -> Libnames.pr_qualid q') others ++ str "?" |
| 1811 |
in |
| 1812 |
str "The reference" ++ spc () ++ str ppq ++ |
| 1813 |
spc () ++ str "was not found" ++ |
| 1814 |
spc () ++ str "in the current" ++ spc () ++ str "environment." ++ |
| 1815 |
ppothers |
| 1816 |
| Tacticals.FailError (i,s) -> |
| 1817 |
let s = Lazy.force s in |
| 1818 |
str "Tactic failure" ++ |
| 1819 |
(if Pp.ismt s then s else str ": " ++ s) ++ |
| 1820 |
if Int.equal i 0 then str "." else str " (level " ++ int i ++ str")." |
| 1821 |
| Logic_monad.TacticFailure e -> |
| 1822 |
vernac_interp_error_handler e |
| 1823 |
| Environ.RewriteRulesNotAllowed symb_or_rule -> |
| 1824 |
error_not_allowed_rewrite_rules symb_or_rule |
| 1825 |
| _ -> |
| 1826 |
raise Unhandled |
| 1827 |
|
| 1828 |
let _ = CErrors.register_handler (wrap_unhandled vernac_interp_error_handler) |
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
let explain_notation_not_reference = function |
| 1833 |
| Notation.AmbiguousNotationAsReference _ -> |
| 1834 |
str "Ambiguous notation." |
| 1835 |
| Notation.NotationNotReference (env,sigma,ntn,ntns) -> |
| 1836 |
match ntns with |
| 1837 |
| [] -> str "Unable to interpret " ++ quote (str ntn) ++ str " as a reference." |
| 1838 |
| ntns -> |
| 1839 |
let f (df, r) = |
| 1840 |
str "Notation" ++ brk (1,2) ++ |
| 1841 |
Notation_ops.pr_notation_info (Printer.pr_notation_interpretation_env env sigma) df r in |
| 1842 |
str "Unable to unambiguously interpret " ++ quote (str ntn) ++ |
| 1843 |
str " as a reference. Found:" ++ fnl () ++ |
| 1844 |
v 0 (hov 0 (prlist_with_sep spc f ntns)) |
| 1845 |
|
| 1846 |
let _ = CErrors.register_handler (function |
| 1847 |
| Notation.NotationAsReferenceError e -> Some (explain_notation_not_reference e) |
| 1848 |
| _ -> None) |