[nullsafe][annotation graph] Don't try to annotate primitives

Summary:
In the previous diff we introduced
AnnotatedNullability.is_annotatable_as_nullable method.

Lets now use it in all places where we issue ProvisionallyNullable
annotation.

This will lead to more precise nullability graph (without attempts to
annotate primitives).

Reviewed By: artempyanykh

Differential Revision: D24650951

fbshipit-source-id: 8ea0bb97d
master
Mitya Lyubarskiy 4 years ago committed by Facebook GitHub Bot
parent a4efdce9b0
commit 18ccc321c8

@ -47,18 +47,25 @@ let nullability_for_return ~proc_name ~is_callee_in_trust_list ~nullsafe_mode ~i
AnnotatedNullability.of_type_and_annotation ~is_callee_in_trust_list ~nullsafe_mode AnnotatedNullability.of_type_and_annotation ~is_callee_in_trust_list ~nullsafe_mode
~is_third_party ret_type ret_annotations ~is_third_party ret_type ret_annotations
in in
(* if any param is annotated with propagates nullable, then the result is nullable *) (* if any param is annotated with propagates nullable, the return nullability is also nullable *)
match nullability with let nullability =
| AnnotatedNullability.Nullable _ -> match nullability with
nullability (* We already know it is nullable - lets not overwrite the origin *) | AnnotatedNullability.Nullable _ ->
| _ when has_propagates_nullable_in_param -> nullability (* We already know it is nullable - lets not overwrite the origin *)
(* if any params is propagates nullable, the return type can be only nullable *) | _ when has_propagates_nullable_in_param ->
AnnotatedNullability.Nullable AnnotatedNullability.HasPropagatesNullableInParam (* if any params is propagates nullable, the return type can be only nullable *)
| _ when is_provisional_annotation_mode -> AnnotatedNullability.Nullable AnnotatedNullability.HasPropagatesNullableInParam
(* Not explicitly annotated with [@Nullable] - make it provisionally nullable *) | _ ->
AnnotatedNullability.ProvisionallyNullable (ProvisionalAnnotation.Method proc_name) nullability
| _ -> in
nullability let final_nullability =
if
is_provisional_annotation_mode
&& AnnotatedNullability.can_be_considered_for_provisional_annotation nullability
then AnnotatedNullability.ProvisionallyNullable (ProvisionalAnnotation.Method proc_name)
else nullability
in
final_nullability
let nullability_for_param ~proc_name ~param_num ~is_callee_in_trust_list ~nullsafe_mode let nullability_for_param ~proc_name ~param_num ~is_callee_in_trust_list ~nullsafe_mode
@ -67,14 +74,13 @@ let nullability_for_param ~proc_name ~param_num ~is_callee_in_trust_list ~nullsa
AnnotatedNullability.of_type_and_annotation ~is_callee_in_trust_list ~nullsafe_mode AnnotatedNullability.of_type_and_annotation ~is_callee_in_trust_list ~nullsafe_mode
~is_third_party param_type param_annotations ~is_third_party param_type param_annotations
in in
match nullability with if
| AnnotatedNullability.Nullable _ -> is_provisional_annotation_mode
nullability && AnnotatedNullability.can_be_considered_for_provisional_annotation nullability
| _ when is_provisional_annotation_mode -> then
AnnotatedNullability.ProvisionallyNullable AnnotatedNullability.ProvisionallyNullable
(ProvisionalAnnotation.Param {method_info= proc_name; num= param_num}) (ProvisionalAnnotation.Param {method_info= proc_name; num= param_num})
| _ -> else nullability
nullability
(* Given annotations for method signature, extract nullability information (* Given annotations for method signature, extract nullability information

Loading…
Cancel
Save