Skip to content

Commit

Permalink
[flow] remove natural_inference_exports_primitive_const option
Browse files Browse the repository at this point in the history
Summary:
Enabled by default in latest version.

Removes 4 `*_UNSOUND` types from type_sig_merge.ml.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D67585674

fbshipit-source-id: 944f293f26f8122852ac9d2d2d35f5875ef16ab2
  • Loading branch information
panagosg7 authored and facebook-github-bot committed Dec 23, 2024
1 parent 4804b12 commit ef92045
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 74 deletions.
2 changes: 0 additions & 2 deletions src/commands/commandUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1441,8 +1441,6 @@ let make_options
opt_strict_mode = strict_mode;
opt_merge_timeout;
opt_missing_module_generators = FlowConfig.missing_module_generators flowconfig;
opt_natural_inference_exports_primitive_const =
FlowConfig.natural_inference_exports_primitive_const flowconfig;
opt_no_unchecked_indexed_access = FlowConfig.no_unchecked_indexed_access flowconfig;
opt_saved_state_fetcher;
opt_saved_state_force_recheck = saved_state_options_flags.saved_state_force_recheck;
Expand Down
8 changes: 0 additions & 8 deletions src/commands/config/flowConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ module Opts = struct
multi_platform_extension_group_mapping: (string * string list) list;
multi_platform_ambient_supports_platform_directory_overrides: (string * string list) list;
munge_underscores: bool;
natural_inference_exports_primitive_const: bool;
no_flowlib: bool;
no_unchecked_indexed_access: bool;
node_main_fields: string list;
Expand Down Expand Up @@ -253,7 +252,6 @@ module Opts = struct
multi_platform_extension_group_mapping = [];
multi_platform_ambient_supports_platform_directory_overrides = [];
munge_underscores = false;
natural_inference_exports_primitive_const = true;
no_flowlib = false;
no_unchecked_indexed_access = false;
node_main_fields = ["main"];
Expand Down Expand Up @@ -1079,9 +1077,6 @@ module Opts = struct
("module.use_strict", boolean (fun opts v -> Ok { opts with modules_are_use_strict = v }));
("munge_underscores", boolean (fun opts v -> Ok { opts with munge_underscores = v }));
("name", root_name_parser);
( "experimental.natural_inference.exports.primitive_const",
boolean (fun opts v -> Ok { opts with natural_inference_exports_primitive_const = v })
);
("no_flowlib", boolean (fun opts v -> Ok { opts with no_flowlib = v }));
( "no_unchecked_indexed_access",
boolean (fun opts v -> Ok { opts with no_unchecked_indexed_access = v })
Expand Down Expand Up @@ -1808,9 +1803,6 @@ let multi_platform_ambient_supports_platform_directory_overrides c =

let munge_underscores c = c.options.Opts.munge_underscores

let natural_inference_exports_primitive_const c =
c.options.Opts.natural_inference_exports_primitive_const

let no_flowlib c = c.options.Opts.no_flowlib

let no_unchecked_indexed_access c = c.options.Opts.no_unchecked_indexed_access
Expand Down
2 changes: 0 additions & 2 deletions src/commands/config/flowConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ val multi_platform_ambient_supports_platform_directory_overrides :

val munge_underscores : config -> bool

val natural_inference_exports_primitive_const : config -> bool

val no_flowlib : config -> bool

val no_unchecked_indexed_access : config -> bool
Expand Down
4 changes: 0 additions & 4 deletions src/common/options.ml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ type t = {
opt_module_name_mappers: (Str.regexp * string) list;
opt_modules_are_use_strict: bool;
opt_munge_underscores: bool;
opt_natural_inference_exports_primitive_const: bool;
opt_no_unchecked_indexed_access: bool;
opt_node_main_fields: string list;
opt_node_resolver_allow_root_relative: bool;
Expand Down Expand Up @@ -308,9 +307,6 @@ let module_system opts = opts.opt_module

let modules_are_use_strict opts = opts.opt_modules_are_use_strict

let natural_inference_exports_primitive_const opts =
opts.opt_natural_inference_exports_primitive_const

let no_unchecked_indexed_access opts = opts.opt_no_unchecked_indexed_access

let node_main_fields opts = opts.opt_node_main_fields
Expand Down
1 change: 0 additions & 1 deletion src/flow_dot_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ let stub_metadata ~root ~checked =
max_literal_length = 100;
max_workers = 0;
missing_module_generators = [];
natural_inference_exports_primitive_const = false;
no_unchecked_indexed_access = false;
react_custom_jsx_typing = false;
react_ref_as_prop = Options.ReactRefAsProp.PartialSupport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ let stub_metadata ~root ~checked =
max_literal_length = 100;
max_workers = 0;
missing_module_generators = [];
natural_inference_exports_primitive_const = false;
no_unchecked_indexed_access = false;
react_custom_jsx_typing = false;
react_ref_as_prop = Options.ReactRefAsProp.PartialSupport;
Expand Down
1 change: 0 additions & 1 deletion src/typing/__tests__/type_hint_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ let metadata =
max_literal_length = 100;
max_workers = 0;
missing_module_generators = [];
natural_inference_exports_primitive_const = false;
no_unchecked_indexed_access = false;
react_custom_jsx_typing = false;
react_ref_as_prop = Options.ReactRefAsProp.PartialSupport;
Expand Down
1 change: 0 additions & 1 deletion src/typing/__tests__/typed_ast_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ let metadata =
max_literal_length = 100;
max_workers = 0;
missing_module_generators = [];
natural_inference_exports_primitive_const = false;
no_unchecked_indexed_access = false;
react_custom_jsx_typing = false;
react_ref_as_prop = Options.ReactRefAsProp.PartialSupport;
Expand Down
6 changes: 0 additions & 6 deletions src/typing/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type metadata = {
max_literal_length: int;
max_workers: int;
missing_module_generators: (Str.regexp * string) list;
natural_inference_exports_primitive_const: bool;
no_unchecked_indexed_access: bool;
react_custom_jsx_typing: bool;
react_ref_as_prop: Options.ReactRefAsProp.t;
Expand Down Expand Up @@ -287,8 +286,6 @@ let metadata_of_options options =
max_literal_length = Options.max_literal_length options;
max_workers = Options.max_workers options;
missing_module_generators = Options.missing_module_generators options;
natural_inference_exports_primitive_const =
Options.natural_inference_exports_primitive_const options;
no_unchecked_indexed_access = Options.no_unchecked_indexed_access options;
react_custom_jsx_typing = Options.react_custom_jsx_typing options;
react_ref_as_prop = Options.react_ref_as_prop options;
Expand Down Expand Up @@ -644,9 +641,6 @@ let max_workers cx = cx.metadata.max_workers

let missing_module_generators cx = cx.metadata.missing_module_generators

let natural_inference_exports_primitive_const cx =
cx.metadata.natural_inference_exports_primitive_const

let no_unchecked_indexed_access cx = cx.metadata.no_unchecked_indexed_access

let jsx cx = cx.metadata.jsx
Expand Down
3 changes: 0 additions & 3 deletions src/typing/context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ type metadata = {
max_literal_length: int;
max_workers: int;
missing_module_generators: (Str.regexp * string) list;
natural_inference_exports_primitive_const: bool;
no_unchecked_indexed_access: bool;
react_custom_jsx_typing: bool;
react_ref_as_prop: Options.ReactRefAsProp.t;
Expand Down Expand Up @@ -304,8 +303,6 @@ val max_workers : t -> int

val missing_module_generators : t -> (Str.regexp * string) list

val natural_inference_exports_primitive_const : t -> bool

val no_unchecked_indexed_access : t -> bool

val jsx : t -> Options.jsx_mode
Expand Down
53 changes: 9 additions & 44 deletions src/typing/type_sig_merge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,7 @@ let merge_ref :
match ref with
| Pack.LocalRef { ref_loc; index } ->
let (lazy (def_loc, name, t_general, t_const)) = Local_defs.get file.local_defs index in
let t =
Lazy.force
( if Context.natural_inference_exports_primitive_const file.cx && const_decl then
t_const
else
t_general
)
in
let t = Lazy.force (Utils_js.ite const_decl t_const t_general) in
let t = reposition_sig_tvar file.cx ref_loc t in
f t ~ref_loc ~def_loc name
| Pack.RemoteRef { ref_loc; index } ->
Expand Down Expand Up @@ -1116,19 +1109,12 @@ and merge_value ?(as_const = false) ?(const_decl = false) env file = function
let reason = Reason.(mk_reason RString loc) in
Type.(DefT (reason, StrGeneralT AnyLiteral))
| StringLit (loc, lit) ->
if Context.natural_inference_exports_primitive_const file.cx then
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RStringLit (OrdinaryName lit)) loc) in
Type.(DefT (reason, SingletonStrT (Reason.OrdinaryName lit)))
else
let reason = Reason.(mk_reason RString loc) in
Type.(DefT (reason, StrGeneralT AnyLiteral))
else if as_const then
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RStringLit (OrdinaryName lit)) loc) in
Type.(DefT (reason, SingletonStrT (Reason.OrdinaryName lit)))
else
let reason = Reason.(mk_reason RString loc) in
Type.(DefT (reason, StrT_UNSOUND (None, Reason.OrdinaryName lit)))
Type.(DefT (reason, StrGeneralT AnyLiteral))
| LongStringLit loc ->
let len = Context.max_literal_length file.cx in
let reason = Reason.(mk_annot_reason (RLongStringLit len) loc) in
Expand All @@ -1137,53 +1123,32 @@ and merge_value ?(as_const = false) ?(const_decl = false) env file = function
let reason = Reason.(mk_reason RNumber loc) in
Type.(DefT (reason, NumGeneralT AnyLiteral))
| NumberLit (loc, num, raw) ->
if Context.natural_inference_exports_primitive_const file.cx then
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RNumberLit raw) loc) in
Type.(DefT (reason, SingletonNumT (num, raw)))
else
let reason = Reason.(mk_reason RNumber loc) in
Type.(DefT (reason, NumGeneralT AnyLiteral))
else if as_const then
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RNumberLit raw) loc) in
Type.(DefT (reason, SingletonNumT (num, raw)))
else
let reason = Reason.(mk_reason RNumber loc) in
Type.(DefT (reason, NumT_UNSOUND (None, (num, raw))))
Type.(DefT (reason, NumGeneralT AnyLiteral))
| BigIntVal loc ->
let reason = Reason.(mk_reason RBigInt loc) in
Type.(DefT (reason, BigIntGeneralT AnyLiteral))
| BigIntLit (loc, bigint, raw) ->
if Context.natural_inference_exports_primitive_const file.cx then
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RBigIntLit raw) loc) in
Type.(DefT (reason, SingletonBigIntT (bigint, raw)))
else
let reason = Reason.(mk_reason RBigInt loc) in
Type.(DefT (reason, BigIntGeneralT AnyLiteral))
else if as_const then
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RBigIntLit raw) loc) in
Type.(DefT (reason, SingletonBigIntT (bigint, raw)))
else
let reason = Reason.(mk_reason RBigInt loc) in
Type.(DefT (reason, BigIntT_UNSOUND (None, (bigint, raw))))
Type.(DefT (reason, BigIntGeneralT AnyLiteral))
| BooleanVal loc ->
let reason = Reason.(mk_reason RBoolean loc) in
Type.(DefT (reason, BoolGeneralT))
| BooleanLit (loc, lit) ->
if Context.natural_inference_exports_primitive_const file.cx then
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RBooleanLit lit) loc) in
Type.(DefT (reason, SingletonBoolT lit))
else
let reason = Reason.(mk_reason RBoolean loc) in
Type.(DefT (reason, BoolGeneralT))
else if as_const then
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RBooleanLit lit) loc) in
Type.(DefT (reason, SingletonBoolT lit))
else
let reason = Reason.(mk_reason RBoolean loc) in
Type.(DefT (reason, BoolT_UNSOUND lit))
Type.(DefT (reason, BoolGeneralT))
| NullLit loc -> Type.NullT.at loc
| DeclareModuleImplicitlyExportedObject { loc; module_name; props } ->
merge_declare_module_implicitly_exported_object env file (loc, module_name, props)
Expand Down
1 change: 0 additions & 1 deletion tests/natural_inference_primitive/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@

[options]
all=true
experimental.natural_inference.exports.primitive_const=true

[strict]

0 comments on commit ef92045

Please sign in to comment.