From 44cf69791a976fd126ce889852308c2ca5a6848d Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 Apr 2018 06:43:10 -0700 Subject: [PATCH] Callbacks, cleanup 2: some lazyness Summary: Only RacerD uses the Cluster callbacks but we used to compute a lot of things anyway. Reviewed By: sblackshear Differential Revision: D7516279 fbshipit-source-id: 22f2b86 --- infer/src/backend/callbacks.ml | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/infer/src/backend/callbacks.ml b/infer/src/backend/callbacks.ml index d0871c904..d44d5337a 100644 --- a/infer/src/backend/callbacks.ml +++ b/infer/src/backend/callbacks.ml @@ -46,8 +46,11 @@ let register_cluster_callback language (callback: cluster_callback_t) = (** Collect what we need to know about a procedure for the analysis. *) let get_procedure_definition exe_env proc_name = - let tenv = Exe_env.get_tenv exe_env proc_name in - Option.map ~f:(fun proc_desc -> (tenv, proc_desc)) (Exe_env.get_proc_desc exe_env proc_name) + Option.map + ~f:(fun proc_desc -> + let tenv = Exe_env.get_tenv exe_env proc_name in + (tenv, proc_desc) ) + (Exe_env.get_proc_desc exe_env proc_name) let get_language proc_name = @@ -78,18 +81,19 @@ let iterate_procedure_callbacks get_proc_desc exe_env summary proc_desc = (** Invoke all registered cluster callbacks on a cluster of procedures. *) let iterate_cluster_callbacks all_procs exe_env get_proc_desc = - let procedures = List.filter_map ~f:(get_procedure_definition exe_env) all_procs in - let environment = {procedures; get_proc_desc} in - let language_matches language = - match procedures with - | (_, pdesc) :: _ -> - Language.equal language (get_language (Procdesc.get_proc_name pdesc)) - | _ -> - true - in - List.iter - ~f:(fun {language; callback} -> if language_matches language then callback environment) - !cluster_callbacks + if !cluster_callbacks <> [] then + let procedures = List.filter_map ~f:(get_procedure_definition exe_env) all_procs in + let environment = {procedures; get_proc_desc} in + let language_matches language = + match procedures with + | (_, pdesc) :: _ -> + Language.equal language (get_language (Procdesc.get_proc_name pdesc)) + | _ -> + true + in + List.iter + ~f:(fun {language; callback} -> if language_matches language then callback environment) + !cluster_callbacks let dump_duplicate_procs (exe_env: Exe_env.t) procs =