From 303263eb2ea45101ce617c733d6c303e440ea219 Mon Sep 17 00:00:00 2001 From: Mitya Lyubarskiy Date: Mon, 21 Oct 2019 04:40:14 -0700 Subject: [PATCH] [nullsafe] Don't join types in a fancy way. Summary: The goal of this logic is unclear: 1/ See the comments 2/ I can not see the scenario where classes and proper types can be joined in a legit Java program 3/ Even it if was the case, I don't see how this heuristic is justified. So I assume it is not. Reviewed By: artempyanykh Differential Revision: D17876568 fbshipit-source-id: c9c6cd604 --- infer/src/absint/PatternMatch.ml | 8 -------- infer/src/absint/PatternMatch.mli | 3 --- infer/src/nullsafe/typeState.ml | 14 +++++++++----- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/infer/src/absint/PatternMatch.ml b/infer/src/absint/PatternMatch.ml index 68409cd75..65afd3825 100644 --- a/infer/src/absint/PatternMatch.ml +++ b/infer/src/absint/PatternMatch.ml @@ -9,14 +9,6 @@ open! IStd (** Module for Pattern matching. *) -let type_is_object typ = - match typ.Typ.desc with - | Tptr ({desc= Tstruct name}, _) -> - Typ.Name.equal name Typ.Name.Java.java_lang_object - | _ -> - false - - (** Holds iff the predicate holds on a supertype of the named type, including the type itself *) let rec supertype_exists tenv pred name = match Tenv.lookup tenv name with diff --git a/infer/src/absint/PatternMatch.mli b/infer/src/absint/PatternMatch.mli index dbe2ab4f5..99ab84283 100644 --- a/infer/src/absint/PatternMatch.mli +++ b/infer/src/absint/PatternMatch.mli @@ -132,9 +132,6 @@ val type_get_class_name : Typ.t -> Typ.Name.t option val type_is_class : Typ.t -> bool (** Is the type a class type *) -val type_is_object : Typ.t -> bool -(** Is the type java.lang.Object *) - val get_fields_nullified : Procdesc.t -> Typ.Fieldname.Set.t (** return the set of instance fields that are assigned to a null literal in [procdesc] *) diff --git a/infer/src/nullsafe/typeState.ml b/infer/src/nullsafe/typeState.ml index 7647e2db5..db715fc11 100644 --- a/infer/src/nullsafe/typeState.ml +++ b/infer/src/nullsafe/typeState.ml @@ -36,17 +36,21 @@ let pp fmt typestate = pp_map typestate -let type_join typ1 typ2 = if PatternMatch.type_is_object typ1 then typ2 else typ1 - 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), (typ2, inferred_nullability2)) -> + ~f:(fun (((typ1, inferred_nullability1) as range1), (_, inferred_nullability2)) -> InferredNullability.join inferred_nullability1 inferred_nullability2 |> Option.value_map ~default:range1 ~f:(fun ta' -> - let typ' = type_join typ1 typ2 in - (typ', 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' ) ) ) in if phys_equal m1 m2 then m1 else M.merge range_join m1 m2