[cost][inferbo] Refactor to use Payload.read/read_full

Reviewed By: ngorogiannis

Differential Revision: D19327692

fbshipit-source-id: 58f8177c4
master
Sungkeun Cho 5 years ago committed by Facebook Github Bot
parent 2e419c6110
commit 4371a2c2f0

@ -24,6 +24,8 @@ module type S = sig
val read : caller_summary:Summary.t -> callee_pname:Procname.t -> t option 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 val read_toplevel_procedure : Procname.t -> t option
end 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 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 = let read_toplevel_procedure callee_pname =
Ondemand.analyze_proc_name_no_caller callee_pname |> get_payload |> Option.map ~f:snd Ondemand.analyze_proc_name_no_caller callee_pname |> get_payload |> Option.map ~f:snd
end end

@ -29,6 +29,9 @@ module type S = sig
val read : caller_summary:Summary.t -> callee_pname:Procname.t -> t option 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. *) (** 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 val read_toplevel_procedure : Procname.t -> t option
end end

@ -466,13 +466,9 @@ let cached_compute_invariant_map =
(* this should never happen *) (* this should never happen *)
assert false assert false
| None -> | None ->
let get_summary callee_pname = let get_summary callee_pname = Payload.read ~caller_summary:summary ~callee_pname in
Ondemand.analyze_proc_name ~caller_summary:summary callee_pname
|> Option.bind ~f:Payload.of_summary
in
let get_formals callee_pname = let get_formals callee_pname =
Ondemand.analyze_proc_name ~caller_summary:summary callee_pname Payload.read_proc_desc ~caller_summary:summary ~callee_pname
|> Option.map ~f:Summary.get_proc_desc
|> Option.map ~f:Procdesc.get_pvar_formals |> Option.map ~f:Procdesc.get_pvar_formals
in in
let inv_map = let inv_map =

@ -423,12 +423,9 @@ let checker : Callbacks.proc_callback_args -> Summary.t =
let cfg = CFG.from_pdesc proc_desc in let cfg = CFG.from_pdesc proc_desc in
let checks = let checks =
let get_checks_summary callee_pname = let get_checks_summary callee_pname =
Ondemand.analyze_proc_name ~caller_summary:summary callee_pname Payload.read_full ~caller_summary:summary ~callee_pname
|> Option.bind ~f:(fun summary -> |> Option.map ~f:(fun (callee_pdesc, callee_summary) ->
let checker_payload = Payload.of_summary summary in (Procdesc.get_pvar_formals callee_pdesc, callee_summary) )
Option.map checker_payload ~f:(fun checker_payload ->
(Summary.get_proc_desc summary |> Procdesc.get_pvar_formals, checker_payload)
) )
in in
compute_checks get_checks_summary proc_desc tenv integer_type_widths cfg inv_map compute_checks get_checks_summary proc_desc tenv integer_type_widths cfg inv_map
in in

@ -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 get_node_nb_exec = compute_get_node_nb_exec node_cfg bound_map in
let astate = let astate =
let get_callee_summary_and_formals callee_pname = let get_callee_summary_and_formals callee_pname =
Ondemand.analyze_proc_name ~caller_summary:summary callee_pname Payload.read_full ~caller_summary:summary ~callee_pname
|> Option.bind ~f:(fun summary -> |> Option.map ~f:(fun (callee_pdesc, callee_summary) ->
Payload.of_summary summary (callee_summary, Procdesc.get_pvar_formals callee_pdesc) )
|> Option.map ~f:(fun payload ->
(payload, Summary.get_proc_desc summary |> Procdesc.get_pvar_formals) ) )
in in
let instr_cfg = InstrCFG.from_pdesc proc_desc in let instr_cfg = InstrCFG.from_pdesc proc_desc in
let instr_cfg_wto = InstrCFG.wto instr_cfg in let instr_cfg_wto = InstrCFG.wto instr_cfg in

@ -7,6 +7,8 @@
open! IStd open! IStd
module Payload : SummaryPayload.S with type t = CostDomain.summary
val checker : Callbacks.proc_callback_t val checker : Callbacks.proc_callback_t
val instantiate_cost : val instantiate_cost :

@ -168,12 +168,9 @@ let checker Callbacks.{summary; exe_env} : Summary.t =
BufferOverrunAnalysis.cached_compute_invariant_map summary tenv integer_type_widths BufferOverrunAnalysis.cached_compute_invariant_map summary tenv integer_type_widths
in in
let get_callee_cost_summary_and_formals callee_pname = let get_callee_cost_summary_and_formals callee_pname =
Ondemand.analyze_proc_name ~caller_summary:summary callee_pname Cost.Payload.read_full ~caller_summary:summary ~callee_pname
|> Option.bind ~f:(fun summary -> |> Option.map ~f:(fun (callee_pdesc, callee_summary) ->
summary.Summary.payloads.Payloads.cost (callee_summary, Procdesc.get_pvar_formals callee_pdesc) )
|> Option.map ~f:(fun cost_summary ->
(cost_summary, Summary.get_proc_desc summary |> Procdesc.get_pvar_formals) )
)
in in
get_cost_if_expensive tenv integer_type_widths get_callee_cost_summary_and_formals get_cost_if_expensive tenv integer_type_widths get_callee_cost_summary_and_formals
inferbo_invariant_map inferbo_invariant_map

Loading…
Cancel
Save