From 61b83c037dfd165c72170775a34588d1db9c9fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Thu, 16 Jan 2020 02:00:31 -0800 Subject: [PATCH] [purity] Simplify should_report Reviewed By: skcho Differential Revision: D19413263 fbshipit-source-id: 3a3da9231 --- infer/src/checkers/impurity.ml | 2 +- infer/src/checkers/purity.ml | 28 +++++++++++++--------------- infer/src/checkers/purity.mli | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/infer/src/checkers/impurity.ml b/infer/src/checkers/impurity.ml index c168e9c3d..935db2ccb 100644 --- a/infer/src/checkers/impurity.ml +++ b/infer/src/checkers/impurity.ml @@ -130,7 +130,7 @@ let report_errors summary modified_opt = Reporting.log_error summary ~loc:pname_loc ~ltr:[impure_fun_ltr] IssueType.impure_function impure_fun_desc | Some (ImpurityDomain.{modified_globals; modified_params} as astate) -> - if Purity.should_report pdesc && not (ImpurityDomain.is_pure astate) then + if Purity.should_report proc_name && not (ImpurityDomain.is_pure astate) then let modified_ltr param_source set acc = ImpurityDomain.ModifiedVarSet.fold (ImpurityDomain.add_to_errlog ~nesting:1 param_source) diff --git a/infer/src/checkers/purity.ml b/infer/src/checkers/purity.ml index 1e699debb..735f73d19 100644 --- a/infer/src/checkers/purity.ml +++ b/infer/src/checkers/purity.ml @@ -184,20 +184,18 @@ end module Analyzer = LowerHil.MakeAbstractInterpreter (TransferFunctions) -let should_report pdesc = - let proc_name = Procdesc.get_proc_name pdesc in - (not (Procname.is_constructor proc_name)) - && - match proc_name with - | Procname.Java java_pname -> - not - (Procname.Java.is_class_initializer java_pname || Procname.Java.is_access_method java_pname) - | Procname.ObjC_Cpp name -> - not - ( Procname.ObjC_Cpp.is_destructor name - || Procname.ObjC_Cpp.is_objc_constructor name.method_name ) - | _ -> - true +let should_report proc_name = + not + ( Procname.is_constructor proc_name + || + match proc_name with + | Procname.Java java_pname -> + Procname.Java.is_class_initializer java_pname || Procname.Java.is_access_method java_pname + | Procname.ObjC_Cpp name -> + Procname.ObjC_Cpp.is_destructor name + || Procname.ObjC_Cpp.is_objc_constructor name.method_name + | _ -> + false ) let report_errors astate summary = @@ -205,7 +203,7 @@ let report_errors astate summary = let proc_name = Procdesc.get_proc_name pdesc in match astate with | Some astate -> - if should_report pdesc && PurityDomain.is_pure astate then + if should_report proc_name && PurityDomain.is_pure astate then let loc = Procdesc.get_loc pdesc in let exp_desc = F.asprintf "Side-effect free function %a" Procname.pp proc_name in let ltr = [Errlog.make_trace_element 0 loc exp_desc []] in diff --git a/infer/src/checkers/purity.mli b/infer/src/checkers/purity.mli index 455a55f9f..144e8f209 100644 --- a/infer/src/checkers/purity.mli +++ b/infer/src/checkers/purity.mli @@ -9,4 +9,4 @@ open! IStd val checker : Callbacks.proc_callback_t -val should_report : Procdesc.t -> bool +val should_report : Procname.t -> bool