diff --git a/infer/src/IR/Annot.ml b/infer/src/IR/Annot.ml index 580df3c73..187726c76 100644 --- a/infer/src/IR/Annot.ml +++ b/infer/src/IR/Annot.ml @@ -49,7 +49,7 @@ module Item = struct (** Empty item annotation. *) let empty = [] - (** Check if the item annodation is empty. *) + (** Check if the item annotation is empty. *) let is_empty ia = List.is_empty ia end @@ -66,17 +66,16 @@ module Class = struct end module Method = struct - (** Annotation for a method: return value and list of parameters. *) - type t = Item.t * Item.t list [@@deriving compare] - - let equal = [%compare.equal: t] + type t = {return: Item.t; params: Item.t list} (** Pretty print a method annotation. *) - let pp s fmt (ia, ial) = F.fprintf fmt "%a %s(%a)" Item.pp ia s (Pp.seq Item.pp) ial + let pp s fmt {return; params} = + F.fprintf fmt "%a %s(%a)" Item.pp return s (Pp.seq Item.pp) params + (** Empty method annotation. *) - let empty = ([], []) + let empty = {return= []; params= []} - (** Check if the method annodation is empty. *) - let is_empty (ia, ial) = List.for_all ~f:Item.is_empty (ia :: ial) + (** Check if the method annotation is empty. *) + let is_empty {return; params} = Item.is_empty return && List.for_all ~f:Item.is_empty params end diff --git a/infer/src/IR/Annot.mli b/infer/src/IR/Annot.mli index bc9e2928e..01883d495 100644 --- a/infer/src/IR/Annot.mli +++ b/infer/src/IR/Annot.mli @@ -47,15 +47,13 @@ end module Method : sig (** Annotation for a method: return value and list of parameters. *) - type t = Item.t * Item.t list [@@deriving compare] - - val equal : t -> t -> bool + type t = {return: Item.t; params: Item.t list} val empty : t (** Empty method annotation. *) val is_empty : t -> bool - (** Check if the method annodation is empty. *) + (** Check if the method annotation is empty. *) val pp : string -> F.formatter -> t -> unit (** Pretty print a method annotation. *) diff --git a/infer/src/IR/ProcAttributes.ml b/infer/src/IR/ProcAttributes.ml index 480be23ca..5c1d41f81 100644 --- a/infer/src/IR/ProcAttributes.ml +++ b/infer/src/IR/ProcAttributes.ml @@ -63,9 +63,6 @@ type t = ; proc_name: Typ.Procname.t (** name of the procedure *) ; ret_type: Typ.t (** return type *) ; has_added_return_param: bool (** whether or not a return param was added *) } -[@@deriving compare] - -let equal = [%compare.equal: t] let default translation_unit proc_name = { access= PredSymb.Default @@ -175,7 +172,7 @@ let pp f locals ; pp_bool_default ~default:default.has_added_return_param "has_added_return_param" has_added_return_param f () ; - if not (Annot.Method.equal default.method_annotation method_annotation) then + if not (Annot.Method.is_empty method_annotation) then F.fprintf f "; method_annotation= %a@," (Annot.Method.pp "") method_annotation ; if not ([%compare.equal: objc_accessor_type option] default.objc_accessor objc_accessor) then F.fprintf f "; objc_accessor= %a@," (Pp.option pp_objc_accessor_type) objc_accessor ; diff --git a/infer/src/IR/ProcAttributes.mli b/infer/src/IR/ProcAttributes.mli index 25c4a8676..ea9365133 100644 --- a/infer/src/IR/ProcAttributes.mli +++ b/infer/src/IR/ProcAttributes.mli @@ -47,9 +47,6 @@ type t = ; ret_type: Typ.t (** return type *) ; has_added_return_param: bool (** whether or not a return param was added *) } -val equal : t -> t -> bool [@@warning "-32"] -(** can be useful for debugging *) - val default : SourceFile.t -> Typ.Procname.t -> t (** Create a proc_attributes with default values. *) diff --git a/infer/src/IR/SpecializeProcdesc.ml b/infer/src/IR/SpecializeProcdesc.ml index 7f5804c26..755c3111e 100644 --- a/infer/src/IR/SpecializeProcdesc.ml +++ b/infer/src/IR/SpecializeProcdesc.ml @@ -299,7 +299,7 @@ let with_block_args callee_pdesc pname_with_block_args block_args = let new_formals_blocks_captured_vars, extended_formals_annots = let new_formals_blocks_captured_vars_with_annots = let formals_annots = - List.zip_exn callee_attributes.formals (snd callee_attributes.method_annotation) + List.zip_exn callee_attributes.formals callee_attributes.method_annotation.params in List.fold formals_annots ~init:[] ~f:(fun acc ((param_name, typ), annot) -> try @@ -327,7 +327,8 @@ let with_block_args callee_pdesc pname_with_block_args block_args = proc_name= pname_with_block_args ; is_defined= true ; formals= new_formals_blocks_captured_vars - ; method_annotation= (fst callee_attributes.method_annotation, extended_formals_annots) + ; method_annotation= + {return= callee_attributes.method_annotation.return; params= extended_formals_annots} ; translation_unit } in let resolved_pdesc = Procdesc.from_proc_attributes resolved_attributes in diff --git a/infer/src/backend/reporting.ml b/infer/src/backend/reporting.ml index 73f826433..58b7cd2e7 100644 --- a/infer/src/backend/reporting.ml +++ b/infer/src/backend/reporting.ml @@ -39,7 +39,7 @@ let log_issue_from_summary severity summary ~node ~session ~loc ~ltr ?extras exn let should_suppress_lint = Language.curr_language_is Java && Annotations.ia_is_suppress_lint - (fst (Summary.get_attributes summary).ProcAttributes.method_annotation) + (Summary.get_attributes summary).ProcAttributes.method_annotation.return in if should_suppress_lint || is_java_generated_method then () (* Skip the reporting *) else diff --git a/infer/src/biabduction/SymExec.ml b/infer/src/biabduction/SymExec.ml index f0edef6bc..ac67ee8ed 100644 --- a/infer/src/biabduction/SymExec.ml +++ b/infer/src/biabduction/SymExec.ml @@ -1056,8 +1056,7 @@ let execute_load ?(report_deref_errors = true) pname pdesc tenv id rhs_exp typ l let load_ret_annots pname = match Attributes.load pname with | Some attrs -> - let ret_annots, _ = attrs.ProcAttributes.method_annotation in - ret_annots + attrs.ProcAttributes.method_annotation.return | None -> Annot.Item.empty @@ -1346,7 +1345,7 @@ let rec sym_exec exe_env tenv current_pdesc instr_ (prop_ : Prop.normal Prop.t) (call_args prop_ callee_pname norm_args ret_id_typ loc) | Some reason -> let proc_attrs = Summary.get_attributes resolved_summary in - let ret_annots, _ = proc_attrs.ProcAttributes.method_annotation in + let ret_annots = proc_attrs.ProcAttributes.method_annotation.return in exec_skip_call ~reason resolved_pname ret_annots proc_attrs.ProcAttributes.ret_type ) ) | Java callee_pname_java -> @@ -1372,7 +1371,7 @@ let rec sym_exec exe_env tenv current_pdesc instr_ (prop_ : Prop.normal Prop.t) proc_call exe_env callee_summary handled_args | Some reason -> let proc_attrs = Summary.get_attributes callee_summary in - let ret_annots, _ = proc_attrs.ProcAttributes.method_annotation in + let ret_annots = proc_attrs.ProcAttributes.method_annotation.return in exec_skip_call ~reason ret_annots proc_attrs.ProcAttributes.ret_type ) in List.fold ~f:(fun acc pname -> exec_one_pname pname @ acc) ~init:[] resolved_pnames @@ -1427,10 +1426,7 @@ let rec sym_exec exe_env tenv current_pdesc instr_ (prop_ : Prop.normal Prop.t) let ret_annots = match resolved_summary_opt with | Some summ -> - let ret_annots, _ = - (Summary.get_attributes summ).ProcAttributes.method_annotation - in - ret_annots + (Summary.get_attributes summ).ProcAttributes.method_annotation.return | None -> load_ret_annots resolved_pname in diff --git a/infer/src/biabduction/Tabulation.ml b/infer/src/biabduction/Tabulation.ml index c382dc36e..d9f28f2de 100644 --- a/infer/src/biabduction/Tabulation.ml +++ b/infer/src/biabduction/Tabulation.ml @@ -1430,7 +1430,7 @@ let exe_call_postprocess tenv ret_id trace_call callee_pname callee_attrs loc re ~f:(fun (p, path) -> (quantify_path_idents_remove_constant_strings tenv p, path)) res_with_path_idents in - let ret_annot, _ = callee_attrs.ProcAttributes.method_annotation in + let ret_annot = callee_attrs.ProcAttributes.method_annotation.return in let returns_nullable ret_annot = Annotations.ia_is_nullable ret_annot in let should_add_ret_attr _ = let is_likely_getter = function diff --git a/infer/src/checkers/annotations.ml b/infer/src/checkers/annotations.ml index 940e26077..3caa41fbb 100644 --- a/infer/src/checkers/annotations.ml +++ b/infer/src/checkers/annotations.ml @@ -115,9 +115,10 @@ let ia_has_annotation_with (ia : Annot.Item.t) (predicate : Annot.t -> bool) : b List.exists ~f:(fun (a, _) -> predicate a) ia -let ma_has_annotation_with ((ia, ial) : Annot.Method.t) (predicate : Annot.t -> bool) : bool = +let ma_has_annotation_with ({return; params} : Annot.Method.t) (predicate : Annot.t -> bool) : bool + = let has_annot a = ia_has_annotation_with a predicate in - has_annot ia || List.exists ~f:has_annot ial + has_annot return || List.exists ~f:has_annot params (** [annot_ends_with annot ann_name] returns true if the class name of [annot], without the package, @@ -137,7 +138,7 @@ let ia_ends_with ia ann_name = List.exists ~f:(fun (a, _) -> annot_ends_with a a let ia_contains ia ann_name = List.exists ~f:(class_name_matches ann_name) ia let pdesc_get_return_annot pdesc = - fst (Procdesc.get_attributes pdesc).ProcAttributes.method_annotation + (Procdesc.get_attributes pdesc).ProcAttributes.method_annotation.return let pdesc_has_return_annot pdesc predicate = predicate (pdesc_get_return_annot pdesc) @@ -151,7 +152,7 @@ let pdesc_return_annot_ends_with pdesc annot = let pname_has_return_annot pname ~attrs_of_pname predicate = match attrs_of_pname pname with | Some attributes -> - predicate (fst attributes.ProcAttributes.method_annotation) + predicate attributes.ProcAttributes.method_annotation.return | None -> false diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index 9d219fbd5..e7efd7bd6 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -223,12 +223,12 @@ let create_local_procdesc ?(set_objc_accessor_attr = false) trans_unit_ctx cfg t in let create_new_procdesc () = let all_params = Option.to_list ms.CMethodSignature.class_param @ ms.CMethodSignature.params in - let params_annots = - List.map ~f:(fun ({annot} : CMethodSignature.param_type) -> annot) all_params - in - let return_annot = snd ms.CMethodSignature.ret_type in let has_added_return_param = ms.CMethodSignature.has_added_return_param in - let method_annotation = (return_annot, params_annots) in + let method_annotation = + let return = snd ms.CMethodSignature.ret_type in + let params = List.map ~f:(fun ({annot} : CMethodSignature.param_type) -> annot) all_params in + Annot.Method.{return; params} + in let formals = List.map ~f:(fun ({name; typ} : CMethodSignature.param_type) -> (name, typ)) all_params in diff --git a/infer/src/eradicate/AnnotatedSignature.ml b/infer/src/eradicate/AnnotatedSignature.ml index 3a3cc8fd8..18504ced1 100644 --- a/infer/src/eradicate/AnnotatedSignature.ml +++ b/infer/src/eradicate/AnnotatedSignature.ml @@ -25,7 +25,7 @@ let get proc_attributes : t = let method_annotation = proc_attributes.ProcAttributes.method_annotation in let formals = proc_attributes.ProcAttributes.formals in let ret_type = proc_attributes.ProcAttributes.ret_type in - let ia, ial0 = method_annotation in + let Annot.Method.({return; params}) = method_annotation in let natl = let rec extract ial parl = match (ial, parl) with @@ -38,9 +38,9 @@ let get proc_attributes : t = | _ :: _, [] -> assert false in - List.rev (extract (List.rev ial0) (List.rev formals)) + List.rev (extract (List.rev params) (List.rev formals)) in - let annotated_signature = {ret= (ia, ret_type); params= natl} in + let annotated_signature = {ret= (return, ret_type); params= natl} in annotated_signature diff --git a/infer/src/java/jAnnotation.ml b/infer/src/java/jAnnotation.ml index 7efb1a1ac..8ba61860c 100644 --- a/infer/src/java/jAnnotation.ml +++ b/infer/src/java/jAnnotation.ml @@ -44,6 +44,6 @@ let translate_item avlist : Annot.Item.t = let translate_method ann : Annot.Method.t = let global_ann = ann.Javalib.ma_global in let param_ann = ann.Javalib.ma_parameters in - let ret_item = translate_item global_ann in - let param_items = List.map ~f:translate_item param_ann in - (ret_item, param_items) + let return = translate_item global_ann in + let params = List.map ~f:translate_item param_ann in + {return; params}