Skip to content

Commit dc249d5

Browse files
namasikanamclaude
andcommitted
goal printing infrastructure: -upto and -lastgoals options
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7035747 commit dc249d5

5 files changed

Lines changed: 55 additions & 7 deletions

File tree

src/ec.ml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ let main () =
415415
(*---*) gccompact : int option;
416416
(*---*) docgen : bool;
417417
(*---*) outdirp : string option;
418+
(*---*) upto : (int * int option) option;
418419
mutable trace : trace1 list option;
419420
}
420421

@@ -493,6 +494,7 @@ let main () =
493494
; gccompact = None
494495
; docgen = false
495496
; outdirp = None
497+
; upto = None
496498
; trace = None }
497499

498500
end
@@ -511,8 +513,9 @@ let main () =
511513

512514
let gcstats = cmpopts.cmpo_gcstats in
513515
let progress = if cmpopts.cmpo_script then `Script else `Human in
516+
let lastgoals = cmpopts.cmpo_lastgoals in
514517
let terminal =
515-
lazy (T.from_channel ~name ~gcstats ~progress (open_in name))
518+
lazy (T.from_channel ~name ~gcstats ~progress ~lastgoals (open_in name))
516519
in
517520

518521
let trace0 =
@@ -528,6 +531,7 @@ let main () =
528531
; gccompact = cmpopts.cmpo_compact
529532
; docgen = false
530533
; outdirp = None
534+
; upto = cmpopts.cmpo_upto
531535
; trace = trace0 }
532536

533537
end
@@ -572,6 +576,7 @@ let main () =
572576
; gccompact = None
573577
; docgen = true
574578
; outdirp = docopts.doco_outdirp
579+
; upto = None
575580
; trace = None }
576581
end
577582

@@ -669,6 +674,16 @@ let main () =
669674
if T.interactive terminal then
670675
T.notice ~immediate:true `Warning copyright terminal;
671676

677+
(* Check if a location is past the -upto point *)
678+
let past_upto (loc : EcLocation.t) =
679+
match state.upto with
680+
| None -> false
681+
| Some (line, col) ->
682+
let (sl, sc) = loc.loc_start in
683+
sl > line || (sl = line && match col with
684+
| None -> false
685+
| Some c -> sc >= c) in
686+
672687
try
673688
if T.interactive terminal then Sys.catch_break true;
674689

@@ -737,6 +752,14 @@ let main () =
737752
List.iter
738753
(fun p ->
739754
let loc = p.EP.gl_action.EcLocation.pl_loc in
755+
756+
(* -upto: if this command starts past the target, print goals and exit *)
757+
if past_upto loc then begin
758+
T.finalize terminal;
759+
EcCommands.pp_current_goal ~all:true Format.std_formatter;
760+
exit 0
761+
end;
762+
740763
let timed = p.EP.gl_debug = Some `Timed in
741764
let break = p.EP.gl_debug = Some `Break in
742765
let ignore_fail = ref false in

src/ecOptions.ml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ and cmp_option = {
2626
cmpo_noeco : bool;
2727
cmpo_script : bool;
2828
cmpo_trace : bool;
29+
cmpo_lastgoals : bool;
30+
cmpo_upto : (int * int option) option;
2931
}
3032

3133
and cli_option = {
@@ -349,6 +351,8 @@ let specs = {
349351
`Spec ("script" , `Flag , "Computer-friendly output");
350352
`Spec ("no-eco" , `Flag , "Do not cache verification results");
351353
`Spec ("trace" , `Flag , "Save all goals & messages in .eco");
354+
`Spec ("lastgoals" , `Flag , "Print last unproved goals on failure");
355+
`Spec ("upto" , `String, "Compile up to LINE or LINE:COL and print goals");
352356
`Spec ("compact", `Int , "<internal>")]);
353357

354358
("cli", "Run EasyCrypt top-level", [
@@ -519,7 +523,14 @@ let cmp_options_of_values ini values input =
519523
cmpo_tstats = get_string "tstats" values;
520524
cmpo_noeco = get_flag "no-eco" values;
521525
cmpo_script = get_flag "script" values;
522-
cmpo_trace = get_flag "trace" values; }
526+
cmpo_trace = get_flag "trace" values;
527+
cmpo_lastgoals = get_flag "lastgoals" values;
528+
cmpo_upto =
529+
get_string "upto" values |> Option.map (fun s ->
530+
match String.split_on_char ':' s with
531+
| [line] -> (int_of_string line, None)
532+
| [line; col] -> (int_of_string line, Some (int_of_string col))
533+
| _ -> failwith "invalid -upto format: expected LINE or LINE:COL"); }
523534

524535
let runtest_options_of_values ini values (input, scenarios) =
525536
{ runo_input = input;

src/ecOptions.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ and cmp_option = {
2222
cmpo_noeco : bool;
2323
cmpo_script : bool;
2424
cmpo_trace : bool;
25+
cmpo_lastgoals : bool;
26+
cmpo_upto : (int * int option) option;
2527
}
2628

2729
and cli_option = {

src/ecTerminal.ml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ type progress = [ `Human | `Script | `Silent ]
148148
class from_channel
149149
?(gcstats : bool = true)
150150
?(progress : progress option)
151-
~(name : string)
152-
(stream : in_channel)
151+
?(lastgoals : bool = false)
152+
~(name : string)
153+
(stream : in_channel)
153154
: terminal
154155

155156
= object(self)
@@ -160,6 +161,7 @@ class from_channel
160161
val mutable tick = -1
161162
val mutable loc = LC._dummy
162163
val mutable gc = None
164+
val mutable last_goals = ""
163165
val mutable progress =
164166
progress |> ofdfl (fun () ->
165167
if
@@ -280,7 +282,14 @@ class from_channel
280282

281283
method finish (status : status) =
282284
match status with
283-
| `ST_Ok -> ()
285+
| `ST_Ok ->
286+
if lastgoals then begin
287+
let buf = Buffer.create 256 in
288+
let fmt = Format.formatter_of_buffer buf in
289+
EcCommands.pp_current_goal ~all:true fmt;
290+
Format.pp_print_flush fmt ();
291+
last_goals <- Buffer.contents buf
292+
end
284293

285294
| `ST_Failure e -> begin
286295
let (subloc, e) =
@@ -290,6 +299,8 @@ class from_channel
290299
let msg = String.strip (EcPException.tostring e) in
291300

292301
self#_clean_progress_line ();
302+
if lastgoals && last_goals <> "" then
303+
Format.printf "%s%!" last_goals;
293304
self#_notice ?subloc ~immediate:true `Critical msg;
294305
self#_update_progress;
295306
self#_clean_progress_line ~erase:false ();
@@ -314,5 +325,5 @@ class from_channel
314325
Format.pp_set_margin Format.err_formatter i
315326
end
316327

317-
let from_channel ?gcstats ?progress ~name stream =
318-
new from_channel ?gcstats ?progress ~name stream
328+
let from_channel ?gcstats ?progress ?lastgoals ~name stream =
329+
new from_channel ?gcstats ?progress ?lastgoals ~name stream

src/ecTerminal.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type progress = [ `Human | `Script | `Silent ]
2222
val from_channel :
2323
?gcstats:bool
2424
-> ?progress:progress
25+
-> ?lastgoals:bool
2526
-> name:string
2627
-> in_channel
2728
-> terminal

0 commit comments

Comments
 (0)