[infer][backend] cleanup the summary origin that is no longer useful

Summary: Cleanup

Reviewed By: jberdine

Differential Revision: D4357045

fbshipit-source-id: e24b3b1
master
Jeremy Dubreil 9 years ago committed by Facebook Github Bot
parent 4bca15afff
commit a1c1b236a8

@ -337,7 +337,7 @@ type summary =
proc_desc_option : Procdesc.t option; proc_desc_option : Procdesc.t option;
} }
type spec_tbl = (summary * DB.origin) Procname.Hash.t type spec_tbl = summary Procname.Hash.t
let spec_tbl: spec_tbl = Procname.Hash.create 128 let spec_tbl: spec_tbl = Procname.Hash.create 128
@ -521,18 +521,12 @@ let payload_compact sh payload =
let summary_compact sh summary = let summary_compact sh summary =
{ summary with payload = payload_compact sh summary.payload } { summary with payload = payload_compact sh summary.payload }
let set_summary_origin proc_name summary origin = (** Add the summary to the table for the given function *)
Procname.Hash.replace spec_tbl proc_name (summary, origin) let add_summary (proc_name : Procname.t) (summary: summary) : unit =
let add_summary_origin (proc_name : Procname.t) (summary: summary) (origin: DB.origin) : unit =
L.out "Adding summary for %a@\n@[<v 2> %a@]@." L.out "Adding summary for %a@\n@[<v 2> %a@]@."
Procname.pp proc_name Procname.pp proc_name
(pp_summary_text ~whole_seconds:false) summary; (pp_summary_text ~whole_seconds:false) summary;
set_summary_origin proc_name summary origin Procname.Hash.replace spec_tbl proc_name summary
(** Add the summary to the table for the given function *)
let add_summary (proc_name : Procname.t) (summary: summary) : unit =
add_summary_origin proc_name summary DB.Res_dir
let specs_filename pname = let specs_filename pname =
let pname_file = Procname.to_filename pname in let pname_file = Procname.to_filename pname in
@ -578,25 +572,25 @@ let load_summary specs_file =
(** Load procedure summary for the given procedure name and update spec table *) (** Load procedure summary for the given procedure name and update spec table *)
let load_summary_to_spec_table proc_name = let load_summary_to_spec_table proc_name =
let add summ origin = let add summ =
add_summary_origin proc_name summ origin; add_summary proc_name summ;
true in true in
let load_summary_models models_dir = let load_summary_models models_dir =
match load_summary models_dir with match load_summary models_dir with
| None -> false | None -> false
| Some summ -> add summ DB.Models in | Some summ -> add summ in
let rec load_summary_libs = function (* try to load the summary from a list of libs *) let rec load_summary_libs = function (* try to load the summary from a list of libs *)
| [] -> false | [] -> false
| spec_path :: spec_paths -> | spec_path :: spec_paths ->
(match load_summary spec_path with (match load_summary spec_path with
| None -> load_summary_libs spec_paths | None -> load_summary_libs spec_paths
| Some summ -> | Some summ ->
add summ Spec_lib) in add summ) in
let load_summary_ziplibs zip_specs_filename = let load_summary_ziplibs zip_specs_filename =
let zip_specs_path = Filename.concat Config.specs_dir_name zip_specs_filename in let zip_specs_path = Filename.concat Config.specs_dir_name zip_specs_filename in
match ZipLib.load summary_serializer zip_specs_path with match ZipLib.load summary_serializer zip_specs_path with
| None -> false | None -> false
| Some (summary, origin) -> add summary origin in | Some summary -> add summary in
let default_spec_dir = res_dir_specs_filename proc_name in let default_spec_dir = res_dir_specs_filename proc_name in
match load_summary default_spec_dir with match load_summary default_spec_dir with
| None -> | None ->
@ -605,21 +599,16 @@ let load_summary_to_spec_table proc_name =
load_summary_ziplibs (specs_filename proc_name) || load_summary_ziplibs (specs_filename proc_name) ||
load_summary_libs (specs_library_filenames proc_name) load_summary_libs (specs_library_filenames proc_name)
| Some summ -> | Some summ ->
add summ DB.Res_dir add summ
let rec get_summary_origin proc_name = let rec get_summary proc_name =
try try
Some (Procname.Hash.find spec_tbl proc_name) Some (Procname.Hash.find spec_tbl proc_name)
with Not_found -> with Not_found ->
if load_summary_to_spec_table proc_name then if load_summary_to_spec_table proc_name then
get_summary_origin proc_name get_summary proc_name
else None else None
let get_summary proc_name =
match get_summary_origin proc_name with
| Some (summary, _) -> Some summary
| None -> None
let get_summary_unsafe s proc_name = let get_summary_unsafe s proc_name =
match get_summary proc_name with match get_summary proc_name with
| None -> | None ->
@ -671,11 +660,6 @@ let pdesc_resolve_attributes proc_desc =
(* this should not happen *) (* this should not happen *)
assert false assert false
let is_model proc_name =
match get_summary_origin proc_name with
| None -> false
| Some (_, origin) -> origin = DB.Models
let summary_exists proc_name = let summary_exists proc_name =
match get_summary proc_name with match get_summary proc_name with
| Some _ -> true | Some _ -> true
@ -729,9 +713,9 @@ let get_phase summary =
(** Set the current status for the proc *) (** Set the current status for the proc *)
let set_status proc_name status = let set_status proc_name status =
match get_summary_origin proc_name with match get_summary proc_name with
| None -> raise (Failure ("Specs.set_status: " ^ (Procname.to_string proc_name) ^ " Not_found")) | None -> raise (Failure ("Specs.set_status: " ^ (Procname.to_string proc_name) ^ " Not_found"))
| Some (summary, origin) -> set_summary_origin proc_name { summary with status = status } origin | Some summary -> add_summary proc_name { summary with status = status }
(** Create the initial dependency map with the given list of dependencies *) (** Create the initial dependency map with the given list of dependencies *)
let mk_initial_dependency_map proc_list : dependency_map_t = let mk_initial_dependency_map proc_list : dependency_map_t =
@ -744,16 +728,16 @@ let re_initialize_dependency_map dependency_map =
(** Update the dependency map of [proc_name] with the current (** Update the dependency map of [proc_name] with the current
timestamps of the dependents *) timestamps of the dependents *)
let update_dependency_map proc_name = let update_dependency_map proc_name =
match get_summary_origin proc_name with match get_summary proc_name with
| None -> | None ->
raise raise
(Failure ("Specs.update_dependency_map: " ^ (Procname.to_string proc_name) ^ " Not_found")) (Failure ("Specs.update_dependency_map: " ^ (Procname.to_string proc_name) ^ " Not_found"))
| Some (summary, origin) -> | Some summary ->
let current_dependency_map = let current_dependency_map =
Procname.Map.mapi Procname.Map.mapi
(fun _ _ -> get_timestamp summary) (fun _ _ -> get_timestamp summary)
summary.dependency_map in summary.dependency_map in
set_summary_origin proc_name { summary with dependency_map = current_dependency_map } origin add_summary proc_name { summary with dependency_map = current_dependency_map }
let empty_payload = let empty_payload =
{ {
@ -790,7 +774,7 @@ let init_summary
ProcAttributes.proc_flags = proc_flags; }; ProcAttributes.proc_flags = proc_flags; };
proc_desc_option; proc_desc_option;
} in } in
Procname.Hash.replace spec_tbl proc_attributes.ProcAttributes.proc_name (summary, DB.Res_dir) Procname.Hash.replace spec_tbl proc_attributes.ProcAttributes.proc_name summary
(** Reset a summary rebuilding the dependents and preserving the proc attributes if present. *) (** Reset a summary rebuilding the dependents and preserving the proc attributes if present. *)
let reset_summary call_graph proc_name attributes_opt proc_desc_option = let reset_summary call_graph proc_name attributes_opt proc_desc_option =

@ -162,9 +162,6 @@ val clear_spec_tbl : unit -> unit
(** Dump a spec *) (** Dump a spec *)
val d_spec : 'a spec -> unit val d_spec : 'a spec -> unit
(** Returns true if the procedure is a model *)
val is_model: Procname.t -> bool
(** Return the summary option for the procedure name *) (** Return the summary option for the procedure name *)
val get_summary : Procname.t -> summary option val get_summary : Procname.t -> summary option

@ -209,12 +209,6 @@ module Results_dir = struct
Unix.openfile full_fname ~mode:Unix.[O_WRONLY; O_CREAT; O_TRUNC] ~perm:0o777 Unix.openfile full_fname ~mode:Unix.[O_WRONLY; O_CREAT; O_TRUNC] ~perm:0o777
end end
(** origin of a analysis artifact: current results dir, a spec library, or models *)
type origin =
| Res_dir
| Spec_lib
| Models
let global_tenv_fname = let global_tenv_fname =
let basename = Config.global_tenv_filename in let basename = Config.global_tenv_filename in
filename_concat captured_dir basename filename_concat captured_dir basename

@ -69,12 +69,6 @@ module Results_dir : sig
val create_file : path_kind -> path -> Unix.File_descr.t val create_file : path_kind -> path -> Unix.File_descr.t
end end
(** origin of a analysis artifact: current results dir, a spec library, or models *)
type origin =
| Res_dir
| Spec_lib
| Models
(** {2 Source Dirs} *) (** {2 Source Dirs} *)
(** source directory: the directory inside the results dir corresponding to a source file *) (** source directory: the directory inside the results dir corresponding to a source file *)

@ -37,8 +37,7 @@ let load_from_cache serializer zip_path cache_dir zip_library =
end; end;
DB.filename_from_string to_path in DB.filename_from_string to_path in
match deserialize (extract absolute_path) with match deserialize (extract absolute_path) with
| Some data when zip_library.models -> Some (data, DB.Models) | Some data -> Some data
| Some data -> Some (data, DB.Spec_lib)
| None -> None | None -> None
| exception Not_found -> None | exception Not_found -> None
@ -46,8 +45,7 @@ let load_from_zip serializer zip_path zip_library =
let lazy zip_channel = zip_library.zip_channel in let lazy zip_channel = zip_library.zip_channel in
let deserialize = Serialization.from_string serializer in let deserialize = Serialization.from_string serializer in
match deserialize (Zip.read_entry zip_channel (Zip.find_entry zip_channel zip_path)) with match deserialize (Zip.read_entry zip_channel (Zip.find_entry zip_channel zip_path)) with
| Some data when zip_library.models -> Some (data, DB.Models) | Some data -> Some data
| Some data -> Some (data, DB.Spec_lib)
| None -> None | None -> None
| exception Not_found -> None | exception Not_found -> None

@ -12,4 +12,4 @@ open! IStd
(** [load serializer path] searches for the file at the given path in the zip libraries. (** [load serializer path] searches for the file at the given path in the zip libraries.
If Config.infer_cache is set, already deserialized data will be saved there and [path] If Config.infer_cache is set, already deserialized data will be saved there and [path]
will be searched from the cache first. *) will be searched from the cache first. *)
val load : 'a Serialization.serializer -> string -> ('a * DB.origin) option val load : 'a Serialization.serializer -> string -> 'a option

Loading…
Cancel
Save