-
Notifications
You must be signed in to change notification settings - Fork 37
Make :reproducible-resource-limit standards-compliant #1353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,8 +32,16 @@ module DO = D_state_option | |
| module Sy = Symbols | ||
| module O = Options | ||
|
|
||
| type limits = | ||
| { reproducible_resource_limit : int | ||
| } | ||
|
|
||
| let empty_limits = | ||
| { reproducible_resource_limit = 0 } | ||
|
|
||
| type parse_result = { | ||
| path : [`Stdin | `File of string]; | ||
| limits : limits; | ||
| } | ||
|
|
||
| exception Exit_with_code of int | ||
|
|
@@ -172,7 +180,7 @@ let interactive_prompt st = | |
| Some "alt-ergo>" | ||
| | _ -> None | ||
|
|
||
| let process_source ?selector_inst ~print_status src = | ||
| let process_source ?selector_inst ~print_status ?(limits = empty_limits) src = | ||
| let () = Dolmen_loop.Code.init [] in | ||
|
|
||
| let hook_on_status status i = | ||
|
|
@@ -184,7 +192,7 @@ let process_source ?selector_inst ~print_status src = | |
| in | ||
|
|
||
| let solve (module SAT : Sat_solver_sig.S) | ||
| all_context (cnf, goal_name) = | ||
| ~limit all_context (cnf, goal_name) = | ||
| let module FE = Frontend.Make (SAT) in | ||
| if Options.get_debug_commands () then | ||
| Printer.print_dbg "@[<v 2>goal %s:@ %a@]@." | ||
|
|
@@ -203,6 +211,11 @@ let process_source ?selector_inst ~print_status src = | |
| let ftdn_env = FE.init_env ?selector_inst used_context in | ||
| let () = | ||
| try | ||
| (* At the moment we ignore the [Error] case here: the unknown reason | ||
| should have already been set internally by the solver when the | ||
| [Util.Step_limit_reached] exception was raised. *) | ||
|
Comment on lines
+214
to
+216
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which error case?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Old comment from a previous implementation, I'll remove it. |
||
| let ( let& ) f scope = f ~scope in | ||
| let& () = Steps.with_step_limit limit in | ||
|
Comment on lines
+217
to
+218
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The operator seems to be only used once (right after its declaration), I don't know if it's worth keeping it, inlining it would make the code more readable.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd increase indentation though ;) It is the "resource binding" operator from memprof-limits — I think it is useful to have a way to explicitly say "we are creating a scope where resources (here a fixed number of steps) are acquired" rather than a simple function call, but did not want to put it in a module of its own for a single use. I can add a short documentation to explain this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I was not familiar with it, I agree it is useful, I don't know if there is a better place to put it that within the code. And yes a comment would be helpful :) |
||
| List.iter | ||
| (FE.process_decl ~hook_on_status ftdn_env) | ||
| cnf | ||
|
|
@@ -262,6 +275,10 @@ let process_source ?selector_inst ~print_status src = | |
| State.create_key ~pipe:"" "named_terms" | ||
| in | ||
|
|
||
| let reproducible_resource_limit : int State.key = | ||
| State.create_key ~pipe:"" ":reproducible-resource-limit" | ||
| in | ||
|
|
||
| let set_steps_bound i st = | ||
| try DO.Steps.set i st with | ||
| Invalid_argument _ -> (* Raised by Steps.set_steps_bound *) | ||
|
|
@@ -475,22 +492,14 @@ let process_source ?selector_inst ~print_status src = | |
| st | ||
| | ":reproducible-resource-limit", Symbol { name = Simple level; _ } -> | ||
| begin | ||
| if Sys.unix then | ||
| match int_of_string_opt level with | ||
| | Some i when i > 0 -> | ||
| Options.set_timelimit_per_goal true; | ||
| Options.set_timelimit (float_of_int i /. 1000.) | ||
| | Some 0 -> | ||
| Options.set_timelimit_per_goal false; | ||
| Options.set_timelimit 0. | ||
| | None | Some _ -> | ||
| print_wrn_opt ~loc ~name:":reproducible-resource-limit" | ||
| "nonnegative integer" value | ||
| else | ||
| warning ~loc | ||
| "reproducible-resource-limit is only supported on Unix" | ||
| end; | ||
| st | ||
| match int_of_string_opt level with | ||
| | Some i when i >= 0 -> | ||
| State.set reproducible_resource_limit i st | ||
| | None | Some _ -> | ||
| print_wrn_opt ~loc ~name:":reproducible-resource-limit" | ||
| "nonnegative integer" value; | ||
| st | ||
| end | ||
| | ":sat-solver", Symbol { name = Simple solver; _ } -> ( | ||
| if not (is_solver_ctx_empty (State.get solver_ctx_key st)) then ( | ||
| recoverable_error ~loc | ||
|
|
@@ -786,6 +795,9 @@ let process_source ?selector_inst ~print_status src = | |
| in | ||
| let solve_res = | ||
| solve | ||
| ~limit:( | ||
| State.get_or ~default:limits.reproducible_resource_limit | ||
| reproducible_resource_limit st) | ||
| (DO.SatSolverModule.get st) | ||
| all_context | ||
| (cnf, name) | ||
|
|
@@ -967,9 +979,9 @@ let process_source ?selector_inst ~print_status src = | |
| in | ||
| d_fe src | ||
|
|
||
| let main { path } = | ||
| let main { path ; limits } = | ||
| try | ||
| process_source | ||
| process_source ~limits | ||
| ~print_status:Frontend.print_status | ||
| (path :> D_loop.State.source) | ||
| with Exit_with_code code -> exit code | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe give a bit more details here? (e.g. that what we measure is the number of steps and that if the limit is 0 then there is no limit)