[nullsafe] Make Trust list a closed type, and expose only emptiness.

Summary:
As artempyanykh pointed out, exposing trust list might encourage clients to
start writing business logic manipulating with trust lists outside of
NullsafeMode module, which we don't like to happen.

Reviewed By: artempyanykh

Differential Revision: D21230973

fbshipit-source-id: 39bd0b0d8
master
Mitya Lyubarskiy 5 years ago committed by Facebook GitHub Bot
parent d5862b0a22
commit bf1c593d07

@ -44,16 +44,18 @@ type meta_issue =
; severity: Exceptions.severity ; severity: Exceptions.severity
; meta_issue_info: Jsonbug_t.nullsafe_meta_issue_info } ; meta_issue_info: Jsonbug_t.nullsafe_meta_issue_info }
let mode_to_json = function let mode_to_json mode =
| NullsafeMode.Default -> let open NullsafeMode in
match mode with
| Default ->
`Default `Default
| NullsafeMode.Local NullsafeMode.Trust.All -> | Local Trust.All ->
`LocalTrustAll `LocalTrustAll
| NullsafeMode.Local (NullsafeMode.Trust.Only names) when JavaClassName.Set.is_empty names -> | Local (Trust.Only trust_list) when Trust.is_trust_none trust_list ->
`LocalTrustNone `LocalTrustNone
| NullsafeMode.Local (NullsafeMode.Trust.Only _) -> | Local (Trust.Only _) ->
`LocalTrustSome `LocalTrustSome
| NullsafeMode.Strict -> | Strict ->
`Strict `Strict
@ -105,8 +107,8 @@ let make_meta_issue all_issues current_mode class_name =
match mode_to_promote_to with match mode_to_promote_to with
| NullsafeMode.Local NullsafeMode.Trust.All -> | NullsafeMode.Local NullsafeMode.Trust.All ->
trust_all_mode trust_all_mode
| NullsafeMode.Local (NullsafeMode.Trust.Only names) | NullsafeMode.Local (NullsafeMode.Trust.Only trust_list)
when JavaClassName.Set.is_empty names -> when NullsafeMode.Trust.is_trust_none trust_list ->
trust_none_mode trust_none_mode
| NullsafeMode.Strict | NullsafeMode.Strict
(* We don't recommend "strict" for now as it is harder to keep a class in strict mode than it "trust none" mode. (* We don't recommend "strict" for now as it is harder to keep a class in strict mode than it "trust none" mode.

@ -49,13 +49,13 @@ let is_considered_nonnull ~nullsafe_mode nullability =
match nullsafe_mode with match nullsafe_mode with
| NullsafeMode.Strict -> | NullsafeMode.Strict ->
StrictNonnull StrictNonnull
| NullsafeMode.Local (NullsafeMode.Trust.Only classes) when JavaClassName.Set.is_empty classes | NullsafeMode.Local (NullsafeMode.Trust.Only trust_list)
-> when NullsafeMode.Trust.is_trust_none trust_list ->
(* Though "trust none" is technically a subcase of trust some, (* Though "trust none" is technically a subcase of trust some,
we need this pattern to be different from the one below so we can detect possible we need this pattern to be different from the one below so we can detect possible
promotions from "trust some" to "trust none" *) promotions from "trust some" to "trust none" *)
LocallyCheckedNonnull LocallyCheckedNonnull
| NullsafeMode.Local (NullsafeMode.Trust.Only _classes) -> | NullsafeMode.Local (NullsafeMode.Trust.Only _) ->
LocallyTrustedNonnull LocallyTrustedNonnull
| NullsafeMode.Local NullsafeMode.Trust.All -> | NullsafeMode.Local NullsafeMode.Trust.All ->
UncheckedNonnull UncheckedNonnull

@ -9,7 +9,11 @@ open! IStd
module F = Format module F = Format
module Trust = struct module Trust = struct
type t = All | Only of JavaClassName.Set.t [@@deriving compare, equal] type trust_list = JavaClassName.Set.t [@@deriving compare, equal]
type t = All | Only of trust_list [@@deriving compare, equal]
let is_trust_none trust_list = JavaClassName.Set.is_empty trust_list
let none = Only JavaClassName.Set.empty let none = Only JavaClassName.Set.empty

@ -12,7 +12,11 @@ open! IStd
module Trust : sig module Trust : sig
[@@@warning "-32"] [@@@warning "-32"]
type t = All | Only of JavaClassName.Set.t [@@deriving compare, equal] type trust_list
val is_trust_none : trust_list -> bool
type t = All | Only of trust_list [@@deriving compare, equal]
val none : t val none : t

Loading…
Cancel
Save