From ec118e62a794426f3f429428650cdad83c41d132 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 25 Jan 2018 03:11:25 -0800 Subject: [PATCH] [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 --- infer/src/absint/Summary.ml | 2 +- infer/src/backend/SymExecBlocks.ml | 4 +-- infer/src/backend/SymExecBlocks.mli | 2 +- infer/src/backend/callbacks.ml | 2 +- infer/src/backend/ondemand.ml | 28 ++++++++++---------- infer/src/backend/ondemand.mli | 16 +++++------ infer/src/backend/symExec.ml | 19 +++++++------ infer/src/checkers/NullabilitySuggest.ml | 4 ++- infer/src/checkers/annotationReachability.ml | 6 ++--- infer/src/eradicate/typeCheck.ml | 2 +- 10 files changed, 44 insertions(+), 41 deletions(-) diff --git a/infer/src/absint/Summary.ml b/infer/src/absint/Summary.ml index 76fa67890..006651933 100644 --- a/infer/src/absint/Summary.ml +++ b/infer/src/absint/Summary.ml @@ -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 -> diff --git a/infer/src/backend/SymExecBlocks.ml b/infer/src/backend/SymExecBlocks.ml index cb566320e..8b59677cb 100644 --- a/infer/src/backend/SymExecBlocks.ml +++ b/infer/src/backend/SymExecBlocks.ml @@ -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 *) diff --git a/infer/src/backend/SymExecBlocks.mli b/infer/src/backend/SymExecBlocks.mli index fddd9a2eb..394dd987c 100644 --- a/infer/src/backend/SymExecBlocks.mli +++ b/infer/src/backend/SymExecBlocks.mli @@ -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 diff --git a/infer/src/backend/callbacks.ml b/infer/src/backend/callbacks.ml index 30438e866..5976d7c02 100644 --- a/infer/src/backend/callbacks.ml +++ b/infer/src/backend/callbacks.ml @@ -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 ; diff --git a/infer/src/backend/ondemand.ml b/infer/src/backend/ondemand.ml index e8617cbe1..e93b24e1c 100644 --- a/infer/src/backend/ondemand.ml +++ b/infer/src/backend/ondemand.ml @@ -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 diff --git a/infer/src/backend/ondemand.mli b/infer/src/backend/ondemand.mli index aad0e32a5..f3e402472 100644 --- a/infer/src/backend/ondemand.mli +++ b/infer/src/backend/ondemand.mli @@ -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. *) diff --git a/infer/src/backend/symExec.ml b/infer/src/backend/symExec.ml index 58ca59489..010070f51 100644 --- a/infer/src/backend/symExec.ml +++ b/infer/src/backend/symExec.ml @@ -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 = diff --git a/infer/src/checkers/NullabilitySuggest.ml b/infer/src/checkers/NullabilitySuggest.ml index 85a12dbe9..fccb24eae 100644 --- a/infer/src/checkers/NullabilitySuggest.ml +++ b/infer/src/checkers/NullabilitySuggest.ml @@ -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 diff --git a/infer/src/checkers/annotationReachability.ml b/infer/src/checkers/annotationReachability.ml index e3d54a15f..a058470d7 100644 --- a/infer/src/checkers/annotationReachability.ml +++ b/infer/src/checkers/annotationReachability.ml @@ -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 diff --git a/infer/src/eradicate/typeCheck.ml b/infer/src/eradicate/typeCheck.ml index 33ca12f1e..9a74c8e4c 100644 --- a/infer/src/eradicate/typeCheck.ml +++ b/infer/src/eradicate/typeCheck.ml @@ -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