[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 update_summary payload summary = P.update_payload payload summary
let read_summary caller_pdesc callee_pname = 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 ->
None None
| Some summary -> | 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 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 = let pdesc_opt =
match Specs.get_summary pname with match Specs.get_summary pname with
| Some summary -> | 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) (fun _ instr -> Logging.(debug Analysis Verbose) "%a@." (Sil.pp_instr Pp.text) instr)
specialized_pdesc ; specialized_pdesc ;
Logging.(debug Analysis Verbose) "End of instructions@." ; 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 -> | Some summary ->
(* Since the closures in the formals were replaced by the captured variables, (* Since the closures in the formals were replaced by the captured variables,
we do the same with the actual arguments *) we do the same with the actual arguments *)

@ -8,7 +8,7 @@
*) *)
val resolve_method_with_block_args_and_analyze : 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 -> (Specs.summary * (Exp.t * Typ.t) list) option
(* [resolve_method_with_block_args_and_analyze caller_pdesc pname args] (* [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 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 ; if Config.dump_duplicate_symbols then dump_duplicate_procs exe_env procs_to_analyze ;
let analyze_proc_name pname = let analyze_proc_name pname =
Option.iter 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) (Ondemand.get_proc_desc pname)
in in
List.iter ~f:analyze_proc_name procs_to_analyze ; List.iter ~f:analyze_proc_name procs_to_analyze ;

@ -105,8 +105,7 @@ let restore_global_state st =
Timeout.resume_previous_timeout () Timeout.resume_previous_timeout ()
let run_proc_analysis analyze_proc curr_pdesc callee_pdesc = let run_proc_analysis analyze_proc ~caller_pdesc callee_pdesc =
let curr_pname = Procdesc.get_proc_name curr_pdesc in
let callee_pname = Procdesc.get_proc_name callee_pdesc in let callee_pname = Procdesc.get_proc_name callee_pdesc in
let log_elapsed_time = let log_elapsed_time =
let start_time = Mtime_clock.counter () in let start_time = Mtime_clock.counter () in
@ -117,7 +116,8 @@ let run_proc_analysis analyze_proc curr_pdesc callee_pdesc =
in in
L.progressbar_procedure () ; L.progressbar_procedure () ;
if Config.trace_ondemand then 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 ; Typ.Procname.pp callee_pname ;
let preprocess () = let preprocess () =
incr nesting ; 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)) 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 callee_pname = Procdesc.get_proc_name callee_pdesc in
let proc_attributes = Procdesc.get_attributes callee_pdesc in let proc_attributes = Procdesc.get_attributes callee_pdesc in
match !callbacks_ref with match !callbacks_ref with
| None -> | None ->
L.(die InternalError) L.(die InternalError)
"No callbacks registered to analyze proc desc %a when analyzing %a" Typ.Procname.pp "No callbacks registered to analyze proc desc %a (when analyzing %a)" Typ.Procname.pp
callee_pname Typ.Procname.pp callee_pname (Pp.option Typ.Procname.pp)
(Procdesc.get_proc_name curr_pdesc) (Option.map ~f:Procdesc.get_proc_name caller_pdesc)
| Some callbacks -> | Some callbacks ->
if should_be_analyzed callee_pname proc_attributes then 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 else Specs.get_summary callee_pname
(** analyze_proc_name curr_pdesc proc_name performs an on-demand analysis of proc_name triggered (** analyze_proc_name curr_pdesc proc_name performs an on-demand analysis of proc_name triggered
during the analysis of curr_pname *) 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 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 -> try Typ.Procname.Hash.find cached_results callee_pname with Not_found ->
let summary_option = let summary_option =
match !callbacks_ref with match !callbacks_ref with
| None -> | None ->
L.(die InternalError) L.(die InternalError)
"No callbacks registered to analyze proc name %a when analyzing %a@." Typ.Procname.pp "No callbacks registered to analyze proc name %a (when analyzing %a)@."
callee_pname Typ.Procname.pp Typ.Procname.pp callee_pname (Pp.option Typ.Procname.pp)
(Procdesc.get_proc_name curr_pdesc) (Option.map ~f:Procdesc.get_proc_name caller_pdesc)
| Some callbacks -> | Some callbacks ->
if procedure_should_be_analyzed callee_pname then if procedure_should_be_analyzed callee_pname then
match callbacks.get_proc_desc callee_pname with match callbacks.get_proc_desc callee_pname with
| Some callee_pdesc -> | Some callee_pdesc ->
analyze_proc_desc curr_pdesc callee_pdesc analyze_proc_desc ?caller_pdesc callee_pdesc
| None -> | None ->
Specs.get_summary callee_pname Specs.get_summary callee_pname
else 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 val get_proc_desc : get_proc_desc
(** Find a proc desc for the procedure, perhaps loading it from disk. *) (** Find a proc desc for the procedure, perhaps loading it from disk. *)
val analyze_proc_desc : Procdesc.t -> Procdesc.t -> Specs.summary option val analyze_proc_desc : ?caller_pdesc:Procdesc.t -> Procdesc.t -> Specs.summary option
(** analyze_proc_desc curr_pdesc callee_pdesc (** [analyze_proc_desc ~caller_pdesc callee_pdesc] performs an on-demand analysis of callee_pdesc
performs an on-demand analysis of callee_pdesc triggered during the analysis of caller_pdesc *)
triggered during the analysis of curr_pdesc. *)
val analyze_proc_name : ?caller_pdesc:Procdesc.t -> Typ.Procname.t -> Specs.summary option
val analyze_proc_name : Procdesc.t -> Typ.Procname.t -> Specs.summary option (** [analyze_proc_name ~caller_pdesc proc_name] performs an on-demand analysis of proc_name
(** analyze_proc_name curr_pdesc proc_name triggered during the analysis of caller_pdesc *)
performs an on-demand analysis of proc_name
triggered during the analysis of curr_pdesc. *)
val set_callbacks : callbacks -> unit val set_callbacks : callbacks -> unit
(** Set the callbacks used to perform on-demand analysis. *) (** 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 (** Resolve the procedure name and run the analysis of the resolved procedure
if not already analyzed *) 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 = : Typ.Procname.t * Specs.summary option =
(* TODO (#15748878): Fix conflict with method overloading by encoding in the procedure name (* TODO (#15748878): Fix conflict with method overloading by encoding in the procedure name
whether the method is defined or generated by the specialization *) whether the method is defined or generated by the specialization *)
let analyze_ondemand resolved_pname : Specs.summary option = let analyze_ondemand resolved_pname : Specs.summary option =
if Typ.Procname.equal resolved_pname callee_proc_name then 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 else
(* Create the type sprecialized procedure description and analyze it directly *) (* 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 = let resolved_proc_desc_option =
match Ondemand.get_proc_desc resolved_pname with match Ondemand.get_proc_desc resolved_pname with
| Some resolved_proc_desc -> | Some resolved_proc_desc ->
@ -1183,7 +1183,8 @@ let rec sym_exec tenv current_pdesc instr_ (prop_: Prop.normal Prop.t) path
norm_args norm_args
in in
let resolved_pname, resolved_summary_opt = 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 in
match resolved_summary_opt with match resolved_summary_opt with
| None -> | 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) skip_call ~reason norm_prop path pname ret_annots loc ret_id (Some ret_type)
url_handled_args url_handled_args
in in
match Ondemand.analyze_proc_name current_pdesc pname with match Ondemand.analyze_proc_name ~caller_pdesc:current_pdesc pname with
| None -> | None ->
let ret_typ = Typ.Procname.Java.get_return_typ callee_pname_java in let ret_typ = Typ.Procname.Java.get_return_typ callee_pname_java in
let ret_annots = load_ret_annots callee_pname 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 *) (* method with block parameters *)
let with_block_parameters_summary_opt = let with_block_parameters_summary_opt =
if call_flags.CallFlags.cf_with_block_parameters then if call_flags.CallFlags.cf_with_block_parameters then
SymExecBlocks.resolve_method_with_block_args_and_analyze current_pdesc resolved_pname SymExecBlocks.resolve_method_with_block_args_and_analyze ~caller_pdesc:current_pdesc
actual_params resolved_pname actual_params
else None else None
in in
match with_block_parameters_summary_opt with 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) (call_args prop_r resolved_pname n_extended_actual_params ret_id loc)
| None -> | None ->
(* Generic fun call with known name *) (* 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 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 ret_typ_opt = Option.map ~f:Procdesc.get_ret_type callee_pdesc_opt in
let sentinel_result = let sentinel_result =

@ -160,7 +160,9 @@ let is_outside_codebase proc_desc tenv field_name =
let first_method = let first_method =
Option.bind ~f:(fun (cls: Typ.Struct.t) -> List.hd cls.methods) class_struct Option.bind ~f:(fun (cls: Typ.Struct.t) -> List.hd cls.methods) class_struct
in 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 Option.is_none summary
| _ -> | _ ->
false 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 method_overrides_annot annot tenv pname = method_overrides (method_has_annot annot) tenv pname
let lookup_annotation_calls caller_pdesc annot pname = let lookup_annotation_calls ~caller_pdesc annot pname =
match Ondemand.analyze_proc_name caller_pdesc pname with match Ondemand.analyze_proc_name ~caller_pdesc pname with
| Some {Specs.payload= {Specs.annot_map= Some annot_map}} -> ( | Some {Specs.payload= {Specs.annot_map= Some annot_map}} -> (
try AnnotReachabilityDomain.find annot annot_map with Not_found -> try AnnotReachabilityDomain.find annot annot_map with Not_found ->
AnnotReachabilityDomain.SinkMap.empty ) 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 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 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) 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 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_ , etl_
, loc , loc
, cflags ) -> , 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 callee_attributes =
let proc_attriutes_opt = let proc_attriutes_opt =
Option.value_map Option.value_map

Loading…
Cancel
Save