diff --git a/infer/src/nullsafe/AnnotatedSignature.ml b/infer/src/nullsafe/AnnotatedSignature.ml index 34f07bad8..7485329eb 100644 --- a/infer/src/nullsafe/AnnotatedSignature.ml +++ b/infer/src/nullsafe/AnnotatedSignature.ml @@ -11,10 +11,6 @@ module L = Logging type t = {ret: Annot.Item.t * Typ.t; params: (Mangled.t * Annot.Item.t * Typ.t) list} [@@deriving compare] -type annotation = Nullable [@@deriving compare] - -let ia_is ann ia = match ann with Nullable -> Annotations.ia_is_nullable ia - let get proc_attributes : t = let method_annotation = proc_attributes.ProcAttributes.method_annotation in let formals = proc_attributes.ProcAttributes.formals in @@ -58,17 +54,17 @@ let pp proc_name fmt annotated_signature = let mk_ann_str s = {Annot.class_name= s; parameters= []} -let mk_ann = function Nullable -> mk_ann_str Annotations.nullable +let mk_ia_nullable ia = + if Annotations.ia_is_nullable ia then ia else (mk_ann_str Annotations.nullable, true) :: ia -let mk_ia ann ia = if ia_is ann ia then ia else (mk_ann ann, true) :: ia -let mark_ia ann ia x = if x then mk_ia ann ia else ia +let mark_ia_nullability ia x = if x then mk_ia_nullable ia else ia -let mark proc_name ann asig (b, bs) = +let mark_nullability proc_name asig (b, bs) = let ia, t = asig.ret in - let ret' = (mark_ia ann ia b, t) in + let ret' = (mark_ia_nullability ia b, t) in let mark_param (s, ia, t) x = - let ia' = if x then mk_ia ann ia else ia in + let ia' = if x then mk_ia_nullable ia else ia in (s, ia', t) in let params' = diff --git a/infer/src/nullsafe/AnnotatedSignature.mli b/infer/src/nullsafe/AnnotatedSignature.mli index 7c71aa6dc..62e87eb49 100644 --- a/infer/src/nullsafe/AnnotatedSignature.mli +++ b/infer/src/nullsafe/AnnotatedSignature.mli @@ -14,19 +14,17 @@ type t = ; params: (Mangled.t * Annot.Item.t * Typ.t) list (** Annotated parameters. *) } [@@deriving compare] -type annotation = Nullable [@@deriving compare] - val param_has_annot : (Annot.Item.t -> bool) -> Pvar.t -> t -> bool (** Check if the given parameter has an annotation in the given signature *) -val mark : Typ.Procname.t -> annotation -> t -> bool * bool list -> t -(** Mark the annotated signature with the given annotation map. *) +val mark_nullability : Typ.Procname.t -> t -> bool * bool list -> t +(** Mark the annotated signature with the given nullability of the ret value and given nullability of the params ). *) val get : ProcAttributes.t -> t (** Get a method signature with annotations from a proc_attributes. *) -val mk_ia : annotation -> Annot.Item.t -> Annot.Item.t -(** Add the annotation to the item_annotation. *) +val mk_ia_nullable : Annot.Item.t -> Annot.Item.t +(** Add the nullable annotation to the item_annotation, if not already present. *) val pp : Typ.Procname.t -> Format.formatter -> t -> unit (** Pretty print a method signature with annotations. *) diff --git a/infer/src/nullsafe/eradicateChecks.ml b/infer/src/nullsafe/eradicateChecks.ml index 419757500..6eb83c03c 100644 --- a/infer/src/nullsafe/eradicateChecks.ml +++ b/infer/src/nullsafe/eradicateChecks.ml @@ -18,8 +18,7 @@ let get_field_annotation tenv fn typ = let ia' = (* TODO (t4968422) eliminate not !Config.eradicate check by marking fields as nullified *) (* outside of Eradicate in some other way *) - if not Config.eradicate then AnnotatedSignature.mk_ia AnnotatedSignature.Nullable ia - else ia + if not Config.eradicate then AnnotatedSignature.mk_ia_nullable ia else ia in Some (t, ia') diff --git a/infer/src/nullsafe/models.ml b/infer/src/nullsafe/models.ml index 13535fa87..b36ac93a6 100644 --- a/infer/src/nullsafe/models.ml +++ b/infer/src/nullsafe/models.ml @@ -35,7 +35,7 @@ let get_modelled_annotated_signature proc_attributes = let lookup_models_nullable ann_sig = try let mark = Hashtbl.find annotated_table_nullable proc_id in - AnnotatedSignature.mark proc_name AnnotatedSignature.Nullable ann_sig mark + AnnotatedSignature.mark_nullability proc_name ann_sig mark with Caml.Not_found -> ann_sig in annotated_signature |> lookup_models_nullable diff --git a/infer/src/nullsafe/typeAnnotation.ml b/infer/src/nullsafe/typeAnnotation.ml index d9c04e075..7e8ce98ed 100644 --- a/infer/src/nullsafe/typeAnnotation.ml +++ b/infer/src/nullsafe/typeAnnotation.ml @@ -9,19 +9,13 @@ open! IStd (** Module to represent annotations on types. *) -module AnnotationsMap = Caml.Map.Make (struct - type t = AnnotatedSignature.annotation [@@deriving compare] -end) - -type t = {map: bool AnnotationsMap.t; origin: TypeOrigin.t} [@@deriving compare] +type t = {is_nullable: bool; origin: TypeOrigin.t} [@@deriving compare] let equal = [%compare.equal: t] -let is_nullable ta = try AnnotationsMap.find Nullable ta.map with Caml.Not_found -> false - -let set_nullable b ta = - if Bool.equal (is_nullable ta) b then ta else {ta with map= AnnotationsMap.add Nullable b ta.map} +let is_nullable ta = ta.is_nullable +let set_nullable b ta = if Bool.equal (is_nullable ta) b then ta else {ta with is_nullable= b} let descr_origin ta = let descr_opt = TypeOrigin.get_description ta.origin in @@ -56,10 +50,7 @@ let origin_is_fun_library ta = false -let const_nullable b origin = - let ta = {origin; map= AnnotationsMap.empty} in - set_nullable b ta - +let const_nullable is_nullable origin = {origin; is_nullable} let with_origin ta o = {ta with origin= o}