[nullsafe] Simplify signature of InferredNullability.join

Summary:
This function can return `None` if the result is equal to the first
argument of join (why first?). It is unclear if it was an optimization
attempt of over-complicated logic.

Reviewed By: artempyanykh

Differential Revision: D17876561

fbshipit-source-id: 9628fb86e
master
Mitya Lyubarskiy 5 years ago committed by Facebook Github Bot
parent 303263eb2e
commit 46ae3580c2

@ -9,8 +9,6 @@ open! IStd
type t = {nullability: Nullability.t; origin: TypeOrigin.t} [@@deriving compare] type t = {nullability: Nullability.t; origin: TypeOrigin.t} [@@deriving compare]
let equal = [%compare.equal: t]
let get_nullability {nullability} = nullability let get_nullability {nullability} = nullability
let is_nonnull {nullability} = match nullability with Nullable -> false | Nonnull -> true let is_nonnull {nullability} = match nullability with Nullable -> false | Nonnull -> true
@ -50,9 +48,7 @@ let join t1 t2 =
*) *)
TypeOrigin.join t1.origin t2.origin TypeOrigin.join t1.origin t2.origin
in in
let result = {nullability= joined_nullability; origin= joined_origin} in {nullability= joined_nullability; origin= joined_origin}
(* TODO: make the result return non optional value *)
if equal result t1 then None else Some result
let get_origin t = t.origin let get_origin t = t.origin

@ -43,7 +43,7 @@ val of_annotated_nullability : AnnotatedNullability.t -> TypeOrigin.t -> t
val get_origin : t -> TypeOrigin.t val get_origin : t -> TypeOrigin.t
(** The simple explanation of how was nullability inferred. *) (** The simple explanation of how was nullability inferred. *)
val join : t -> t -> t option val join : t -> t -> t
(** This is what happens with nullability when we join two flows in CFG, (** This is what happens with nullability when we join two flows in CFG,
e.g. e.g.
{[ {[

@ -39,18 +39,16 @@ let pp fmt typestate =
let map_join m1 m2 = let map_join m1 m2 =
let range_join _exp range1_opt range2_opt = let range_join _exp range1_opt range2_opt =
Option.both range1_opt range2_opt Option.both range1_opt range2_opt
|> Option.map |> Option.map ~f:(fun ((typ1, inferred_nullability1), (_, inferred_nullability2)) ->
~f:(fun (((typ1, inferred_nullability1) as range1), (_, inferred_nullability2)) -> (* Unlike nullability that Nullsafe infers, Java does not support local type inference
InferredNullability.join inferred_nullability1 inferred_nullability2 (for codebases and Java version nullsafe is currently aimed for).
|> Option.value_map ~default:range1 ~f:(fun ta' -> The real type does not depend on types being joined; it is determined by the corresponding type declaration instead.
( (* Java does not support local type inference (for codebases and Java version nullsafe is currently aimed for). We don't really use type information for reasons not related to things like diagnostic, and using one of types
The real type does not depend on types being joined; it is determined by the corresponding type declaration instead. serves as a good proxy.
We don't really use type information for reasons not related to things like diagnostic, and using one of types Let's take the left one.
serves as a good proxy. *)
Let's take the left one. let joined_type = typ1 in
*) (joined_type, InferredNullability.join inferred_nullability1 inferred_nullability2) )
typ1
, ta' ) ) )
in in
if phys_equal m1 m2 then m1 else M.merge range_join m1 m2 if phys_equal m1 m2 then m1 else M.merge range_join m1 m2

Loading…
Cancel
Save