[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 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
@ -37,10 +37,6 @@ let register_cluster_callback ~name language (callback : cluster_callback_t) =
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. *)
let iterate_procedure_callbacks exe_env summary =
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. *)
let iterate_cluster_callbacks all_procs exe_env source_file =
let iterate_cluster_callbacks procedures exe_env source_file =
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 language_matches language =
match procedures with
| summary :: _ ->
Language.equal language (Procname.get_language (Summary.get_proc_name summary))
| procname :: _ ->
Language.equal language (Procname.get_language procname)
| _ ->
true
in

@ -21,7 +21,7 @@ type proc_callback_args =
type proc_callback_t = proc_callback_args -> Summary.t
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

@ -1110,15 +1110,16 @@ let make_results_table exe_env summaries =
(* aggregate all of the procedures in the file env by their declaring
class. this lets us analyze each class individually *)
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 ->
Ondemand.analyze_proc_name_no_caller procname
|> Option.value_map ~default:acc ~f:(fun summary ->
let pdesc = Summary.get_proc_desc summary in
let procname = Summary.get_proc_name summary in
let tenv = Exe_env.get_tenv exe_env procname in
if should_report_on_proc tenv pdesc then
Procdesc.get_proc_name pdesc |> Procname.get_class_name
|> Option.fold ~init:acc ~f:(fun acc classname ->
String.Map.add_multi acc ~key:classname ~data:summary )
else acc )
else acc ) )
(* 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) =
Domain.CriticalPairs.fold (report_on_pair tenv summary) payload.critical_pairs report_map
in
let report_procedure report_map summary =
let report_procedure report_map procname =
Ondemand.analyze_proc_name_no_caller procname
|> Option.value_map ~default:report_map ~f:(fun summary ->
let proc_desc = Summary.get_proc_desc summary in
let procname = Summary.get_proc_name summary in
let tenv = Exe_env.get_tenv exe_env procname in
if should_report proc_desc then
Payload.read_toplevel_procedure procname
|> Option.fold ~init:report_map ~f:(report_on_summary tenv summary)
else report_map
else report_map )
in
List.fold procedures ~init:ReportMap.empty ~f:report_procedure |> ReportMap.store

Loading…
Cancel
Save