[ondemand] only provide procnames to cluster callbacks

Summary: Currently, empty summaries are passed to the cluster callbacks.  This is pointless and could potentially lead to recomputing already analysed summaries.  This change passes only procnames to the callback, and `Ondemand` is used to load the summary or analyse as needed.

Reviewed By: jvillard

Differential Revision: D19544043

fbshipit-source-id: 28ab642c3
master
Nikos Gorogiannis 5 years ago committed by Facebook Github Bot
parent c878aa6135
commit ecea3ecb93

@ -15,7 +15,7 @@ type proc_callback_args =
type proc_callback_t = proc_callback_args -> Summary.t type proc_callback_t = proc_callback_args -> Summary.t
type cluster_callback_args = type cluster_callback_args =
{procedures: Summary.t list; source_file: SourceFile.t; exe_env: Exe_env.t} {procedures: Procname.t list; source_file: SourceFile.t; exe_env: Exe_env.t}
type cluster_callback_t = cluster_callback_args -> unit type cluster_callback_t = cluster_callback_args -> unit
@ -37,10 +37,6 @@ let register_cluster_callback ~name language (callback : cluster_callback_t) =
cluster_callbacks := {name; language; callback} :: !cluster_callbacks cluster_callbacks := {name; language; callback} :: !cluster_callbacks
let get_procedure_definition proc_name =
Procdesc.load proc_name |> Option.map ~f:Summary.OnDisk.reset
(** Invoke all registered procedure callbacks on the given procedure. *) (** Invoke all registered procedure callbacks on the given procedure. *)
let iterate_procedure_callbacks exe_env summary = let iterate_procedure_callbacks exe_env summary =
let proc_desc = Summary.get_proc_desc summary in let proc_desc = Summary.get_proc_desc summary in
@ -74,14 +70,13 @@ let iterate_procedure_callbacks exe_env summary =
(** Invoke all registered cluster callbacks on a cluster of procedures. *) (** Invoke all registered cluster callbacks on a cluster of procedures. *)
let iterate_cluster_callbacks all_procs exe_env source_file = let iterate_cluster_callbacks procedures exe_env source_file =
if !cluster_callbacks <> [] then if !cluster_callbacks <> [] then
let procedures = List.filter_map ~f:get_procedure_definition all_procs in
let environment = {procedures; source_file; exe_env} in let environment = {procedures; source_file; exe_env} in
let language_matches language = let language_matches language =
match procedures with match procedures with
| summary :: _ -> | procname :: _ ->
Language.equal language (Procname.get_language (Summary.get_proc_name summary)) Language.equal language (Procname.get_language procname)
| _ -> | _ ->
true true
in in

@ -21,7 +21,7 @@ type proc_callback_args =
type proc_callback_t = proc_callback_args -> Summary.t type proc_callback_t = proc_callback_args -> Summary.t
type cluster_callback_args = type cluster_callback_args =
{procedures: Summary.t list; source_file: SourceFile.t; exe_env: Exe_env.t} {procedures: Procname.t list; source_file: SourceFile.t; exe_env: Exe_env.t}
type cluster_callback_t = cluster_callback_args -> unit type cluster_callback_t = cluster_callback_args -> unit

@ -1110,15 +1110,16 @@ let make_results_table exe_env summaries =
(* aggregate all of the procedures in the file env by their declaring (* aggregate all of the procedures in the file env by their declaring
class. this lets us analyze each class individually *) class. this lets us analyze each class individually *)
let aggregate_by_class exe_env file_env = let aggregate_by_class exe_env file_env =
List.fold file_env ~init:String.Map.empty ~f:(fun acc summary -> List.fold file_env ~init:String.Map.empty ~f:(fun acc procname ->
let pdesc = Summary.get_proc_desc summary in Ondemand.analyze_proc_name_no_caller procname
let procname = Summary.get_proc_name summary in |> Option.value_map ~default:acc ~f:(fun summary ->
let tenv = Exe_env.get_tenv exe_env procname in let pdesc = Summary.get_proc_desc summary in
if should_report_on_proc tenv pdesc then let tenv = Exe_env.get_tenv exe_env procname in
Procdesc.get_proc_name pdesc |> Procname.get_class_name if should_report_on_proc tenv pdesc then
|> Option.fold ~init:acc ~f:(fun acc classname -> Procdesc.get_proc_name pdesc |> Procname.get_class_name
String.Map.add_multi acc ~key:classname ~data:summary ) |> Option.fold ~init:acc ~f:(fun acc classname ->
else acc ) String.Map.add_multi acc ~key:classname ~data:summary )
else acc ) )
(* Gathers results by analyzing all the methods in a file, then (* Gathers results by analyzing all the methods in a file, then

@ -732,14 +732,15 @@ let reporting {Callbacks.procedures; exe_env} =
let report_on_summary tenv summary report_map (payload : Domain.summary) = let report_on_summary tenv summary report_map (payload : Domain.summary) =
Domain.CriticalPairs.fold (report_on_pair tenv summary) payload.critical_pairs report_map Domain.CriticalPairs.fold (report_on_pair tenv summary) payload.critical_pairs report_map
in in
let report_procedure report_map summary = let report_procedure report_map procname =
let proc_desc = Summary.get_proc_desc summary in Ondemand.analyze_proc_name_no_caller procname
let procname = Summary.get_proc_name summary in |> Option.value_map ~default:report_map ~f:(fun summary ->
let tenv = Exe_env.get_tenv exe_env procname in let proc_desc = Summary.get_proc_desc summary in
if should_report proc_desc then let tenv = Exe_env.get_tenv exe_env procname in
Payload.read_toplevel_procedure procname if should_report proc_desc then
|> Option.fold ~init:report_map ~f:(report_on_summary tenv summary) Payload.read_toplevel_procedure procname
else report_map |> Option.fold ~init:report_map ~f:(report_on_summary tenv summary)
else report_map )
in in
List.fold procedures ~init:ReportMap.empty ~f:report_procedure |> ReportMap.store List.fold procedures ~init:ReportMap.empty ~f:report_procedure |> ReportMap.store

Loading…
Cancel
Save