[nullsafe] remove 'annotation' abstraction.

Summary:
This abstraction was not always used consistently.

Its usage made more sense when it supported both present annotations and
optional annotation (which got removed in previous diff).

The rought semantic of that was "what is the inferred type for such and
such value (variable or expression) in typestate". So it is not really
_annotation_ in first place, it is more like "what we inferred about
nullability given annotations, known special cases, and current sybmolic
execition state".

Let's explicitly rename `map` to `is_nullable`. If/when we need to
enhance this further (and we likely will), we will do it accordingly.

Reviewed By: jvillard

Differential Revision: D17153434

fbshipit-source-id: 3c85b56df
master
Mitya Lyubarskiy 5 years ago committed by Facebook Github Bot
parent 46cf107411
commit 58fe80fdf5

@ -11,10 +11,6 @@ module L = Logging
type t = {ret: Annot.Item.t * Typ.t; params: (Mangled.t * Annot.Item.t * Typ.t) list} type t = {ret: Annot.Item.t * Typ.t; params: (Mangled.t * Annot.Item.t * Typ.t) list}
[@@deriving compare] [@@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 get proc_attributes : t =
let method_annotation = proc_attributes.ProcAttributes.method_annotation in let method_annotation = proc_attributes.ProcAttributes.method_annotation in
let formals = proc_attributes.ProcAttributes.formals 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_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 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 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) (s, ia', t)
in in
let params' = let params' =

@ -14,19 +14,17 @@ type t =
; params: (Mangled.t * Annot.Item.t * Typ.t) list (** Annotated parameters. *) } ; params: (Mangled.t * Annot.Item.t * Typ.t) list (** Annotated parameters. *) }
[@@deriving compare] [@@deriving compare]
type annotation = Nullable [@@deriving compare]
val param_has_annot : (Annot.Item.t -> bool) -> Pvar.t -> t -> bool val param_has_annot : (Annot.Item.t -> bool) -> Pvar.t -> t -> bool
(** Check if the given parameter has an annotation in the given signature *) (** Check if the given parameter has an annotation in the given signature *)
val mark : Typ.Procname.t -> annotation -> t -> bool * bool list -> t val mark_nullability : Typ.Procname.t -> t -> bool * bool list -> t
(** Mark the annotated signature with the given annotation map. *) (** Mark the annotated signature with the given nullability of the ret value and given nullability of the params ). *)
val get : ProcAttributes.t -> t val get : ProcAttributes.t -> t
(** Get a method signature with annotations from a proc_attributes. *) (** Get a method signature with annotations from a proc_attributes. *)
val mk_ia : annotation -> Annot.Item.t -> Annot.Item.t val mk_ia_nullable : Annot.Item.t -> Annot.Item.t
(** Add the annotation to the item_annotation. *) (** Add the nullable annotation to the item_annotation, if not already present. *)
val pp : Typ.Procname.t -> Format.formatter -> t -> unit val pp : Typ.Procname.t -> Format.formatter -> t -> unit
(** Pretty print a method signature with annotations. *) (** Pretty print a method signature with annotations. *)

@ -18,8 +18,7 @@ let get_field_annotation tenv fn typ =
let ia' = let ia' =
(* TODO (t4968422) eliminate not !Config.eradicate check by marking fields as nullified *) (* TODO (t4968422) eliminate not !Config.eradicate check by marking fields as nullified *)
(* outside of Eradicate in some other way *) (* outside of Eradicate in some other way *)
if not Config.eradicate then AnnotatedSignature.mk_ia AnnotatedSignature.Nullable ia if not Config.eradicate then AnnotatedSignature.mk_ia_nullable ia else ia
else ia
in in
Some (t, ia') Some (t, ia')

@ -35,7 +35,7 @@ let get_modelled_annotated_signature proc_attributes =
let lookup_models_nullable ann_sig = let lookup_models_nullable ann_sig =
try try
let mark = Hashtbl.find annotated_table_nullable proc_id in 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 with Caml.Not_found -> ann_sig
in in
annotated_signature |> lookup_models_nullable annotated_signature |> lookup_models_nullable

@ -9,19 +9,13 @@ open! IStd
(** Module to represent annotations on types. *) (** Module to represent annotations on types. *)
module AnnotationsMap = Caml.Map.Make (struct type t = {is_nullable: bool; origin: TypeOrigin.t} [@@deriving compare]
type t = AnnotatedSignature.annotation [@@deriving compare]
end)
type t = {map: bool AnnotationsMap.t; origin: TypeOrigin.t} [@@deriving compare]
let equal = [%compare.equal: t] let equal = [%compare.equal: t]
let is_nullable ta = try AnnotationsMap.find Nullable ta.map with Caml.Not_found -> false let is_nullable ta = ta.is_nullable
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 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_origin ta =
let descr_opt = TypeOrigin.get_description ta.origin in let descr_opt = TypeOrigin.get_description ta.origin in
@ -56,10 +50,7 @@ let origin_is_fun_library ta =
false false
let const_nullable b origin = let const_nullable is_nullable origin = {origin; is_nullable}
let ta = {origin; map= AnnotationsMap.empty} in
set_nullable b ta
let with_origin ta o = {ta with origin= o} let with_origin ta o = {ta with origin= o}

Loading…
Cancel
Save