Add function to delete summary from disk and caches

Summary:
Add a function to delete a summary from disk and caches

This is needed so that summaries corresponding to invalidated procedures can be removed (as part of incremental diff analysis)

Reviewed By: ngorogiannis

Differential Revision: D16332752

fbshipit-source-id: 7d3c7a121
master
Phoebe Nichols 6 years ago committed by Facebook Github Bot
parent 0682ccc1e9
commit a4c1e94c5f

@ -63,3 +63,7 @@ let summary_iterator spec_files =
let iter_from_config ~f = summary_iterator spec_files_from_cmdline f
let iter ~f = summary_iterator load_specfiles f
let delete pname =
let filename = Summary.specs_filename_of_procname pname |> DB.filename_to_string in
Unix.unlink filename ; Ondemand.remove_from_cache pname ; Summary.remove_from_cache pname

@ -7,8 +7,7 @@
open! IStd
(* Suppress unused value warning because this method is intended for incremental analysis, which is
not yet finished *)
(* Suppress unused value warning until this is used for incremental diff analysis *)
val iter : f:(Summary.t -> unit) -> unit
[@@warning "-32"]
(** Iterates over all summaries from the .specs files *)
@ -16,3 +15,9 @@ val iter : f:(Summary.t -> unit) -> unit
val iter_from_config : f:(Summary.t -> unit) -> unit
(** Iterates over all sumaries from the .specs files unless a list of specs files has been passed on
the command line *)
(* Suppress unused value warning until this is used for incremental diff analysis *)
val delete : Typ.Procname.t -> unit
[@@warning "-32"]
(** Delete the .specs file associated with a summary and remove the summary from the caches in
Summary.ml and ondemand.ml *)

@ -102,6 +102,8 @@ let cache : cache = Typ.Procname.Hash.create 128
let clear_cache () = Typ.Procname.Hash.clear cache
let remove_from_cache pname = Typ.Procname.Hash.remove cache pname
let pp_errlog fmt err_log =
F.fprintf fmt "ERRORS: @[<h>%a@]@\n%!" Errlog.pp_errors err_log ;
F.fprintf fmt "WARNINGS: @[<h>%a@]" Errlog.pp_warnings err_log
@ -147,8 +149,8 @@ let specs_filename pname =
pname_file ^ Config.specs_files_suffix
(** path to the .specs file for the given procedure in the current results directory *)
let res_dir_specs_filename pname =
(** Return the path to the .specs file for the given procedure in the current results directory *)
let specs_filename_of_procname pname =
DB.Results_dir.path_to_filename DB.Results_dir.Abs_root
[Config.specs_dir_name; specs_filename pname]
@ -191,7 +193,7 @@ let load_summary_to_spec_table =
in
fun proc_name ->
let summ_opt =
load_from_file (res_dir_specs_filename proc_name)
load_from_file (specs_filename_of_procname proc_name)
|> or_from load_from_file specs_models_filename proc_name
|> or_from load_summary_ziplibs specs_filename proc_name
|> or_load_summary_libs Config.specs_library proc_name
@ -233,7 +235,7 @@ let store (summ : t) =
(* Make sure the summary in memory is identical to the saved one *)
add proc_name final_summary ;
Serialization.write_to_file summary_serializer
(res_dir_specs_filename proc_name)
(specs_filename_of_procname proc_name)
~data:final_summary
@ -264,7 +266,7 @@ let reset proc_desc = init_summary proc_desc
let reset_all ~filter () =
let reset proc_name =
let filename = res_dir_specs_filename proc_name in
let filename = specs_filename_of_procname proc_name in
Serialization.read_from_file summary_serializer filename
|> Option.iter ~f:(fun summary ->
let blank_summary = reset summary.proc_desc in

@ -58,7 +58,11 @@ val has_model : Typ.Procname.t -> bool
(** Check if a summary for a given procedure exists in the models directory *)
val clear_cache : unit -> unit
(** remove all the elements from the cache of summaries *)
(** Remove all the elements from the cache of summaries *)
val remove_from_cache : Typ.Procname.t -> unit
(** Remove an element from the cache of summaries. Contrast to reset which re-initializes a summary
keeping the same Procdesc and updates the cache accordingly. *)
val get : Typ.Procname.t -> t option
(** Return the summary option for the procedure name *)
@ -87,7 +91,11 @@ val get_status : t -> Status.t
val reset : Procdesc.t -> t
(** Reset a summary rebuilding the dependents and preserving the proc attributes if present. *)
val specs_filename_of_procname : Typ.Procname.t -> DB.filename
(** Return the path to the .specs file for the given procedure in the current results directory *)
val load_from_file : DB.filename -> t option
(** Load procedure summary from the given file *)
val pp_html : SourceFile.t -> Format.formatter -> t -> unit
(** Print the summary in html format *)

@ -350,6 +350,8 @@ let analyze_proc_name_no_caller callee_pname =
let clear_cache () = Typ.Procname.Hash.clear (Lazy.force cached_results)
let remove_from_cache pname = Typ.Procname.Hash.remove (Lazy.force cached_results) pname
let analyze_procedures exe_env procs_to_analyze source_file_opt =
let saved_language = !Language.curr_language in
Option.iter source_file_opt ~f:(fun source_file ->

@ -28,7 +28,10 @@ val set_exe_env : Exe_env.t -> unit
(** Set the execution enviroment used during on-demand analysis. *)
val clear_cache : unit -> unit
(** empty the cache of ondemand results *)
(** Empty the cache of ondemand results *)
val remove_from_cache : Typ.Procname.t -> unit
(** Remove an element from the cache of ondemand results *)
val analyze_file : Exe_env.t -> SourceFile.t -> unit
(** Invoke all the callbacks registered in {!Callbacks} on the given file. *)

Loading…
Cancel
Save