Skip to content

Commit d6ab932

Browse files
committed
checkpoint
1 parent e09ce73 commit d6ab932

File tree

4 files changed

+64
-12
lines changed

4 files changed

+64
-12
lines changed

toplevel/ccompile.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ let compile opts stm_options injections copts ~echo ~f_in ~f_out =
4848
create_empty_file long_f_dot_vok in
4949
match mode with
5050
| BuildVo | BuildVok ->
51+
let recovery_mode = match mode with BuildVok -> true | _ -> false in
5152
let doc, sid = Topfmt.(in_phase ~phase:LoadingPrelude)
5253
Stm.new_doc
5354
Stm.{ doc_type = VoDoc long_f_dot_out; injections; } in
54-
let state = { doc; sid; proof = None; time = Option.map Vernac.make_time_output opts.config.time } in
55+
let state = { doc; sid; proof = None;
56+
time = Option.map Vernac.make_time_output opts.config.time;
57+
failed_proofs = []; in_recovery = false; recovery_mode} in
5558
let state = Load.load_init_vernaculars opts ~state in
5659
let ldir = Stm.get_ldir ~doc:state.doc in
5760
Aux_file.(start_aux_file
@@ -91,7 +94,9 @@ let compile opts stm_options injections copts ~echo ~f_in ~f_out =
9194
Stm.{ doc_type = VosDoc long_f_dot_out; injections;
9295
} in
9396

94-
let state = { doc; sid; proof = None; time = Option.map Vernac.make_time_output opts.config.time } in
97+
let state = { doc; sid; proof = None;
98+
time = Option.map Vernac.make_time_output opts.config.time;
99+
failed_proofs = []; in_recovery = false; recovery_mode = false } in
95100
let state = Load.load_init_vernaculars opts ~state in
96101
let ldir = Stm.get_ldir ~doc:state.doc in
97102
let source = source ldir long_f_dot_in in

toplevel/coqtop.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ let init_document opts stm_options injections =
127127
{ doc_type = Interactive opts.config.logic.toplevel_name;
128128
injections;
129129
}) in
130-
{ doc; sid; proof = None; time = Option.map Vernac.make_time_output opts.config.time }
130+
{ doc; sid; proof = None;
131+
time = Option.map Vernac.make_time_output opts.config.time;
132+
failed_proofs = [];
133+
in_recovery = false;
134+
recovery_mode = false}
131135

132136
let init_toploop opts stm_opts injections =
133137
let state = init_document opts stm_opts injections in

toplevel/vernac.ml

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ module State = struct
5757
sid : Stateid.t;
5858
proof : Proof.t option;
5959
time : time_output option;
60+
failed_proofs : Names.Id.t list;
61+
in_recovery : bool;
62+
recovery_mode : bool;
6063
}
6164

6265
end
@@ -72,26 +75,57 @@ let emit_time state com tstart tend =
7275

7376
let interp_vernac ~check ~state ({CAst.loc;_} as com) =
7477
let open State in
78+
79+
let current_proof_name =
80+
match state.proof with
81+
Some prf -> Some ((Proof.data prf).name)
82+
| None -> None in
83+
84+
let admitted_com =
85+
CAst.make { control = []; attrs = []; expr =
86+
(VernacSynPure (VernacEndProof Admitted))}in
7587
try
76-
let doc, nsid, ntip = Stm.add ~doc:state.doc ~ontop:state.sid (not !Flags.quiet) com in
88+
89+
let new_recovery_status, the_com =
90+
if state.in_recovery then
91+
(match Vernac_classifier.classify_vernac com with
92+
Vernacextend.VtQed _ -> false, Some admitted_com
93+
| _ -> true, None)
94+
else false, Some com in
95+
96+
let doc, nsid, ntip =
97+
match the_com with
98+
| Some com ->
99+
Stm.add ~doc:state.doc ~ontop:state.sid (not !Flags.quiet) com
100+
| None -> state.doc, state.sid, Stm.NewAddTip in
77101

78102
(* Main STM interaction *)
79103
if ntip <> Stm.NewAddTip then
80104
anomaly (str "vernac.ml: We got an unfocus operation on the toplevel!");
81-
105+
106+
82107
(* Force the command *)
83-
let () = if check then Stm.observe ~doc nsid in
108+
let () = if check && not state.in_recovery then Stm.observe ~doc nsid in
84109
let new_proof = Vernacstate.Declare.give_me_the_proof_opt () [@ocaml.warning "-3"] in
85-
{ state with doc; sid = nsid; proof = new_proof; }
86-
with reraise ->
87-
let (reraise, info) = Exninfo.capture reraise in
110+
{ state with doc; sid = nsid; proof = new_proof;
111+
in_recovery = new_recovery_status}
112+
with potentially_catched ->
113+
let (reraise, info) = Exninfo.capture potentially_catched in
88114
let info =
89115
(* Set the loc to the whole command if no loc *)
90116
match Loc.get_loc info, loc with
91117
| None, Some loc -> Loc.add_loc info loc
92-
| Some _, _ | _, None -> info
93-
in
94-
Exninfo.iraise (reraise, info)
118+
| Some _, _ | _, None -> info in
119+
if state.recovery_mode then
120+
match current_proof_name with
121+
Some proof_name ->
122+
if CErrors.noncritical potentially_catched then
123+
{state with in_recovery = true;
124+
failed_proofs = proof_name :: state.failed_proofs}
125+
else
126+
Exninfo.iraise (reraise, info)
127+
| None -> Exninfo.iraise (reraise, info)
128+
else Exninfo.iraise (reraise, info)
95129

96130
(* Load a vernac file. CErrors are annotated with file and location *)
97131
let load_vernac_core ~echo ~check ~state ?source file =
@@ -225,6 +259,12 @@ let beautify_pass ~doc ~comments ~ids ~filename =
225259
pass. *)
226260
let load_vernac ~echo ~check ~state ?source filename =
227261
let ostate, ids, comments = load_vernac_core ~echo ~check ~state ?source filename in
262+
if 1 <= List.length (ostate.failed_proofs) then
263+
user_err (Pp.str "proofs failed in this file "
264+
++ (ostate.failed_proofs
265+
|> List.rev
266+
|> prlist_with_sep pr_comma Names.Id.print)
267+
++ str ".");
228268
(* Pass for beautify *)
229269
if !Flags.beautify then beautify_pass ~doc:ostate.State.doc ~comments ~ids:(List.rev ids) ~filename;
230270
(* End pass *)

toplevel/vernac.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ module State : sig
2020
sid : Stateid.t;
2121
proof : Proof.t option;
2222
time : time_output option;
23+
failed_proofs : Names.Id.t list;
24+
in_recovery : bool;
25+
recovery_mode : bool
2326
}
2427

2528
end

0 commit comments

Comments
 (0)