[cleanup] make caller pdesc an optional argument of `Ondemand.analyze_proc_desc`

Summary:
Also make it optional, since it's only used for debug messages. Name a couple
more of these for other similar functions.

Reviewed By: sblackshear

Differential Revision: D6797385

fbshipit-source-id: e6e9b2e
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent 58e0cbe6ee
commit ec118e62a7

@ -31,7 +31,7 @@ module Make (P : Payload) : S with type payload = P.payload = struct
let update_summary payload summary = P.update_payload payload summary
let read_summary caller_pdesc callee_pname =
match Ondemand.analyze_proc_name caller_pdesc callee_pname with
match Ondemand.analyze_proc_name ~caller_pdesc callee_pname with
| None ->
None
| Some summary ->

@ -44,7 +44,7 @@ let get_extended_args_for_method_with_block_analysis act_params =
List.map ~f:(fun (exp, _, typ) -> (exp, typ)) args_and_captured
let resolve_method_with_block_args_and_analyze caller_pdesc pname act_params =
let resolve_method_with_block_args_and_analyze ~caller_pdesc pname act_params =
let pdesc_opt =
match Specs.get_summary pname with
| Some summary ->
@ -88,7 +88,7 @@ let resolve_method_with_block_args_and_analyze caller_pdesc pname act_params =
(fun _ instr -> Logging.(debug Analysis Verbose) "%a@." (Sil.pp_instr Pp.text) instr)
specialized_pdesc ;
Logging.(debug Analysis Verbose) "End of instructions@." ;
match Ondemand.analyze_proc_desc caller_pdesc specialized_pdesc with
match Ondemand.analyze_proc_desc ~caller_pdesc specialized_pdesc with
| Some summary ->
(* Since the closures in the formals were replaced by the captured variables,
we do the same with the actual arguments *)

@ -8,7 +8,7 @@
*)
val resolve_method_with_block_args_and_analyze :
Procdesc.t -> Typ.Procname.t -> (Exp.t * Typ.t) list
caller_pdesc:Procdesc.t -> Typ.Procname.t -> (Exp.t * Typ.t) list
-> (Specs.summary * (Exp.t * Typ.t) list) option
(* [resolve_method_with_block_args_and_analyze caller_pdesc pname args]
create a copy of the method pname if it is defined and it's called with

@ -140,7 +140,7 @@ let iterate_callbacks (exe_env: Exe_env.t) =
if Config.dump_duplicate_symbols then dump_duplicate_procs exe_env procs_to_analyze ;
let analyze_proc_name pname =
Option.iter
~f:(fun pdesc -> ignore (Ondemand.analyze_proc_desc pdesc pdesc))
~f:(fun pdesc -> ignore (Ondemand.analyze_proc_desc pdesc))
(Ondemand.get_proc_desc pname)
in
List.iter ~f:analyze_proc_name procs_to_analyze ;

@ -105,8 +105,7 @@ let restore_global_state st =
Timeout.resume_previous_timeout ()
let run_proc_analysis analyze_proc curr_pdesc callee_pdesc =
let curr_pname = Procdesc.get_proc_name curr_pdesc in
let run_proc_analysis analyze_proc ~caller_pdesc callee_pdesc =
let callee_pname = Procdesc.get_proc_name callee_pdesc in
let log_elapsed_time =
let start_time = Mtime_clock.counter () in
@ -117,7 +116,8 @@ let run_proc_analysis analyze_proc curr_pdesc callee_pdesc =
in
L.progressbar_procedure () ;
if Config.trace_ondemand then
L.progress "[%d] run_proc_analysis %a -> %a@." !nesting Typ.Procname.pp curr_pname
L.progress "[%d] run_proc_analysis %a -> %a@." !nesting (Pp.option Typ.Procname.pp)
(Option.map caller_pdesc ~f:Procdesc.get_proc_name)
Typ.Procname.pp callee_pname ;
let preprocess () =
incr nesting ;
@ -166,39 +166,39 @@ let run_proc_analysis analyze_proc curr_pdesc callee_pdesc =
log_error_and_continue exn initial_summary (FKcrash (Exn.to_string exn))
let analyze_proc_desc curr_pdesc callee_pdesc : Specs.summary option =
let analyze_proc_desc ?caller_pdesc callee_pdesc : Specs.summary option =
let callee_pname = Procdesc.get_proc_name callee_pdesc in
let proc_attributes = Procdesc.get_attributes callee_pdesc in
match !callbacks_ref with
| None ->
L.(die InternalError)
"No callbacks registered to analyze proc desc %a when analyzing %a" Typ.Procname.pp
callee_pname Typ.Procname.pp
(Procdesc.get_proc_name curr_pdesc)
"No callbacks registered to analyze proc desc %a (when analyzing %a)" Typ.Procname.pp
callee_pname (Pp.option Typ.Procname.pp)
(Option.map ~f:Procdesc.get_proc_name caller_pdesc)
| Some callbacks ->
if should_be_analyzed callee_pname proc_attributes then
Some (run_proc_analysis callbacks.analyze_ondemand curr_pdesc callee_pdesc)
Some (run_proc_analysis callbacks.analyze_ondemand ~caller_pdesc callee_pdesc)
else Specs.get_summary callee_pname
(** analyze_proc_name curr_pdesc proc_name performs an on-demand analysis of proc_name triggered
during the analysis of curr_pname *)
let analyze_proc_name : Procdesc.t -> Typ.Procname.t -> Specs.summary option =
let analyze_proc_name : ?caller_pdesc:Procdesc.t -> Typ.Procname.t -> Specs.summary option =
let cached_results = Typ.Procname.Hash.create 100 in
fun curr_pdesc callee_pname ->
fun ?caller_pdesc callee_pname ->
try Typ.Procname.Hash.find cached_results callee_pname with Not_found ->
let summary_option =
match !callbacks_ref with
| None ->
L.(die InternalError)
"No callbacks registered to analyze proc name %a when analyzing %a@." Typ.Procname.pp
callee_pname Typ.Procname.pp
(Procdesc.get_proc_name curr_pdesc)
"No callbacks registered to analyze proc name %a (when analyzing %a)@."
Typ.Procname.pp callee_pname (Pp.option Typ.Procname.pp)
(Option.map ~f:Procdesc.get_proc_name caller_pdesc)
| Some callbacks ->
if procedure_should_be_analyzed callee_pname then
match callbacks.get_proc_desc callee_pname with
| Some callee_pdesc ->
analyze_proc_desc curr_pdesc callee_pdesc
analyze_proc_desc ?caller_pdesc callee_pdesc
| None ->
Specs.get_summary callee_pname
else Specs.get_summary callee_pname

@ -20,15 +20,13 @@ type callbacks = {analyze_ondemand: analyze_ondemand; get_proc_desc: get_proc_de
val get_proc_desc : get_proc_desc
(** Find a proc desc for the procedure, perhaps loading it from disk. *)
val analyze_proc_desc : Procdesc.t -> Procdesc.t -> Specs.summary option
(** analyze_proc_desc curr_pdesc callee_pdesc
performs an on-demand analysis of callee_pdesc
triggered during the analysis of curr_pdesc. *)
val analyze_proc_name : Procdesc.t -> Typ.Procname.t -> Specs.summary option
(** analyze_proc_name curr_pdesc proc_name
performs an on-demand analysis of proc_name
triggered during the analysis of curr_pdesc. *)
val analyze_proc_desc : ?caller_pdesc:Procdesc.t -> Procdesc.t -> Specs.summary option
(** [analyze_proc_desc ~caller_pdesc callee_pdesc] performs an on-demand analysis of callee_pdesc
triggered during the analysis of caller_pdesc *)
val analyze_proc_name : ?caller_pdesc:Procdesc.t -> Typ.Procname.t -> Specs.summary option
(** [analyze_proc_name ~caller_pdesc proc_name] performs an on-demand analysis of proc_name
triggered during the analysis of caller_pdesc *)
val set_callbacks : callbacks -> unit
(** Set the callbacks used to perform on-demand analysis. *)

@ -684,16 +684,16 @@ let resolve_java_pname tenv prop args pname_java call_flags : Typ.Procname.Java.
(** Resolve the procedure name and run the analysis of the resolved procedure
if not already analyzed *)
let resolve_and_analyze tenv caller_pdesc prop args callee_proc_name call_flags
let resolve_and_analyze tenv ~caller_pdesc prop args callee_proc_name call_flags
: Typ.Procname.t * Specs.summary option =
(* TODO (#15748878): Fix conflict with method overloading by encoding in the procedure name
whether the method is defined or generated by the specialization *)
let analyze_ondemand resolved_pname : Specs.summary option =
if Typ.Procname.equal resolved_pname callee_proc_name then
Ondemand.analyze_proc_name caller_pdesc callee_proc_name
Ondemand.analyze_proc_name ~caller_pdesc callee_proc_name
else
(* Create the type sprecialized procedure description and analyze it directly *)
let analyze specialized_pdesc = Ondemand.analyze_proc_desc caller_pdesc specialized_pdesc in
let analyze specialized_pdesc = Ondemand.analyze_proc_desc ~caller_pdesc specialized_pdesc in
let resolved_proc_desc_option =
match Ondemand.get_proc_desc resolved_pname with
| Some resolved_proc_desc ->
@ -1183,7 +1183,8 @@ let rec sym_exec tenv current_pdesc instr_ (prop_: Prop.normal Prop.t) path
norm_args
in
let resolved_pname, resolved_summary_opt =
resolve_and_analyze tenv current_pdesc norm_prop norm_args callee_pname call_flags
resolve_and_analyze tenv ~caller_pdesc:current_pdesc norm_prop norm_args callee_pname
call_flags
in
match resolved_summary_opt with
| None ->
@ -1210,7 +1211,7 @@ let rec sym_exec tenv current_pdesc instr_ (prop_: Prop.normal Prop.t) path
skip_call ~reason norm_prop path pname ret_annots loc ret_id (Some ret_type)
url_handled_args
in
match Ondemand.analyze_proc_name current_pdesc pname with
match Ondemand.analyze_proc_name ~caller_pdesc:current_pdesc pname with
| None ->
let ret_typ = Typ.Procname.Java.get_return_typ callee_pname_java in
let ret_annots = load_ret_annots callee_pname in
@ -1239,8 +1240,8 @@ let rec sym_exec tenv current_pdesc instr_ (prop_: Prop.normal Prop.t) path
(* method with block parameters *)
let with_block_parameters_summary_opt =
if call_flags.CallFlags.cf_with_block_parameters then
SymExecBlocks.resolve_method_with_block_args_and_analyze current_pdesc resolved_pname
actual_params
SymExecBlocks.resolve_method_with_block_args_and_analyze ~caller_pdesc:current_pdesc
resolved_pname actual_params
else None
in
match with_block_parameters_summary_opt with
@ -1253,7 +1254,9 @@ let rec sym_exec tenv current_pdesc instr_ (prop_: Prop.normal Prop.t) path
(call_args prop_r resolved_pname n_extended_actual_params ret_id loc)
| None ->
(* Generic fun call with known name *)
let resolved_summary_opt = Ondemand.analyze_proc_name current_pdesc resolved_pname in
let resolved_summary_opt =
Ondemand.analyze_proc_name ~caller_pdesc:current_pdesc resolved_pname
in
let callee_pdesc_opt = Ondemand.get_proc_desc resolved_pname in
let ret_typ_opt = Option.map ~f:Procdesc.get_ret_type callee_pdesc_opt in
let sentinel_result =

@ -160,7 +160,9 @@ let is_outside_codebase proc_desc tenv field_name =
let first_method =
Option.bind ~f:(fun (cls: Typ.Struct.t) -> List.hd cls.methods) class_struct
in
let summary = Option.bind ~f:(Ondemand.analyze_proc_name proc_desc) first_method in
let summary =
Option.bind ~f:(Ondemand.analyze_proc_name ~caller_pdesc:proc_desc) first_method
in
Option.is_none summary
| _ ->
false

@ -118,8 +118,8 @@ let method_has_annot annot tenv pname =
let method_overrides_annot annot tenv pname = method_overrides (method_has_annot annot) tenv pname
let lookup_annotation_calls caller_pdesc annot pname =
match Ondemand.analyze_proc_name caller_pdesc pname with
let lookup_annotation_calls ~caller_pdesc annot pname =
match Ondemand.analyze_proc_name ~caller_pdesc pname with
| Some {Specs.payload= {Specs.annot_map= Some annot_map}} -> (
try AnnotReachabilityDomain.find annot annot_map with Not_found ->
AnnotReachabilityDomain.SinkMap.empty )
@ -220,7 +220,7 @@ let report_src_snk_path {Callbacks.proc_desc; tenv; summary} sink_map snk_annot
if method_overrides_annot src_annot tenv proc_name then
let f_report = report_annotation_stack src_annot.Annot.class_name snk_annot.Annot.class_name in
report_call_stack summary (method_has_annot snk_annot tenv)
(lookup_annotation_calls proc_desc snk_annot)
(lookup_annotation_calls ~caller_pdesc:proc_desc snk_annot)
f_report (CallSite.make proc_name loc) sink_map

@ -530,7 +530,7 @@ let typecheck_instr tenv ext calls_this checks (node: Procdesc.Node.t) idenv get
, etl_
, loc
, cflags ) ->
let callee_summary_opt = Ondemand.analyze_proc_name curr_pdesc callee_pname in
let callee_summary_opt = Ondemand.analyze_proc_name ~caller_pdesc:curr_pdesc callee_pname in
let callee_attributes =
let proc_attriutes_opt =
Option.value_map

Loading…
Cancel
Save