Codebase list coq / 813d651
Merge tag 'upstream/8.4pl2dfsg' into experimental/master Upstream version 8.4pl2dfsg Stephane Glondu 11 years ago
170 changed file(s) with 1298 addition(s) and 725 deletion(s). Raw diff Collapse all Expand all
0 Changes from V8.4pl1 to V8.4pl2
1 ===============================
2
3 Bug fixes
4
5 - Solved bugs :
6 #2466 #2629 #2668 #2750 #2839 #2869 #2954 #2955 #2959 #2962 #2966 #2967
7 #2969 #2970 #2975 #2976 #2977 #2978 #2981 #2983 #2995 #3000 #3004 #3008
8 - Partially fixed bugs : #2830 #2949
9 - Coqtop should now react more reliably when receiving interrupt signals:
10 all the "try...with" constructs have been protected against undue
11 handling of the Sys.Break exception.
12
13 Coqide
14
15 - The Windows-specific code handling the interrupt button of Coqide
16 had to be reworked (cf. bug #2869). Now, in Win32 this button does
17 not target a specific coqtop client, but instead sends a Ctrl-C to
18 any process sharing its console with Coqide. To avoid awkward
19 effects, it is recommended to launch Coqide via its icon, its menu,
20 or in a dedicated console window.
21
22 Extraction
23
24 - The option Extraction AccessOpaque is now set by default,
25 restoring compatibility of older versions of Coq (cf bug #2952).
26
027 Changes from V8.4 to V8.4pl1
128 ============================
229
24372464
24382465 - Correctness proof of Stalmarck tautology checker algorithm
24392466 [Stalmarck] (Laurent Théry, Pierre Letouzey, Sophia-Antipolis)
2467
2468 LocalWords: recommended
289289 let (md,table,digest) =
290290 try
291291 let ch = with_magic_number_check raw_intern_library f in
292 let (md:library_disk) = System.marshal_in ch in
293 let digest = System.marshal_in ch in
294 let table = (System.marshal_in ch : Safe_typing.LightenLibrary.table) in
292 let (md:library_disk) = System.marshal_in f ch in
293 let digest = System.marshal_in f ch in
294 let table = (System.marshal_in f ch : Safe_typing.LightenLibrary.table) in
295295 close_in ch;
296296 if dir <> md.md_name then
297297 errorlabstrm "load_physical_library"
370370 compile_files ();
371371 flush_all()
372372 with e ->
373 (Pp.ppnl(explain_exn e);
373 (flush_all();
374 Pp.ppnl(explain_exn e);
374375 flush_all();
375376 exit 1)
376377
132132 with Not_found ->
133133 failwith ("Unknown module type: "^string_of_mp mp)
134134
135 let lookup_module mp env =
136 try Environ.lookup_module mp env
137 with Not_found ->
138 failwith ("Unknown module: "^string_of_mp mp)
139
135140 let rec check_with env mtb with_decl mp=
136141 match with_decl with
137142 | With_definition_body (idl,c) ->
198203 SFBmodule msb -> msb
199204 | _ -> error_not_a_module l
200205 in
201 let (_:module_body) = (lookup_module mp1 env) in ()
206 let (_:module_body) = (Environ.lookup_module mp1 env) in ()
202207 else
203208 let old = match spec with
204209 SFBmodule msb -> msb
55 #
66 ##################################
77
8 VERSION=8.4pl1
8 VERSION=8.4pl2
99 VOMAGIC=08400
1010 STATEMAGIC=58400
1111 DATE=`LC_ALL=C LANG=C date +"%B %Y"`
199199
200200 (* Set usual printing since the global env is available from the tracer *)
201201 let _ = Constrextern.in_debugger := false
202 let _ = Constrextern.set_debug_global_reference_printer
203 (fun loc r -> Libnames.Qualid (loc,Nametab.shortest_qualid_of_global Idset.empty r));;
202 let _ = Constrextern.set_extern_reference
203 (fun loc _ r -> Libnames.Qualid (loc,Nametab.shortest_qualid_of_global Idset.empty r));;
204204
205205 open Toplevel
206206 let go = loop
458458 Qualid (loc, make_qualid
459459 (make_dirpath (List.rev (id_of_string prefix::dir@suffix))) id)
460460
461 let raw_string_of_ref loc = function
461 let raw_string_of_ref loc _ = function
462462 | ConstRef cst ->
463463 let (mp,dir,id) = repr_con cst in
464464 encode_path loc "CST" (Some (mp,dir)) [] (id_of_label id)
474474 | VarRef id ->
475475 encode_path loc "SECVAR" None [] id
476476
477 let short_string_of_ref loc = function
477 let short_string_of_ref loc _ = function
478478 | VarRef id -> Ident (loc,id)
479479 | ConstRef cst -> Ident (loc,id_of_label (pi3 (repr_con cst)))
480480 | IndRef (kn,0) -> Ident (loc,id_of_label (pi3 (repr_mind kn)))
490490 pretty-printer should not make calls to the global env since ocamldebug
491491 runs in a different process and does not have the proper env at hand *)
492492 let _ = Constrextern.in_debugger := true
493 let _ = Constrextern.set_debug_global_reference_printer
493 let _ = Constrextern.set_extern_reference
494494 (if !rawdebug then raw_string_of_ref else short_string_of_ref)
211211 try Sys.set_signal i (Sys.Signal_handle crash_save)
212212 with _ -> prerr_endline "Signal ignored (normal if Win32)")
213213 signals_to_crash;
214 (* We ignore the Ctrl-C, this is required for the Stop button to work,
215 since we will actually send Ctrl-C to all processes sharing
216 our console (including us) *)
214217 Sys.set_signal Sys.sigint Sys.Signal_ignore
215218
216219
901904 if stop#compare start > 0 && is_sentence_end stop#backward_char
902905 then Some (start,stop)
903906 else None
904 with Not_found -> None
907 with StartError -> None
905908
906909 method complete_at_offset (offset:int) =
907910 prerr_endline ("Completion at offset : " ^ string_of_int offset);
24482451 try configure ~apply:update_notebook_pos ()
24492452 with _ -> flash_info "Cannot save preferences"
24502453 end;
2451 reset_revert_timer ()) ~accel:"<Ctrl>," ~stock:`PREFERENCES;
2454 reset_revert_timer ()) ~accel:"<Ctrl>comma" ~stock:`PREFERENCES;
24522455 (* GAction.add_action "Save preferences" ~label:"_Save preferences" ~callback:(fun _ -> save_pref ()); *) ];
24532456 GAction.add_actions view_actions [
24542457 GAction.add_action "View" ~label:"_View";
3737
3838 let () = catch_gtk_messages ()
3939
40 (* We anticipate a bit the argument parsing and look for -debug *)
41
42 let early_set_debug () =
43 Ideutils.debug := List.mem "-debug" (Array.to_list Sys.argv)
44
4045 (* On win32, we add the directory of coqide to the PATH at launch-time
4146 (this used to be done in a .bat script). *)
4247
4550 (Filename.dirname Sys.executable_name ^ ";" ^
4651 (try Sys.getenv "PATH" with _ -> ""))
4752
48 (* On win32, since coqide is now console-free, we re-route stdout/stderr
49 to avoid Sys_error if someone writes to them. We write to a pipe which
50 is never read (by default) or to a temp log file (when in debug mode).
51 *)
53 (* On win32, in debug mode we duplicate stdout/stderr in a log file. *)
5254
53 let reroute_stdout_stderr () =
54 (* We anticipate a bit the argument parsing and look for -debug *)
55 let debug = List.mem "-debug" (Array.to_list Sys.argv) in
56 Ideutils.debug := debug;
57 let out_descr =
58 if debug then
59 let (name,chan) = Filename.open_temp_file "coqide_" ".log" in
60 Coqide.logfile := Some name;
61 Unix.descr_of_out_channel chan
62 else
63 snd (Unix.pipe ())
64 in
55 let log_stdout_stderr () =
56 let (name,chan) = Filename.open_temp_file "coqide_" ".log" in
57 Coqide.logfile := Some name;
58 let out_descr = Unix.descr_of_out_channel chan in
6559 Unix.set_close_on_exec out_descr;
6660 Unix.dup2 out_descr Unix.stdout;
6761 Unix.dup2 out_descr Unix.stderr
6862
6963 (* We also provide specific kill and interrupt functions. *)
7064
71 (* Since [win32_interrupt] involves some hack about the process console,
72 only one should run at the same time, we simply skip execution of
73 [win32_interrupt] if another instance is already running *)
74
75 let ctrl_c_mtx = Mutex.create ()
76
77 let ctrl_c_protect f i =
78 if not (Mutex.try_lock ctrl_c_mtx) then ()
79 else try f i; Mutex.unlock ctrl_c_mtx with _ -> Mutex.unlock ctrl_c_mtx
80
8165 IFDEF WIN32 THEN
8266 external win32_kill : int -> unit = "win32_kill"
83 external win32_interrupt : int -> unit = "win32_interrupt"
67 external win32_interrupt_all : unit -> unit = "win32_interrupt_all"
68 external win32_hide_console : unit -> unit = "win32_hide_console"
69
8470 let () =
71 set_win32_path ();
8572 Coq.killer := win32_kill;
86 Coq.interrupter := ctrl_c_protect win32_interrupt;
87 set_win32_path ();
88 reroute_stdout_stderr ()
73 Coq.interrupter := (fun pid -> win32_interrupt_all ());
74 early_set_debug ();
75 if !Ideutils.debug then
76 log_stdout_stderr ()
77 else
78 win32_hide_console ()
8979 END
9080
9181 IFDEF QUARTZ THEN
55 (* * GNU Lesser General Public License Version 2.1 *)
66 (************************************************************************)
77
8 open Ideutils
89
910 let underscore = Glib.Utf8.to_unichar "_" ~pos:(ref 0)
1011 let arobase = Glib.Utf8.to_unichar "@" ~pos:(ref 0)
1818 CAMLreturn(Val_unit);
1919 }
2020
21
2221 /* Win32 emulation of a kill -2 (SIGINT) */
2322
24 /* This code rely of the fact that coqide is now without initial console.
25 Otherwise, no console creation in win32unix/createprocess.c, hence
26 the same console for coqide and all coqtop, and everybody will be
27 signaled at the same time by the code below. */
23 /* For simplicity, we signal all processes sharing a console with coqide.
24 This shouldn't be an issue since currently at most one coqtop is busy
25 at a given time. Earlier, we tried to be more precise via
26 FreeConsole and AttachConsole before generating the Ctrl-C, but
27 that wasn't working so well (see #2869).
28 This code rely now on the fact that coqide is a console app,
29 and that coqide itself ignores Ctrl-C.
30 */
2831
29 /* Moreover, AttachConsole exists only since WinXP, and GetProcessId
30 since WinXP SP1. For avoiding the GetProcessId, we could adapt code
31 from win32unix/createprocess.c to make it return both the pid and the
32 handle. For avoiding the AttachConsole, I don't know, maybe having
33 an intermediate process between coqide and coqtop ? */
34
35 CAMLprim value win32_interrupt(value pseudopid) {
36 CAMLparam1(pseudopid);
37 HANDLE h;
38 DWORD pid;
39 FreeConsole(); /* Normally unnecessary, just to be sure... */
40 h = (HANDLE)(Long_val(pseudopid));
41 pid = GetProcessId(h);
42 AttachConsole(pid);
43 /* We want to survive the Ctrl-C that will also concerns us */
44 SetConsoleCtrlHandler(NULL,TRUE); /* NULL + TRUE means ignore */
45 GenerateConsoleCtrlEvent(CTRL_C_EVENT,0); /* signal our co-console */
46 FreeConsole();
32 CAMLprim value win32_interrupt_all(value unit) {
33 CAMLparam1(unit);
34 GenerateConsoleCtrlEvent(CTRL_C_EVENT,0);
4735 CAMLreturn(Val_unit);
4836 }
37
38 /* Get rid of the nasty console window (only if we created it) */
39
40 CAMLprim value win32_hide_console (value unit) {
41 CAMLparam1(unit);
42 DWORD pid;
43 HWND hw = GetConsoleWindow();
44 if (hw != NULL) {
45 GetWindowThreadProcessId(hw, &pid);
46 if (pid == GetCurrentProcessId())
47 ShowWindow(hw, SW_HIDE);
48 }
49 CAMLreturn(Val_unit);
50 }
136136 let extern_evar loc n l =
137137 if !print_evar_arguments then CEvar (loc,n,l) else CEvar (loc,n,None)
138138
139 let debug_global_reference_printer =
140 ref (fun _ -> failwith "Cannot print a global reference")
139 (** We allow customization of the global_reference printer.
140 For instance, in the debugger the tables of global references
141 may be inaccurate *)
142
143 let default_extern_reference loc vars r =
144 Qualid (loc,shortest_qualid_of_global vars r)
145
146 let my_extern_reference = ref default_extern_reference
147
148 let set_extern_reference f = my_extern_reference := f
149 let get_extern_reference () = !my_extern_reference
150
151 let extern_reference loc vars l = !my_extern_reference loc vars l
141152
142153 let in_debugger = ref false
143
144 let set_debug_global_reference_printer f =
145 debug_global_reference_printer := f
146
147 let extern_reference loc vars r =
148 if !in_debugger then
149 (* Debugger does not have the tables of global reference at hand *)
150 !debug_global_reference_printer loc r
151 else
152 Qualid (loc,shortest_qualid_of_global vars r)
153154
154155
155156 (************************************************************************)
302303 match decompose_notation_key ntn, l with
303304 | [Terminal "-"; Terminal x], [] ->
304305 (try mkprim (loc, Numeral (Bigint.neg (Bigint.of_string x)))
305 with _ -> mknot (loc,ntn,[]))
306 with e when Errors.noncritical e -> mknot (loc,ntn,[]))
306307 | [Terminal x], [] ->
307308 (try mkprim (loc, Numeral (Bigint.of_string x))
308 with _ -> mknot (loc,ntn,[]))
309 with e when Errors.noncritical e -> mknot (loc,ntn,[]))
309310 | _ ->
310311 mknot (loc,ntn,l)
311312
815816 match f with
816817 | GRef (_,ref) ->
817818 let subscopes =
818 try list_skipn n (find_arguments_scope ref) with _ -> [] in
819 try list_skipn n (find_arguments_scope ref)
820 with e when Errors.noncritical e -> [] in
819821 let impls =
820822 let impls =
821823 select_impargs_size
822824 (List.length args) (implicits_of_global ref) in
823 try list_skipn n impls with _ -> [] in
825 try list_skipn n impls
826 with e when Errors.noncritical e -> [] in
824827 subscopes,impls
825828 | _ ->
826829 [], [] in
4949 val print_no_symbol : bool ref
5050 val print_projections : bool ref
5151
52 (** Debug printing options *)
53 val set_debug_global_reference_printer :
54 (loc -> global_reference -> reference) -> unit
52 (** Customization of the global_reference printer *)
53 val set_extern_reference :
54 (loc -> Idset.t -> global_reference -> reference) -> unit
55 val get_extern_reference :
56 unit -> (loc -> Idset.t -> global_reference -> reference)
57
5558 val in_debugger : bool ref
5659
5760 (** This governs printing of implicit arguments. If [with_implicits] is
649649 let scopes = find_arguments_scope ref in
650650 Dumpglob.dump_reference loc "<>" (string_of_qualid (Decls.variable_secpath id)) "var";
651651 GRef (loc, ref), impls, scopes, []
652 with _ ->
652 with e when Errors.noncritical e ->
653653 (* [id] a goal variable *)
654654 GVar (loc,id), [], [], []
655655
715715 try
716716 let r,args2 = intern_non_secvar_qualid loc qid intern env lvar args in
717717 find_appl_head_data r, args2
718 with e ->
718 with e when Errors.noncritical e ->
719719 (* Extra allowance for non globalizing functions *)
720720 if !interning_grammar || env.unb then
721721 (GVar (loc,id), [], [], []),args
968968 | [] -> anomaly "Number of projections mismatch"
969969 | (_, regular)::tm ->
970970 let boolean = not regular in
971 if ConstRef name = global_reference_of_reference refer
972 then
971 (match global_reference_of_reference refer with
972 | ConstRef name' when eq_constant name name' ->
973973 if boolean && mode then
974974 user_err_loc (loc, "", str"No local fields allowed in a record construction.")
975975 else build_patt b tm (i + 1) (i, snd acc) (* we found it *)
976 else
976 | _ ->
977977 build_patt b tm (if boolean&&mode then i else i + 1)
978978 (if boolean && mode then acc
979 else fst acc, (i, ConstRef name) :: snd acc))
979 else fst acc, (i, ConstRef name) :: snd acc)))
980980 | None :: b-> (* we don't want anonymous fields *)
981981 if mode then
982982 user_err_loc (loc, "", str "This record contains anonymous fields.")
10081008 (loc, "",
10091009 str "This record contains fields of different records.")
10101010 | (i, a) :: b->
1011 if glob_refer = a
1011 if eq_gr glob_refer a
10121012 then (i,List.rev_append acc l)
10131013 else add_patt b ((i,a)::acc)
10141014 in
8787 if Idset.mem x ids then false
8888 else
8989 try ignore(Environ.lookup_named x env) ; false
90 with _ -> not (is_global x)
91 with _ -> true
90 with e when Errors.noncritical e -> not (is_global x)
91 with e when Errors.noncritical e -> true
9292
9393 (* Auxiliary functions for the inference of implicitly quantified variables. *)
9494
837837 let with_notation_protection f x =
838838 let fs = freeze () in
839839 try let a = f x in unfreeze fs; a
840 with e -> unfreeze fs; raise e
840 with reraise -> unfreeze fs; raise reraise
189189 and val_of_constr env c =
190190 let (_,fun_code,_ as ccfv) =
191191 try compile env c
192 with e -> print_string "can not compile \n";Format.print_flush();raise e in
192 with reraise ->
193 print_string "can not compile \n";Format.print_flush();raise reraise
194 in
193195 eval_to_patch env (to_memory ccfv)
194196
195197 let set_transparent_const kn =
8282 | Equiv kn -> string_of_kn kn
8383
8484 let debug_string_of_delta resolve =
85 let kn_to_string kn hint s =
86 s^", "^(string_of_kn kn)^"=>"^(string_of_hint hint)
87 in
88 let mp_to_string mp mp' s =
89 s^", "^(string_of_mp mp)^"=>"^(string_of_mp mp')
90 in
91 Deltamap.fold mp_to_string kn_to_string resolve ""
85 let kn_to_string kn hint l =
86 (string_of_kn kn ^ "=>" ^ string_of_hint hint) :: l
87 in
88 let mp_to_string mp mp' l =
89 (string_of_mp mp ^ "=>" ^ string_of_mp mp') :: l
90 in
91 let l = Deltamap.fold mp_to_string kn_to_string resolve [] in
92 String.concat ", " (List.rev l)
9293
9394 let list_contents sub =
9495 let one_pair (mp,reso) = (string_of_mp mp,debug_string_of_delta reso) in
172173
173174 let kn_of_delta resolve kn =
174175 try solve_delta_kn resolve kn
175 with _ -> kn
176 with e when Errors.noncritical e -> kn
176177
177178 let constant_of_delta_kn resolve kn =
178179 constant_of_kn_equiv kn (kn_of_delta resolve kn)
181182 try
182183 let new_kn = solve_delta_kn resolve kn in
183184 if kn == new_kn then x else fix_can new_kn
184 with _ -> x
185 with e when Errors.noncritical e -> x
185186
186187 let constant_of_delta resolve con =
187188 let kn = user_con con in
222223 let kn1,kn2 = canonical_con con,user_con con in
223224 try find_inline_of_delta kn2 resolve
224225 with Not_found ->
225 try find_inline_of_delta kn1 resolve
226 with Not_found -> None
226 if kn1 == kn2 then None
227 else
228 try find_inline_of_delta kn1 resolve
229 with Not_found -> None
227230
228231 let subst_mp0 sub mp = (* 's like subst *)
229232 let rec aux mp =
271274 | Canonical
272275
273276 let gen_subst_mp f sub mp1 mp2 =
274 match subst_mp0 sub mp1, subst_mp0 sub mp2 with
277 let o1 = subst_mp0 sub mp1 in
278 let o2 = if mp1 == mp2 then o1 else subst_mp0 sub mp2 in
279 match o1, o2 with
275280 | None, None -> raise No_subst
276281 | Some (mp',resolve), None -> User, (f mp' mp2), resolve
277282 | None, Some (mp',resolve) -> Canonical, (f mp1 mp'), resolve
3232 | NotConvertibleInductiveField of identifier
3333 | NotConvertibleConstructorField of identifier
3434 | NotConvertibleBodyField
35 | NotConvertibleTypeField
35 | NotConvertibleTypeField of env * types * types
3636 | NotSameConstructorNamesField
3737 | NotSameInductiveNameInBlockField
3838 | FiniteInductiveFieldExpected of bool
88 open Util
99 open Names
1010 open Univ
11 open Term
1112 open Environ
1213 open Declarations
1314 open Entries
5960 | NotConvertibleInductiveField of identifier
6061 | NotConvertibleConstructorField of identifier
6162 | NotConvertibleBodyField
62 | NotConvertibleTypeField
63 | NotConvertibleTypeField of env * types * types
6364 | NotSameConstructorNamesField
6465 | NotSameInductiveNameInBlockField
6566 | FiniteInductiveFieldExpected of bool
204204 let constant_of_kn kn = (kn,kn)
205205 let constant_of_kn_equiv kn1 kn2 = (kn1,kn2)
206206 let make_con mp dir l = constant_of_kn (mp,dir,l)
207 let make_con_equiv mp1 mp2 dir l = ((mp1,dir,l),(mp2,dir,l))
207 let make_con_equiv mp1 mp2 dir l =
208 if mp1 == mp2 then make_con mp1 dir l
209 else ((mp1,dir,l),(mp2,dir,l))
208210 let canonical_con con = snd con
209211 let user_con con = fst con
210212 let repr_con con = fst con
262264
263265 let mind_of_kn kn = (kn,kn)
264266 let mind_of_kn_equiv kn1 kn2 = (kn1,kn2)
265 let make_mind mp dir l = ((mp,dir,l),(mp,dir,l))
266 let make_mind_equiv mp1 mp2 dir l = ((mp1,dir,l),(mp2,dir,l))
267 let make_mind mp dir l = mind_of_kn (mp,dir,l)
268 let make_mind_equiv mp1 mp2 dir l =
269 if mp1 == mp2 then make_mind mp1 dir l
270 else ((mp1,dir,l),(mp2,dir,l))
267271 let canonical_mind mind = snd mind
268272 let user_mind mind = fst mind
269273 let repr_mind mind = fst mind
8989
9090 let lookup_rel_val n env =
9191 try List.nth env.env_rel_val (n - 1)
92 with _ -> raise Not_found
92 with e when Errors.noncritical e -> raise Not_found
9393
9494 let env_of_rel n env =
9595 { env with
476476 in
477477 let str = match sign with
478478 | SEBstruct(str_l) -> str_l
479 | _ -> error ("You cannot Include a high-order structure.")
479 | _ -> error ("You cannot Include a higher-order structure.")
480480 in
481481 let senv = update_resolver (add_delta_resolver resolver) senv
482482 in
872872 let k = key_of_lazy_constr k in
873873 let access key =
874874 try (Lazy.force table).(key)
875 with _ -> error "Error while retrieving an opaque body"
875 with e when Errors.noncritical e ->
876 error "Error while retrieving an opaque body"
876877 in
877878 match load_proof with
878879 | Flags.Force ->
218218 let check_conv cst f = check_conv_error error cst f in
219219 let check_type cst env t1 t2 =
220220
221 let err = NotConvertibleTypeField (env, t1, t2) in
222
221223 (* If the type of a constant is generated, it may mention
222224 non-variable algebraic universes that the general conversion
223225 algorithm is not ready to handle. Anyway, generated types of
256258 (the user has to use an explicit type in the interface *)
257259 error NoTypeConstraintExpected
258260 with NotArity ->
259 error NotConvertibleTypeField end
261 error err end
260262 | _ ->
261263 t1,t2
262264 else
263265 (t1,t2) in
264 check_conv NotConvertibleTypeField cst conv_leq env t1 t2
266 check_conv err cst conv_leq env t1 t2
265267 in
266268
267269 match info1 with
300302 if constant_has_body cb2 then error DefinitionFieldExpected;
301303 let arity1 = type_of_inductive env (mind1,mind1.mind_packets.(i)) in
302304 let typ2 = Typeops.type_of_constant_type env cb2.const_type in
303 check_conv NotConvertibleTypeField cst conv_leq env arity1 typ2
305 let error = NotConvertibleTypeField (env, arity1, typ2) in
306 check_conv error cst conv_leq env arity1 typ2
304307 | IndConstr (((kn,i),j) as cstr,mind1) ->
305308 ignore (Util.error (
306309 "The kernel does not recognize yet that a parameter can be " ^
311314 if constant_has_body cb2 then error DefinitionFieldExpected;
312315 let ty1 = type_of_constructor cstr (mind1,mind1.mind_packets.(i)) in
313316 let ty2 = Typeops.type_of_constant_type env cb2.const_type in
314 check_conv NotConvertibleTypeField cst conv env ty1 ty2
317 let error = NotConvertibleTypeField (env, ty1, ty2) in
318 check_conv error cst conv env ty1 ty2
315319
316320 let rec check_modules cst env msb1 msb2 subst1 subst2 =
317321 let mty1 = module_type_of_module None msb1 in
2121 let _ =
2222 if Coq_config.arch = "win32" then
2323 Unix.putenv "PATH" (coqbin ^ ";" ^ System.getenv_else "PATH" "")
24
25 let exe s = s ^ Coq_config.exec_extension
2426
2527 let reldir instdir testfile oth =
2628 let rpath = if Coq_config.local then [] else instdir in
8688 else which tl f
8789
8890 let guess_camlbin () =
89 let path = try Sys.getenv "PATH" with _ -> raise Not_found in
91 let path = Sys.getenv "PATH" in (* may raise Not_found *)
9092 let lpath = path_to_list path in
91 which lpath "ocamlc"
93 which lpath (exe "ocamlc")
9294
9395 let guess_camlp4bin () =
94 let path = try Sys.getenv "PATH" with _ -> raise Not_found in
96 let path = Sys.getenv "PATH" in (* may raise Not_found *)
9597 let lpath = path_to_list path in
96 which lpath Coq_config.camlp4
98 which lpath (exe Coq_config.camlp4)
9799
98100 let camlbin () =
99101 if !Flags.camlbin_spec then !Flags.camlbin else
100102 if !Flags.boot then Coq_config.camlbin else
101 try guess_camlbin () with _ -> Coq_config.camlbin
103 try guess_camlbin () with e when e <> Sys.Break -> Coq_config.camlbin
102104
103105 let camllib () =
104106 if !Flags.boot
112114 let camlp4bin () =
113115 if !Flags.camlp4bin_spec then !Flags.camlp4bin else
114116 if !Flags.boot then Coq_config.camlp4bin else
115 try guess_camlp4bin () with _ -> let cb = camlbin () in
116 if Sys.file_exists (Filename.concat cb Coq_config.camlp4) then cb
117 else Coq_config.camlp4bin
117 try guess_camlp4bin () with e when e <> Sys.Break ->
118 let cb = camlbin () in
119 if Sys.file_exists (Filename.concat cb (exe Coq_config.camlp4)) then cb
120 else Coq_config.camlp4bin
118121
119122 let camlp4lib () =
120123 if !Flags.boot
2727 try h e
2828 with
2929 | Unhandled -> print_gen bottom stk' e
30 | e' -> print_gen bottom stk' e'
30 | any -> print_gen bottom stk' any
3131
3232 (** Only anomalies should reach the bottom of the handler stack.
3333 In usual situation, the [handle_stack] is treated as it if was always
6565 | _ -> raise Unhandled
6666 end
6767
68 (** Critical exceptions shouldn't be catched and ignored by mistake
69 by inner functions during a [vernacinterp]. They should be handled
70 only at the very end of interp, to be displayed to the user. *)
71
72 (** NB: in the 8.4 branch, for maximal compatibility, anomalies
73 are considered non-critical *)
74
75 let noncritical = function
76 | Sys.Break | Out_of_memory | Stack_overflow -> false
77 | _ -> true
78
3838 (** Same as [print], except that anomalies are not printed but re-raised
3939 (used for the Fail command) *)
4040 val print_no_anomaly : exn -> Pp.std_ppcmds
41
42 (** Critical exceptions shouldn't be catched and ignored by mistake
43 by inner functions during a [vernacinterp]. They should be handled
44 only in [Toplevel.do_vernac] (or Ideslave), to be displayed to the user.
45 Typical example: [Sys.Break]. In the 8.4 branch, for maximal
46 compatibility, anomalies are not considered as critical...
47 *)
48 val noncritical : exn -> bool
88 let with_option o f x =
99 let old = !o in o:=true;
1010 try let r = f x in o := old; r
11 with e -> o := old; raise e
11 with reraise -> o := old; raise reraise
1212
1313 let without_option o f x =
1414 let old = !o in o:=false;
1515 try let r = f x in o := old; r
16 with e -> o := old; raise e
16 with reraise -> o := old; raise reraise
1717
1818 let boot = ref false
1919
8888 match rest2 with
8989 | Empty -> add hash key; key
9090 | Cons (k3, h3, rest3) ->
91 if hash == h2 && E.equals key k3 then k3
91 if hash == h3 && E.equals key k3 then k3
9292 else find_rec hash key rest3
9393
9494 end
278278 try
279279 Stream.iter pp_dir dirstream; com_brk ft
280280 with
281 | e -> Format.pp_print_flush ft () ; raise e
281 | reraise -> Format.pp_print_flush ft () ; raise reraise
282282
283283
284284 (* pretty print on stdout and stderr *)
259259 let _dw = dummy_spent_alloc () in
260260 let _dt = get_time () in
261261 ()
262 with _ -> assert false
262 with e when e <> Sys.Break -> assert false
263263 done;
264264 let after = get_time () in
265265 let beforeloop = get_time () in
389389 (match !stack with [] -> assert false | _::s -> stack := s);
390390 last_alloc := get_alloc ();
391391 r
392 with exn ->
393 let dw = spent_alloc () in
394 let dt = get_time () - t in
395 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
396 ajoute_ownalloc e dw;
397 ajoute_totalloc e dw;
398 p.owntime <- p.owntime - dt;
399 ajoute_totalloc p (e.totalloc -. totalloc0);
400 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
401 p.immcount <- p.immcount + 1;
402 if not (p==e) then
403 (match !stack with [] -> assert false | _::s -> stack := s);
404 last_alloc := get_alloc ();
405 raise exn
392 with reraise ->
393 let dw = spent_alloc () in
394 let dt = get_time () - t in
395 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
396 ajoute_ownalloc e dw;
397 ajoute_totalloc e dw;
398 p.owntime <- p.owntime - dt;
399 ajoute_totalloc p (e.totalloc -. totalloc0);
400 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
401 p.immcount <- p.immcount + 1;
402 if not (p==e) then
403 (match !stack with [] -> assert false | _::s -> stack := s);
404 last_alloc := get_alloc ();
405 raise reraise
406406
407407 let profile2 e f a b =
408408 let dw = spent_alloc () in
431431 (match !stack with [] -> assert false | _::s -> stack := s);
432432 last_alloc := get_alloc ();
433433 r
434 with exn ->
435 let dw = spent_alloc () in
436 let dt = get_time () - t in
437 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
438 ajoute_ownalloc e dw;
439 ajoute_totalloc e dw;
440 p.owntime <- p.owntime - dt;
441 ajoute_totalloc p (e.totalloc -. totalloc0);
442 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
443 p.immcount <- p.immcount + 1;
444 if not (p==e) then
445 (match !stack with [] -> assert false | _::s -> stack := s);
446 last_alloc := get_alloc ();
447 raise exn
434 with reraise ->
435 let dw = spent_alloc () in
436 let dt = get_time () - t in
437 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
438 ajoute_ownalloc e dw;
439 ajoute_totalloc e dw;
440 p.owntime <- p.owntime - dt;
441 ajoute_totalloc p (e.totalloc -. totalloc0);
442 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
443 p.immcount <- p.immcount + 1;
444 if not (p==e) then
445 (match !stack with [] -> assert false | _::s -> stack := s);
446 last_alloc := get_alloc ();
447 raise reraise
448448
449449 let profile3 e f a b c =
450450 let dw = spent_alloc () in
473473 (match !stack with [] -> assert false | _::s -> stack := s);
474474 last_alloc := get_alloc ();
475475 r
476 with exn ->
477 let dw = spent_alloc () in
478 let dt = get_time () - t in
479 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
480 ajoute_ownalloc e dw;
481 ajoute_totalloc e dw;
482 p.owntime <- p.owntime - dt;
483 ajoute_totalloc p (e.totalloc -. totalloc0);
484 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
485 p.immcount <- p.immcount + 1;
486 if not (p==e) then
487 (match !stack with [] -> assert false | _::s -> stack := s);
488 last_alloc := get_alloc ();
489 raise exn
476 with reraise ->
477 let dw = spent_alloc () in
478 let dt = get_time () - t in
479 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
480 ajoute_ownalloc e dw;
481 ajoute_totalloc e dw;
482 p.owntime <- p.owntime - dt;
483 ajoute_totalloc p (e.totalloc -. totalloc0);
484 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
485 p.immcount <- p.immcount + 1;
486 if not (p==e) then
487 (match !stack with [] -> assert false | _::s -> stack := s);
488 last_alloc := get_alloc ();
489 raise reraise
490490
491491 let profile4 e f a b c d =
492492 let dw = spent_alloc () in
515515 (match !stack with [] -> assert false | _::s -> stack := s);
516516 last_alloc := get_alloc ();
517517 r
518 with exn ->
519 let dw = spent_alloc () in
520 let dt = get_time () - t in
521 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
522 ajoute_ownalloc e dw;
523 ajoute_totalloc e dw;
524 p.owntime <- p.owntime - dt;
525 ajoute_totalloc p (e.totalloc -. totalloc0);
526 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
527 p.immcount <- p.immcount + 1;
528 if not (p==e) then
529 (match !stack with [] -> assert false | _::s -> stack := s);
530 last_alloc := get_alloc ();
531 raise exn
518 with reraise ->
519 let dw = spent_alloc () in
520 let dt = get_time () - t in
521 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
522 ajoute_ownalloc e dw;
523 ajoute_totalloc e dw;
524 p.owntime <- p.owntime - dt;
525 ajoute_totalloc p (e.totalloc -. totalloc0);
526 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
527 p.immcount <- p.immcount + 1;
528 if not (p==e) then
529 (match !stack with [] -> assert false | _::s -> stack := s);
530 last_alloc := get_alloc ();
531 raise reraise
532532
533533 let profile5 e f a b c d g =
534534 let dw = spent_alloc () in
557557 (match !stack with [] -> assert false | _::s -> stack := s);
558558 last_alloc := get_alloc ();
559559 r
560 with exn ->
561 let dw = spent_alloc () in
562 let dt = get_time () - t in
563 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
564 ajoute_ownalloc e dw;
565 ajoute_totalloc e dw;
566 p.owntime <- p.owntime - dt;
567 ajoute_totalloc p (e.totalloc -. totalloc0);
568 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
569 p.immcount <- p.immcount + 1;
570 if not (p==e) then
571 (match !stack with [] -> assert false | _::s -> stack := s);
572 last_alloc := get_alloc ();
573 raise exn
560 with reraise ->
561 let dw = spent_alloc () in
562 let dt = get_time () - t in
563 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
564 ajoute_ownalloc e dw;
565 ajoute_totalloc e dw;
566 p.owntime <- p.owntime - dt;
567 ajoute_totalloc p (e.totalloc -. totalloc0);
568 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
569 p.immcount <- p.immcount + 1;
570 if not (p==e) then
571 (match !stack with [] -> assert false | _::s -> stack := s);
572 last_alloc := get_alloc ();
573 raise reraise
574574
575575 let profile6 e f a b c d g h =
576576 let dw = spent_alloc () in
599599 (match !stack with [] -> assert false | _::s -> stack := s);
600600 last_alloc := get_alloc ();
601601 r
602 with exn ->
603 let dw = spent_alloc () in
604 let dt = get_time () - t in
605 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
606 ajoute_ownalloc e dw;
607 ajoute_totalloc e dw;
608 p.owntime <- p.owntime - dt;
609 ajoute_totalloc p (e.totalloc -. totalloc0);
610 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
611 p.immcount <- p.immcount + 1;
612 if not (p==e) then
613 (match !stack with [] -> assert false | _::s -> stack := s);
614 last_alloc := get_alloc ();
615 raise exn
602 with reraise ->
603 let dw = spent_alloc () in
604 let dt = get_time () - t in
605 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
606 ajoute_ownalloc e dw;
607 ajoute_totalloc e dw;
608 p.owntime <- p.owntime - dt;
609 ajoute_totalloc p (e.totalloc -. totalloc0);
610 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
611 p.immcount <- p.immcount + 1;
612 if not (p==e) then
613 (match !stack with [] -> assert false | _::s -> stack := s);
614 last_alloc := get_alloc ();
615 raise reraise
616616
617617 let profile7 e f a b c d g h i =
618618 let dw = spent_alloc () in
641641 (match !stack with [] -> assert false | _::s -> stack := s);
642642 last_alloc := get_alloc ();
643643 r
644 with exn ->
645 let dw = spent_alloc () in
646 let dt = get_time () - t in
647 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
648 ajoute_ownalloc e dw;
649 ajoute_totalloc e dw;
650 p.owntime <- p.owntime - dt;
651 ajoute_totalloc p (e.totalloc -. totalloc0);
652 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
653 p.immcount <- p.immcount + 1;
654 if not (p==e) then
655 (match !stack with [] -> assert false | _::s -> stack := s);
656 last_alloc := get_alloc ();
657 raise exn
644 with reraise ->
645 let dw = spent_alloc () in
646 let dt = get_time () - t in
647 e.tottime <- e.tottime + dt; e.owntime <- e.owntime + dt;
648 ajoute_ownalloc e dw;
649 ajoute_totalloc e dw;
650 p.owntime <- p.owntime - dt;
651 ajoute_totalloc p (e.totalloc -. totalloc0);
652 p.intcount <- p.intcount + e.intcount - intcount0 + 1;
653 p.immcount <- p.immcount + 1;
654 if not (p==e) then
655 (match !stack with [] -> assert false | _::s -> stack := s);
656 last_alloc := get_alloc ();
657 raise reraise
658658
659659 (* Some utilities to compute the logical and physical sizes and depth
660660 of ML objects *)
5252 in
5353 let get s =
5454 try Some (Obj.obj (Util.Intmap.find fid s))
55 with _ -> None
55 with Not_found -> None
5656 in
5757 let remove s =
5858 Util.Intmap.remove fid s
139139
140140 let ok_dirname f =
141141 f <> "" && f.[0] <> '.' && not (List.mem f !skipped_dirnames) &&
142 try ignore (check_ident f); true with _ -> false
142 try ignore (check_ident f); true
143 with e when e <> Sys.Break -> false
143144
144145 let all_subdirs ~unix_path:root =
145146 let l = ref [] in
222223 try access name [R_OK];true with Unix_error (_, _, _) -> false
223224
224225 let open_trapping_failure name =
225 try open_out_bin name with _ -> error ("Can't open " ^ name)
226 try open_out_bin name
227 with e when e <> Sys.Break -> error ("Can't open " ^ name)
226228
227229 let try_remove filename =
228230 try Sys.remove filename
229 with _ -> msgnl (str"Warning: " ++ str"Could not remove file " ++
230 str filename ++ str" which is corrupted!" )
231 with e when e <> Sys.Break ->
232 msgnl (str"Warning: " ++ str"Could not remove file " ++
233 str filename ++ str" which is corrupted!" )
231234
232235 let marshal_out ch v = Marshal.to_channel ch v []
233 let marshal_in ch =
236 let marshal_in filename ch =
234237 try Marshal.from_channel ch
235 with End_of_file -> error "corrupted file: reached end of file"
238 with
239 | End_of_file -> error "corrupted file: reached end of file"
240 | Failure _ (* e.g. "truncated object" *) ->
241 error (filename ^ " is corrupted, try to rebuild it.")
236242
237243 exception Bad_magic_number of string
238244
258264 try
259265 marshal_out channel val_0;
260266 close_out channel
261 with e ->
262 begin try_remove filename; raise e end
267 with reraise ->
268 begin try_remove filename; raise reraise end
263269 with Sys_error s -> error ("System error: " ^ s)
264270 and intern_state paths name =
265271 try
266272 let _,filename = find_file_in_path ~warn paths (make_suffix name suffix) in
267273 let channel = raw_intern filename in
268 let v = marshal_in channel in
274 let v = marshal_in filename channel in
269275 close_in channel;
270276 v
271277 with Sys_error s ->
4646 when the check fails, with the full file name. *)
4747
4848 val marshal_out : out_channel -> 'a -> unit
49 val marshal_in : in_channel -> 'a
49 val marshal_in : string -> in_channel -> 'a
5050
5151 exception Bad_magic_number of string
5252
174174 if xparser.check_eof && pop s <> Xml_lexer.Eof then raise (Internal_error EOFExpected);
175175 Xml_lexer.close source;
176176 x
177 with e ->
177 with e when e <> Sys.Break ->
178178 Xml_lexer.close source;
179179 raise (!xml_error (error_of_exn stk e) source)
180180
189189 close_in ch;
190190 x
191191 with
192 e ->
192 reraise ->
193193 close_in ch;
194 raise e
194 raise reraise
195195
196196
197197 let error_msg = function
989989 let protect_summaries f =
990990 let fs = Summary.freeze_summaries () in
991991 try f fs
992 with e ->
992 with reraise ->
993993 (* Something wrong: undo the whole process *)
994 Summary.unfreeze_summaries fs; raise e
994 Summary.unfreeze_summaries fs; raise reraise
995995
996996 let declare_include interp_struct me_asts =
997997 protect_summaries
8787 | Sort _ | Ind _ | Prod _ -> RigidHead RigidType
8888 | Cast (c,_,_) -> aux k l c b
8989 | Lambda (_,_,c) when l = [] -> assert (not b); aux (k+1) [] c b
90 | Lambda (_,_,c) -> aux (k+1) (List.tl l) (subst1 (List.hd l) c) b
90 | Lambda (_,_,c) -> aux k (List.tl l) (subst1 (List.hd l) c) b
9191 | LetIn _ -> assert false
9292 | Meta _ | Evar _ -> NotImmediatelyComputableHead
9393 | App (c,al) -> aux k (Array.to_list al @ l) c b
7373 let rslt = f x in
7474 implicit_args := oflags;
7575 rslt
76 with e -> begin
76 with reraise -> begin
7777 implicit_args := oflags;
78 raise e
78 raise reraise
7979 end
8080
8181 let set_maximality imps b =
367367 let try_locate_absolute_library dir =
368368 try
369369 locate_absolute_library dir
370 with e ->
370 with e when Errors.noncritical e ->
371371 explain_locate_library_error (qualid_of_dirpath dir) e
372372
373373 let try_locate_qualified_library (loc,qid) =
374374 try
375375 let (_,dir,f) = locate_qualified_library (Flags.is_verbose()) qid in
376376 dir,f
377 with e ->
377 with e when Errors.noncritical e ->
378378 explain_locate_library_error qid e
379379
380380
397397 try
398398 let ch = System.with_magic_number_check raw_intern_library f in
399399 seek_in ch pos;
400 if System.marshal_in ch <> digest then failwith "File changed!";
401 let table = (System.marshal_in ch : LightenLibrary.table) in
400 if System.marshal_in f ch <> digest then failwith "File changed!";
401 let table = (System.marshal_in f ch : LightenLibrary.table) in
402402 close_in ch;
403403 table
404 with _ ->
404 with e when Errors.noncritical e ->
405405 error
406406 ("The file "^f^" is inaccessible or has changed,\n" ^
407407 "cannot load some opaque constant bodies in it.\n")
408408
409409 let intern_from_file f =
410410 let ch = System.with_magic_number_check raw_intern_library f in
411 let lmd = System.marshal_in ch in
411 let lmd = System.marshal_in f ch in
412412 let pos = pos_in ch in
413 let digest = System.marshal_in ch in
413 let digest = System.marshal_in f ch in
414414 let table = lazy (fetch_opaque_table (f,pos,digest)) in
415415 register_library_filename lmd.md_name f;
416416 let library = mk_library lmd table digest in
654654 System.marshal_out ch di;
655655 System.marshal_out ch table;
656656 close_out ch
657 with e -> warning ("Removed file "^f'); close_out ch; Sys.remove f'; raise e
657 with reraise ->
658 warning ("Removed file "^f'); close_out ch; Sys.remove f'; raise reraise
658659
659660 (************************************************************************)
660661 (*s Display the memory use of a library. *)
392392 Cmd (S [P w32res;A "--input-format";A "rc";A "--input";P rc;
393393 A "--output-format";A "coff";A "--output"; Px o]));
394394
395 (** The windows version of Coqide is now a console-free win32 app,
396 which moreover contains the Coq icon. If necessary, the mkwinapp
397 tool can be used later to restore or suppress the console of Coqide. *)
395 (** Embed the Coq icon inside the windows version of Coqide *)
398396
399397 if w32 then dep ["link"; "ocaml"; "program"; "ide"] [w32ico];
400
401 if w32 then flag ["link"; "ocaml"; "program"; "ide"]
402 (S [A "-ccopt"; A "-link -Wl,-subsystem,windows"; P w32ico]);
398 if w32 then flag ["link"; "ocaml"; "program"; "ide"] (P w32ico);
399
400 (** Ealier we tried to make Coqide a console-free win32 app,
401 but that was troublesome (unavailable stdout/stderr, issues
402 with the stop button,...). If somebody really want to try again,
403 the extra args to add are :
404 [A "-ccopt"; A "-link -Wl,-subsystem,windows"]
405 Other solution: use the mkwinapp tool. *)
403406
404407 (** The mingw32-ocaml cross-compiler currently uses Filename.dir_sep="/".
405408 Let's tweak that... *)
145145 (* an exception rather than returning a value; *)
146146 (* declares loc because some code can refer to it; *)
147147 (* ensures loc is used to avoid "unused variable" warning *)
148 (true, <:expr< try Some $aux prods$ with [ _ -> None ] >>)
148 (true, <:expr< try Some $aux prods$ with [ e when Errors.noncritical e -> None ] >>)
149149 else
150150 (* Static optimisation *)
151151 (false, aux prods)
364364 let with_grammar_rule_protection f x =
365365 let fs = freeze () in
366366 try let a = f x in unfreeze fs; a
367 with e -> unfreeze fs; raise e
367 with reraise -> unfreeze fs; raise reraise
125125 let induction_arg_of_constr (c,lbind as clbind) =
126126 if lbind = NoBindings then
127127 try ElimOnIdent (constr_loc c,snd(coerce_to_id c))
128 with _ -> ElimOnConstr clbind
128 with e when Errors.noncritical e -> ElimOnConstr clbind
129129 else ElimOnConstr clbind
130130
131131 let mkTacCase with_evar = function
103103
104104 let get_xml_inductive_kn al =
105105 inductive_of_cdata (* uriType apparent synonym of uri *)
106 (try get_xml_attr "uri" al with _ -> get_xml_attr "uriType" al)
106 (try get_xml_attr "uri" al
107 with e when Errors.noncritical e -> get_xml_attr "uriType" al)
107108
108109 let get_xml_constant al = constant_of_cdata (get_xml_attr "uri" al)
109110
272272
273273 let print_inductive_renames =
274274 print_args_data_of_inductive_ids
275 (fun r -> try List.hd (Arguments_renaming.arguments_names r) with _ -> [])
275 (fun r ->
276 try List.hd (Arguments_renaming.arguments_names r)
277 with e when Errors.noncritical e -> [])
276278 ((<>) Anonymous)
277279 print_renames_list
278280
736738 let index_of_class cl =
737739 try
738740 fst (class_info cl)
739 with _ ->
741 with e when Errors.noncritical e ->
740742 errorlabstrm "index_of_class"
741743 (pr_class cl ++ spc() ++ str "not a defined class.")
742744
746748 let p =
747749 try
748750 lookup_path_between_class (i,j)
749 with _ ->
751 with e when Errors.noncritical e ->
750752 errorlabstrm "index_cl_of_id"
751753 (str"No path between " ++ pr_class cls ++ str" and " ++ pr_class clt
752754 ++ str ".")
2323 open Ppconstr
2424 open Constrextern
2525 open Tacexpr
26 open Declarations
2627
2728 open Store.Field
2829
116117 let pr_sort s = pr_glob_sort (extern_sort s)
117118
118119 let _ = Termops.set_print_constr pr_lconstr_env
120
121
122 (** Term printers resilient to [Nametab] errors *)
123
124 (** When the nametab isn't up-to-date, the term printers above
125 could raise [Not_found] during [Nametab.shortest_qualid_of_global].
126 In this case, we build here a fully-qualified name based upon
127 the kernel modpath and label of constants, and the idents in
128 the [mutual_inductive_body] for the inductives and constructors
129 (needs an environment for this). *)
130
131 let id_of_global env = function
132 | ConstRef kn -> id_of_label (con_label kn)
133 | IndRef (kn,0) -> id_of_label (mind_label kn)
134 | IndRef (kn,i) ->
135 (Environ.lookup_mind kn env).mind_packets.(i).mind_typename
136 | ConstructRef ((kn,i),j) ->
137 (Environ.lookup_mind kn env).mind_packets.(i).mind_consnames.(j-1)
138 | VarRef v -> v
139
140 let cons_dirpath id dp = make_dirpath (id :: repr_dirpath dp)
141
142 let rec dirpath_of_mp = function
143 | MPfile sl -> sl
144 | MPbound uid -> make_dirpath [id_of_mbid uid]
145 | MPdot (mp,l) -> cons_dirpath (id_of_label l) (dirpath_of_mp mp)
146
147 let dirpath_of_global = function
148 | ConstRef kn -> dirpath_of_mp (con_modpath kn)
149 | IndRef (kn,_) | ConstructRef ((kn,_),_) ->
150 dirpath_of_mp (mind_modpath kn)
151 | VarRef _ -> empty_dirpath
152
153 let qualid_of_global env r =
154 Libnames.make_qualid (dirpath_of_global r) (id_of_global env r)
155
156 let safe_gen f env c =
157 let orig_extern_ref = Constrextern.get_extern_reference () in
158 let extern_ref loc vars r =
159 try orig_extern_ref loc vars r
160 with e when Errors.noncritical e ->
161 Libnames.Qualid (loc, qualid_of_global env r)
162 in
163 Constrextern.set_extern_reference extern_ref;
164 try
165 let p = f env c in
166 Constrextern.set_extern_reference orig_extern_ref;
167 p
168 with e when Errors.noncritical e ->
169 Constrextern.set_extern_reference orig_extern_ref;
170 str "??"
171
172 let safe_pr_lconstr_env = safe_gen pr_lconstr_env
173 let safe_pr_constr_env = safe_gen pr_constr_env
174 let safe_pr_lconstr t = safe_pr_lconstr_env (Global.env()) t
175 let safe_pr_constr t = safe_pr_constr_env (Global.env()) t
176
119177
120178 (**********************************************************************)
121179 (* Global references *)
388446 | None ->
389447 let exl = Evarutil.non_instantiated sigma in
390448 if exl = [] then
391 (str"No more subgoals."
449 (str"No more subgoals." ++ fnl ()
392450 ++ emacs_print_dependent_evars sigma seeds)
393451 else
394452 let pei = pr_evars_int 1 exl in
414472 v 0 (
415473 int(List.length rest+1) ++ str" subgoals" ++
416474 str (emacs_str ", subgoal 1") ++ pr_goal_tag g1 ++ cut ()
417 ++ goals
475 ++ goals ++ fnl ()
418476 ++ emacs_print_dependent_evars sigma seeds
419477 )
420478 | g1::rest,a::l ->
588646 str (string_of_mp mp ^ "." ^ string_of_label lab)
589647 in
590648 let safe_pr_ltype typ =
591 try str " : " ++ pr_ltype typ with _ -> mt ()
649 try str " : " ++ pr_ltype typ with e when Errors.noncritical e -> mt ()
592650 in
593651 let (vars,axioms,opaque) =
594652 ContextObjectMap.fold (fun t typ r ->
646704
647705 (** Inductive declarations *)
648706
649 open Declarations
650707 open Termops
651708 open Reduction
652709 open Inductive
2929
3030 val pr_constr_env : env -> constr -> std_ppcmds
3131 val pr_constr : constr -> std_ppcmds
32
33 (** Same, but resilient to [Nametab] errors. Prints fully-qualified
34 names when [shortest_qualid_of_global] has failed. Prints "??"
35 in case of remaining issues (such as reference not in env). *)
36
37 val safe_pr_lconstr_env : env -> constr -> std_ppcmds
38 val safe_pr_lconstr : constr -> std_ppcmds
39
40 val safe_pr_constr_env : env -> constr -> std_ppcmds
41 val safe_pr_constr : constr -> std_ppcmds
42
3243
3344 val pr_open_constr_env : env -> open_constr -> std_ppcmds
3445 val pr_open_constr : open_constr -> std_ppcmds
6767 with
6868 Not_found -> print_modpath locals kn
6969
70 (** Each time we have to print a non-globally visible structure,
71 we place its elements in a fake fresh namespace. *)
72
73 let mk_fake_top =
74 let r = ref 0 in
75 fun () -> incr r; id_of_string ("FAKETOP"^(string_of_int !r))
76
7077 let nametab_register_dir mp =
71 let id = id_of_string "FAKETOP" in
72 let fp = Libnames.make_path empty_dirpath id in
78 let id = mk_fake_top () in
7379 let dir = make_dirpath [id] in
74 Nametab.push_dir (Nametab.Until 1) dir (DirModule (dir,(mp,empty_dirpath)));
75 fp
80 Nametab.push_dir (Nametab.Until 1) dir (DirModule (dir,(mp,empty_dirpath)))
7681
7782 (** Nota: the [global_reference] we register in the nametab below
7883 might differ from internal ones, since we cannot recreate here
8085 the user names. This works nonetheless since we search now
8186 [Nametab.the_globrevtab] modulo user name. *)
8287
83 let nametab_register_body mp fp (l,body) =
88 let nametab_register_body mp dir (l,body) =
8489 let push id ref =
85 Nametab.push (Nametab.Until 1) (make_path (dirpath fp) id) ref
90 Nametab.push (Nametab.Until (1+List.length (repr_dirpath dir)))
91 (make_path dir id) ref
8692 in
8793 match body with
8894 | SFBmodule _ -> () (* TODO *)
97103 Array.iteri (fun j id -> push id (ConstructRef ((mind,i),j+1)))
98104 mip.mind_consnames)
99105 mib.mind_packets
106
107 let nametab_register_module_body mp struc =
108 (* If [mp] is a globally visible module, we simply import it *)
109 try Declaremods.really_import_module mp
110 with Not_found ->
111 (* Otherwise we try to emulate an import by playing with nametab *)
112 nametab_register_dir mp;
113 List.iter (nametab_register_body mp empty_dirpath) struc
114
115 let nametab_register_module_param mbid seb =
116 (* For algebraic seb, we use a Declaremods function that converts into mse *)
117 try Declaremods.process_module_seb_binding mbid seb
118 with e when Errors.noncritical e ->
119 (* Otherwise, for expanded structure, we try to play with the nametab *)
120 match seb with
121 | SEBstruct struc ->
122 let mp = MPbound mbid in
123 let dir = make_dirpath [id_of_mbid mbid] in
124 nametab_register_dir mp;
125 List.iter (nametab_register_body mp dir) struc
126 | _ -> ()
100127
101128 let print_body is_impl env mp (l,body) =
102129 let name = str (string_of_label l) in
125152 try
126153 let env = Option.get env in
127154 Printer.pr_mutual_inductive_body env (make_mind mp empty_dirpath l) mib
128 with _ ->
155 with e when Errors.noncritical e ->
129156 (if mib.mind_finite then str "Inductive " else str "CoInductive")
130157 ++ name)
131158
132159 let print_struct is_impl env mp struc =
133 begin
134 (* If [mp] is a globally visible module, we simply import it *)
135 try Declaremods.really_import_module mp
136 with _ ->
137 (* Otherwise we try to emulate an import by playing with nametab *)
138 let fp = nametab_register_dir mp in
139 List.iter (nametab_register_body mp fp) struc
140 end;
141160 prlist_with_sep spc (print_body is_impl env mp) struc
142161
143162 let rec flatten_app mexpr l = match mexpr with
155174 let seb1 = Option.default mtb1.typ_expr mtb1.typ_expr_alg in
156175 let locals' = (mbid, get_new_id locals (id_of_mbid mbid))::locals
157176 in
158 (try Declaremods.process_module_seb_binding mbid seb1 with _ -> ());
177 nametab_register_module_param mbid seb1;
159178 hov 2 (str "Funsig" ++ spc () ++ str "(" ++
160179 pr_id (id_of_mbid mbid) ++ str ":" ++
161180 print_modtype env mp1 locals seb1 ++
163182 | SEBstruct (sign) ->
164183 let env' = Option.map
165184 (Modops.add_signature mp sign Mod_subst.empty_delta_resolver) env in
185 nametab_register_module_body mp sign;
166186 hv 2 (str "Sig" ++ spc () ++ print_struct false env' mp sign ++
167187 brk (1,-2) ++ str "End")
168188 | SEBapply _ ->
189209 (Modops.add_module (Modops.module_body_of_type mp' mty)) env in
190210 let typ = Option.default mty.typ_expr mty.typ_expr_alg in
191211 let locals' = (mbid, get_new_id locals (id_of_mbid mbid))::locals in
192 (try Declaremods.process_module_seb_binding mbid typ with _ -> ());
212 nametab_register_module_param mbid typ;
193213 hov 2 (str "Functor" ++ spc() ++ str"(" ++ pr_id(id_of_mbid mbid) ++
194214 str ":" ++ print_modtype env mp' locals typ ++
195215 str ")" ++ spc () ++ print_modexpr env' mp locals' mexpr)
196216 | SEBstruct struc ->
197217 let env' = Option.map
198218 (Modops.add_signature mp struc Mod_subst.empty_delta_resolver) env in
219 nametab_register_module_body mp struc;
199220 hv 2 (str "Struct" ++ spc () ++ print_struct true env' mp struc ++
200221 brk (1,-2) ++ str "End")
201222 | SEBapply _ ->
242263 try
243264 if !short then raise ShortPrinting;
244265 print_module' (Some (Global.env ())) mp with_body me ++ fnl ()
245 with _ ->
266 with e when Errors.noncritical e ->
246267 print_module' None mp with_body me ++ fnl ()
247268
248269 let print_modtype kn =
253274 (try
254275 if !short then raise ShortPrinting;
255276 print_modtype' (Some (Global.env ())) kn mtb.typ_expr
256 with _ ->
277 with e when Errors.noncritical e ->
257278 print_modtype' None kn mtb.typ_expr))
187187 Tacexpr.TacExtend($default_loc$,$se$,l)))
188188 | None -> () ])
189189 $atomic_tactics$
190 with e ->
190 with [ e when Errors.noncritical e ->
191191 Pp.msg_warning
192192 (Stream.iapp
193193 (Pp.str ("Exception in tactic extend " ^ $se$ ^": "))
194 (Errors.print e));
194 (Errors.print e)) ];
195195 Egrammar.extend_tactic_grammar $se$ $gl$;
196196 List.iter Pptactic.declare_extra_tactic_pprule $pp$; } >>
197197 ])
5454 declare_str_items loc
5555 [ <:str_item< do {
5656 try Vernacinterp.vinterp_add $se$ $funcl$
57 with e ->
57 with [ e when Errors.noncritical e ->
5858 Pp.msg_warning
5959 (Stream.iapp
6060 (Pp.str ("Exception in vernac extend " ^ $se$ ^": "))
61 (Errors.print e));
61 (Errors.print e)) ];
6262 Egrammar.extend_vernac_command_grammar $se$ $nt$ $gl$
6363 } >> ]
6464
403403 let build_subst uf subst =
404404 Array.map (fun i ->
405405 try term uf i
406 with _ -> anomaly "incomplete matching") subst
406 with e when Errors.noncritical e ->
407 anomaly "incomplete matching") subst
407408
408409 let rec inst_pattern subst = function
409410 PVar i ->
729730 let new_state_var typ state =
730731 let id = pf_get_new_id __eps__ state.gls in
731732 let {it=gl ; sigma=sigma} = state.gls in
732 let new_hyps =
733 Environ.push_named_context_val (id,None,typ) (Goal.V82.hyps sigma gl) in
734 let gls = Goal.V82.new_goal_with sigma gl new_hyps in
733 let gls = Goal.V82.new_goal_with sigma gl [id,None,typ] in
735734 state.gls<- gls;
736735 id
737736
128128
129129 let patterns_of_constr env sigma nrels term=
130130 let f,args=
131 try destApp (whd_delta env term) with _ -> raise Not_found in
131 try destApp (whd_delta env term)
132 with e when Errors.noncritical e -> raise Not_found
133 in
132134 if eq_constr f (Lazy.force _eq) && (Array.length args)=3
133135 then
134136 let patt1,rels1 = pattern_of_constr env sigma args.(1)
7474 Mode_proof
7575
7676 let get_current_mode () =
77 try
77 try
7878 mode_of_pftreestate (Pfedit.get_pftreestate ())
79 with _ -> Mode_none
79 with e when Errors.noncritical e -> Mode_none
8080
8181 let check_not_proof_mode str =
8282 if get_current_mode () = Mode_proof then
380380 se.se_meta submetas se.se_meta_list}
381381 else
382382 dfs (pred n)
383 with _ ->
383 with e when Errors.noncritical e ->
384384 begin
385385 enstack_subsubgoals env se stack gls;
386386 dfs n
518518
519519 let instr_rew _thus rew_side cut gls0 =
520520 let last_id =
521 try get_last (pf_env gls0) with _ -> error "No previous equality." in
521 try get_last (pf_env gls0)
522 with e when Errors.noncritical e ->
523 error "No previous equality."
524 in
522525 let typ,lhs,rhs = decompose_eq last_id gls0 in
523526 let items_tac gls =
524527 match cut.cut_by with
848851 let ind =
849852 try
850853 destInd hd
851 with _ ->
854 with e when Errors.noncritical e ->
852855 error "Case analysis must be done on an inductive object." in
853856 let mind,oind = Global.lookup_inductive ind in
854857 let nparams,index =
396396 in
397397 let id =
398398 if lang () <> Haskell then default_id
399 else try id_of_string (Filename.basename f)
400 with _ -> error "Extraction: provided filename is not a valid identifier"
399 else
400 try id_of_string (Filename.basename f)
401 with e when Errors.noncritical e ->
402 error "Extraction: provided filename is not a valid identifier"
401403 in
402404 Some (f^d.file_suffix), Option.map ((^) f) d.sig_suffix, id
403405
472474 msg_with ft (d.preamble mo opened unsafe_needs);
473475 msg_with ft (d.pp_struct struc);
474476 Option.iter close_out cout;
475 with e ->
476 Option.iter close_out cout; raise e
477 with reraise ->
478 Option.iter close_out cout; raise reraise
477479 end;
478480 if not dry then Option.iter info_file fn;
479481 (* Now, let's print the signature *)
486488 msg_with ft (d.sig_preamble mo opened unsafe_needs);
487489 msg_with ft (d.pp_sig (signature_of_structure struc));
488490 close_out cout;
489 with e ->
490 close_out cout; raise e
491 with reraise ->
492 close_out cout; raise reraise
491493 end;
492494 info_file si)
493495 (if dry then None else si);
526528 | r::l ->
527529 let q = snd (qualid_of_reference r) in
528530 let mpo = try Some (Nametab.locate_module q) with Not_found -> None
529 and ro = try Some (Smartlocate.global_with_alias r) with _ -> None
531 and ro =
532 try Some (Smartlocate.global_with_alias r)
533 with e when Errors.noncritical e -> None
530534 in
531535 match mpo, ro with
532536 | None, None -> Nametab.error_global_not_found q
148148 (fun i ->
149149 assert ((0 < i) && (i <= n));
150150 MLexn ("IMPLICIT "^ msg_non_implicit r (n+1-i) (fn_name i)))
151 with _ -> MLexn s)
151 with e when Errors.noncritical e -> MLexn s)
152152 | a -> ast_map (handle_exn r n fn_name) a
153153
154154 (*S Management of type variable contexts. *)
682682 let l,l' = list_chop (projection_arity (ConstRef kn)) mla in
683683 if l' <> [] then (List.map (fun _ -> MLexn "Proj Args") l) @ l'
684684 else mla
685 with _ -> mla
685 with e when Errors.noncritical e -> mla
686686 in
687687 (* For strict languages, purely logical signatures with at least
688688 one [Kill Kother] lead to a dummy lam. So a [MLdummy] is left
8080 let rec pp_type par vl t =
8181 let rec pp_rec par = function
8282 | Tmeta _ | Tvar' _ -> assert false
83 | Tvar i -> (try pr_id (List.nth vl (pred i)) with _ -> (str "a" ++ int i))
83 | Tvar i ->
84 (try pr_id (List.nth vl (pred i))
85 with e when Errors.noncritical e -> (str "a" ++ int i))
8486 | Tglob (r,[]) -> pp_global Type r
8587 | Tglob (IndRef(kn,0),l)
8688 when not (keep_singleton ()) && kn = mk_ind "Coq.Init.Specif" "sig" ->
878878 (try
879879 ignore (int_of_string (String.sub s n (String.length s - n)));
880880 String.sub s 0 n = br
881 with _ -> false)
881 with e when Errors.noncritical e -> false)
882882 | Tmp _ | Dummy -> false
883883
884884 let expand_linear_let o id e =
13111311 let c = match r with ConstRef c -> c | _ -> assert false in
13121312 let has_body =
13131313 try constant_has_body (Global.lookup_constant c)
1314 with _ -> false
1314 with e when Errors.noncritical e -> false
13151315 in
13161316 has_body &&
13171317 (let t1 = eta_red t in
118118 let rec pp_rec par = function
119119 | Tmeta _ | Tvar' _ | Taxiom -> assert false
120120 | Tvar i -> (try pp_tvar (List.nth vl (pred i))
121 with _ -> (str "'a" ++ int i))
121 with e when Errors.noncritical e ->
122 (str "'a" ++ int i))
122123 | Tglob (r,[a1;a2]) when is_infix r ->
123124 pp_par par (pp_rec true a1 ++ str (get_infix r) ++ pp_rec true a2)
124125 | Tglob (r,[]) -> pp_global Type r
187188 let args = list_skipn (projection_arity r) args in
188189 let record = List.hd args in
189190 pp_apply (record ++ str "." ++ pp_global Term r) par (List.tl args)
190 with _ -> apply (pp_global Term r))
191 with e when Errors.noncritical e -> apply (pp_global Term r))
191192 | MLfix (i,ids,defs) ->
192193 let ids',env' = push_vars (List.rev (Array.to_list ids)) env in
193194 pp_fix par env' i (Array.of_list (List.rev ids'),defs) args
254254
255255 let string_of_global r =
256256 try string_of_qualid (Nametab.shortest_qualid_of_global Idset.empty r)
257 with _ -> string_of_id (safe_basename_of_global r)
257 with e when Errors.noncritical e -> string_of_id (safe_basename_of_global r)
258258
259259 let safe_pr_global r = str (string_of_global r)
260260
262262
263263 let safe_pr_long_global r =
264264 try Printer.pr_global r
265 with _ -> match r with
265 with e when Errors.noncritical e -> match r with
266266 | ConstRef kn ->
267267 let mp,_,l = repr_con kn in
268268 str ((string_of_mp mp)^"."^(string_of_label l))
451451
452452 (*s Extraction AccessOpaque *)
453453
454 let access_opaque = my_bool_option "AccessOpaque" false
454 let access_opaque = my_bool_option "AccessOpaque" true
455455
456456 (*s Extraction AutoInline *)
457457
8484 extend_with_auto_hints bases (extend_with_ref_list ids seq gl) gl in
8585 let result=ground_tac solver startseq gl in
8686 qflag:=backup;result
87 with e ->qflag:=backup;raise e
87 with reraise ->qflag:=backup;raise reraise
8888
8989 (* special for compatibility with Intuition
9090
128128 | _-> anomaly "can't happen" in
129129 let ntt=try
130130 Pretyping.Default.understand evmap env (raux m rawt)
131 with _ ->
131 with e when Errors.noncritical e ->
132132 error "Untypable instance, maybe higher-order non-prenex quantification" in
133133 decompose_lam_n_assum m ntt
134134
174174 raise (Failure "contradiction found"))
175175 |_->assert false)
176176 lr)
177 with _ -> ());
177 with e when Errors.noncritical e -> ());
178178 !res
179179 ;;
180180
3939
4040 let flin_zero () = {fhom=Constrhash.create 50;fcste=r0};;
4141
42 let flin_coef f x = try (Constrhash.find f.fhom x) with _-> r0;;
42 let flin_coef f x = try (Constrhash.find f.fhom x) with Not_found -> r0;;
4343
4444 let flin_add f x c =
4545 let cx = flin_coef f x in
140140 (try (let a=(rational_of_constr args.(0)) in
141141 try (let b = (rational_of_constr args.(1)) in
142142 (flin_add_cste (flin_zero()) (rmult a b)))
143 with _-> (flin_add (flin_zero())
143 with e when Errors.noncritical e ->
144 (flin_add (flin_zero())
144145 args.(1)
145146 a))
146 with _-> (flin_add (flin_zero())
147 with e when Errors.noncritical e ->
148 (flin_add (flin_zero())
147149 args.(0)
148150 (rational_of_constr args.(1))))
149151 | "Rinv"->
153155 (let b=(rational_of_constr args.(1)) in
154156 try (let a = (rational_of_constr args.(0)) in
155157 (flin_add_cste (flin_zero()) (rdiv a b)))
156 with _-> (flin_add (flin_zero())
158 with e when Errors.noncritical e ->
159 (flin_add (flin_zero())
157160 args.(0)
158161 (rinv b)))
159162 |_->assert false)
163166 |"R0" -> flin_zero ()
164167 |_-> assert false)
165168 |_-> assert false)
166 with _ -> flin_add (flin_zero())
169 with e when Errors.noncritical e ->
170 flin_add (flin_zero())
167171 c
168172 r1
169173 ;;
493497 |_->assert false)
494498 |_->assert false
495499 in tac gl)
496 with _ ->
500 with e when Errors.noncritical e ->
497501 (* les hypothèses *)
498502 let hyps = List.map (fun (h,t)-> (mkVar h,t))
499503 (list_of_sign (pf_hyps gl)) in
500504 let lineq =ref [] in
501505 List.iter (fun h -> try (lineq:=(ineq1_of_constr h)@(!lineq))
502 with _ -> ())
506 with e when Errors.noncritical e -> ())
503507 hyps;
504508 (* lineq = les inéquations découlant des hypothèses *)
505509 if !lineq=[] then Util.error "No inequalities";
3232
3333 let do_observe_tac s tac g =
3434 try let v = tac g in (* msgnl (goal ++ fnl () ++ (str s)++(str " ")++(str "finished")); *) v
35 with e ->
36 let e = Cerrors.process_vernac_interp_error e in
37 let goal = begin try (Printer.pr_goal g) with _ -> assert false end in
35 with reraise ->
36 let e = Cerrors.process_vernac_interp_error reraise in
37 let goal =
38 try (Printer.pr_goal g)
39 with e when Errors.noncritical e -> assert false
40 in
3841 msgnl (str "observation "++ s++str " raised exception " ++
3942 Errors.print e ++ str " on goal " ++ goal );
4043 raise e;;
118121 eq_constr t1 t2 && eq_constr a1 a2
119122 | _ -> false
120123 end
121 with _ -> false
124 with e when Errors.noncritical e -> false
122125 in
123126 (* observe (str "is_trivial_eq " ++ Printer.pr_lconstr t ++ (if res then str " true" else str " false")); *)
124127 res
144147 (eq_constr u1 u2 &&
145148 incompatible_constructor_terms t1 t2)
146149 | _ -> false
147 with _ -> false
150 with e when Errors.noncritical e -> false
148151 in
149152 if res then observe (str "is_incompatible_eq " ++ Printer.pr_lconstr t);
150153 res
231234 then
232235 (jmeq_refl (),(args.(1),args.(0)),(args.(3),args.(2)),args.(0))
233236 else nochange "not an equality"
234 with _ -> nochange "not an equality"
237 with e when Errors.noncritical e -> nochange "not an equality"
235238 in
236239 if not ((closed0 (fst t1)) && (closed0 (snd t1)))then nochange "not a closed lhs";
237240 let rec compute_substitution sub t1 t2 =
607610 let my_orelse tac1 tac2 g =
608611 try
609612 tac1 g
610 with e ->
613 with e when Errors.noncritical e ->
611614 (* observe (str "using snd tac since : " ++ Errors.print e); *)
612615 tac2 g
613616
12111214 let ctxt,pte_app = (decompose_prod_assum (pf_concl gl)) in
12121215 let pte,pte_args = (decompose_app pte_app) in
12131216 try
1214 let pte = try destVar pte with _ -> anomaly "Property is not a variable" in
1217 let pte =
1218 try destVar pte
1219 with e when Errors.noncritical e ->
1220 anomaly "Property is not a variable"
1221 in
12151222 let fix_info = Idmap.find pte ptes_to_fix in
12161223 let nb_args = fix_info.nb_realargs in
12171224 tclTHENSEQ
301301 "defined"
302302 ((try
303303 str "On goal : " ++ fnl () ++ pr_open_subgoals () ++ fnl ()
304 with _ -> mt ()
304 with e when Errors.noncritical e -> mt ()
305305 ) ++msg)
306 | e -> raise e
307
308
309306
310307 let build_functional_principle interactive_proof old_princ_type sorts funs i proof_tac hook =
311308 (* First we get the type of the old graph principle *)
400397 Don't forget to close the goal if an error is raised !!!!
401398 *)
402399 save false new_princ_name entry g_kind hook
403 with e ->
400 with e when Errors.noncritical e ->
404401 begin
405402 begin
406403 try
412409 then Pfedit.delete_current_proof ()
413410 else ()
414411 else ()
415 with _ -> ()
412 with e when Errors.noncritical e -> ()
416413 end;
417414 raise (Defining_principle e)
418415 end
553550 0
554551 (prove_princ_for_struct false 0 (Array.of_list funs))
555552 (fun _ _ _ -> ())
556 with e ->
553 with e when Errors.noncritical e ->
557554 begin
558555 begin
559556 try
565562 then Pfedit.delete_current_proof ()
566563 else ()
567564 else ()
568 with _ -> ()
565 with e when Errors.noncritical e -> ()
569566 end;
570567 raise (Defining_principle e)
571568 end
207207 try Functional_principles_types.build_scheme fas
208208 with Functional_principles_types.No_graph_found ->
209209 Util.error ("Cannot generate induction principle(s)")
210 | e ->
210 | e when Errors.noncritical e ->
211211 let names = List.map (fun (_,na,_) -> na) fas in
212212 warning_error names e
213213
214214 end
215215 | _ -> assert false (* we can only have non empty list *)
216216 end
217 | e ->
217 | e when Errors.noncritical e ->
218218 let names = List.map (fun (_,na,_) -> na) fas in
219219 warning_error names e
220220 end
947947 try
948948 observe (str "computing new type for eq : " ++ pr_glob_constr rt);
949949 let t' =
950 try Pretyping.Default.understand Evd.empty env t with _ -> raise Continue
950 try Pretyping.Default.understand Evd.empty env t
951 with e when Errors.noncritical e -> raise Continue
951952 in
952953 let is_in_b = is_free_in id b in
953954 let _keep_eq =
12461247 l := param::!l
12471248 )
12481249 rels_params.(0)
1249 with _ ->
1250 with e when Errors.noncritical e ->
12501251 ()
12511252 in
12521253 List.rev !l
14521453 in
14531454 observe (msg);
14541455 raise e
1455 | e ->
1456 | reraise ->
14561457 let _time3 = System.get_time () in
14571458 (* Pp.msgnl (str "error : "++ str (string_of_float (System.time_difference time2 time3))); *)
14581459 let repacked_rel_inds =
14631464 str "while trying to define"++ spc () ++
14641465 Ppvernac.pr_vernac (Vernacexpr.VernacInductive(Decl_kinds.Finite,false,repacked_rel_inds))
14651466 ++ fnl () ++
1466 Errors.print e
1467 Errors.print reraise
14671468 in
14681469 observe msg;
1469 raise e
1470 raise reraise
14701471
14711472
14721473
14731474 let build_inductive funnames funsargs returned_types rtl =
14741475 try
14751476 do_build_inductive funnames funsargs returned_types rtl
1476 with e -> raise (Building_graph e)
1477
1478
1477 with e when Errors.noncritical e -> raise (Building_graph e)
1478
1479
533533 else
534534 let eqs' =
535535 try ((List.combine cpl1 cpl2)@eqs)
536 with _ -> anomaly "are_unifiable_aux"
536 with e when Errors.noncritical e ->
537 anomaly "are_unifiable_aux"
537538 in
538539 are_unifiable_aux eqs'
539540
555556 else
556557 let eqs' =
557558 try ((List.combine cpl1 cpl2)@eqs)
558 with _ -> anomaly "eq_cases_pattern_aux"
559 with e when Errors.noncritical e ->
560 anomaly "eq_cases_pattern_aux"
559561 in
560562 eq_cases_pattern_aux eqs'
561563 | _ -> raise NotUnifiable
8181 List.fold_right
8282 (fun a acc ->
8383 try Idset.add (destVar a) acc
84 with _ -> acc
84 with e when Errors.noncritical e -> acc
8585 )
8686 args
8787 Idset.empty
165165 sigma rec_sign rec_impls def
166166 )
167167 lnameargsardef
168 with e ->
169 States.unfreeze fs; raise e in
168 with reraise ->
169 States.unfreeze fs; raise reraise in
170170 States.unfreeze fs; def
171171 in
172172 recdef,rec_impls
250250 (fun id -> destInd (Constrintern.global_reference (mk_rel_id id)))
251251 fix_names
252252 )
253 with e ->
253 with e when Errors.noncritical e ->
254254 let e' = Cerrors.process_vernac_interp_error e in
255255 msg_warning
256256 (str "Cannot build inversion information" ++
257257 if do_observe () then (fnl() ++ Errors.print e') else mt ())
258 with _ -> ()
258 with e when Errors.noncritical e -> ()
259259
260260 let warning_error names e =
261261 let e = Cerrors.process_vernac_interp_error e in
345345 Array.iter (add_Function is_general) funs_kn;
346346 ()
347347 end
348 with e ->
348 with e when Errors.noncritical e ->
349349 on_error names e
350350
351351 let register_struct is_rec (fixpoint_exprl:(Vernacexpr.fixpoint_expr * Vernacexpr.decl_notation list) list) =
412412 functional_ref eq_ref rec_arg_num rec_arg_type nb_args relation
413413 );
414414 derive_inversion [fname]
415 with e ->
415 with e when Errors.noncritical e ->
416416 (* No proof done *)
417417 ()
418418 in
5454 f x
5555 with
5656 | Not_found -> raise (Util.UserError("", msg))
57 | e -> raise e
5857
5958
6059 let filter_map filter f =
122121 (try (match Declarations.body_of_constant (Global.lookup_constant sp) with
123122 | Some c -> Declarations.force c
124123 | _ -> assert false)
125 with _ -> assert false)
124 with e when Errors.noncritical e -> assert false)
126125 |_ -> assert false
127126
128127 let coq_constant s =
214213 Dumpglob.continue ();
215214 res
216215 with
217 | e ->
216 | reraise ->
218217 Impargs.make_implicit_args old_implicit_args;
219218 Impargs.make_strict_implicit_args old_strict_implicit_args;
220219 Impargs.make_contextual_implicit_args old_contextual_implicit_args;
221220 Flags.raw_print := old_rawprint;
222221 Dumpglob.continue ();
223 raise e
222 raise reraise
224223
225224
226225
349348 let pr_info f_info =
350349 str "function_constant := " ++ Printer.pr_lconstr (mkConst f_info.function_constant)++ fnl () ++
351350 str "function_constant_type := " ++
352 (try Printer.pr_lconstr (Global.type_of_global (ConstRef f_info.function_constant)) with _ -> mt ()) ++ fnl () ++
351 (try Printer.pr_lconstr (Global.type_of_global (ConstRef f_info.function_constant))
352 with e when Errors.noncritical e -> mt ()) ++ fnl () ++
353353 str "equation_lemma := " ++ (Option.fold_right (fun v acc -> Printer.pr_lconstr (mkConst v)) f_info.equation_lemma (mt ()) ) ++ fnl () ++
354354 str "completeness_lemma :=" ++ (Option.fold_right (fun v acc -> Printer.pr_lconstr (mkConst v)) f_info.completeness_lemma (mt ()) ) ++ fnl () ++
355355 str "correctness_lemma := " ++ (Option.fold_right (fun v acc -> Printer.pr_lconstr (mkConst v)) f_info.correctness_lemma (mt ()) ) ++ fnl () ++
501501 let init_constant dir s =
502502 try
503503 Coqlib.gen_constant "Function" dir s
504 with e -> raise (ToShow e)
504 with e when Errors.noncritical e -> raise (ToShow e)
505505
506506 let jmeq () =
507507 try
508508 (Coqlib.check_required_library ["Coq";"Logic";"JMeq"];
509509 init_constant ["Logic";"JMeq"] "JMeq")
510 with e -> raise (ToShow e)
510 with e when Errors.noncritical e -> raise (ToShow e)
511511
512512 let jmeq_rec () =
513513 try
514514 Coqlib.check_required_library ["Coq";"Logic";"JMeq"];
515515 init_constant ["Logic";"JMeq"] "JMeq_rec"
516 with e -> raise (ToShow e)
516 with e when Errors.noncritical e -> raise (ToShow e)
517517
518518 let jmeq_refl () =
519519 try
520520 Coqlib.check_required_library ["Coq";"Logic";"JMeq"];
521521 init_constant ["Logic";"JMeq"] "JMeq_refl"
522 with e -> raise (ToShow e)
522 with e when Errors.noncritical e -> raise (ToShow e)
5858
5959
6060 let do_observe_tac s tac g =
61 let goal = begin try (Printer.pr_goal g) with _ -> assert false end in
61 let goal =
62 try Printer.pr_goal g
63 with e when Errors.noncritical e -> assert false
64 in
6265 try
6366 let v = tac g in msgnl (goal ++ fnl () ++ s ++(str " ")++(str "finished")); v
64 with e ->
65 let e' = Cerrors.process_vernac_interp_error e in
67 with reraise ->
68 let e' = Cerrors.process_vernac_interp_error reraise in
6669 msgnl (str "observation "++ s++str " raised exception " ++
6770 Errors.print e' ++ str " on goal " ++ goal );
68 raise e;;
71 raise reraise;;
6972
7073
7174 let observe_tac s tac g =
567570 observe_tac "reflexivity_with_destruct_cases" reflexivity_with_destruct_cases
568571 ]
569572 | _ -> reflexivity
570 with _ -> reflexivity
573 with e when Errors.noncritical e -> reflexivity
571574 in
572575 let eq_ind = Coqlib.build_coq_eq () in
573576 let discr_inject =
861864 update_Function {finfo with completeness_lemma = Some lem_cst}
862865 )
863866 funs;
864 with e ->
867 with reraise ->
865868 (* In case of problem, we reset all the lemmas *)
866869 Pfedit.delete_all_proofs ();
867870 States.unfreeze previous_state;
868 raise e
871 raise reraise
869872
870873
871874
6969 let ans = CRef (Libnames.Ident (dummy_loc,id)) in
7070 let _ = ignore (Constrintern.intern_constr Evd.empty (Global.env()) ans) in
7171 true
72 with _ -> false
72 with e when Errors.noncritical e -> false
7373
7474 (** [next_ident_fresh id] returns a fresh identifier (ie not linked in
7575 global env) with base [id]. *)
792792
793793 let params1 =
794794 try fst (glob_decompose_prod_n shift.nrecprms1 (List.hd lcstr1))
795 with _ -> [] in
795 with e when Errors.noncritical e -> [] in
796796 let params2 =
797797 try fst (glob_decompose_prod_n shift.nrecprms2 (List.hd lcstr2))
798 with _ -> [] in
798 with e when Errors.noncritical e -> [] in
799799
800800 let lcstr1 = List.combine (Array.to_list oib1.mind_consnames) lcstr1 in
801801 let lcstr2 = List.combine (Array.to_list oib2.mind_consnames) lcstr2 in
9393 let v = tac g in
9494 ignore(Stack.pop debug_queue);
9595 v
96 with e ->
96 with reraise ->
9797 if not (Stack.is_empty debug_queue)
9898 then
99 print_debug_queue true e;
100 raise e
99 print_debug_queue true reraise;
100 raise reraise
101101
102102 let observe_tac s tac g =
103103 if Tacinterp.get_debug () <> Tactic_debug.DebugOff
139139 (try (match body_of_constant (Global.lookup_constant sp) with
140140 | Some c -> Declarations.force c
141141 | _ -> assert false)
142 with _ ->
142 with e when Errors.noncritical e ->
143143 anomaly ("Cannot find definition of constant "^
144144 (string_of_id (id_of_label (con_label sp))))
145145 )
379379 (fun g1 ->
380380 let ty_teq = pf_type_of g1 (mkVar teq) in
381381 let teq_lhs,teq_rhs =
382 let _,args = try destApp ty_teq with _ -> Pp.msgnl (Printer.pr_goal g1 ++ fnl () ++ pr_id teq ++ str ":" ++ Printer.pr_lconstr ty_teq); assert false in
382 let _,args =
383 try destApp ty_teq
384 with e when Errors.noncritical e ->
385 Pp.msgnl (Printer.pr_goal g1 ++ fnl () ++ pr_id teq ++ str ":" ++ Printer.pr_lconstr ty_teq); assert false
386 in
383387 args.(1),args.(2)
384388 in
385389 cont_function (mkVar teq::eqs) (Termops.replace_term teq_lhs teq_rhs expr) g1
700704 (match find_call_occs nb_arg 0 f_constr expr with
701705 _,[] ->
702706 (try observe_tac "base_leaf" (base_leaf func eqs expr)
703 with e -> (msgerrnl (str "failure in base case");raise e ))
707 with reraise ->
708 (msgerrnl (str "failure in base case");raise reraise ))
704709 | _, _::_ ->
705710 observe_tac "rec_leaf"
706711 (rec_leaf is_mes acc_inv hrec func eqs expr)) in
707712 v
708 with e -> begin msgerrnl(str "failure in proveterminate"); raise e end
713 with reraise ->
714 begin
715 msgerrnl(str "failure in proveterminate");
716 raise reraise
717 end
709718 in
710719 proveterminate
711720
930939 let id_name = string_of_id id in
931940 try
932941 String.sub id_name 0 (String.length rec_res_name) = rec_res_name
933 with _ -> false
942 with e when Errors.noncritical e -> false
934943
935944 let clear_goals =
936945 let rec clear_goal t =
968977 | Some s -> s
969978 | None ->
970979 try (add_suffix current_proof_name "_subproof")
971 with _ -> anomaly "open_new_goal with an unamed theorem"
980 with e when Errors.noncritical e ->
981 anomaly "open_new_goal with an unamed theorem"
972982 in
973983 let sign = initialize_named_context_for_proof () in
974984 let na = next_global_ident_away name [] in
14381448 let stop = ref false in
14391449 begin
14401450 try com_eqn (List.length res_vars) equation_id functional_ref f_ref term_ref (subst_var function_name equation_lemma_type)
1441 with e ->
1451 with e when Errors.noncritical e ->
14421452 begin
14431453 if Tacinterp.get_debug () <> Tactic_debug.DebugOff
14441454 then pperrnl (str "Cannot create equation Lemma " ++ Errors.print e)
14731483 using_lemmas
14741484 (List.length res_vars)
14751485 hook
1476 with e ->
1486 with reraise ->
14771487 begin
1478 (try ignore (Backtrack.backto previous_label) with _ -> ());
1488 (try ignore (Backtrack.backto previous_label)
1489 with e when Errors.noncritical e -> ());
14791490 (* anomaly "Cannot create termination Lemma" *)
1480 raise e
1491 raise reraise
14811492 end
330330 | Inr _ -> None
331331 | Inl cert -> Some (rats_to_ints (Vect.to_list cert))
332332 (* should not use rats_to_ints *)
333 with x ->
333 with x when Errors.noncritical x ->
334334 if debug
335335 then (Printf.printf "raw certificate %s" (Printexc.to_string x);
336336 flush stdout) ;
376376
377377
378378 let linear_prover n_spec l =
379 try linear_prover n_spec l with
380 x -> (print_string (Printexc.to_string x); None)
379 try linear_prover n_spec l
380 with x when x <> Sys.Break ->
381 (print_string (Printexc.to_string x); None)
381382
382383 let linear_prover_with_cert spec l =
383384 match linear_prover spec l with
936936 let (expr,env) = parse_expr env args.(0) in
937937 let power = (parse_exp expr args.(1)) in
938938 (power , env)
939 with _ -> (* if the exponent is a variable *)
939 with e when e <> Sys.Break ->
940 (* if the exponent is a variable *)
940941 let (env,n) = Env.compute_rank_add env term in (Mc.PEX n, env)
941942 end
942943 | Ukn s ->
11111112
11121113 let parse_formula parse_atom env tg term =
11131114
1114 let parse_atom env tg t = try let (at,env) = parse_atom env t in
1115 (A(at,tg,t), env,Tag.next tg) with _ -> (X(t),env,tg) in
1115 let parse_atom env tg t =
1116 try
1117 let (at,env) = parse_atom env t in
1118 (A(at,tg,t), env,Tag.next tg)
1119 with e when e <> Sys.Break -> (X(t),env,tg)
1120 in
11161121
11171122 let rec xparse_formula env tg term =
11181123 match kind_of_term term with
11881193 let rec xsame_proof sg =
11891194 match sg with
11901195 | [] -> true
1191 | n::sg -> (try List.nth cl1 n = List.nth cl2 n with _ -> false)
1196 | n::sg ->
1197 (try List.nth cl1 n = List.nth cl2 n with e when e <> Sys.Break -> false)
11921198 && (xsame_proof sg ) in
11931199 xsame_proof sg
11941200
12521258 let btree_of_array typ a =
12531259 try
12541260 btree_of_array typ a
1255 with x ->
1261 with x when x <> Sys.Break ->
12561262 failwith (Printf.sprintf "btree of array : %s" (Printexc.to_string x))
12571263
12581264 let dump_varmap typ env =
13211327 try
13221328 let (c,env,tg) = parse_formula parse_arith env tg t in
13231329 ((i,c)::lhyps, env,tg)
1324 with _ -> (lhyps,env,tg)
1330 with e when e <> Sys.Break -> (lhyps,env,tg)
13251331 (*(if debug then Printf.printf "parse_arith : %s\n" x);*)
13261332
13271333
14651471 (pp_ml_list prover.pp_f) (List.map fst new_cl) ;
14661472 flush stdout
14671473 end ; *)
1468 let res = try prover.compact prf remap with x ->
1474 let res = try prover.compact prf remap with x when x <> Sys.Break ->
14691475 if debug then Printf.fprintf stdout "Proof compaction %s" (Printexc.to_string x) ;
14701476 (* This should not happen -- this is the recovery plan... *)
14711477 match prover.prover (List.map fst new_cl) with
20302036 try
20312037 micromega_gen parse_zarith Mc.negate Mc.normalise Mc.zunsat Mc.zdeduce zz_domain_spec
20322038 [ linear_Z ] gl
2033 with z -> (*Printexc.print_backtrace stdout ;*) raise z
2039 with reraise -> (*Printexc.print_backtrace stdout ;*) raise reraise
20342040
20352041 let xnlia gl =
20362042 try
20372043 micromega_gen parse_zarith Mc.negate Mc.normalise Mc.zunsat Mc.zdeduce zz_domain_spec
20382044 [ nlinear_Z ] gl
2039 with z -> (*Printexc.print_backtrace stdout ;*) raise z
2045 with reraise -> (*Printexc.print_backtrace stdout ;*) raise reraise
20402046
20412047
20422048
149149 S (Some proof)
150150 with
151151 | Sos_lib.TooDeep -> S None
152 | x -> F (Printexc.to_string x)
152 | x when x <> Sys.Break -> F (Printexc.to_string x)
153153
154154 (* This is somewhat buggy, over Z, strict inequality vanish... *)
155155 let pure_sos l =
173173 S (Some proof)
174174 with
175175 (* | Sos.CsdpNotFound -> F "Sos.CsdpNotFound" *)
176 | x -> (* May be that could be refined *) S None
176 | x when x <> Sys.Break -> (* May be that could be refined *) S None
177177
178178
179179
202202 Marshal.to_channel chan (cert:csdp_certificate) [] ;
203203 flush chan ;
204204 exit 0
205 with x -> (Printf.fprintf chan "error %s" (Printexc.to_string x) ; exit 1)
205 with any -> (Printf.fprintf chan "error %s" (Printexc.to_string any) ; exit 1)
206206
207207 ;;
208208
727727 try
728728 Some (bound_of_variable IMap.empty fresh s.sys)
729729 with
730 x -> Printf.printf "optimise Exception : %s" (Printexc.to_string x) ; None
730 x when x <> Sys.Break ->
731 Printf.printf "optimise Exception : %s" (Printexc.to_string x) ; None
731732
732733
733734 let find_point cstrs =
2828 try
2929 let res = f () in
3030 rst () ; res
31 with x ->
31 with reraise ->
3232 (try rst ()
33 with _ -> raise x
34 ); raise x
33 with any -> raise reraise
34 ); raise reraise
3535
3636 let map_option f x =
3737 match x with
430430 | Unix.WEXITED 0 ->
431431 let inch = Unix.in_channel_of_descr stdout_read in
432432 begin try Marshal.from_channel inch
433 with x -> failwith (Printf.sprintf "command \"%s\" exited %s" exe_path (Printexc.to_string x))
433 with x when x <> Sys.Break ->
434 failwith (Printf.sprintf "command \"%s\" exited %s" exe_path (Printexc.to_string x))
434435 end
435436 | Unix.WEXITED i -> failwith (Printf.sprintf "command \"%s\" exited %i" exe_path i)
436437 | Unix.WSIGNALED i -> failwith (Printf.sprintf "command \"%s\" killed %i" exe_path i)
437438 | Unix.WSTOPPED i -> failwith (Printf.sprintf "command \"%s\" stopped %i" exe_path i))
438439 (* Cleanup *)
439440 (fun () ->
440 List.iter (fun x -> try Unix.close x with _ -> ()) [stdin_read; stdin_write; stdout_read; stdout_write; stderr_read; stderr_write])
441 List.iter (fun x -> try Unix.close x with e when e <> Sys.Break -> ())
442 [stdin_read; stdin_write; stdout_read; stdout_write; stderr_read; stderr_write])
441443
442444 (* Local Variables: *)
443445 (* coding: utf-8 *)
8181 try
8282 let res = f () in
8383 rst () ; res
84 with x ->
84 with reraise ->
8585 (try rst ()
86 with _ -> raise x
87 ); raise x
86 with any -> raise reraise
87 ); raise reraise
8888
8989
9090 let read_key_elem inch =
9292 Some (Marshal.from_channel inch)
9393 with
9494 | End_of_file -> None
95 | _ -> raise InvalidTableFormat
95 | e when e <> Sys.Break -> raise InvalidTableFormat
9696
9797 (** In win32, it seems that we should unlock the exact zone
9898 that has been locked, and not the whole file *)
150150 Table.iter
151151 (fun k e -> Marshal.to_channel outch (k,e) [Marshal.No_sharing]) htbl;
152152 flush outch ;
153 with _ -> () )
153 with e when e <> Sys.Break -> () )
154154 ;
155155 unlock out ;
156156 { outch = outch ;
236236
237237 let getvar lv i =
238238 try (nth lv i)
239 with _ -> (fold_left (fun r x -> r^" "^x) "lv= " lv)
239 with e when Errors.noncritical e ->
240 (fold_left (fun r x -> r^" "^x) "lv= " lv)
240241 ^" i="^(string_of_int i)
241242
242243 let string_of_pol zeroP hdP tlP coefterm monterm string_of_coef
589590 (* coef of q in p = sum_i c_i*q_i *)
590591 let coefpoldep_find p q =
591592 try (Hashtbl.find coefpoldep (p.num,q.num))
592 with _ -> []
593 with Not_found -> []
593594
594595 let coefpoldep_remove p q =
595596 Hashtbl.remove coefpoldep (p.num,q.num)
172172 then failwith "raté")
173173 p1;
174174 true)
175 with _ -> false)
175 with e when Errors.noncritical e -> false)
176176 | (_,_) -> false
177177
178178 (* normalize polynomial: remove head zeros, coefficients are normalized
523523 q x in
524524 (* degueulasse, mais c 'est pour enlever un warning *)
525525 if s==s then true else true)
526 with _ -> false
526 with e when Errors.noncritical e -> false
527527
528528 (***********************************************************************
529529 5. Pseudo-division and gcd with subresultants.
3232
3333 let memos s memoire nf f x =
3434 try (let v = Hashtbl.find memoire (nf x) in pr s;v)
35 with _ -> (pr "#";
36 let v = f x in
37 Hashtbl.add memoire (nf x) v;
38 v)
35 with e when Errors.noncritical e ->
36 (pr "#";
37 let v = f x in
38 Hashtbl.add memoire (nf x) v;
39 v)
3940
4041
4142 (**********************************************************************
6364 if not (constant r)
6465 then l1:=r::(!l1)
6566 else p_dans_lmin:=true)
66 with _ -> ())
67 with e when Errors.noncritical e -> ())
6768 lmin;
6869 if !p_dans_lmin
6970 then factor lmin lp1
7475 List.iter (fun q -> try (let r = div q p in
7576 if not (constant r)
7677 then l1:=r::(!l1))
77 with _ -> lmin1:=q::(!lmin1))
78 with e when Errors.noncritical e ->
79 lmin1:=q::(!lmin1))
7880 lmin;
7981 factor (List.rev (p::(!lmin1))) !l1)
8082 (* au moins un q de lmin divise p non trivialement *)
104106 li:=j::(!li);
105107 r:=rr;
106108 done)
107 with _ -> ())
109 with e when Errors.noncritical e -> ())
108110 l1;
109111 res.(i)<-(!r,!li))
110112 f;
884884 try
885885 let v,th,_ = find_constr t' in
886886 [clever_rewrite_base p (mkVar v) (mkVar th)], Oatom v
887 with _ ->
887 with e when Errors.noncritical e ->
888888 let v = new_identifier_var ()
889889 and th = new_identifier () in
890890 hide_constr t' v th isnat;
923923 | _ -> default false t
924924 end
925925 | Kapp((Zpos|Zneg|Z0),_) ->
926 (try ([],Oz(recognize_number t)) with _ -> default false t)
926 (try ([],Oz(recognize_number t))
927 with e when Errors.noncritical e -> default false t)
927928 | Kvar s -> [],Oatom s
928929 | Kapp(Zopp,[t]) ->
929930 let tac,t' = transform (P_APP 1 :: p) t in
220220 (*s Now the function [compute_ivs] itself *)
221221
222222 let compute_ivs gl f cs =
223 let cst = try destConst f with _ -> i_can't_do_that () in
223 let cst =
224 try destConst f
225 with e when Errors.noncritical e -> i_can't_do_that ()
226 in
224227 let body = Environ.constant_value (Global.env()) cst in
225228 match decomp_term body with
226229 | Fix(([| len |], 0), ([| name |], [| typ |], [| body2 |])) ->
291291 (* Protects the convertibility test against undue exceptions when using it
292292 with untyped terms *)
293293
294 let safe_pf_conv_x gl c1 c2 = try pf_conv_x gl c1 c2 with _ -> false
294 let safe_pf_conv_x gl c1 c2 =
295 try pf_conv_x gl c1 c2 with e when Errors.noncritical e -> false
295296
296297
297298 (* Add a Ring or a Semi-Ring to the database after a type verification *)
334334 | Kapp("Z.succ",[t]) -> Tsucc t
335335 | Kapp("Z.pred",[t]) -> Tplus(t, mk_Z (Bigint.neg Bigint.one))
336336 | Kapp(("Zpos"|"Zneg"|"Z0"),_) ->
337 (try Tnum (recognize t) with _ -> Tother)
337 (try Tnum (recognize t) with e when Errors.noncritical e -> Tother)
338338 | _ -> Tother
339339 with e when Logic.catchable_exception e -> Tother
340340
356356 | Kapp(("Z.opp"|"Z.succ"|"Z.pred"),[t]) -> aux t
357357 | Kapp(("Zpos"|"Zneg"|"Z0"),_) -> let _ = recognize t in true
358358 | _ -> false in
359 try aux t with _ -> false
359 try aux t with e when Errors.noncritical e -> false
360360
361361 end
224224 env.terms <- env.terms @ [t]; i
225225
226226 let get_reified_atom env =
227 try List.nth env.terms with _ -> failwith "get_reified_atom"
227 try List.nth env.terms
228 with e when Errors.noncritical e -> failwith "get_reified_atom"
228229
229230 (* \subsection{Gestion de l'environnement de proposition pour Omega} *)
230231 (* ajout d'une proposition *)
234235 let i = List.length env.props in env.props <- env.props @ [t]; i
235236
236237 (* accès a une proposition *)
237 let get_prop v env = try List.nth v env with _ -> failwith "get_prop"
238 let get_prop v env =
239 try List.nth v env
240 with e when Errors.noncritical e -> failwith "get_prop"
238241
239242 (* \subsection{Gestion du nommage des équations} *)
240243 (* Ajout d'une equation dans l'environnement de reification *)
246249 (* accès a une equation *)
247250 let get_equation env id =
248251 try Hashtbl.find env.equations id
249 with e -> Printf.printf "Omega Equation %d non trouvée\n" id; raise e
252 with Not_found as e ->
253 Printf.printf "Omega Equation %d non trouvée\n" id; raise e
250254
251255 (* Affichage des termes réifiés *)
252256 let rec oprint ch = function
348352 app coq_t_minus [| reified_of_formula env t1; reified_of_formula env t2 |]
349353
350354 let reified_of_formula env f =
351 begin try reified_of_formula env f with e -> oprint stderr f; raise e end
355 try reified_of_formula env f
356 with reraise -> oprint stderr f; raise reraise
352357
353358 let rec reified_of_proposition env = function
354359 Pequa (_,{ e_comp=Eq; e_left=t1; e_right=t2 }) ->
379384 | Pprop t -> app coq_p_prop [| mk_nat (add_prop env t) |]
380385
381386 let reified_of_proposition env f =
382 begin try reified_of_proposition env f
383 with e -> pprint stderr f; raise e end
387 try reified_of_proposition env f
388 with reraise -> pprint stderr f; raise reraise
384389
385390 (* \subsection{Omega vers COQ réifié} *)
386391
396401 List.fold_right mk_coeff body coeff_constant
397402
398403 let reified_of_omega env body c =
399 begin try
404 try
400405 reified_of_omega env body c
401 with e ->
402 display_eq display_omega_var (body,c); raise e
403 end
406 with reraise ->
407 display_eq display_omega_var (body,c); raise reraise
408
404409
405410 (* \section{Opérations sur les équations}
406411 Ces fonctions préparent les traces utilisées par la tactique réfléchie
9991004 let weighted = filter_compatible_systems path all_solutions in
10001005 let (winner_sol,winner_deps) =
10011006 try select_smaller weighted
1002 with e ->
1007 with reraise ->
10031008 Printf.printf "%d - %d\n"
10041009 (List.length weighted) (List.length all_solutions);
1005 List.iter display_depend path; raise e in
1010 List.iter display_depend path; raise reraise
1011 in
10061012 build_tree winner_sol (List.rev path) winner_deps
10071013
10081014 let find_path {o_hyp=id;o_path=p} env =
8989
9090 let try_catch_exn f e =
9191 try f e
92 with exn -> errorlabstrm "Program" (Errors.print exn)
92 with exn when Errors.noncritical exn ->
93 errorlabstrm "Program" (Errors.print exn)
9394
9495 let subtac_obligation e = try_catch_exn Subtac_obligations.subtac_obligation e
9596 let next_obligation e = try_catch_exn Subtac_obligations.next_obligation e
220220 | (Loc.Exc_located (loc, Proof_type.LtacLocated (_,e')) |
221221 Loc.Exc_located (loc, e') as e) -> raise e
222222
223 | e ->
223 | reraise ->
224224 (* msg_warning (str "Uncaught exception: " ++ Errors.print e); *)
225 raise e
225 raise reraise
341341 let pred = predicate 0 c in
342342 let env' = push_rel_context (context_of_arsign arsign) env in
343343 ignore(Typing.sort_of env' evm pred); pred
344 with _ -> lift nar c
344 with e when Errors.noncritical e -> lift nar c
345345
346346 module Cases_F(Coercion : Coercion.S) : S = struct
347347
14641464 | None -> list_tabulate (fun _ -> Anonymous) nrealargs in
14651465 let arsign = fst (get_arity env0 indf) in
14661466 (na,None,build_dependent_inductive env0 indf)
1467 ::(try List.map2 (fun x (_,c,t) ->(x,c,t)) realnal arsign with _ -> assert false) in
1467 ::(try List.map2 (fun x (_,c,t) ->(x,c,t)) realnal arsign
1468 with e when Errors.noncritical e -> assert false) in
14681469 let rec buildrec = function
14691470 | [],[] -> []
14701471 | (_,tm)::ltm, x::tmsign ->
355355 jres),
356356 jres.uj_type)
357357 (hj,typ_cl) p)
358 with _ -> anomaly "apply_coercion"
358 with e when Errors.noncritical e -> anomaly "apply_coercion"
359359
360360 let inh_app_fun env isevars j =
361361 let isevars = ref isevars in
505505 with NoSubtacCoercion ->
506506 error_cannot_coerce env' isevars (t, t'))
507507 else isevars
508 with _ -> isevars
508 with e when Errors.noncritical e -> isevars
509509 end
247247 | [(_, None, t); (_, None, u)], Sort (Prop Null)
248248 when Reductionops.is_conv env !isevars t u -> t
249249 | _, _ -> error ()
250 with _ -> error ()
250 with e when Errors.noncritical e -> error ()
251251 in
252252 let measure = interp_casted_constr isevars binders_env measure relargty in
253253 let wf_rel, wf_rel_fun, measure_fn =
439439 let sort = Retyping.get_type_of env !evdref t in
440440 let fixprot =
441441 try mkApp (delayed_force Subtac_utils.fix_proto, [|sort; t|])
442 with e -> t
442 with e when Errors.noncritical e -> t
443443 in
444444 (id,None,fixprot) :: env')
445445 [] fixnames fixtypes
120120 let xobl = obls.(x) in
121121 let oblb =
122122 try get_obligation_body expand xobl
123 with _ -> assert(false)
123 with e when Errors.noncritical e -> assert(false)
124124 in (xobl.obl_name, (xobl.obl_type, oblb)) :: acc)
125125 deps []
126126
497497 let obls = Array.copy obls in
498498 let _ = obls.(num) <- obl in
499499 let res = try update_obls prg obls (pred rem)
500 with e -> pperror (Errors.print (Cerrors.process_vernac_interp_error e))
500 with e when Errors.noncritical e ->
501 pperror (Errors.print (Cerrors.process_vernac_interp_error e))
501502 in
502503 match res with
503504 | Remain n when n > 0 ->
551552 | Refiner.FailError (_, s) ->
552553 user_err_loc (fst obl.obl_location, "solve_obligation", Lazy.force s)
553554 | Util.Anomaly _ as e -> raise e
554 | e -> false
555 | e when Errors.noncritical e -> false
555556
556557 and solve_prg_obligations prg ?oblset tac =
557558 let obls, rem = prg.prg_obligations in
301301 make_judge (mkFix ((indexes,i),fixdecls)) ftys.(i)
302302 | GCoFix i ->
303303 let cofix = (i,(names,ftys,fdefs)) in
304 (try check_cofix env cofix with e -> Loc.raise loc e);
304 (try check_cofix env cofix
305 with e when Errors.noncritical e -> Loc.raise loc e);
305306 make_judge (mkCoFix cofix) ftys.(i) in
306307 inh_conv_coerce_to_tycon loc env evdref fixj tycon
307308
600601 ~split:true ~fail:true env !evdref;
601602 evdref := Typeclasses.resolve_typeclasses ~filter:Typeclasses.all_evars
602603 ~split:true ~fail:false env !evdref
603 with e -> if fail_evar then raise e else ());
604 with e when Errors.noncritical e ->
605 if fail_evar then raise e else ());
604606 evdref := consider_remaining_unif_problems env !evdref;
605607 let c = if expand_evar then nf_evar !evdref c' else c' in
606608 if fail_evar then check_evars env Evd.empty !evdref c;
231231 let hyptype = substl names t in
232232 trace (spc () ++ str ("treating evar " ^ string_of_id n));
233233 (try trace (str " assert: " ++ my_print_constr (Global.env ()) hyptype)
234 with _ -> ());
234 with e when Errors.noncritical e -> ());
235235 let tac = assert_tac (Name n) hyptype in
236236 let conttac =
237237 (fun cont ->
330330 Ind i when i = Term.destInd (delayed_force ex_ind) && Array.length args = 2 ->
331331 let (dom, rng) =
332332 try (args.(0), args.(1))
333 with _ -> assert(false)
333 with e when Errors.noncritical e -> assert(false)
334334 in
335335 let pi1 = (mk_ex_pi1 dom rng acc) in
336336 let rng_body =
374374 Inductiveops.control_only_guard (Global.env ())
375375 const.Entries.const_entry_body;
376376 const.Entries.const_entry_body
377 with e ->
377 with reraise ->
378378 Pfedit.delete_current_proof();
379 raise e
379 raise reraise
380380
381381 (* let apply_tac t goal = t goal *)
382382
348348 if computeinnertypes then
349349 try
350350 Acic.CicHash.find terms_to_types tt
351 with _ ->
351 with e when e <> Sys.Break ->
352352 (*CSC: Warning: it really happens, for example in Ring_theory!!! *)
353353 Pp.ppnl (Pp.(++) (Pp.str "BUG: this subterm was not visited during the double-type-inference: ") (Printer.pr_lconstr tt)) ; assert false
354354 else
146146 (*CSC: universes. *)
147147 (try
148148 Typeops.judge_of_type u
149 with _ -> (* Successor of a non universe-variable universe anomaly *)
149 with e when e <> Sys.Break ->
150 (* Successor of a non universe-variable universe anomaly *)
150151 (Pp.ppnl (Pp.str "Warning: universe refresh performed!!!") ; flush stdout ) ;
151152 Typeops.judge_of_type (Termops.new_univ ())
152153 )
142142 | he::tail ->
143143 (try
144144 Unix.mkdir cwd 0o775
145 with _ -> () (* Let's ignore the errors on mkdir *)
145 with e when e <> Sys.Break -> () (* Let's ignore the errors on mkdir *)
146146 ) ;
147147 let newcwd = cwd ^ "/" ^ he in
148148 join_dirs newcwd tail
125125 jres),
126126 jres.uj_type)
127127 (hj,typ_cl) p)
128 with _ -> anomaly "apply_coercion"
128 with e when Errors.noncritical e -> anomaly "apply_coercion"
129129
130130 let inh_app_fun env evd j =
131131 let t = whd_betadeltaiota env evd j.uj_type in
271271 try
272272 let sign,ccl = decompose_lam_n_assum n c in
273273 noccur_between 1 (rel_context_length sign) ccl
274 with _ -> (* Not eta-expanded or not reduced *)
274 with e when Errors.noncritical e -> (* Not eta-expanded or not reduced *)
275275 false
276276
277277 let extract_nondep_branches test c b n =
385385 | Var id ->
386386 (try
387387 let _ = Global.lookup_named id in GRef (dl, VarRef id)
388 with _ ->
388 with e when Errors.noncritical e ->
389389 GVar (dl, id))
390390 | Sort s -> GSort (dl,detype_sort s)
391391 | Cast (c1,REVERTcast,c2) when not !Flags.raw_print ->
491491 let mat = build_tree Anonymous isgoal (avoid,env) ci bl in
492492 List.map (fun (pat,((avoid,env),c)) -> (dl,[],[pat],detype isgoal avoid env c))
493493 mat
494 with _ ->
494 with e when Errors.noncritical e ->
495495 Array.to_list
496496 (array_map3 (detype_eqn isgoal avoid env) constructs consnargsl bl)
497497
453453 else Evd.set_leq_sort evd s1 s2
454454 in (evd', true)
455455 with Univ.UniverseInconsistency _ -> (evd, false)
456 | _ -> (evd, false))
456 | e when Errors.noncritical e -> (evd, false))
457457
458458 | Prod (n,c1,c'1), Prod (_,c2,c'2) when l1=[] & l2=[] ->
459459 ise_and evd
729729 let (term2,l2 as appr2) = decompose_app t2 in
730730 match kind_of_term term1, kind_of_term term2 with
731731 | Evar (evk1,args1), (Rel _|Var _) when l1 = [] & l2 = []
732 & array_for_all (fun a -> eq_constr a term2 or isEvar a) args1 ->
732 & List.for_all (fun a -> eq_constr a term2 or isEvar a)
733 (remove_instance_local_defs evd evk1 (Array.to_list args1)) ->
733734 (* The typical kind of constraint coming from pattern-matching return
734735 type inference *)
735736 choose_less_dependent_instance evk1 evd term2 args1
736737 | (Rel _|Var _), Evar (evk2,args2) when l1 = [] & l2 = []
737 & array_for_all (fun a -> eq_constr a term1 or isEvar a) args2 ->
738 & List.for_all (fun a -> eq_constr a term1 or isEvar a)
739 (remove_instance_local_defs evd evk2 (Array.to_list args2)) ->
738740 (* The typical kind of constraint coming from pattern-matching return
739741 type inference *)
740742 choose_less_dependent_instance evk2 evd term1 args2
11931193
11941194 let closure_of_filter evd evk filter =
11951195 let evi = Evd.find_undefined evd evk in
1196 let vars = collect_vars (evar_concl evi) in
1197 let ids = List.map pi1 (evar_context evi) in
1198 let test id b = b || Idset.mem id vars in
1199 let newfilter = List.map2 test ids filter in
1196 let vars = collect_vars (nf_evar evd (evar_concl evi)) in
1197 let test (id,c,_) b = b || Idset.mem id vars || c <> None in
1198 let newfilter = List.map2 test (evar_context evi) filter in
12001199 if newfilter = evar_filter evi then None else Some newfilter
12011200
12021201 let restrict_hyps evd evk filter candidates =
13511350 let f,args = decompose_app_vect t in
13521351 match kind_of_term f with
13531352 | Construct (ind,_) ->
1354 let nparams = (fst (Global.lookup_inductive ind)).Declarations.mind_nparams in
1355 let params,_ = array_chop nparams args in
1356 array_for_all (is_constrainable_in k g) params
1353 let nparams =
1354 (fst (Global.lookup_inductive ind)).Declarations.mind_nparams
1355 in
1356 if nparams > Array.length args
1357 then true (* We don't try to be more clever *)
1358 else
1359 let params,_ = array_chop nparams args in
1360 array_for_all (is_constrainable_in k g) params
13571361 | Ind _ -> array_for_all (is_constrainable_in k g) args
13581362 | Prod (_,t1,t2) -> is_constrainable_in k g t1 && is_constrainable_in k g t2
13591363 | Evar (ev',_) -> ev' <> ev (*If ev' needed, one may also try to restrict it*)
14411445 (* FIXME: The body might be ill-typed when this is called from w_merge *)
14421446 let ty =
14431447 try Retyping.get_type_of evenv evd body
1444 with _ -> error "Ill-typed evar instance"
1448 with e when Errors.noncritical e -> error "Ill-typed evar instance"
14451449 in
14461450 let evd,b = conv_algo evenv evd Reduction.CUMUL ty evi.evar_concl in
14471451 if b then evd else
14911495 (filter_compatible_candidates conv_algo env evd evi args rhs) l in
14921496 match l' with
14931497 | [] -> error_cannot_unify env evd (mkEvar ev, rhs)
1494 | [c,evd] -> Evd.define evk c evd
1498 | [c,evd] ->
1499 (* solve_candidates might have been called recursively in the mean *)
1500 (* time and the evar been solved by the filtering process *)
1501 if Evd.is_undefined evd evk then Evd.define evk c evd else evd
14951502 | l when List.length l < List.length l' ->
14961503 let candidates = List.map fst l in
14971504 restrict_evar evd evk None (Some candidates)
16421649 map_constr_with_full_binders (fun d (env,k) -> push_rel d env, k+1)
16431650 imitate envk t in
16441651 t::l
1645 with _ -> l in
1652 with e when Errors.noncritical e -> l in
16461653 (match candidates with
16471654 | [x] -> x
16481655 | _ ->
229229 val check_evar_instance : evar_map -> existential_key -> constr -> conv_fun ->
230230 evar_map
231231
232 val remove_instance_local_defs : evar_map -> existential_key -> constr list -> constr list
6666 let evar_context evi = named_context_of_val evi.evar_hyps
6767 let evar_body evi = evi.evar_body
6868 let evar_filter evi = evi.evar_filter
69 let evar_unfiltered_env evi = Global.env_of_context evi.evar_hyps
7069 let evar_filtered_context evi =
7170 snd (list_filter2 (fun b c -> b) (evar_filter evi,evar_context evi))
71 let evar_filtered_hyps evi =
72 List.fold_right push_named_context_val (evar_filtered_context evi)
73 empty_named_context_val
74 let evar_unfiltered_env evi = Global.env_of_context evi.evar_hyps
7275 let evar_env evi =
7376 List.fold_right push_named (evar_filtered_context evi)
7477 (reset_context (Global.env()))
126126 val evar_context : evar_info -> named_context
127127 val evar_filtered_context : evar_info -> named_context
128128 val evar_hyps : evar_info -> named_context_val
129 val evar_filtered_hyps : evar_info -> named_context_val
129130 val evar_body : evar_info -> evar_body
130131 val evar_filter : evar_info -> bool list
131132 val evar_unfiltered_env : evar_info -> env
289289 match kind_of_term t with
290290 | Ind ind ->
291291 let (mib,mip) = Inductive.lookup_mind_specif env ind in
292 if mib.mind_nparams > List.length l then raise Not_found;
292293 let (par,rargs) = list_chop mib.mind_nparams l in
293294 IndType((ind, par),rargs)
294295 | _ -> raise Not_found
6868 if List.for_all (fun l->1=List.length l) possible_indexes then
6969 let indexes = Array.of_list (List.map List.hd possible_indexes) in
7070 let fix = ((indexes, 0),fixdefs) in
71 (try check_fix env fix with
72 | e -> if loc = dummy_loc then raise e else Loc.raise loc e);
71 (try check_fix env fix
72 with e when Errors.noncritical e ->
73 if loc = dummy_loc then raise e else Loc.raise loc e);
7374 indexes
7475 else
7576 (* we now search recursively amoungst all combinations *)
108109 (* Resolve eagerly, potentially making wrong choices *)
109110 evdref := (try consider_remaining_unif_problems
110111 ~ts:(Typeclasses.classes_transparent_state ()) env !evdref
111 with e -> if fail_evar then raise e else !evdref)
112 with e when Errors.noncritical e ->
113 if fail_evar then raise e else !evdref)
112114
113115 let solve_remaining_evars fail_evar use_classes hook env initial_sigma (evd,c) =
114116 let evdref = ref evd in
440442 make_judge (mkFix ((indexes,i),fixdecls)) ftys.(i)
441443 | GCoFix i ->
442444 let cofix = (i,(names,ftys,fdefs)) in
443 (try check_cofix env cofix with e -> Loc.raise loc e);
445 (try check_cofix env cofix
446 with e when Errors.noncritical e -> Loc.raise loc e);
444447 make_judge (mkCoFix cofix) ftys.(i) in
445448 inh_conv_coerce_to_tycon loc env evdref fixj tycon
446449
206206 match kind_of_term t with
207207 App (f,vargs) ->
208208 begin
209 try Const_cs (global_of_constr f) , -1, Array.to_list vargs with
210 _ -> raise Not_found
209 try Const_cs (global_of_constr f) , -1, Array.to_list vargs
210 with e when Errors.noncritical e -> raise Not_found
211211 end
212212 | Rel n -> Default_cs, pred n, []
213213 | Prod (_,a,b) when not (Termops.dependent (mkRel 1) b) -> Prod_cs, -1, [a; Termops.pop b]
214214 | Sort s -> Sort_cs (family_of_sort s), -1, []
215215 | _ ->
216216 begin
217 try Const_cs (global_of_constr t) , -1, [] with
218 _ -> raise Not_found
217 try Const_cs (global_of_constr t) , -1, []
218 with e when Errors.noncritical e -> raise Not_found
219219 end
220220
221221 (* Intended to always succeed *)
923923 let u = whd_betaiota Evd.empty u in
924924 match kind_of_term u with
925925 | Case (ci,p,c,bl) when isMeta c or isCast c & isMeta (pi1 (destCast c)) ->
926 let m = try destMeta c with _ -> destMeta (pi1 (destCast c)) in
926 let m =
927 try destMeta c
928 with e when Errors.noncritical e -> destMeta (pi1 (destCast c))
929 in
927930 (match
928931 try
929932 let g,s = List.assoc m metas in
933936 | Some g -> irec (mkCase (ci,p,g,bl))
934937 | None -> mkCase (ci,irec p,c,Array.map irec bl))
935938 | App (f,l) when isMeta f or isCast f & isMeta (pi1 (destCast f)) ->
936 let m = try destMeta f with _ -> destMeta (pi1 (destCast f)) in
939 let m =
940 try destMeta f
941 with e when Errors.noncritical e -> destMeta (pi1 (destCast f))
942 in
937943 (match
938944 try
939945 let g,s = List.assoc m metas in
2929 (* et sinon on substitue *)
3030
3131 let sort_of_atomic_type env sigma ft args =
32 let rec concl_of_arity env ar =
33 match kind_of_term (whd_betadeltaiota env sigma ar) with
34 | Prod (na, t, b) -> concl_of_arity (push_rel (na,None,t) env) b
35 | Sort s -> s
36 | _ -> decomp_sort env sigma (subst_type env sigma ft (Array.to_list args))
37 in concl_of_arity env ft
32 let rec concl_of_arity env ar args =
33 match kind_of_term (whd_betadeltaiota env sigma ar), args with
34 | Prod (na, t, b), h::l -> concl_of_arity (push_rel (na,Some h,t) env) b l
35 | Sort s, [] -> s
36 | _ -> anomaly "Not a sort"
37 in concl_of_arity env ft (Array.to_list args)
3838
3939 let type_of_var env id =
4040 try let (_,_,ty) = lookup_named id env in ty
124124
125125 (* We use a cache registered as a global table *)
126126
127 let eval_table = ref Cmap.empty
128
129 type frozen = (int * constant_evaluation) Cmap.t
127 let eval_table = ref Cmap_env.empty
128
129 type frozen = (int * constant_evaluation) Cmap_env.t
130130
131131 let init () =
132 eval_table := Cmap.empty
132 eval_table := Cmap_env.empty
133133
134134 let freeze () =
135135 !eval_table
290290 let reference_eval sigma env = function
291291 | EvalConst cst as ref ->
292292 (try
293 Cmap.find cst !eval_table
293 Cmap_env.find cst !eval_table
294294 with Not_found -> begin
295295 let v = compute_consteval sigma env ref in
296 eval_table := Cmap.add cst v !eval_table;
296 eval_table := Cmap_env.add cst v !eval_table;
297297 v
298298 end)
299299 | ref -> compute_consteval sigma env ref
117117
118118 let class_info c =
119119 try Gmap.find c !classes
120 with _ -> not_a_class (Global.env()) (constr_of_global c)
120 with Not_found -> not_a_class (Global.env()) (constr_of_global c)
121121
122122 let global_class_of_constr env c =
123123 try class_info (global_of_constr c)
131131 let rels, c = Term.decompose_prod_assum c in
132132 rels, dest_class_app env c
133133
134 let class_of_constr c = try Some (dest_class_arity (Global.env ()) c) with _ -> None
134 let class_of_constr c =
135 try Some (dest_class_arity (Global.env ()) c)
136 with e when Errors.noncritical e -> None
135137
136138 let rec is_class_type evd c =
137139 match kind_of_term c with
214216 try
215217 let cst = Tacred.evaluable_of_global_reference (Global.env ()) cl.cl_impl in
216218 set_typeclass_transparency cst false false; cl
217 with _ -> cl
219 with e when Errors.noncritical e -> cl
218220
219221 let class_input : typeclass -> obj =
220222 declare_object
237239 let (evd, c) = resolve_one_typeclass env sigma
238240 (Retyping.get_type_of env sigma c) in
239241 Evd.is_empty (Evd.undefined_evars evd)
240 with _ -> false
242 with e when Errors.noncritical e -> false
241243
242244 let build_subclasses ~check env sigma glob pri =
243245 let rec aux pri c =
429429 then Evd.set_leq_sort sigma s1 s2
430430 else Evd.set_eq_sort sigma s1 s2
431431 in (sigma', metasubst, evarsubst)
432 with _ -> error_cannot_unify curenv sigma (m,n))
433
432 with e when Errors.noncritical e ->
433 error_cannot_unify curenv sigma (m,n))
434
434435 | Lambda (na,t1,c1), Lambda (_,t2,c2) ->
435436 unirec_rec (push (na,t1) curenvnb) CONV true wt
436437 (unirec_rec curenvnb CONV true false substn t1 t2) c1 c2
707708 else (right, st2, res)
708709 | (IsSuperType,IsSubType) ->
709710 (try (left, IsSubType, unify_0 env sigma CUMUL flags c2 c1)
710 with _ -> (right, IsSubType, unify_0 env sigma CUMUL flags c1 c2))
711 with e when Errors.noncritical e ->
712 (right, IsSubType, unify_0 env sigma CUMUL flags c1 c2))
711713 | (IsSubType,IsSuperType) ->
712714 (try (left, IsSuperType, unify_0 env sigma CUMUL flags c1 c2)
713 with _ -> (right, IsSuperType, unify_0 env sigma CUMUL flags c2 c1))
715 with e when Errors.noncritical e ->
716 (right, IsSuperType, unify_0 env sigma CUMUL flags c2 c1))
714717
715718 (* Unification
716719 *
912915 let rec process_eqns failures = function
913916 | (mv,status,c)::eqns ->
914917 (match (try Inl (unify_type env evd flags mv status c)
915 with e -> Inr e)
918 with e when Errors.noncritical e -> Inr e)
916919 with
917920 | Inr e -> process_eqns (((mv,status,c),e)::failures) eqns
918921 | Inl (evd,metas,evars) ->
4343 let find_rectype_a env c =
4444 let (t, l) =
4545 let t = whd_betadeltaiota env c in
46 try destApp t with _ -> (t,[||]) in
46 try destApp t with e when Errors.noncritical e -> (t,[||]) in
4747 match kind_of_term t with
4848 | Ind ind -> (ind, l)
4949 | _ -> raise Not_found
175175 nf_stk env (mkApp(c,args)) t stk
176176 | Zfix (f,vargs) :: stk ->
177177 let fa, typ = nf_fix_app env f vargs in
178 let _,_,codom = try decompose_prod env typ with _ -> exit 120 in
178 let _,_,codom =
179 try decompose_prod env typ
180 with e when Errors.noncritical e -> exit 120
181 in
179182 nf_stk env (mkApp(fa,[|c|])) (subst1 c codom) stk
180183 | Zswitch sw :: stk ->
181184 let (mind,_ as ind),allargs = find_rectype_a env t in
205208 | Vfun f, Prod _ ->
206209 let k = nb_rel env in
207210 let vb = body_of_vfun k f in
208 let name,dom,codom = try decompose_prod env pT with _ -> exit 121 in
211 let name,dom,codom =
212 try decompose_prod env pT
213 with e when Errors.noncritical e -> exit 121
214 in
209215 let dep,body =
210216 nf_predicate (push_rel (name,None,dom) env) ind mip params vb codom in
211217 dep, mkLambda(name,dom,body)
227233 let args =
228234 Array.init len
229235 (fun i ->
230 let _,dom,codom = try decompose_prod env !t with _ -> exit 123 in
236 let _,dom,codom =
237 try decompose_prod env !t
238 with e when Errors.noncritical e -> exit 123
239 in
231240 let c = nf_val env (arg vargs i) dom in
232241 t := subst1 c codom; c) in
233242 !t,args
238247 let args =
239248 Array.init len
240249 (fun i ->
241 let _,dom,codom = try decompose_prod env !t with _ -> exit 124 in
250 let _,dom,codom =
251 try decompose_prod env !t
252 with e when Errors.noncritical e -> exit 124
253 in
242254 let c = nf_val env (bfield b i) dom in
243255 t := subst1 c codom; c) in
244256 args
248260 let vb = body_of_vfun k f in
249261 let name,dom,codom =
250262 try decompose_prod env typ
251 with _ ->
263 with e when Errors.noncritical e ->
252264 raise (Type_errors.TypeError(env,Type_errors.ReferenceVariables typ))
253265 in
254266 let body = nf_val (push_rel (name,None,dom) env) vb codom in
4141 let sigma',typed_c =
4242 try Pretyping.Default.understand_ltac ~resolve_classes:true true sigma env ltac_var
4343 (Pretyping.OfType (Some evi.evar_concl)) rawc
44 with _ ->
44 with e when Errors.noncritical e ->
4545 let loc = Glob_term.loc_of_glob_constr rawc in
4646 user_err_loc
4747 (loc,"",Pp.str ("Instance is not well-typed in the environment of " ^
275275
276276 let recheck_typability (what,id) env sigma t =
277277 try check_typability env sigma t
278 with _ ->
278 with e when Errors.noncritical e ->
279279 let s = match what with
280280 | None -> "the conclusion"
281281 | Some id -> "hypothesis "^(Names.string_of_id id) in
473473 (* Old style hyps primitive *)
474474 let hyps evars gl =
475475 let evi = content evars gl in
476 evi.Evd.evar_hyps
476 Evd.evar_filtered_hyps evi
477477
478478 (* Access to ".evar_concl" *)
479479 let concl evars gl =
553553 with a good implementation of them.
554554 *)
555555
556 (* Used for congruence closure *)
557 let new_goal_with sigma gl new_hyps =
556 (* Used for congruence closure and change *)
557 let new_goal_with sigma gl extra_hyps =
558558 let evi = content sigma gl in
559 let new_evi = { evi with Evd.evar_hyps = new_hyps } in
559 let hyps = evi.Evd.evar_hyps in
560 let new_hyps =
561 List.fold_right Environ.push_named_context_val extra_hyps hyps in
562 let extra_filter = List.map (fun _ -> true) extra_hyps in
563 let new_filter = extra_filter @ evi.Evd.evar_filter in
564 let new_evi =
565 { evi with Evd.evar_hyps = new_hyps; Evd.evar_filter = new_filter } in
560566 let new_evi = Typeclasses.mark_unresolvable new_evi in
561567 let evk = Evarutil.new_untyped_evar () in
562568 let new_sigma = Evd.add Evd.empty evk new_evi in
231231 val same_goal : Evd.evar_map -> goal -> Evd.evar_map -> goal -> bool
232232
233233 (* Used for congruence closure *)
234 val new_goal_with : Evd.evar_map -> goal -> Environ.named_context_val -> goal Evd.sigma
234 val new_goal_with : Evd.evar_map -> goal -> Sign.named_context -> goal Evd.sigma
235235
236236 (* Used by the compatibility layer and typeclasses *)
237237 val nf_evar : Evd.evar_map -> goal -> goal * Evd.evar_map
104104
105105 let recheck_typability (what,id) env sigma t =
106106 try check_typability env sigma t
107 with _ ->
107 with e when Errors.noncritical e ->
108108 let s = match what with
109109 | None -> "the conclusion"
110110 | Some id -> "hypothesis "^(string_of_id id) in
6767 | None -> Proofview.tclUNIT ()
6868 in
6969 try Proof_global.run_tactic tac
70 with e -> Proof_global.discard_current (); raise e
70 with reraise -> Proof_global.discard_current (); raise reraise
7171
7272 let restart_proof () = undo_todepth 1
7373
163163 let _,(const,_,_,_) = cook_proof (fun _ -> ()) in
164164 delete_current_proof ();
165165 const
166 with e ->
166 with reraise ->
167167 delete_current_proof ();
168 raise e
168 raise reraise
169169
170170 let build_by_tactic env typ tac =
171171 let id = id_of_string ("temporary_proof"^string_of_int (next())) in
322322 let transaction pr t =
323323 init_transaction pr;
324324 try t (); commit pr
325 with e -> rollback pr; raise e
325 with reraise -> rollback pr; raise reraise
326326
327327
328328 (* Focus command (focuses on the [i]th subgoal) *)
428428 let tacticced_proofview = Proofview.apply env tac sp in
429429 pr.state <- { pr.state with proofview = tacticced_proofview };
430430 push_undo starting_point pr
431 with e ->
431 with reraise ->
432432 restore_state starting_point pr;
433 raise e
433 raise reraise
434434
435435 (*** Commands ***)
436436
475475 let new_proofview = Proofview.V82.instantiate_evar n com sp in
476476 pr.state <- { pr.state with proofview = new_proofview };
477477 push_undo starting_point pr
478 with e ->
478 with reraise ->
479479 restore_state starting_point pr;
480 raise e
481 end
480 raise reraise
481 end
319319 (* takes a tactic which can raise exception and makes it pure by *failing*
320320 on with these exceptions. Does not catch anomalies. *)
321321 let purify t =
322 let t' env = { go = fun sk fk step -> try (t env).go (fun x -> sk (Util.Inl x)) fk step
323 with Util.Anomaly _ as e -> raise e
324 | e -> sk (Util.Inr e) fk step
325 }
322 let t' env =
323 { go = fun sk fk step ->
324 try (t env).go (fun x -> sk (Util.Inl x)) fk step
325 with Util.Anomaly _ as e -> raise e
326 | e when Errors.noncritical e -> sk (Util.Inr e) fk step
327 }
326328 in
327329 tclBIND t' begin function
328330 | Util.Inl x -> tclUNIT x
254254 try
255255 t1 g
256256 with (* Breakpoint *)
257 | e -> catch_failerror e; t2 g
257 | e when Errors.noncritical e -> catch_failerror e; t2 g
258258
259259 (* ORELSE t1 t2 tries to apply t1 and if it fails or does not progress,
260260 then applies t2 *)
266266 let tclORELSE_THEN t1 t2then t2else gls =
267267 match
268268 try Some(tclPROGRESS t1 gls)
269 with e -> catch_failerror e; None
269 with e when Errors.noncritical e -> catch_failerror e; None
270270 with
271271 | None -> t2else gls
272272 | Some sgl ->
297297 try
298298 tcal tac_if0 continue gl
299299 with (* Breakpoint *)
300 | e -> catch_failerror e; tac_else0 e gl
300 | e when Errors.noncritical e -> catch_failerror e; tac_else0 e gl
301301
302302 (* Try the first tactic and, if it succeeds, continue with
303303 the second one, and if it fails, use the third one *)
351351 | TacTimeout | Loc.Exc_located(_,TacTimeout) ->
352352 restore_timeout ();
353353 errorlabstrm "Refiner.tclTIMEOUT" (str"Timeout!")
354 | e -> restore_timeout (); raise e
354 | reraise -> restore_timeout (); raise reraise
355355
356356 (* Beware: call by need of CAML, g is needed *)
357357 let rec tclREPEAT t g =
139139 else (decr skip; run false; if !skip=0 then skipped:=0; DebugOn (lev+1)) in
140140 (* What to execute *)
141141 try f newlevel
142 with e ->
142 with reraise ->
143143 skip:=0; skipped:=0;
144 if Logic.catchable_exception e then
145 ppnl (str "Level " ++ int lev ++ str ": " ++ !explain_logic_error e);
146 raise e
144 if Logic.catchable_exception reraise then
145 ppnl (str "Level " ++ int lev ++ str ": " ++ !explain_logic_error reraise);
146 raise reraise
147147
148148 (* Prints a constr *)
149149 let db_constr debug env c =
4444 [ "Camlp4Top.cmo";
4545 "Camlp4Parsers/Camlp4OCamlRevisedParser.cmo";
4646 "Camlp4Parsers/Camlp4OCamlParser.cmo";
47 "Camlp4Parsers/Camlp4GrammarParser.cmo";
48 "q_util.cmo"; "q_coqast.cmo" ]
47 "Camlp4Parsers/Camlp4GrammarParser.cmo" ]
4948 let topobjs = camlp4topobjs
5049
5150 let gramobjs = []
256255 output_string oc "Coqtop.start();;\n";
257256 close_out oc;
258257 main_name
259 with e ->
260 clean main_name; raise e
258 with reraise ->
259 clean main_name; raise reraise
261260
262261 (* main part *)
263262 let main () =
310309 clean main_file;
311310 (* command gives the exit code in HSB, and signal in LSB !!! *)
312311 if retcode > 255 then retcode lsr 8 else retcode
313 with e ->
314 clean main_file; raise e
312 with reraise ->
313 clean main_file; raise reraise
315314
316315 let retcode =
317 try Printexc.print main () with _ -> 1
316 try Printexc.print main () with any -> 1
318317
319318 let _ = exit retcode
828828
829829 let path_of_constr_expr c =
830830 match c with
831 | Topconstr.CRef r -> (try PathHints [global r] with _ -> PathAny)
831 | Topconstr.CRef r ->
832 (try PathHints [global r] with e when Errors.noncritical e -> PathAny)
832833 | _ -> PathAny
833834
834835 let interp_hints h =
11691170 let out = tac gl in
11701171 msg_debug (str s ++ spc () ++ pp () ++ str ". (*success*)");
11711172 out
1172 with e ->
1173 with reraise ->
11731174 msg_debug (str s ++ spc () ++ pp () ++ str ". (*fail*)");
1174 raise e
1175 raise reraise
11751176 end
11761177 | Info ->
11771178 (* For "info (trivial/auto)", we store a log trace *)
11801181 let out = tac gl in
11811182 trace := (depth, Some pp) :: !trace;
11821183 out
1183 with e ->
1184 with reraise ->
11841185 trace := (depth, None) :: !trace;
1185 raise e
1186 raise reraise
11861187 end
11871188
11881189 (** For info, from the linear trace information, we reconstitute the part
207207
208208 (* Functions necessary to the library object declaration *)
209209 let cache_hintrewrite (_,(rbase,lrl)) =
210 let base = try find_base rbase with _ -> HintDN.empty in
211 let max = try fst (Util.list_last (HintDN.find_all base)) with _ -> 0 in
210 let base =
211 try find_base rbase
212 with e when Errors.noncritical e -> HintDN.empty
213 in
214 let max =
215 try fst (Util.list_last (HintDN.find_all base))
216 with e when Errors.noncritical e -> 0
217 in
212218 let lrl = HintDN.map (fun (i,h) -> (i + max, h)) lrl in
213219 rewtab:=Stringmap.add rbase (HintDN.union lrl base) !rewtab
214220
247253 try
248254 ignore(Unification.w_unify ~flags:Unification.elim_flags env evd Reduction.CONV x y); true
249255 (* try ignore(Evarconv.the_conv_x env x y evd); true *)
250 with _ -> false
256 with e when Errors.noncritical e -> false
251257
252258 let decompose_applied_relation metas env sigma c ctype left2right =
253259 let find_rel ty =
684684 let evd =
685685 try Evarconv.consider_remaining_unif_problems
686686 ~ts:(Typeclasses.classes_transparent_state ()) env evd
687 with _ -> evd
687 with e when Errors.noncritical e -> evd
688688 in
689689 resolve_all_evars debug m env (initial_select_evars filter) evd split fail
690690
775775
776776 let typeclasses_eauto ?(only_classes=false) ?(st=full_transparent_state) dbs gl =
777777 try
778 let dbs = list_map_filter (fun db -> try Some (Auto.searchtable_map db) with _ -> None) dbs in
778 let dbs = list_map_filter
779 (fun db -> try Some (Auto.searchtable_map db)
780 with e when Errors.noncritical e -> None) dbs
781 in
779782 let st = match dbs with x :: _ -> Hint_db.transparent_state x | _ -> st in
780783 eauto ?limit:!typeclasses_depth ~only_classes ~st dbs gl
781784 with Not_found -> tclFAIL 0 (str" typeclasses eauto failed on: " ++ Printer.pr_goal gl) gl
204204 (* let gl = Proof_trees.db_pr_goal (List.hd (sig_it glls)) in *)
205205 (* msg (hov 1 (pptac ++ str" gives: \n" ++ pr_goals lgls ++ str"\n")); *)
206206 (lgls,pptac) :: aux tacl
207 with e -> Refiner.catch_failerror e; aux tacl
207 with e when Errors.noncritical e ->
208 Refiner.catch_failerror e; aux tacl
208209 in aux l
209210
210211 (* Ordering of states is lexicographic on depth (greatest first) then
333333 try
334334 rewrite_side_tac (!general_rewrite_clause cls
335335 lft2rgt occs (c,l) ~new_goals:[]) tac gl
336 with e -> (* Try to see if there's an equality hidden *)
336 with e when Errors.noncritical e ->
337 (* Try to see if there's an equality hidden *)
337338 let env' = push_rel_context rels env in
338339 let rels',t' = splay_prod_assum env' sigma t in (* Search for underlying eq *)
339340 match match_with_equality_type t' with
11551156 ]
11561157 (* not a dep eq or no decidable type found *)
11571158 ) else (raise Not_dep_pair)
1158 ) with _ ->
1159 ) with e when Errors.noncritical e ->
11591160 inject_at_positions env sigma u eq_clause posns
11601161 (fun _ -> intros_pattern no_move ipats)
11611162
605605 hResolve id c n t gl
606606 with
607607 | UserError _ as e -> raise e
608 | _ -> resolve_auto (n+1)
608 | e when Errors.noncritical e -> resolve_auto (n+1)
609609 in
610610 resolve_auto 1
611611
6363
6464 (* Test dependencies *)
6565
66 (* NB: we consider also the let-in case in the following function,
67 since they may appear in types of inductive constructors (see #2629) *)
68
6669 let rec has_nodep_prod_after n c =
6770 match kind_of_term c with
68 | Prod (_,_,b) ->
71 | Prod (_,_,b) | LetIn (_,_,_,b) ->
6972 ( n>0 || not (dependent (mkRel 1) b))
7073 && (has_nodep_prod_after (n-1) b)
7174 | _ -> true
354357 let coq_eq_true_pattern = lazy PATTERN [ %coq_eq_true_ref ?X1 ]
355358
356359 let match_eq eqn eq_pat =
357 let pat = try Lazy.force eq_pat with _ -> raise PatternMatchingFailure in
360 let pat =
361 try Lazy.force eq_pat
362 with e when Errors.noncritical e -> raise PatternMatchingFailure
363 in
358364 match matches pat eqn with
359365 | [(m1,t);(m2,x);(m3,y)] ->
360366 assert (m1 = meta1 & m2 = meta2 & m3 = meta3);
496496 (* The most general inversion tactic *)
497497 let inversion inv_kind status names id gls =
498498 try (raw_inversion inv_kind id status names) gls
499 with e -> wrap_inv_error id e
499 with e when Errors.noncritical e -> wrap_inv_error id e
500500
501501 (* Specializing it... *)
502502
539539 inversion (false,k) NoDep names id;
540540 intros_replace_ids])
541541 gls
542 with e -> wrap_inv_error id e
542 with e when Errors.noncritical e -> wrap_inv_error id e
543543
544544 let invIn_gen k names idl = try_intros_until (invIn k names idl)
545545
120120 let inst = mkApp (Lazy.force rewrite_relation_class, [| evar; mkApp (c, params) |]) in
121121 let _ = Typeclasses.resolve_one_typeclass env' evd inst in
122122 Some (it_mkProd_or_LetIn t rels)
123 with _ -> None)
123 with e when Errors.noncritical e -> None)
124124 | _ -> None
125125
126126 let _ =
144144 new_cstr_evar evars env
145145 (* ~src:(dummy_loc, ImplicitArg (ConstRef (Lazy.force respectful), (n, Some na))) *) t
146146 in
147 let mk_relty evars env ty obj =
147 let mk_relty evars newenv ty obj =
148148 match obj with
149149 | None | Some (_, None) ->
150150 let relty = mk_relation ty in
151 new_evar evars env relty
151 if closed0 ty then
152 let env' = Environ.reset_with_named_context (Environ.named_context_val env) env in
153 new_evar evars env' relty
154 else new_evar evars newenv relty
152155 | Some (x, Some rel) -> evars, rel
153156 in
154157 let rec aux env evars ty l =
226229
227230 let evd_convertible env evd x y =
228231 try ignore(Evarconv.the_conv_x env x y evd); true
229 with _ -> false
232 with e when Errors.noncritical e -> false
230233
231234 let rec decompose_app_rel env evd t =
232235 match kind_of_term t with
492495 | [] -> rel
493496
494497 let pointwise_or_dep_relation n t car rel =
495 if noccurn 1 car then
498 if noccurn 1 car && noccurn 1 rel then
496499 mkApp (Lazy.force pointwise_relation, [| t; lift (-1) car; lift (-1) rel |])
497500 else
498501 mkApp (Lazy.force forall_relation,
10471050 let sigma, c = Constrintern.interp_open_constr (goalevars evars) env c in
10481051 let unfolded =
10491052 try Tacred.try_red_product env sigma c
1050 with _ -> error "fold: the term is not unfoldable !"
1053 with e when Errors.noncritical e ->
1054 error "fold: the term is not unfoldable !"
10511055 in
10521056 try
10531057 let sigma = Unification.w_unify env sigma CONV ~flags:Unification.elim_flags unfolded t in
10551059 Some (Some { rew_car = ty; rew_from = t; rew_to = c';
10561060 rew_prf = RewCast DEFAULTcast;
10571061 rew_evars = sigma, cstrevars evars })
1058 with _ -> None
1062 with e when Errors.noncritical e -> None
10591063
10601064 let fold_glob c : strategy =
10611065 fun env avoid t ty cstr evars ->
10631067 let sigma, c = Pretyping.Default.understand_tcc (goalevars evars) env c in
10641068 let unfolded =
10651069 try Tacred.try_red_product env sigma c
1066 with _ -> error "fold: the term is not unfoldable !"
1070 with e when Errors.noncritical e ->
1071 error "fold: the term is not unfoldable !"
10671072 in
10681073 try
10691074 let sigma = Unification.w_unify env sigma CONV ~flags:Unification.elim_flags unfolded t in
10711076 Some (Some { rew_car = ty; rew_from = t; rew_to = c';
10721077 rew_prf = RewCast DEFAULTcast;
10731078 rew_evars = sigma, cstrevars evars })
1074 with _ -> None
1079 with e when Errors.noncritical e -> None
10751080
10761081
10771082 end
19761981 let evm = project gl in
19771982 let car = pi3 (List.hd (fst (Reduction.dest_prod env (Typing.type_of env evm rel)))) in
19781983 fn env evm car rel gl
1979 with e ->
1984 with e when Errors.noncritical e ->
19801985 try fallback gl
19811986 with Hipattern.NoEquationFound ->
19821987 match e with
4949 open Evd
5050
5151 let safe_msgnl s =
52 try msgnl s with e ->
52 try msgnl s with e when Errors.noncritical e ->
5353 msgnl
5454 (str "bug in the debugger: " ++
5555 str "an exception is raised while printing debug information")
9191 if call_trace = [] then tac g else try tac g with
9292 | LtacLocated _ as e -> raise e
9393 | Loc.Exc_located (_,LtacLocated _) as e -> raise e
94 | e ->
94 | e when Errors.noncritical e ->
9595 let (nrep,loc',c),tail = list_sep_last call_trace in
9696 let loc,e' = match e with Loc.Exc_located(loc,e) -> loc,e | _ ->dloc,e in
9797 if tail = [] then
568568 try
569569 Dumpglob.add_glob (loc_of_or_by_notation Libnames.loc_of_reference r)
570570 (Smartlocate.smart_global r)
571 with _ -> ()) occs
571 with e when Errors.noncritical e -> ()) occs
572572 | Cbv grf | Lazy grf ->
573573 List.iter (fun r ->
574574 try
575575 Dumpglob.add_glob (loc_of_or_by_notation Libnames.loc_of_reference r)
576576 (Smartlocate.smart_global r)
577 with _ -> ()) grf.rConst
577 with e when Errors.noncritical e -> ()) grf.rConst
578578 | _ -> ()
579579
580580 let intern_red_expr ist = function
14111411 | ConstrTerm c ->
14121412 try
14131413 f ist gl c
1414 with e ->
1415 debugging_exception_step ist false e (fun () ->
1414 with reraise ->
1415 debugging_exception_step ist false reraise (fun () ->
14161416 str"interpretation of term " ++ pr_glob_constr_env (pf_env gl) (fst c));
1417 raise e
1417 raise reraise
14181418
14191419 (* Interprets a constr expression possibly to first evaluate *)
14201420 let interp_constr_may_eval ist gl c =
14211421 let (sigma,csr) =
14221422 try
14231423 interp_may_eval pf_interp_constr ist gl c
1424 with e ->
1425 debugging_exception_step ist false e (fun () -> str"evaluation of term");
1426 raise e
1424 with reraise ->
1425 debugging_exception_step ist false reraise (fun () ->
1426 str"evaluation of term");
1427 raise reraise
14271428 in
14281429 begin
14291430 db_constr ist.debug (pf_env gl) csr;
17611762 let pack_sigma (sigma,c) = {it=c;sigma=sigma}
17621763
17631764 let extend_gl_hyps { it=gl ; sigma=sigma } sign =
1764 let hyps = Goal.V82.hyps sigma gl in
1765 let new_hyps = List.fold_right Environ.push_named_context_val sign hyps in
1766 (* spiwack: (2010/01/13) if a bug was reintroduced in [change] in is probably here *)
1767 Goal.V82.new_goal_with sigma gl new_hyps
1765 Goal.V82.new_goal_with sigma gl sign
17681766
17691767 (* Interprets an l-tac expression into a value *)
17701768 let rec val_interp ist gl (tac:glob_tactic_expr) =
19241922 try
19251923 catch_error trace
19261924 (val_interp {ist with lfun=newlfun@olfun; trace=trace} gl) body
1927 with e ->
1928 debugging_exception_step ist false e (fun () -> str "evaluation");
1929 raise e in
1925 with reraise ->
1926 debugging_exception_step ist false reraise
1927 (fun () -> str "evaluation");
1928 raise reraise
1929 in
19301930 let gl = { gl with sigma=sigma } in
19311931 debugging_step ist
19321932 (fun () ->
22112211 (try
22122212 let lmatch =
22132213 try extended_matches c csr
2214 with e ->
2215 debugging_exception_step ist false e (fun () ->
2214 with reraise ->
2215 debugging_exception_step ist false reraise (fun () ->
22162216 str "matching with pattern" ++ fnl () ++
22172217 pr_constr_pattern_env (pf_env g) c);
2218 raise e in
2218 raise reraise
2219 in
22192220 try
22202221 let lfun = extend_values_with_bindings lmatch ist.lfun in
22212222 eval_with_fail { ist with lfun=lfun } lz g mt
2222 with e ->
2223 debugging_exception_step ist false e (fun () ->
2223 with reraise ->
2224 debugging_exception_step ist false reraise (fun () ->
22242225 str "rule body for pattern" ++
22252226 pr_constr_pattern_env (pf_env g) c);
2226 raise e
2227 raise reraise
22272228 with e when is_match_catchable e ->
22282229 debugging_step ist (fun () -> str "switching to the next rule");
22292230 apply_match ist sigma csr tl)
22352236 errorlabstrm "Tacinterp.apply_match" (str
22362237 "No matching clauses for match.") in
22372238 let (sigma,csr) =
2238 try interp_ltac_constr ist g constr with e ->
2239 debugging_exception_step ist true e
2239 try interp_ltac_constr ist g constr with reraise ->
2240 debugging_exception_step ist true reraise
22402241 (fun () -> str "evaluation of the matched expression");
2241 raise e in
2242 raise reraise in
22422243 let ilr = read_match_rule (fst (extract_ltac_constr_values ist (pf_env g))) ist (pf_env g) sigma lmr in
22432244 let res =
2244 try apply_match ist sigma csr ilr with e ->
2245 debugging_exception_step ist true e (fun () -> str "match expression");
2246 raise e in
2245 try apply_match ist sigma csr ilr with reraise ->
2246 debugging_exception_step ist true reraise
2247 (fun () -> str "match expression");
2248 raise reraise in
22472249 debugging_step ist (fun () ->
22482250 str "match expression returns " ++ pr_value (Some (pf_env g)) (snd res));
22492251 res
24032405 (h_generalize_dep c_interp)
24042406 | TacLetTac (na,c,clp,b,eqpat) ->
24052407 let clp = interp_clause ist gl clp in
2408 let eqpat = Option.map (interp_intro_pattern ist gl) eqpat in
24062409 if clp = nowhere then
24072410 (* We try to fully-typecheck the term *)
24082411 let (sigma,c_interp) = pf_interp_constr ist gl c in
31793182 let tacticIn t =
31803183 globTacticIn (fun ist ->
31813184 try glob_tactic (t ist)
3182 with e -> anomalylabstrm "tacticIn"
3185 with e when Errors.noncritical e ->
3186 anomalylabstrm "tacticIn"
31833187 (str "Incorrect tactic expression. Received exception is:" ++
31843188 Errors.print e))
31853189
10171017 let thm = nf_betaiota gl.sigma (pf_type_of gl d) in
10181018 let rec aux clause =
10191019 try progress_with_clause flags innerclause clause
1020 with err ->
1020 with err when Errors.noncritical err ->
10211021 try aux (clenv_push_prod clause)
10221022 with NotExtensibleClause -> raise err in
10231023 aux (make_clenv_binding gl (d,thm) lbind)
17071707 let flags = default_matching_flags sigma0 in
17081708 let matching_fun t =
17091709 try let sigma = w_unify env sigma Reduction.CONV ~flags c t in Some(sigma,t)
1710 with _ -> raise NotUnifiable in
1710 with e when Errors.noncritical e -> raise NotUnifiable in
17111711 let merge_fun c1 c2 =
17121712 match c1, c2 with
17131713 | Some (_,c1), Some (_,c2) when not (is_fconv Reduction.CONV env sigma0 c1 c2) ->
25532553
25542554
25552555 let specialize_eqs id gl =
2556 if try ignore(clear [id] gl); false with _ -> true then
2556 if
2557 (try ignore(clear [id] gl); false
2558 with e when Errors.noncritical e -> true)
2559 then
25572560 tclFAIL 0 (str "Specialization not allowed on dependent hypotheses") gl
25582561 else specialize_eqs id gl
25592562
27152718 | Some ( _,None,ind) ->
27162719 let indhd,indargs = decompose_app ind in
27172720 try {!res with indref = Some (global_of_constr indhd) }
2718 with _ -> error "Cannot find the inductive type of the inductive scheme.";;
2721 with e when Errors.noncritical e ->
2722 error "Cannot find the inductive type of the inductive scheme.";;
27192723
27202724 let compute_scheme_signature scheme names_info ind_type_guess =
27212725 let f,l = decompose_app scheme.concl in
35503554 in
35513555 let evd = w_unify (pf_env gl) (project gl) Reduction.CONV ~flags x y
35523556 in tclEVARS evd gl
3553 with _ -> tclFAIL 0 (str"Not unifiable") gl
3557 with e when Errors.noncritical e ->
3558 tclFAIL 0 (str"Not unifiable") gl
0 Require Import Coq.Arith.Arith.
1
2 Module A.
3
4 Fixpoint foo (n:nat) :=
5 match n with
6 | 0 => 0
7 | S n => bar n
8 end
9
10 with bar (n:nat) :=
11 match n with
12 | 0 => 0
13 | S n => foo n
14 end.
15
16 Lemma using_foo:
17 forall (n:nat), foo n = 0 /\ bar n = 0.
18 Proof.
19 induction n ; split ; auto ;
20 destruct IHn ; auto.
21 Qed.
22
23 End A.
24
25
26 Module B.
27
28 Module A := A.
29 Import A.
30
31 End B.
32
33 Module E.
34
35 Module B := B.
36 Import B.A.
37
38 (* Bug 1 *)
39 Lemma test_1:
40 forall (n:nat), foo n = 0.
41 Proof.
42 intros ; destruct n.
43 reflexivity.
44 specialize (A.using_foo (S n)) ; intros.
45 simpl in H.
46 simpl.
47 destruct H.
48 assumption.
49 Qed.
50
51 End E.
0 Class Join (t: Type) : Type := mkJoin {join: t -> t -> t -> Prop}.
1
2 Class sepalg (t: Type) {JOIN: Join t} : Type :=
3 SepAlg {
4 join_eq: forall {x y z z'}, join x y z -> join x y z' -> z = z';
5 join_assoc: forall {a b c d e}, join a b d -> join d c e ->
6 {f : t & join b c f /\ join a f e};
7 join_com: forall {a b c}, join a b c -> join b a c;
8 join_canc: forall {a1 a2 b c}, join a1 b c -> join a2 b c -> a1=a2;
9
10 unit_for : t -> t -> Prop := fun e a => join e a a;
11 join_ex_units: forall a, {e : t & unit_for e a}
12 }.
13
14 Definition joins {A} `{Join A} (a b : A) : Prop :=
15 exists c, join a b c.
16
17 Lemma join_joins {A} `{sepalg A}: forall {a b c},
18 join a b c -> joins a b.
19 Proof.
20 firstorder.
21 Qed.
0 Require Import MSetPositive.
1 Require Import MSetProperties.
2
3 Module Pos := MSetPositive.PositiveSet.
4 Module PPPP := MSetProperties.WPropertiesOn(Pos).
5 Print Module PPPP.
0 Require Import Arith List.
1 Require Import OrderedTypeEx.
2
3 Module Adr.
4 Include Nat_as_OT.
5 Definition nat2t (i: nat) : t := i.
6 End Adr.
7
8 Inductive expr := Const: Adr.t -> expr.
9
10 Inductive control := Go: expr -> control.
11
12 Definition program := (Adr.t * (control))%type.
13
14 Fail Definition myprog : program := (Adr.nat2t 0, Go (Adr.nat2t 0) ).
0
1 Module Type ModWithRecord.
2
3 Record foo : Type :=
4 { A : nat
5 ; B : nat
6 }.
7 End ModWithRecord.
8
9 Module Test_ModWithRecord (M : ModWithRecord).
10
11 Definition test1 : M.foo :=
12 {| M.A := 0
13 ; M.B := 2
14 |}.
15
16 Module B := M.
17
18 Definition test2 : M.foo :=
19 {| M.A := 0
20 ; M.B := 2
21 |}.
22 End Test_ModWithRecord.
0 Class Equiv A := equiv: A -> A -> Prop.
1 Infix "=" := equiv : type_scope.
2
3 Class Associative {A} f `{Equiv A} := associativity x y z : f x (f y z) = f (f x y) z.
4
5 Class SemiGroup A op `{Equiv A} := { sg_ass :>> Associative op }.
6
7 Class SemiLattice A op `{Equiv A} :=
8 { semilattice_sg :>> SemiGroup A op
9 ; redundant : Associative op
10 }.
0 Module Type ModA.
1 End ModA.
2 Module Type ModB(A : ModA).
3 End ModB.
4 Module Foo(A : ModA)(B : ModB A).
5 End Foo.
6
7 Print Module Foo.
0 Module Type Interface.
1 Parameter error: nat.
2 End Interface.
3
4 Module Implementation <: Interface.
5 Definition t := bool.
6 Definition error: t := false.
7 Fail End Implementation.
8 (* A UserError here is expected, not an uncaught Not_found *)
0 Inductive t (t':Type) : Type := A | B.
1 Definition d := match t with _ => 1 end. (* used to fail on list_chop *)
0 Set Implicit Arguments.
1 Unset Strict Implicit.
2 Parameter (M : nat -> Type).
3 Parameter (mp : forall (T1 T2 : Type) (f : T1 -> T2), list T1 -> list T2).
4
5 Definition foo (s : list {n : nat & M n}) :=
6 let exT := existT in mp (fun x => projT1 x) s.
0 Module Type Intf1.
1 Parameter T : Type.
2 Inductive a := A.
3 End Intf1.
4
5 Module Impl1 <: Intf1.
6 Definition T := unit.
7 Inductive a := A.
8 End Impl1.
9
10 Module Type Intf2
11 (Impl1 : Intf1).
12 Parameter x : Impl1.A=Impl1.A -> Impl1.T.
13 End Intf2.
14
15 Module Type Intf3
16 (Impl1 : Intf1)
17 (Impl2 : Intf2(Impl1)).
18 End Intf3.
19
20 Fail Module Toto
21 (Impl1' : Intf1)
22 (Impl2 : Intf2(Impl1'))
23 (Impl3 : Intf3(Impl1)(Impl2)).
24 (* A UserError is expected here, not an uncaught Not_found *)
25
26 (* NB : the Inductive above and the A=A weren't in the initial test,
27 they are here only to force an access to the environment
28 (cf [Printer.qualid_of_global]) and check that this env is ok. *)
33 | None => None
44 end
55 : option L -> option L
6 fun n : nat => let x := A n in ?12 ?15:T n
7 : forall n : nat, T n
8 fun n : nat => ?20 ?23:T n
9 : forall n : nat, T n
1111 end.
1212
1313 Print P.
14
15 (* Check that the heuristic to solve constraints is not artificially
16 dependent on the presence of a let-in, and in particular that the
17 second [_] below is not inferred to be n, as if obtained by
18 first-order unification with [T n] of the conclusion [T _] of the
19 type of the first [_]. *)
20
21 (* Note: exact numbers of evars are not important... *)
22
23 Inductive T (n:nat) : Type := A : T n.
24 Check fun n (x:=A n:T n) => _ _ : T n.
25 Check fun n => _ _ : T n.
55 Fail remember nat as X in H. (* This line used to succeed in 8.3 *)
66 Fail remember nat as X.
77 Abort.
8
9 (* Testing Ltac interpretation of remember (was not working up to r16181) *)
10
11 Goal (1 + 2 + 3 = 6).
12 let name := fresh "fresh" in
13 remember (1 + 2) as x eqn:name.
14 rewrite fresh.
15 Abort.
645645
646646 Module NZOrderedType (NZ : NZDecOrdSig')
647647 <: DecidableTypeFull <: OrderedTypeFull
648 := NZ <+ NZBaseProp <+ NZOrderProp <+ Compare2EqBool <+ HasEqBool2Dec.
648 := NZ <+ NZBaseProp <+ NZOrderProp NZ <+ Compare2EqBool <+ HasEqBool2Dec.
110110
111111 let check_bool_is_defined () =
112112 try let _ = Global.type_of_global Coqlib.glob_bool in ()
113 with _ -> raise (UndefinedCst "bool")
113 with e when Errors.noncritical e -> raise (UndefinedCst "bool")
114114
115115 let beq_scheme_kind_aux = ref (fun _ -> failwith "Undefined")
116116
303303 try let u,v = destApp c in
304304 let indc = destInd u in
305305 indc,v
306 with _-> let indc = destInd c in
307 indc,[||]
306 with e when Errors.noncritical e ->
307 let indc = destInd c in
308 indc,[||]
308309
309310 (*
310311 In the following, avoid is the list of names to avoid.
328329 else error ("Var "^(string_of_id s)^" seems unknown.")
329330 )
330331 in mkVar (find 1)
331 with _ -> (* if this happen then the args have to be already declared as a
332 Parameter*)
332 with e when Errors.noncritical e ->
333 (* if this happen then the args have to be already declared as a
334 Parameter*)
333335 (
334336 let mp,dir,lbl = repr_con (destConst v) in
335337 mkConst (make_con mp dir (mk_label (
375377 else error ("Var "^(string_of_id s)^" seems unknown.")
376378 )
377379 in mkVar (find 1)
378 with _ -> (* if this happen then the args have to be already declared as a
379 Parameter*)
380 with e when Errors.noncritical e ->
381 (* if this happen then the args have to be already declared as a
382 Parameter*)
380383 (
381384 let mp,dir,lbl = repr_con (destConst v) in
382385 mkConst (make_con mp dir (mk_label (
393396 else (
394397 let u,v = try destruct_ind tt1
395398 (* trick so that the good sequence is returned*)
396 with _ -> ind,[||]
399 with e when Errors.noncritical e -> ind,[||]
397400 in if u = ind
398401 then (Equality.replace t1 t2)::(Auto.default_auto)::(aux q1 q2)
399402 else (
426429 | ([],[]) -> []
427430 | _ -> error "Both side of the equality must have the same arity."
428431 in
429 let (ind1,ca1) = try destApp lft with
430 _ -> error "replace failed."
431 and (ind2,ca2) = try destApp rgt with
432 _ -> error "replace failed."
433 in
434 let (sp1,i1) = try destInd ind1 with
435 _ -> (try fst (destConstruct ind1) with _ ->
436 error "The expected type is an inductive one.")
437 and (sp2,i2) = try destInd ind2 with
438 _ -> (try fst (destConstruct ind2) with _ ->
439 error "The expected type is an inductive one.")
432 let (ind1,ca1) =
433 try destApp lft with e when Errors.noncritical e -> error "replace failed."
434 and (ind2,ca2) =
435 try destApp rgt with e when Errors.noncritical e -> error "replace failed."
436 in
437 let (sp1,i1) =
438 try destInd ind1 with e when Errors.noncritical e ->
439 try fst (destConstruct ind1) with e when Errors.noncritical e ->
440 error "The expected type is an inductive one."
441 and (sp2,i2) =
442 try destInd ind2 with e when Errors.noncritical e ->
443 try fst (destConstruct ind2) with e when Errors.noncritical e ->
444 error "The expected type is an inductive one."
440445 in
441446 if (sp1 <> sp2) || (i1 <> i2)
442447 then (error "Eq should be on the same type")
713718 (* Decidable equality *)
714719
715720 let check_not_is_defined () =
716 try ignore (Coqlib.build_coq_not ()) with _ -> raise (UndefinedCst "not")
721 try ignore (Coqlib.build_coq_not ())
722 with e when Errors.noncritical e -> raise (UndefinedCst "not")
717723
718724 (* {n=m}+{n<>m} part *)
719725 let compute_dec_goal ind lnamesparrec nparrec =
203203 (ce,Decl_kinds.IsDefinition Decl_kinds.Instance) in
204204 Typeclasses.add_instance (Typeclasses.new_instance cl (Some 100) true (ConstRef cst));
205205 new_instance_message ident typ def
206 with e -> msgnl (str"Error defining instance := "++pr_constr def++str" : "++pr_constr typ++str" "++Errors.print e)
206 with e when Errors.noncritical e ->
207 msgnl (str"Error defining instance := "++pr_constr def++str" : "++pr_constr typ++str" "++Errors.print e)
207208
208209 let rec iter_under_prod (f:rel_context->constr->unit) (ctx:rel_context) t = f ctx t;
209210 match kind_of_term t with
9595 Stack.push
9696 { label = Lib.current_command_label ();
9797 nproofs = List.length (Pfedit.get_all_proof_names ());
98 prfname = (try Some (Pfedit.get_current_proof_name ()) with _ -> None);
98 prfname =
99 (try Some (Pfedit.get_current_proof_name ())
100 with Proof_global.NoCurrentProof -> None);
99101 prfdepth = max 0 (Pfedit.current_proof_depth ());
100102 reachable = true;
101103 ngoals = get_ngoals ();
3636 let _ =
3737 Typeclasses.register_add_instance_hint
3838 (fun inst local pri ->
39 let path = try Auto.PathHints [global_of_constr inst] with _ -> Auto.PathAny in
39 let path =
40 try Auto.PathHints [global_of_constr inst]
41 with e when Errors.noncritical e -> Auto.PathAny
42 in
4043 Flags.silently (fun () ->
4144 Auto.add_hints local [typeclasses_db]
4245 (Auto.HintsResolveEntry
299302 let fullctx = Evarutil.nf_rel_context_evar !evars fullctx in
300303 let ce t = Evarutil.check_evars env Evd.empty !evars t in
301304 List.iter (fun (n, b, t) -> Option.iter ce b; ce t) fullctx;
302 let ctx = try named_of_rel_context fullctx with _ ->
303 error "Anonymous variables not allowed in contexts."
305 let ctx =
306 try named_of_rel_context fullctx
307 with e when Errors.noncritical e ->
308 error "Anonymous variables not allowed in contexts."
304309 in
305310 let fn (id, _, t) =
306311 if Lib.is_modtype () && not (Lib.sections_are_opened ()) then
4545 mSGNL (str ("No coqrc or coqrc."^Coq_config.version^
4646 " found. Skipping rcfile loading."))
4747 *)
48 with e ->
48 with reraise ->
4949 (msgnl (str"Load of rcfile failed.");
50 raise e)
50 raise reraise)
5151 else
5252 Flags.if_verbose msgnl (str"Skipping rcfile loading.")
5353
2323 let ver = input_line ch in
2424 let rev = input_line ch in
2525 (ver,rev)
26 with _ -> (Coq_config.version,Coq_config.date)
26 with e when Errors.noncritical e ->
27 (Coq_config.version,Coq_config.date)
2728
2829 let print_header () =
2930 let (ver,rev) = (get_version_date ()) in
309310 with Stream.Failure ->
310311 msgnl (Errors.print e); exit 1
311312 end
312 | e -> begin msgnl (Errors.print e); exit 1 end
313 | any -> begin msgnl (Errors.print any); exit 1 end
313314
314315 let init arglist =
315316 Sys.catch_break false; (* Ctrl-C is fatal during the initialisation *)
343344 load_vernacular ();
344345 compile_files ();
345346 outputstate ()
346 with e ->
347 with any ->
347348 flush_all();
348349 if not !batch_mode then message "Error during initialization:";
349 msgnl (Toplevel.print_toplevel_error e);
350 msgnl (Toplevel.print_toplevel_error any);
350351 exit 1
351352 end;
352353 if !batch_mode then
2727 open Printer
2828 open Glob_term
2929 open Evd
30 open Libnames
31 open Declarations
3032
3133 let pr_lconstr c = quote (pr_lconstr c)
3234 let pr_lconstr_env e c = quote (pr_lconstr_env e c)
306308 let fixenv = make_all_name_different fixenv in
307309 let pvd = pr_lconstr_env fixenv vdefj.(i).uj_val in
308310 str"Recursive definition is:" ++ spc () ++ pvd ++ str "."
309 with _ -> mt ())
311 with e when Errors.noncritical e -> mt ())
310312
311313 let explain_ill_typed_rec_body env sigma i names vdefj vargs =
312314 let vdefj = jv_nf_evar sigma vdefj in
541543 str "types given to " ++ str (string_of_id id) ++ str " differ"
542544 | NotConvertibleBodyField ->
543545 str "the body of definitions differs"
544 | NotConvertibleTypeField ->
545 str "types differ"
546 | NotConvertibleTypeField (env, typ1, typ2) ->
547 str "expected type" ++ spc () ++
548 quote (Printer.safe_pr_lconstr_env env typ2) ++ spc () ++
549 str "but found type" ++ spc () ++
550 quote (Printer.safe_pr_lconstr_env env typ1)
546551 | NotSameConstructorNamesField ->
547552 str "constructor names differ"
548553 | NotSameInductiveNameInBlockField ->
8888 | Quit -> Obj.magic (handler.quit () : unit)
8989 | About -> Obj.magic (handler.about () : coq_info)
9090 in Good res
91 with e ->
92 let (l, str) = handler.handle_exn e in
91 with any ->
92 let (l, str) = handler.handle_exn any in
9393 Fail (l,str)
9494
9595 (** * XML data marshalling *)
274274 let loc_s = int_of_string (List.assoc "loc_s" attrs) in
275275 let loc_e = int_of_string (List.assoc "loc_e" attrs) in
276276 Some (loc_s, loc_e)
277 with _ -> None
277 with e when e <> Sys.Break -> None
278278 in
279279 let msg = raw_string l in
280280 Fail (loc, msg)
236236 in
237237 let proof =
238238 try Some (Names.string_of_id (Proof_global.get_current_proof_name ()))
239 with _ -> None
239 with Proof_global.NoCurrentProof -> None
240240 in
241241 let allproofs =
242242 let l = Proof_global.get_all_proof_names () in
258258 | (Interface.Name_Pattern s, b) :: l ->
259259 let regexp =
260260 try Str.regexp s
261 with _ -> Util.error ("Invalid regexp: " ^ s)
261 with e when Errors.noncritical e ->
262 Util.error ("Invalid regexp: " ^ s)
262263 in
263264 extract_flags ((regexp, b) :: name) tpe subtpe mods blacklist l
264265 | (Interface.Type_Pattern s, b) :: l ->
453454 Xml_utils.print_xml !orig_stdout xml_answer;
454455 flush !orig_stdout
455456 done
456 with e ->
457 let msg = Printexc.to_string e in
457 with any ->
458 let msg = Printexc.to_string any in
458459 let r = "Fatal exception in coqtop:\n" ^ msg in
459460 pr_debug ("==> " ^ r);
460461 (try
461462 Xml_utils.print_xml !orig_stdout (fail r);
462463 flush !orig_stdout
463 with _ -> ());
464 with any -> ());
464465 exit 1
8585 (Hashtbl.create 17 : (string, string * scheme_object_function) Hashtbl.t)
8686
8787 let declare_scheme_object s aux f =
88 (try check_ident ("ind"^s) with _ ->
89 error ("Illegal induction scheme suffix: "^s));
88 (try check_ident ("ind"^s)
89 with e when Errors.noncritical e ->
90 error ("Illegal induction scheme suffix: "^s));
9091 let key = if aux = "" then s else aux in
9192 try
9293 let _ = Hashtbl.find scheme_object_table key in
158158 (strbrk "Required constant " ++ str s ++ str " undefined.")
159159 | AlreadyDeclared msg ->
160160 alarm what internal (msg ++ str ".")
161 | _ ->
161 | e when Errors.noncritical e ->
162162 alarm what internal
163163 (str "Unknown exception during scheme creation.")
164164
244244
245245 let declare_eq_decidability = declare_eq_decidability_scheme_with []
246246
247 let ignore_error f x = try ignore (f x) with _ -> ()
247 let ignore_error f x =
248 try ignore (f x) with e when Errors.noncritical e -> ()
248249
249250 let declare_rewriting_schemes ind =
250251 if Hipattern.is_inductive_equality ind then begin
265266 if Hipattern.is_equality_type (mkInd ind) then begin
266267 if
267268 try Coqlib.check_required_library Coqlib.logic_module_name; true
268 with _ -> false
269 with e when Errors.noncritical e -> false
269270 then
270271 ignore (define_individual_scheme congr_scheme_kind KernelVerbose None ind)
271272 else
228228 id,{const with const_entry_opaque = opacity},do_guard,persistence,hook
229229
230230 let save_named opacity =
231 let id,const,do_guard,persistence,hook = get_proof opacity in
232 save id const do_guard persistence hook
231 let p = Proof_global.give_me_the_proof () in
232 Proof.transaction p begin fun () ->
233 let id,const,do_guard,persistence,hook = get_proof opacity in
234 save id const do_guard persistence hook
235 end
233236
234237 let check_anonymity id save_ident =
235238 if atompart_of_id id <> string_of_id (default_thm_id) then
236239 error "This command can only be used for unnamed theorem."
237240
238241 let save_anonymous opacity save_ident =
239 let id,const,do_guard,persistence,hook = get_proof opacity in
240 check_anonymity id save_ident;
241 save save_ident const do_guard persistence hook
242 let p = Proof_global.give_me_the_proof () in
243 Proof.transaction p begin fun () ->
244 let id,const,do_guard,persistence,hook = get_proof opacity in
245 check_anonymity id save_ident;
246 save save_ident const do_guard persistence hook
247 end
242248
243249 let save_anonymous_with_strength kind opacity save_ident =
244 let id,const,do_guard,_,hook = get_proof opacity in
245 check_anonymity id save_ident;
246 (* we consider that non opaque behaves as local for discharge *)
247 save save_ident const do_guard (Global, Proof kind) hook
250 let p = Proof_global.give_me_the_proof () in
251 Proof.transaction p begin fun () ->
252 let id,const,do_guard,_,hook = get_proof opacity in
253 check_anonymity id save_ident;
254 (* we consider that non opaque behaves as local for discharge *)
255 save save_ident const do_guard (Global, Proof kind) hook
256 end
248257
249258 (* Starting a goal *)
250259
236236 | _ -> error "Box closed without being opened in format."
237237 else
238238 error "Empty format."
239 with e ->
239 with e when Errors.noncritical e ->
240240 Loc.raise loc e
241241
242242 (***********************)
276276
277277 let out_nt = function NonTerminal x -> x | _ -> assert false
278278
279 let msg_expected_form_of_recursive_notation =
280 "In the notation, the special symbol \"..\" must occur in\na configuration of the form \"x symbs .. symbs y\"."
281
279282 let rec find_pattern nt xl = function
280283 | Break n as x :: l, Break n' :: l' when n=n' ->
281284 find_pattern nt (x::xl) (l,l')
288291 | _, Break s :: _ | Break s :: _, _ ->
289292 error ("A break occurs on one side of \"..\" but not on the other side.")
290293 | _, [] ->
291 error ("The special symbol \"..\" must occur in a configuration of the form\n\"x symbs .. symbs y\".")
294 error msg_expected_form_of_recursive_notation
292295 | ((SProdList _ | NonTerminal _) :: _), _ | _, (SProdList _ :: _) ->
293296 anomaly "Only Terminal or Break expected on left, non-SProdList on right"
294297
295298 let rec interp_list_parser hd = function
296299 | [] -> [], List.rev hd
297300 | NonTerminal id :: tl when id = ldots_var ->
301 if hd = [] then error msg_expected_form_of_recursive_notation;
298302 let hd = List.rev hd in
299303 let ((x,y,sl),tl') = find_pattern (List.hd hd) [] (List.tl hd,tl) in
300304 let xyl,tl'' = interp_list_parser [] tl' in
336340 let is_numeral symbs =
337341 match List.filter (function Break _ -> false | _ -> true) symbs with
338342 | ([Terminal "-"; Terminal x] | [Terminal x]) ->
339 (try let _ = Bigint.of_string x in true with _ -> false)
343 (try let _ = Bigint.of_string x in true
344 with e when Errors.noncritical e -> false)
340345 | _ ->
341346 false
342347
994999 let with_lib_stk_protection f x =
9951000 let fs = Lib.freeze () in
9961001 try let a = f x in Lib.unfreeze fs; a
997 with e -> Lib.unfreeze fs; raise e
1002 with reraise -> Lib.unfreeze fs; raise reraise
9981003
9991004 let with_syntax_protection f x =
10001005 with_lib_stk_protection
9191 (try t.load_obj s
9292 with
9393 | (UserError _ | Failure _ | Anomaly _ | Not_found as u) -> raise u
94 | _ -> errorlabstrm "Mltop.load_object" (str"Cannot link ml-object " ++
95 str s ++ str" to Coq code."))
94 | e when Errors.noncritical e ->
95 errorlabstrm "Mltop.load_object"
96 (str"Cannot link ml-object " ++ str s ++ str" to Coq code."))
9697 (* TO DO: .cma loading without toplevel *)
9798 | WithoutTop ->
9899 IFDEF HasDynlink THEN
141142
142143 let convert_string d =
143144 try Names.id_of_string d
144 with _ ->
145 with e when Errors.noncritical e ->
145146 if_warn msg_warning
146147 (str ("Directory "^d^" cannot be used as a Coq identifier (skipped)"));
147148 flush_all ();
268269 try
269270 f name fname;
270271 msgnl (str (info^" done]"));
271 with e ->
272 with reraise ->
272273 msgnl (str (info^" failed]"));
273 raise e
274 raise reraise
274275
275276 (** Load a module for the first time (i.e. dynlink it)
276277 or simulate its reload (i.e. doing nothing except maybe
136136 try
137137 try
138138 is_matching pat (head c)
139 with _ ->
139 with e when Errors.noncritical e ->
140140 is_matching
141141 pat (head (Typing.type_of (Global.env()) Evd.empty c))
142142 with UserError _ ->
179179 str", line " ++ int line ++ str", characters " ++
180180 Cerrors.print_loc (make_loc (bp-bol,ep-bol))) ++ str":" ++
181181 fnl ()
182 with e ->
182 with e when Errors.noncritical e ->
183183 (close_in ic;
184184 hov 1 (errstrm ++ spc() ++ str"(invalid location):") ++ fnl ())
185185
207207 let make_prompt () =
208208 try
209209 (Names.string_of_id (Pfedit.get_current_proof_name ())) ^ " < "
210 with _ ->
210 with Proof_global.NoCurrentProof ->
211211 "Coq < "
212212
213213 (*let build_pending_list l =
339339 discard_to_dot (); e
340340 with
341341 | End_of_input -> End_of_input
342 | de -> if is_pervasive_exn de then de else e
342 | any -> if is_pervasive_exn any then any else e
343343
344344 (* do_vernac reads and executes a toplevel phrase, and print error
345345 messages when an exception is raised, except for the following:
353353 begin
354354 try
355355 raw_do_vernac top_buffer.tokens
356 with e ->
357 msgnl (print_toplevel_error (process_error e))
356 with any ->
357 msgnl (print_toplevel_error (process_error any))
358358 end;
359359 flush_all()
360360
373373 | Vernacexpr.Drop -> ()
374374 | End_of_input -> msgerrnl (mt ()); pp_flush(); exit 0
375375 | Vernacexpr.Quit -> exit 0
376 | e ->
376 | any ->
377377 msgerrnl (str"Anomaly. Please report.");
378378 loop ()
155155 match verb with
156156 | Some verb_ch -> close_in verb_ch
157157 | _ -> ()
158 with _ -> ()
158 with e when Errors.noncritical e -> ()
159159
160160 let verbose_phrase verbch loc =
161161 let loc = unloc loc in
231231 Lexer.restore_com_state cs;
232232 Pp.comments := cl;
233233 Dumpglob.coqdoc_unfreeze cds
234 with e ->
234 with reraise ->
235235 if !Flags.beautify_file then close_out !chan_beautify;
236236 chan_beautify := ch;
237237 Lexer.restore_com_state cs;
238238 Pp.comments := cl;
239239 Dumpglob.coqdoc_unfreeze cds;
240 raise e
240 raise reraise
241241 end
242242
243243 | VernacList l -> List.iter (fun (_,v) -> interp v) l
249249 (* If the command actually works, ignore its effects on the state *)
250250 States.with_state_protection
251251 (fun v -> interp v; raise HasNotFailed) v
252 with e -> match real_error e with
252 with e when Errors.noncritical e -> match real_error e with
253253 | HasNotFailed ->
254254 errorlabstrm "Fail" (str "The command has not failed !")
255255 | e ->
277277 States.with_heavy_rollback interpfun
278278 Cerrors.process_vernac_interp_error v;
279279 restore_timeout psh
280 with e -> restore_timeout psh; raise e
280 with reraise -> restore_timeout psh; raise reraise
281281 in
282282 try
283283 checknav loc com;
284284 current_timeout := !default_timeout;
285285 if do_beautify () then pr_new_syntax loc (Some com);
286286 interp com
287 with e ->
287 with any ->
288288 Format.set_formatter_out_channel stdout;
289 raise (DuringCommandInterp (loc, e))
289 raise (DuringCommandInterp (loc, any))
290290
291291 and read_vernac_file verbosely s =
292292 Flags.make_warn verbosely;
315315 end_inner_command (snd loc_ast);
316316 pp_flush ()
317317 done
318 with e -> (* whatever the exception *)
318 with reraise -> (* whatever the exception *)
319319 Format.set_formatter_out_channel stdout;
320320 close_input in_chan input; (* we must close the file first *)
321 match real_error e with
321 match real_error reraise with
322322 | End_of_input ->
323323 if do_beautify () then pr_new_syntax (make_loc (max_int,max_int)) None
324 | _ -> raise_with_file fname e
324 | _ -> raise_with_file fname reraise
325325
326326 (** [eval_expr : ?preserving:bool -> Pp.loc * Vernacexpr.vernac_expr -> unit]
327327 It executes one vernacular command. By default the command is
358358 Lib.mark_end_of_command (); (* in case we're still in coqtop init *)
359359 read_vernac_file verb file;
360360 if !Flags.beautify_file then close_out !chan_beautify;
361 with e ->
361 with reraise ->
362362 if !Flags.beautify_file then close_out !chan_beautify;
363 raise_with_file file e
363 raise_with_file file reraise
364364
365365 (* Compile a vernac file (f is assumed without .v suffix) *)
366366 let compile verbosely f =
294294 close ();
295295 msgnl (str ("Universes written to file \""^s^"\"."))
296296 with
297 e -> close (); raise e
297 reraise -> close (); raise reraise
298298
299299 let dump_universes sorted s =
300300 let g = Global.universes () in
330330 let print_located_library r =
331331 let (loc,qid) = qualid_of_reference r in
332332 try msg_found_library (Library.locate_qualified_library false qid)
333 with e -> msg_notfound_library loc qid e
333 with e when Errors.noncritical e -> msg_notfound_library loc qid e
334334
335335 let print_located_module r =
336336 let (loc,qid) = qualid_of_reference r in
363363 try
364364 let gr = Smartlocate.smart_global r in
365365 Dumpglob.add_glob (Genarg.loc_of_or_by_notation loc_of_reference r) gr
366 with _ -> ()
366 with e when Errors.noncritical e -> ()
367367 (**********)
368368 (* Syntax *)
369369
387387 (* Gallina *)
388388
389389 let start_proof_and_print k l hook =
390 check_locality (); (* early check, cf #2975 *)
390391 start_proof_com k l hook;
391392 print_subgoals ();
392393 if !pcoq <> None then (Option.get !pcoq).start_proof ()
909910 | None -> None
910911 | Some (o, k) ->
911912 try Some(ignore(Notation.find_scope k); k)
912 with _ -> Some (Notation.find_delimiters_scope o k)) scopes in
913 with e when Errors.noncritical e ->
914 Some (Notation.find_delimiters_scope o k)) scopes
915 in
913916 let some_scopes_specified = List.exists ((<>) None) scopes in
914917 let rargs =
915918 Util.list_map_filter (function (n, true) -> Some n | _ -> None)
14161419 let gr = Smartlocate.global_with_alias (Ident id) in
14171420 Dumpglob.add_glob (fst id) gr;
14181421 true
1419 with _ -> false in
1422 with e when Errors.noncritical e -> false in
14201423
14211424 if not globalized then begin
14221425 try begin match Lib.find_opening_node (snd id) with
5959 hunk()
6060 with
6161 | Drop -> raise Drop
62 | e ->
62 | reraise ->
6363 if !Flags.debug then
6464 msgnl (str"Vernac Interpreter " ++ str !loc);
65 raise e
65 raise reraise