From 7c85306e2fc7d7c607dbb1183ca35430f48f9193 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Fri, 24 Feb 2017 07:28:26 -0800 Subject: [PATCH] [infer][backend] remove duplicate function to store summaries to disk Summary: The function `Checkers.ST.store_summary` was only used in one place. This revision moves the functionality to the only place where this function was used, except the part swallowing `Sys_error` which may have the bad side-effect of making issues like race-conditions silent. Reviewed By: cristianoc Differential Revision: D4608790 fbshipit-source-id: b84c8ce --- infer/src/backend/InferAnalyze.re | 2 +- infer/src/backend/callbacks.ml | 10 ++++++++-- infer/src/backend/callbacks.mli | 2 +- infer/src/backend/specs.ml | 3 +++ infer/src/backend/specs.mli | 3 +++ infer/src/checkers/checkers.ml | 9 --------- infer/src/checkers/checkers.mli | 3 --- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/infer/src/backend/InferAnalyze.re b/infer/src/backend/InferAnalyze.re index 8cb9dedd9..277d3db24 100644 --- a/infer/src/backend/InferAnalyze.re +++ b/infer/src/backend/InferAnalyze.re @@ -23,7 +23,7 @@ let analyze_exe_env exe_env => { if Config.checkers { /* run the checkers only */ let call_graph = Exe_env.get_cg exe_env; - Callbacks.iterate_callbacks Checkers.ST.store_summary call_graph exe_env; + Callbacks.iterate_callbacks call_graph exe_env; Printer.write_all_html_files exe_env } else { /* run the full analysis */ diff --git a/infer/src/backend/callbacks.ml b/infer/src/backend/callbacks.ml index 0de1dbe40..db00d649f 100644 --- a/infer/src/backend/callbacks.ml +++ b/infer/src/backend/callbacks.ml @@ -133,7 +133,7 @@ let iterate_cluster_callbacks all_procs exe_env proc_names = !cluster_callbacks (** Invoke all procedure and cluster callbacks on a given environment. *) -let iterate_callbacks store_summary call_graph exe_env = +let iterate_callbacks call_graph exe_env = let procs_to_analyze = (* analyze all the currently defined procedures *) Cg.get_defined_nodes call_graph in @@ -178,6 +178,12 @@ let iterate_callbacks store_summary call_graph exe_env = ~f:(iterate_cluster_callbacks originally_defined_procs exe_env) (cluster procs_to_analyze); - List.iter ~f:store_summary procs_to_analyze; + (* Store all the summaries to disk *) + List.iter + ~f:(fun pname -> + let updated_summary_opt = + Option.map (Specs.get_summary pname) ~f:Specs.increment_timestamp in + Option.iter ~f:(Specs.store_summary pname) updated_summary_opt) + procs_to_analyze; Config.curr_language := saved_language diff --git a/infer/src/backend/callbacks.mli b/infer/src/backend/callbacks.mli index 6cdb18361..985e25fe1 100644 --- a/infer/src/backend/callbacks.mli +++ b/infer/src/backend/callbacks.mli @@ -45,4 +45,4 @@ val register_cluster_callback : Config.language option -> cluster_callback_t -> val unregister_all_callbacks : unit -> unit (** Invoke all the registered callbacks. *) -val iterate_callbacks : (Procname.t -> unit) -> Cg.t -> Exe_env.t -> unit +val iterate_callbacks : Cg.t -> Exe_env.t -> unit diff --git a/infer/src/backend/specs.ml b/infer/src/backend/specs.ml index 750422cb1..08ec85da1 100644 --- a/infer/src/backend/specs.ml +++ b/infer/src/backend/specs.ml @@ -673,6 +673,9 @@ let is_active summary = let get_timestamp summary = summary.timestamp +let increment_timestamp summary = + { summary with timestamp = summary.timestamp + 1 } + let get_proc_name summary = summary.attributes.ProcAttributes.proc_name diff --git a/infer/src/backend/specs.mli b/infer/src/backend/specs.mli index 2fae294e9..0e4c9a838 100644 --- a/infer/src/backend/specs.mli +++ b/infer/src/backend/specs.mli @@ -201,6 +201,9 @@ val get_summary_unsafe : string -> Procname.t -> summary (** Return the current timestamp for the summary *) val get_timestamp : summary -> int +(** Increment the number of times a summary has been updated *) +val increment_timestamp : summary -> summary + (** Return the status (active v.s. inactive) of a procedure summary *) val get_status : summary -> status diff --git a/infer/src/checkers/checkers.ml b/infer/src/checkers/checkers.ml index ce65cd01d..8da72352e 100644 --- a/infer/src/checkers/checkers.ml +++ b/infer/src/checkers/checkers.ml @@ -55,15 +55,6 @@ module ST = struct end end - let store_summary proc_name = - Option.iter - ~f:(fun summary -> - let summary' = - { summary with - Specs.timestamp = summary.Specs.timestamp + 1 } in - try Specs.store_summary proc_name summary' with Sys_error s -> L.err "%s@." s) - (Specs.get_summary proc_name) - let report_error tenv proc_name proc_desc diff --git a/infer/src/checkers/checkers.mli b/infer/src/checkers/checkers.mli index d2d1ca302..a540e7aa2 100644 --- a/infer/src/checkers/checkers.mli +++ b/infer/src/checkers/checkers.mli @@ -35,9 +35,6 @@ module ST : sig string -> unit - (** Store the summary to a .specs file. *) - val store_summary : Procname.t -> unit - end (* ST *) module PP : sig