From bcfcb5d405e43e4b87d66a7acdbbc0f978349d6d Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Mon, 30 Jan 2017 10:51:23 -0800 Subject: [PATCH] [cleanup] restrict uses of annotated_signature to eradicate Summary: One of the things that confuses me about the current annotations API is that there's a lot of ways to do the same thing. Some of the concepts like `annotated_signature` are only really needed by Eradicate. This diff removes usages of `annotated_signature` outside of Eradicate (everyone else was just using `get_annotated_signature` as a roundabout way to get the return annotation of a procedure). In the future, I'll move `get_annotated_signature` and other Eradicate-specific functionality into its own module inside the Eradicate directory. Reviewed By: jberdine Differential Revision: D4472058 fbshipit-source-id: 5bb0846 --- infer/src/backend/rearrange.ml | 10 ++-------- infer/src/backend/reporting.ml | 7 ++----- infer/src/checkers/ThreadSafety.ml | 5 +---- infer/src/checkers/annotationReachability.ml | 5 +---- infer/src/checkers/annotations.ml | 6 ++++-- infer/src/checkers/annotations.mli | 3 +++ 6 files changed, 13 insertions(+), 23 deletions(-) diff --git a/infer/src/backend/rearrange.ml b/infer/src/backend/rearrange.ml index 602546b0e..11193a5f0 100644 --- a/infer/src/backend/rearrange.ml +++ b/infer/src/backend/rearrange.ml @@ -775,10 +775,7 @@ let add_guarded_by_constraints tenv prop lexp pdesc = let enforce_guarded_access_ accessed_fld guarded_by_str prop = (* return true if [pdesc] has an annotation that matches [guarded_by_str] *) let proc_has_matching_annot pdesc guarded_by_str = - let proc_signature = - Annotations.get_annotated_signature (Procdesc.get_attributes pdesc) in - let proc_annot, _ = proc_signature.Annotations.ret in - match extract_guarded_by_str proc_annot with + match extract_guarded_by_str (Annotations.pdesc_get_return_annot pdesc) with | Some proc_guarded_by_str -> (* the lock is not held, but the procedure is annotated with @GuardedBy *) String.equal proc_guarded_by_str guarded_by_str @@ -817,10 +814,7 @@ let add_guarded_by_constraints tenv prop lexp pdesc = String.equal "itself" (String.lowercase guarded_by_str) || String.is_suffix ~suffix:guarded_by_str (Ident.fieldname_to_string accessed_fld) in let proc_has_suppress_guarded_by_annot pdesc = - let proc_signature = - Annotations.get_annotated_signature (Procdesc.get_attributes pdesc) in - let proc_annot, _ = proc_signature.Annotations.ret in - match extract_suppress_warnings_str proc_annot with + match extract_suppress_warnings_str (Annotations.pdesc_get_return_annot pdesc) with | Some suppression_str-> String.equal suppression_str "InvalidAccessToGuardedField" | None -> false in diff --git a/infer/src/backend/reporting.ml b/infer/src/backend/reporting.ml index 7dc4fef3c..06e7d5906 100644 --- a/infer/src/backend/reporting.ml +++ b/infer/src/backend/reporting.ml @@ -52,12 +52,9 @@ let log_issue ?session ?ltr exn = - let should_suppress_lint summary = + let should_suppress_lint (summary : Specs.summary) = Config.curr_language_is Config.Java && - let annotated_signature = - Annotations.get_annotated_signature summary.Specs.attributes in - let ret_annotation, _ = annotated_signature.Annotations.ret in - Annotations.ia_is_suppress_lint ret_annotation in + Annotations.ia_is_suppress_lint (fst summary.attributes.ProcAttributes.method_annotation) in match Specs.get_summary proc_name with | Some summary when should_suppress_lint summary -> () | Some summary -> diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index 7ca22698d..246a536c6 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -596,10 +596,7 @@ let process_results_table file_env tab = let check_method_attributes check pname = match Specs.proc_resolve_attributes pname with | None -> false - | Some attributes -> - let annotated_signature = Annotations.get_annotated_signature attributes in - let ret_annotation, _ = annotated_signature.Annotations.ret in - check ret_annotation in + | Some attributes -> check (fst attributes.ProcAttributes.method_annotation) in let found = ref false in PatternMatch.proc_iter_overridden_methods (fun pn -> diff --git a/infer/src/checkers/annotationReachability.ml b/infer/src/checkers/annotationReachability.ml index fc77a3c72..c01e4cd5b 100644 --- a/infer/src/checkers/annotationReachability.ml +++ b/infer/src/checkers/annotationReachability.ml @@ -130,10 +130,7 @@ let check_attributes check tenv pname = let check_method_attributes check pname = match Specs.proc_resolve_attributes pname with | None -> false - | Some attributes -> - let annotated_signature = Annotations.get_annotated_signature attributes in - let ret_annotation, _ = annotated_signature.Annotations.ret in - check ret_annotation in + | Some attributes -> check (fst attributes.ProcAttributes.method_annotation) in PatternMatch.check_class_attributes check tenv pname || check_method_attributes check pname let method_overrides is_annotated tenv pname = diff --git a/infer/src/checkers/annotations.ml b/infer/src/checkers/annotations.ml index 32ccecad0..fe54ff0e1 100644 --- a/infer/src/checkers/annotations.ml +++ b/infer/src/checkers/annotations.ml @@ -98,9 +98,11 @@ let pdesc_has_parameter_annot pdesc predicate = let _, param_annotations = (Procdesc.get_attributes pdesc).ProcAttributes.method_annotation in IList.exists predicate param_annotations +let pdesc_get_return_annot pdesc = + fst (Procdesc.get_attributes pdesc).ProcAttributes.method_annotation + let pdesc_has_return_annot pdesc predicate = - let return_annotation, _ = (Procdesc.get_attributes pdesc).ProcAttributes.method_annotation in - predicate return_annotation + predicate (pdesc_get_return_annot pdesc) let pdesc_return_annot_ends_with pdesc annot = pdesc_has_return_annot pdesc (fun ia -> ia_ends_with ia annot) diff --git a/infer/src/checkers/annotations.mli b/infer/src/checkers/annotations.mli index 1e8bbc758..60aaf0d02 100644 --- a/infer/src/checkers/annotations.mli +++ b/infer/src/checkers/annotations.mli @@ -119,6 +119,9 @@ val ia_is_volatile : Annot.Item.t -> bool parameters *) val pdesc_has_parameter_annot : Procdesc.t -> (Annot.Item.t -> bool) -> bool +(** get the list of annotations on the return value of [pdesc] *) +val pdesc_get_return_annot : Procdesc.t -> Annot.Item.t + (** return true if the given predicate evaluates to true on the annotation of [pdesc]'s return value *) val pdesc_has_return_annot : Procdesc.t -> (Annot.Item.t -> bool) -> bool