[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]
let equal = [%compare.equal: t]
let get_nullability {nullability} = nullability
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
in
let result = {nullability= joined_nullability; origin= joined_origin} in
(* TODO: make the result return non optional value *)
if equal result t1 then None else Some result
{nullability= joined_nullability; origin= joined_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
(** 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,
e.g.
{[

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

Loading…
Cancel
Save