Skip to content

Commit 6125ee1

Browse files
authored
Remove get file (OCamlPro#1286)
* Remove the option get_file One step after another, we get rid of the global state! * Create a new type for parse_command result
1 parent d1de99e commit 6125ee1

File tree

12 files changed

+36
-49
lines changed

12 files changed

+36
-49
lines changed

src/bin/common/parse_command.ml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,12 @@ let mk_opts file () () debug_flags ddebug_flags dddebug_flags backtrace
568568
Debug.mk ~verbosity:3 dddebug_flags;
569569
if backtrace then Printexc.record_backtrace true;
570570
Rule.mk rule;
571-
if halt_opt then `Ok false
571+
let path =
572+
match file with
573+
| Some f -> `File f
574+
| None -> `Stdin
575+
in
576+
if halt_opt then `Ok None
572577
(* If save_used_context was invoked as an option it should
573578
automatically set unsat_core to true *)
574579
else begin
@@ -579,14 +584,13 @@ let mk_opts file () () debug_flags ddebug_flags dddebug_flags backtrace
579584
Filename.chop_extension f
580585
with Invalid_argument _ -> f
581586
in
582-
set_file f;
583587
set_session_file (base_file^".agr");
584588
set_used_context_file base_file;
585589
| _ -> ()
586590
);
587591

588592
Gc.set { (Gc.get()) with Gc.allocation_policy = gc };
589-
`Ok true
593+
`Ok (Some path)
590594
end
591595

592596
let mk_output_channel_opt regular_output diagnostic_output =
@@ -1500,7 +1504,8 @@ let main =
15001504
($(i,.mlw) and $(i,.why) are deprecated), \
15011505
$(i,.smt2) or $(i,.psmt2)." in
15021506
let i = Arg.(info [] ~docv:"FILE" ~doc) in
1503-
Arg.(value & pos ~rev:true 0 (some file) None & i) in
1507+
Arg.(value & pos ~rev:true 0 (some file) None & i)
1508+
in
15041509

15051510
let doc = "Execute Alt-Ergo on the given file." in
15061511
let exits = Cmd.Exit.defaults in
@@ -1576,8 +1581,8 @@ let parse_cmdline_arguments () =
15761581
at_exit Options.Output.close_all;
15771582
let r = Cmd.eval_value main in
15781583
match r with
1579-
| Ok `Ok true -> ()
1580-
| Ok `Ok false -> raise (Exit_parse_command 0)
1584+
| Ok `Ok Some path -> Solving_loop.{ path }
1585+
| Ok `Ok None -> raise (Exit_parse_command 0)
15811586
| Ok `Version | Ok `Help -> exit 0
15821587
| Error `Parse -> exit Cmd.Exit.cli_error
15831588
| Error `Term -> exit Cmd.Exit.internal_error

src/bin/common/parse_command.mli

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
(** {1 Parse_command module used at start-up to parse the command line} *)
2929

3030
(** Only exported function. Calling it will parse the command line options
31-
and set them accordingly for the rest of the execution *)
32-
val parse_cmdline_arguments : unit -> unit
33-
31+
and set them accordingly for the rest of the execution. *)
32+
val parse_cmdline_arguments : unit -> Solving_loop.parse_result
3433

3534
(** Exception used to exit with corresponding retcode *)
3635
exception Exit_parse_command of int

src/bin/common/solving_loop.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ module DO = D_state_option
3232
module Sy = Symbols
3333
module O = Options
3434

35+
type parse_result = {
36+
path : [`Stdin | `File of string];
37+
}
38+
3539
exception Exit_with_code of int
3640

3741
type solver_ctx = {
@@ -937,11 +941,9 @@ let process_source ?selector_inst ~print_status src =
937941
in
938942
d_fe src
939943

940-
let main () =
941-
let path = Options.get_file () in
944+
let main { path } =
942945
try
943-
if String.equal path "" then
944-
process_source ~print_status:Frontend.print_status `Stdin
945-
else
946-
process_source ~print_status:Frontend.print_status @@ (`File path)
946+
process_source
947+
~print_status:Frontend.print_status
948+
(path :> D_loop.State.source)
947949
with Exit_with_code code -> exit code

src/bin/common/solving_loop.mli

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ exception Exit_with_code of int
2929
(** Exception raised to notify that [process_source] cannot continue.
3030
The integer corresponds to an error code. *)
3131

32-
val main : unit -> unit
33-
(** Main function solve the input problem. The processed source is given
34-
by the file located at [Options.get_file ()]. *)
32+
type parse_result = {
33+
path : [`Stdin | `File of string];
34+
(** Path to the input file. *)
35+
}
36+
37+
val main : parse_result -> unit
38+
(** [main path] solves the input problem [path]. *)
3539

3640
val process_source :
3741
?selector_inst:(AltErgoLib.Expr.t -> bool) ->

src/bin/js/main_text_js.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ let parse_cmdline () =
3434
with Parse_command.Exit_parse_command i -> exit i
3535

3636
let () =
37-
parse_cmdline ();
37+
let path = parse_cmdline () in
3838
AltErgoLib.Printer.init_colors ();
3939
AltErgoLib.Printer.init_output_format ();
4040
Signals_profiling.init_signals ();
4141
Logs.set_reporter (AltErgoLib.Printer.reporter);
42-
Solving_loop.main ()
42+
Solving_loop.main path

src/bin/js/options_interface.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,3 @@ let set_options r =
193193
set_options_opt Options.set_restricted r.restricted;
194194
set_options_opt Options.set_tighten_vars r.tighten_vars;
195195
set_options_opt Options.set_timers r.timers;
196-
197-
set_options_opt Options.set_file r.file;

src/bin/js/worker_example.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ let solve () =
6565
let options =
6666
{(Worker_interface.init_options ()) with
6767
input_format = None;
68-
file = Some "try-alt-ergo";
6968
debug = Some true;
7069
verbose = Some true;
7170
answers_with_loc = Some false;

src/bin/js/worker_interface.ml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@ type options = {
252252
restricted : bool option;
253253
tighten_vars : bool option;
254254
timers : bool option;
255-
256-
file : string option;
257255
}
258256

259257
let init_options () = {
@@ -351,8 +349,6 @@ let init_options () = {
351349
restricted = None;
352350
tighten_vars = None;
353351
timers = None;
354-
355-
file = None;
356352
}
357353

358354

@@ -496,7 +492,7 @@ let opt7_encoding =
496492
conv
497493
(fun opt7 -> opt7)
498494
(fun opt7 -> opt7)
499-
(obj9
495+
(obj8
500496
(opt "no_contracongru" bool)
501497
(opt "no_fm" bool)
502498
(opt "no_nla" bool)
@@ -505,7 +501,6 @@ let opt7_encoding =
505501
(opt "restricted" bool)
506502
(opt "tighten_vars" bool)
507503
(opt "timers" bool)
508-
(opt "file" string)
509504
)
510505

511506
let options_encoding =
@@ -620,8 +615,7 @@ let options_to_json opt =
620615
opt.no_theory,
621616
opt.restricted,
622617
opt.tighten_vars,
623-
opt.timers,
624-
opt.file)
618+
opt.timers)
625619
in
626620
let json_all_options = Json.construct options_encoding
627621
(dbg_opt1,
@@ -731,8 +725,7 @@ let options_from_json options =
731725
no_theory,
732726
restricted,
733727
tighten_vars,
734-
timers,
735-
file) = all_opt7 in
728+
timers) = all_opt7 in
736729
{
737730
debug;
738731
debug_ac;
@@ -813,8 +806,7 @@ let options_from_json options =
813806
no_theory;
814807
restricted;
815808
tighten_vars;
816-
timers;
817-
file
809+
timers
818810
}
819811
| Error _e -> assert false
820812

src/bin/js/worker_interface.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ type options = {
149149
restricted : bool option;
150150
tighten_vars : bool option;
151151
timers : bool option;
152-
153-
file : string option;
154152
}
155153

156154
type used_axiom =

src/bin/text/main_text.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ let parse_cmdline () =
3434
with Parse_command.Exit_parse_command i -> exit i
3535

3636
let () =
37-
parse_cmdline ();
37+
let path = parse_cmdline () in
3838
AltErgoLib.Printer.init_colors ();
3939
AltErgoLib.Printer.init_output_format ();
4040
Signals_profiling.init_signals ();
4141
Logs.set_reporter (AltErgoLib.Printer.reporter);
42-
Solving_loop.main ()
42+
Solving_loop.main path

0 commit comments

Comments
 (0)