From ef920454318444fd2eb6f2472141377932567b8f Mon Sep 17 00:00:00 2001 From: Panos Vekris Date: Mon, 23 Dec 2024 10:25:12 -0800 Subject: [PATCH] [flow] remove natural_inference_exports_primitive_const option 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 --- src/commands/commandUtils.ml | 2 - src/commands/config/flowConfig.ml | 8 --- src/commands/config/flowConfig.mli | 2 - src/common/options.ml | 4 -- src/flow_dot_js.ml | 1 - .../__tests__/refactor_extract_utils_tests.ml | 1 - src/typing/__tests__/type_hint_test.ml | 1 - src/typing/__tests__/typed_ast_test.ml | 1 - src/typing/context.ml | 6 --- src/typing/context.mli | 3 -- src/typing/type_sig_merge.ml | 53 ++++--------------- tests/natural_inference_primitive/.flowconfig | 1 - 12 files changed, 9 insertions(+), 74 deletions(-) diff --git a/src/commands/commandUtils.ml b/src/commands/commandUtils.ml index b022edf1e89..3f396e58b97 100644 --- a/src/commands/commandUtils.ml +++ b/src/commands/commandUtils.ml @@ -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; diff --git a/src/commands/config/flowConfig.ml b/src/commands/config/flowConfig.ml index de2e14606be..0d8de0db7a4 100644 --- a/src/commands/config/flowConfig.ml +++ b/src/commands/config/flowConfig.ml @@ -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; @@ -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"]; @@ -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 }) @@ -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 diff --git a/src/commands/config/flowConfig.mli b/src/commands/config/flowConfig.mli index 26b62cb2fad..a275affc35a 100644 --- a/src/commands/config/flowConfig.mli +++ b/src/commands/config/flowConfig.mli @@ -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 diff --git a/src/common/options.ml b/src/common/options.ml index 198651091dd..45ca88e3e0c 100644 --- a/src/common/options.ml +++ b/src/common/options.ml @@ -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; @@ -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 diff --git a/src/flow_dot_js.ml b/src/flow_dot_js.ml index 9f9c99fa01f..1669f196671 100644 --- a/src/flow_dot_js.ml +++ b/src/flow_dot_js.ml @@ -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; diff --git a/src/services/code_action/__tests__/refactor_extract_utils_tests.ml b/src/services/code_action/__tests__/refactor_extract_utils_tests.ml index 9ef2c6fcab5..2d0c4f63a7c 100644 --- a/src/services/code_action/__tests__/refactor_extract_utils_tests.ml +++ b/src/services/code_action/__tests__/refactor_extract_utils_tests.ml @@ -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; diff --git a/src/typing/__tests__/type_hint_test.ml b/src/typing/__tests__/type_hint_test.ml index f30a6a6fd19..8f73b0943ec 100644 --- a/src/typing/__tests__/type_hint_test.ml +++ b/src/typing/__tests__/type_hint_test.ml @@ -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; diff --git a/src/typing/__tests__/typed_ast_test.ml b/src/typing/__tests__/typed_ast_test.ml index 009c39c0fd5..8112301a415 100644 --- a/src/typing/__tests__/typed_ast_test.ml +++ b/src/typing/__tests__/typed_ast_test.ml @@ -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; diff --git a/src/typing/context.ml b/src/typing/context.ml index 59d6801889e..cbe1435cc5c 100644 --- a/src/typing/context.ml +++ b/src/typing/context.ml @@ -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; @@ -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; @@ -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 diff --git a/src/typing/context.mli b/src/typing/context.mli index a551722abbd..ec09faea5c5 100644 --- a/src/typing/context.mli +++ b/src/typing/context.mli @@ -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; @@ -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 diff --git a/src/typing/type_sig_merge.ml b/src/typing/type_sig_merge.ml index eeaaf47828a..ca330763df6 100644 --- a/src/typing/type_sig_merge.ml +++ b/src/typing/type_sig_merge.ml @@ -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 } -> @@ -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 @@ -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) diff --git a/tests/natural_inference_primitive/.flowconfig b/tests/natural_inference_primitive/.flowconfig index 48d74ccc0da..08bb313bf3e 100644 --- a/tests/natural_inference_primitive/.flowconfig +++ b/tests/natural_inference_primitive/.flowconfig @@ -8,6 +8,5 @@ [options] all=true -experimental.natural_inference.exports.primitive_const=true [strict]