From 8629ee53811a968964ecf3cb6381d9e10d255af0 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Tue, 21 Feb 2017 18:59:07 -0800 Subject: [PATCH] [cleanup] make PatternMatch.override_exists check the current procname too Reviewed By: jeremydubreil Differential Revision: D4594441 fbshipit-source-id: 7798f29 --- infer/src/checkers/ThreadSafety.ml | 24 ++++++++------------ infer/src/checkers/annotationReachability.ml | 1 - infer/src/checkers/patternMatch.ml | 2 ++ infer/src/checkers/patternMatch.mli | 9 ++++---- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index e27d26f6f..c8c964314 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -194,10 +194,6 @@ module TransferFunctions (CFG : ProcCfg.S) = struct ~attrs_of_pname:Specs.proc_resolve_attributes predicate - (* like PatternMatch.override_exists, but also applies [predicate] to [pname] *) - let proc_or_override_exists pname tenv (predicate : Procname.t -> bool) = - predicate pname || PatternMatch.override_exists predicate tenv pname - let is_functional pname = let is_annotated_functional = has_return_annot Annotations.ia_is_functional in @@ -486,7 +482,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct astate_callee | Some (ret_id, ret_typ) -> let add_if_annotated predicate attribute attribute_map = - if proc_or_override_exists callee_pname tenv predicate + if PatternMatch.override_exists predicate tenv callee_pname then AttributeMapDomain.add_attribute (AccessPath.of_id ret_id ret_typ) attribute attribute_map @@ -834,16 +830,14 @@ let process_results_table file_env tab = let should_report_on_all_procs = should_report_on_file file_env in (* TODO (t15588153): clean this up *) let is_thread_safe_method pdesc tenv = - let overrides_thread_safe_method pname tenv = - PatternMatch.override_exists - (fun pn -> - Annotations.pname_has_return_annot - pn - ~attrs_of_pname:Specs.proc_resolve_attributes - Annotations.ia_is_thread_safe_method) - tenv pname in - Annotations.pdesc_return_annot_ends_with pdesc Annotations.thread_safe_method || - overrides_thread_safe_method (Procdesc.get_proc_name pdesc) tenv in + PatternMatch.override_exists + (fun pn -> + Annotations.pname_has_return_annot + pn + ~attrs_of_pname:Specs.proc_resolve_attributes + Annotations.ia_is_thread_safe_method) + tenv + (Procdesc.get_proc_name pdesc) in let should_report ((_, tenv, _, pdesc) as proc_env) = (should_report_on_all_procs || is_thread_safe_method pdesc tenv) && should_report_on_proc proc_env in diff --git a/infer/src/checkers/annotationReachability.ml b/infer/src/checkers/annotationReachability.ml index 2550fe922..18459269c 100644 --- a/infer/src/checkers/annotationReachability.ml +++ b/infer/src/checkers/annotationReachability.ml @@ -140,7 +140,6 @@ let check_attributes check tenv pname = Annotations.pname_has_return_annot pname ~attrs_of_pname:Specs.proc_resolve_attributes check let method_overrides is_annotated tenv pname = - is_annotated tenv pname || PatternMatch.override_exists (fun pn -> is_annotated tenv pn) tenv pname let method_has_annot annot tenv pname = diff --git a/infer/src/checkers/patternMatch.ml b/infer/src/checkers/patternMatch.ml index 22eaa7e2b..65ba369e8 100644 --- a/infer/src/checkers/patternMatch.ml +++ b/infer/src/checkers/patternMatch.ml @@ -343,6 +343,8 @@ let override_exists f tenv proc_name = List.exists ~f:(super_type_exists tenv) supers | _ -> false in + + f proc_name || match proc_name with | Procname.Java proc_name_java -> let type_name = Typename.Java.from_string (Procname.java_get_class_name proc_name_java) in diff --git a/infer/src/checkers/patternMatch.mli b/infer/src/checkers/patternMatch.mli index 0e97b0093..f09d5e61c 100644 --- a/infer/src/checkers/patternMatch.mli +++ b/infer/src/checkers/patternMatch.mli @@ -82,13 +82,12 @@ val proc_calls : (Procname.t -> ProcAttributes.t -> bool) -> (Procname.t * ProcAttributes.t) list -(** Return true if applying the given predicate to an override of [procname] returns [true]. Note - that this does apply the predicate to [procname] itself. For the moment, this only works for - Java *) +(** Return true if applying the given predicate to an override of [procname] or [procname] itself + returns true. For the moment, this only works for Java *) val override_exists : (Procname.t -> bool) -> Tenv.t -> Procname.t -> bool -(** Apply the given predicate to each override of [procname]. Notet hat this does apply the - predicate to [procname] itself. For the moment, this only works for Java *) +(** Apply the given predicate to procname and each override of [procname]. For the moment, this only + works for Java *) val override_iter : (Procname.t -> unit) -> Tenv.t -> Procname.t -> unit val type_get_annotation : Tenv.t -> Typ.t -> Annot.Item.t option