diff --git a/infer/src/backend/SpecsFiles.ml b/infer/src/backend/SpecsFiles.ml index aa672032b..aaabb41ba 100644 --- a/infer/src/backend/SpecsFiles.ml +++ b/infer/src/backend/SpecsFiles.ml @@ -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 diff --git a/infer/src/backend/SpecsFiles.mli b/infer/src/backend/SpecsFiles.mli index 3339bc5e7..3daafbe6b 100644 --- a/infer/src/backend/SpecsFiles.mli +++ b/infer/src/backend/SpecsFiles.mli @@ -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 *) diff --git a/infer/src/backend/Summary.ml b/infer/src/backend/Summary.ml index f3da8be56..22ea72466 100644 --- a/infer/src/backend/Summary.ml +++ b/infer/src/backend/Summary.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: @[%a@]@\n%!" Errlog.pp_errors err_log ; F.fprintf fmt "WARNINGS: @[%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 diff --git a/infer/src/backend/Summary.mli b/infer/src/backend/Summary.mli index a79f2f790..d922bab64 100644 --- a/infer/src/backend/Summary.mli +++ b/infer/src/backend/Summary.mli @@ -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 *) diff --git a/infer/src/backend/ondemand.ml b/infer/src/backend/ondemand.ml index d2a6f0cb1..2425cf748 100644 --- a/infer/src/backend/ondemand.ml +++ b/infer/src/backend/ondemand.ml @@ -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 -> diff --git a/infer/src/backend/ondemand.mli b/infer/src/backend/ondemand.mli index 286804fe8..6980f874a 100644 --- a/infer/src/backend/ondemand.mli +++ b/infer/src/backend/ondemand.mli @@ -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. *)