From e622e7b431de53740db716a318f501f921d69649 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Mon, 4 Dec 2017 08:38:26 -0800 Subject: [PATCH] [infer][ondemand] cache the results of the on-demand analysis Summary: For the Buck integration for Java, caching when a summary is not found avoids going through the whole classpath every time a summary for the same method is not found. Reviewed By: mbouaziz, jvillard Differential Revision: D6402833 fbshipit-source-id: 4feb422 --- infer/src/backend/ondemand.ml | 36 +++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/infer/src/backend/ondemand.ml b/infer/src/backend/ondemand.ml index b002882e3..bdf06aaaa 100644 --- a/infer/src/backend/ondemand.ml +++ b/infer/src/backend/ondemand.ml @@ -183,21 +183,29 @@ let analyze_proc_desc curr_pdesc callee_pdesc : Specs.summary option = (** 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 curr_pdesc callee_pname : Specs.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) - | 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 +let analyze_proc_name : Procdesc.t -> Typ.Procname.t -> Specs.summary option = + let cached_results = Typ.Procname.Hash.create 100 in + fun curr_pdesc callee_pname -> + try Typ.Procname.Hash.find cached_results callee_pname with Not_found -> + let summary_option = + match !callbacks_ref with | None -> - Specs.get_summary callee_pname - else Specs.get_summary callee_pname + 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) + | 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 + | None -> + Specs.get_summary callee_pname + else Specs.get_summary callee_pname + in + if not (is_active callee_pname) then + Typ.Procname.Hash.add cached_results callee_pname summary_option ; + summary_option (** Find a proc desc for the procedure, perhaps loading it from disk. *)