Skip to content

Commit 77bcabb

Browse files
committed
Fix #3934: coqc -time -quick gives unreadable output
1 parent 727d4da commit 77bcabb

File tree

7 files changed

+30
-36
lines changed

7 files changed

+30
-36
lines changed

lib/system.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -287,20 +287,20 @@ let fmt_time_difference (startreal,ustart,sstart) (stopreal,ustop,sstop) =
287287
real (round (sstop -. sstart)) ++ str "s" ++
288288
str ")"
289289

290-
let with_time ~batch f x =
290+
let with_time ~batch ~header f x =
291291
let tstart = get_time() in
292292
let msg = if batch then "" else "Finished transaction in " in
293293
try
294294
let y = f x in
295295
let tend = get_time() in
296296
let msg2 = if batch then "" else " (successful)" in
297-
Feedback.msg_info (str msg ++ fmt_time_difference tstart tend ++ str msg2);
297+
Feedback.msg_info (header ++ str msg ++ fmt_time_difference tstart tend ++ str msg2);
298298
y
299299
with e ->
300300
let tend = get_time() in
301301
let msg = if batch then "" else "Finished failing transaction in " in
302302
let msg2 = if batch then "" else " (failure)" in
303-
Feedback.msg_info (str msg ++ fmt_time_difference tstart tend ++ str msg2);
303+
Feedback.msg_info (header ++ str msg ++ fmt_time_difference tstart tend ++ str msg2);
304304
raise e
305305

306306
(* We use argv.[0] as we don't want to resolve symlinks *)

lib/system.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ val time_difference : time -> time -> float (** in seconds *)
105105

106106
val fmt_time_difference : time -> time -> Pp.t
107107

108-
val with_time : batch:bool -> ('a -> 'b) -> 'a -> 'b
108+
val with_time : batch:bool -> header:Pp.t -> ('a -> 'b) -> 'a -> 'b
109109

110110
(** [get_toplevel_path program] builds a complete path to the
111111
executable denoted by [program]. This involves:

stm/stm.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,7 @@ end = struct (* {{{ *)
20172017
find ~time:false ~batch:false ~fail:false e in
20182018
let st = Vernacstate.freeze_interp_state ~marshallable:false in
20192019
Vernacentries.with_fail st fail (fun () ->
2020-
(if time then System.with_time ~batch else (fun x -> x)) (fun () ->
2020+
(if time then System.with_time ~batch ~header:(Pp.mt ()) else (fun x -> x)) (fun () ->
20212021
ignore(TaskQueue.with_n_workers nworkers (fun queue ->
20222022
Proof_global.with_current_proof (fun _ p ->
20232023
let Proof.{goals} = Proof.data p in

toplevel/vernac.ml

-29
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,6 @@ let vernac_echo ?loc in_chan = let open Loc in
3737
Feedback.msg_notice @@ str @@ really_input_string in_chan len
3838
) loc
3939

40-
(* For coqtop -time, we display the position in the file,
41-
and a glimpse of the executed command *)
42-
43-
let pp_cmd_header {CAst.loc;v=com} =
44-
let shorten s =
45-
if Unicode.utf8_length s > 33 then (Unicode.utf8_sub s 0 30) ^ "..." else s
46-
in
47-
let noblank s = String.map (fun c ->
48-
match c with
49-
| ' ' | '\n' | '\t' | '\r' -> '~'
50-
| x -> x
51-
) s
52-
in
53-
let (start,stop) = Option.cata Loc.unloc (0,0) loc in
54-
let safe_pr_vernac x =
55-
try Ppvernac.pr_vernac x
56-
with e -> str (Printexc.to_string e) in
57-
let cmd = noblank (shorten (string_of_ppcmds (safe_pr_vernac com)))
58-
in str "Chars " ++ int start ++ str " - " ++ int stop ++
59-
str " [" ++ str cmd ++ str "] "
60-
61-
(* This is a special case where we assume we are in console batch mode
62-
and take control of the console.
63-
*)
64-
let print_cmd_header com =
65-
Pp.pp_with !Topfmt.std_ft (pp_cmd_header com);
66-
Format.pp_print_flush !Topfmt.std_ft ()
67-
6840
(* Reenable when we get back to feedback printing *)
6941
(* let is_end_of_input any = match any with *)
7042
(* Stm.End_of_input -> true *)
@@ -88,7 +60,6 @@ let interp_vernac ~check ~interactive ~state ({CAst.loc;_} as com) =
8860
due to the way it prints. *)
8961
let com = if state.time
9062
then begin
91-
print_cmd_header com;
9263
CAst.make ?loc @@ VernacTime(state.time,com)
9364
end else com in
9465
let doc, nsid, ntip = Stm.add ~doc:state.doc ~ontop:state.sid (not !Flags.quiet) com in

vernac/topfmt.ml

+21
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,24 @@ let with_output_to_file fname func input =
406406
deep_ft := Util.pi3 old_fmt;
407407
close_out channel;
408408
Exninfo.iraise reraise
409+
410+
(* For coqtop -time, we display the position in the file,
411+
and a glimpse of the executed command *)
412+
413+
let pr_cmd_header {CAst.loc;v=com} =
414+
let shorten s =
415+
if Unicode.utf8_length s > 33 then (Unicode.utf8_sub s 0 30) ^ "..." else s
416+
in
417+
let noblank s = String.map (fun c ->
418+
match c with
419+
| ' ' | '\n' | '\t' | '\r' -> '~'
420+
| x -> x
421+
) s
422+
in
423+
let (start,stop) = Option.cata Loc.unloc (0,0) loc in
424+
let safe_pr_vernac x =
425+
try Ppvernac.pr_vernac x
426+
with e -> str (Printexc.to_string e) in
427+
let cmd = noblank (shorten (string_of_ppcmds (safe_pr_vernac com)))
428+
in str "Chars " ++ int start ++ str " - " ++ int stop ++
429+
str " [" ++ str cmd ++ str "] "

vernac/topfmt.mli

+1
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ val print_err_exn : exn -> unit
7171
redirected to a file [file] *)
7272
val with_output_to_file : string -> ('a -> 'b) -> 'a -> 'b
7373

74+
val pr_cmd_header : Vernacexpr.vernac_control CAst.t -> Pp.t

vernac/vernacentries.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -2388,8 +2388,9 @@ let interp ?(verbosely=true) ?proof ~st {CAst.loc;v=c} =
23882388
control v
23892389
| VernacRedirect (s, {v}) ->
23902390
Topfmt.with_output_to_file s control v
2391-
| VernacTime (batch, {v}) ->
2392-
System.with_time ~batch control v;
2391+
| VernacTime (batch, com) ->
2392+
let header = if batch then Topfmt.pr_cmd_header com else Pp.mt () in
2393+
System.with_time ~batch ~header control com.CAst.v;
23932394

23942395
and aux ~atts : _ -> unit =
23952396
function

0 commit comments

Comments
 (0)