From 4371a2c2f0d81986d69fafe940405399caf94920 Mon Sep 17 00:00:00 2001 From: Sungkeun Cho Date: Thu, 9 Jan 2020 05:25:27 -0800 Subject: [PATCH] [cost][inferbo] Refactor to use Payload.read/read_full Reviewed By: ngorogiannis Differential Revision: D19327692 fbshipit-source-id: 58f8177c4 --- infer/src/absint/SummaryPayload.ml | 6 ++++++ infer/src/absint/SummaryPayload.mli | 3 +++ infer/src/bufferoverrun/bufferOverrunAnalysis.ml | 8 ++------ infer/src/bufferoverrun/bufferOverrunChecker.ml | 9 +++------ infer/src/checkers/cost.ml | 8 +++----- infer/src/checkers/cost.mli | 2 ++ infer/src/checkers/hoisting.ml | 9 +++------ 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/infer/src/absint/SummaryPayload.ml b/infer/src/absint/SummaryPayload.ml index cd48d958d..10cbb4be0 100644 --- a/infer/src/absint/SummaryPayload.ml +++ b/infer/src/absint/SummaryPayload.ml @@ -24,6 +24,8 @@ module type S = sig val read : caller_summary:Summary.t -> callee_pname:Procname.t -> t option + val read_proc_desc : caller_summary:Summary.t -> callee_pname:Procname.t -> Procdesc.t option + val read_toplevel_procedure : Procname.t -> t option end @@ -54,6 +56,10 @@ module Make (P : Payload) : S with type t = P.t = struct Ondemand.analyze_proc_name ~caller_summary callee_pname |> get_payload |> Option.map ~f:snd + let read_proc_desc ~caller_summary ~callee_pname = + Ondemand.analyze_proc_name ~caller_summary callee_pname |> get_payload |> Option.map ~f:fst + + let read_toplevel_procedure callee_pname = Ondemand.analyze_proc_name_no_caller callee_pname |> get_payload |> Option.map ~f:snd end diff --git a/infer/src/absint/SummaryPayload.mli b/infer/src/absint/SummaryPayload.mli index 6b042ab3e..440d0b600 100644 --- a/infer/src/absint/SummaryPayload.mli +++ b/infer/src/absint/SummaryPayload.mli @@ -29,6 +29,9 @@ module type S = sig val read : caller_summary:Summary.t -> callee_pname:Procname.t -> t option (** Return the payload for the given procedure. Runs the analysis on-demand if necessary. *) + val read_proc_desc : caller_summary:Summary.t -> callee_pname:Procname.t -> Procdesc.t option + (** Return the proc desc for the given procedure. Runs the analysis on-demand if necessary. *) + val read_toplevel_procedure : Procname.t -> t option end diff --git a/infer/src/bufferoverrun/bufferOverrunAnalysis.ml b/infer/src/bufferoverrun/bufferOverrunAnalysis.ml index d14e7073e..043edfdae 100644 --- a/infer/src/bufferoverrun/bufferOverrunAnalysis.ml +++ b/infer/src/bufferoverrun/bufferOverrunAnalysis.ml @@ -466,13 +466,9 @@ let cached_compute_invariant_map = (* this should never happen *) assert false | None -> - let get_summary callee_pname = - Ondemand.analyze_proc_name ~caller_summary:summary callee_pname - |> Option.bind ~f:Payload.of_summary - in + let get_summary callee_pname = Payload.read ~caller_summary:summary ~callee_pname in let get_formals callee_pname = - Ondemand.analyze_proc_name ~caller_summary:summary callee_pname - |> Option.map ~f:Summary.get_proc_desc + Payload.read_proc_desc ~caller_summary:summary ~callee_pname |> Option.map ~f:Procdesc.get_pvar_formals in let inv_map = diff --git a/infer/src/bufferoverrun/bufferOverrunChecker.ml b/infer/src/bufferoverrun/bufferOverrunChecker.ml index 76d475c2b..02e2f64df 100644 --- a/infer/src/bufferoverrun/bufferOverrunChecker.ml +++ b/infer/src/bufferoverrun/bufferOverrunChecker.ml @@ -423,12 +423,9 @@ let checker : Callbacks.proc_callback_args -> Summary.t = let cfg = CFG.from_pdesc proc_desc in let checks = let get_checks_summary callee_pname = - Ondemand.analyze_proc_name ~caller_summary:summary callee_pname - |> Option.bind ~f:(fun summary -> - let checker_payload = Payload.of_summary summary in - Option.map checker_payload ~f:(fun checker_payload -> - (Summary.get_proc_desc summary |> Procdesc.get_pvar_formals, checker_payload) - ) ) + Payload.read_full ~caller_summary:summary ~callee_pname + |> Option.map ~f:(fun (callee_pdesc, callee_summary) -> + (Procdesc.get_pvar_formals callee_pdesc, callee_summary) ) in compute_checks get_checks_summary proc_desc tenv integer_type_widths cfg inv_map in diff --git a/infer/src/checkers/cost.ml b/infer/src/checkers/cost.ml index 39e6b419c..e68d1d146 100644 --- a/infer/src/checkers/cost.ml +++ b/infer/src/checkers/cost.ml @@ -855,11 +855,9 @@ let checker {Callbacks.exe_env; summary} : Summary.t = let get_node_nb_exec = compute_get_node_nb_exec node_cfg bound_map in let astate = let get_callee_summary_and_formals callee_pname = - Ondemand.analyze_proc_name ~caller_summary:summary callee_pname - |> Option.bind ~f:(fun summary -> - Payload.of_summary summary - |> Option.map ~f:(fun payload -> - (payload, Summary.get_proc_desc summary |> Procdesc.get_pvar_formals) ) ) + Payload.read_full ~caller_summary:summary ~callee_pname + |> Option.map ~f:(fun (callee_pdesc, callee_summary) -> + (callee_summary, Procdesc.get_pvar_formals callee_pdesc) ) in let instr_cfg = InstrCFG.from_pdesc proc_desc in let instr_cfg_wto = InstrCFG.wto instr_cfg in diff --git a/infer/src/checkers/cost.mli b/infer/src/checkers/cost.mli index 4a0337f68..022146417 100644 --- a/infer/src/checkers/cost.mli +++ b/infer/src/checkers/cost.mli @@ -7,6 +7,8 @@ open! IStd +module Payload : SummaryPayload.S with type t = CostDomain.summary + val checker : Callbacks.proc_callback_t val instantiate_cost : diff --git a/infer/src/checkers/hoisting.ml b/infer/src/checkers/hoisting.ml index 36fa4a474..3742a5cb7 100644 --- a/infer/src/checkers/hoisting.ml +++ b/infer/src/checkers/hoisting.ml @@ -168,12 +168,9 @@ let checker Callbacks.{summary; exe_env} : Summary.t = BufferOverrunAnalysis.cached_compute_invariant_map summary tenv integer_type_widths in let get_callee_cost_summary_and_formals callee_pname = - Ondemand.analyze_proc_name ~caller_summary:summary callee_pname - |> Option.bind ~f:(fun summary -> - summary.Summary.payloads.Payloads.cost - |> Option.map ~f:(fun cost_summary -> - (cost_summary, Summary.get_proc_desc summary |> Procdesc.get_pvar_formals) ) - ) + Cost.Payload.read_full ~caller_summary:summary ~callee_pname + |> Option.map ~f:(fun (callee_pdesc, callee_summary) -> + (callee_summary, Procdesc.get_pvar_formals callee_pdesc) ) in get_cost_if_expensive tenv integer_type_widths get_callee_cost_summary_and_formals inferbo_invariant_map