From 1b8141c936a38f36c716d8967685b0c6183bba65 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Mon, 29 Apr 2024 18:02:07 -0700 Subject: [PATCH] [flow][cleanup] Kill Reason.InternalModuleName Summary: This is never a good idea. There would never be a place where accepting both an OrdinaryName and InternalModuleName make sense. This is the diff that kills it. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D56730071 fbshipit-source-id: 687b73fc328158b1adb605a30aa798486dbe45fa --- src/common/reason.ml | 20 +++---------------- src/common/reason.mli | 5 ----- src/flow_dot_js.ml | 2 +- src/parser_utils/signature_utils.ml | 4 +--- .../autocomplete/autocompleteService_js.ml | 6 ++---- src/services/inference/check_service.ml | 2 +- src/services/inference/init_js.ml | 2 +- src/typing/__tests__/type_hint_test.ml | 2 +- src/typing/__tests__/typed_ast_test.ml | 2 +- src/typing/context.ml | 2 +- src/typing/context.mli | 2 +- src/typing/flow_js_utils.ml | 8 ++------ src/typing/members.ml | 3 +-- src/typing/merge_js.ml | 2 +- src/typing/type_env.ml | 3 +-- src/typing/type_operation_utils.ml | 3 +-- src/typing/type_sig_merge.ml | 2 +- 17 files changed, 20 insertions(+), 50 deletions(-) diff --git a/src/common/reason.ml b/src/common/reason.ml index 2e6038c20e2..7e01a44a258 100644 --- a/src/common/reason.ml +++ b/src/common/reason.ml @@ -24,13 +24,11 @@ open String_utils type name = | OrdinaryName of string | InternalName of string - | InternalModuleName of string [@@deriving eq, ord, show] let display_string_of_name = function | OrdinaryName x -> x | InternalName x -> spf ".%s" x - | InternalModuleName x -> spf ".$module__%s" x let mk_id () = HeapIdent.make "" @@ -831,29 +829,17 @@ let internal_name name = InternalName name let internal_name_of_name name = match name with | OrdinaryName str -> internal_name str - | InternalName _ - | InternalModuleName _ -> + | InternalName _ -> (* Already internal *) name let is_internal_name = function | OrdinaryName _ -> false - | InternalName _ - | InternalModuleName _ -> - true - -let internal_module_name name = InternalModuleName name - -let is_internal_module_name = function - | OrdinaryName _ - | InternalName _ -> - false - | InternalModuleName _ -> true + | InternalName _ -> true let uninternal_name = function | OrdinaryName x - | InternalName x - | InternalModuleName x -> + | InternalName x -> x (* Instantiable reasons identify tvars that are created for the purpose of diff --git a/src/common/reason.mli b/src/common/reason.mli index 7f2297fad60..09f532c7095 100644 --- a/src/common/reason.mli +++ b/src/common/reason.mli @@ -10,7 +10,6 @@ val mk_id : unit -> int type name = | OrdinaryName of string | InternalName of string - | InternalModuleName of string [@@deriving eq, ord, show] type 'loc virtual_reason_desc = @@ -283,10 +282,6 @@ val internal_name : string -> name val internal_name_of_name : name -> name -val is_internal_module_name : name -> bool - -val internal_module_name : string -> name - val uninternal_name : name -> string val is_instantiable_reason : 'loc virtual_reason -> bool diff --git a/src/flow_dot_js.ml b/src/flow_dot_js.ml index 066fa21b1ee..85a900f291a 100644 --- a/src/flow_dot_js.ml +++ b/src/flow_dot_js.ml @@ -261,7 +261,7 @@ let init_infer_and_merge ~root filename js_config_object docblock ast file_sig = let builtins = Context.builtins cx in match Builtins.get_builtin_module_opt builtins mref with | Some t -> Ok t - | None -> Error (Reason.internal_module_name mref)) + | None -> Error mref) (File_sig.require_loc_map file_sig); (* infer ast *) let (_, { Flow_ast.Program.all_comments = comments; _ }) = ast in diff --git a/src/parser_utils/signature_utils.ml b/src/parser_utils/signature_utils.ml index 312458d88ce..8f24ac63219 100644 --- a/src/parser_utils/signature_utils.ml +++ b/src/parser_utils/signature_utils.ml @@ -49,9 +49,7 @@ let is_munged_property_string name = String.length name >= 2 && name.[0] = '_' & let is_munged_property_name = function (* TODO consider adding another name variant for munged property strings *) | Reason.OrdinaryName name -> is_munged_property_string name - | Reason.InternalName _ - | Reason.InternalModuleName _ -> - false + | Reason.InternalName _ -> false module This_finder = struct class ['a] finder = diff --git a/src/services/autocomplete/autocompleteService_js.ml b/src/services/autocomplete/autocompleteService_js.ml index 720a7909a3f..d6505db1a81 100644 --- a/src/services/autocomplete/autocompleteService_js.ml +++ b/src/services/autocomplete/autocompleteService_js.ml @@ -471,8 +471,7 @@ let members_of_type let open Reason in match s with | OrdinaryName "constructor" - | InternalName _ - | InternalModuleName _ -> + | InternalName _ -> None (* TODO consider making the $-prefixed names internal *) | OrdinaryName str when (String.length str >= 1 && str.[0] = '$') || SSet.mem str exclude_keys @@ -997,8 +996,7 @@ let exports_of_module_ty let is_kind export_kind = kind = `Either || export_kind = `Either || export_kind = kind in let filter_name name = match name with - | Reason.InternalName _ - | Reason.InternalModuleName _ -> + | Reason.InternalName _ -> (* don't show internal names in autocomplete *) false | Reason.OrdinaryName name -> diff --git a/src/services/inference/check_service.ml b/src/services/inference/check_service.ml index 69addc2265b..39793129f50 100644 --- a/src/services/inference/check_service.ml +++ b/src/services/inference/check_service.ml @@ -37,7 +37,7 @@ let unknown_module_t cx _mref m = let builtins = Context.builtins cx in match Builtins.get_builtin_module_opt builtins module_name with | Some t -> Ok t - | None -> Error (Reason.internal_module_name module_name) + | None -> Error module_name let unchecked_module_t cx file_key mref = let desc = Reason.RUntypedModule mref in diff --git a/src/services/inference/init_js.ml b/src/services/inference/init_js.ml index c2b5a655711..148e6abbb49 100644 --- a/src/services/inference/init_js.ml +++ b/src/services/inference/init_js.ml @@ -62,7 +62,7 @@ let load_lib_files ~ccx ~options ~reader files = metadata builtin_leader_file_key (lazy (ALoc.empty_table builtin_leader_file_key)) - (fun mref -> Error (Reason.InternalModuleName mref)) + (fun mref -> Error mref) mk_builtins in Some cx diff --git a/src/typing/__tests__/type_hint_test.ml b/src/typing/__tests__/type_hint_test.ml index 4edffa9e72a..aba56b2c818 100644 --- a/src/typing/__tests__/type_hint_test.ml +++ b/src/typing/__tests__/type_hint_test.ml @@ -259,7 +259,7 @@ let fun_t ~params ~return_t = let mk_cx ~verbose () = let aloc_table = lazy (ALoc.empty_table dummy_filename) in - let resolve_require mref = Error (Reason.internal_module_name mref) in + let resolve_require mref = Error mref in let ccx = Context.make_ccx () in let metadata = if verbose then diff --git a/src/typing/__tests__/typed_ast_test.ml b/src/typing/__tests__/typed_ast_test.ml index 5a95f8608b0..6bb1d2f8208 100644 --- a/src/typing/__tests__/typed_ast_test.ml +++ b/src/typing/__tests__/typed_ast_test.ml @@ -109,7 +109,7 @@ let before_and_after_stmts file_name = in let cx = let aloc_table = lazy (ALoc.empty_table file_key) in - let resolve_require mref = Error (Reason.internal_module_name mref) in + let resolve_require mref = Error mref in let ccx = Context.make_ccx () in Context.make ccx metadata file_key aloc_table resolve_require mk_builtins in diff --git a/src/typing/context.ml b/src/typing/context.ml index d736c428927..7f5dab8ac8a 100644 --- a/src/typing/context.ml +++ b/src/typing/context.ml @@ -213,7 +213,7 @@ type typing_mode = | SynthesisMode | HintEvaluationMode -type resolved_require = (Type.t, Reason.name) result +type resolved_require = (Type.t, string) result type t = { ccx: component_t; diff --git a/src/typing/context.mli b/src/typing/context.mli index 4ff9eea96b3..4e4a0c25a6c 100644 --- a/src/typing/context.mli +++ b/src/typing/context.mli @@ -116,7 +116,7 @@ type typing_mode = | SynthesisMode | HintEvaluationMode -type resolved_require = (Type.t, Reason.name) result +type resolved_require = (Type.t, string) result type resolve_require = string -> resolved_require diff --git a/src/typing/flow_js_utils.ml b/src/typing/flow_js_utils.ml index f50725ac507..b7f52dbb2fc 100644 --- a/src/typing/flow_js_utils.ml +++ b/src/typing/flow_js_utils.ml @@ -2239,9 +2239,7 @@ module GetPropT_kit (F : Get_prop_helper_sig) = struct | OrdinaryName _ -> let t = enum_proto cx ~reason:access_reason ~enum_object_t ~enum_value_t ~representation_t in F.cg_get_prop cx trace t access - | InternalName _ - | InternalModuleName _ -> - error_invalid_access ~suggestion:None + | InternalName _ -> error_invalid_access ~suggestion:None let on_array_length cx trace reason arity reason_op = (* Use definition as the reason for the length, as this is @@ -2458,9 +2456,7 @@ let keylist_of_props props reason_op = | OrdinaryName _ -> let reason = replace_desc_new_reason (RStringLit name) reason_op in DefT (reason, SingletonStrT name) :: acc - | InternalName _ - | InternalModuleName _ -> - acc) + | InternalName _ -> acc) props [] diff --git a/src/typing/members.ml b/src/typing/members.ml index 8b83f44afb3..8742f9c49df 100644 --- a/src/typing/members.ml +++ b/src/typing/members.ml @@ -489,8 +489,7 @@ let find_props cx = | OrdinaryName key -> (* Filter out keys that start with "$" *) not (String.length key >= 1 && key.[0] = '$') - | InternalName _ - | InternalModuleName _ -> + | InternalName _ -> (* TODO we probably should filter out internal names too, but for now keeping behavior the same *) true ) diff --git a/src/typing/merge_js.ml b/src/typing/merge_js.ml index 7bf6838736e..bd539503eef 100644 --- a/src/typing/merge_js.ml +++ b/src/typing/merge_js.ml @@ -732,7 +732,7 @@ let mk_builtins metadata master_cx = { metadata with Context.checked = false } builtin_leader_file_key (lazy (ALoc.empty_table builtin_leader_file_key)) - (fun mref -> Error (Reason.InternalModuleName mref)) + (fun mref -> Error mref) (fun _ -> !builtins_ref) in let (values, types, modules) = diff --git a/src/typing/type_env.ml b/src/typing/type_env.ml index 808bdcd170d..cbaa6c26f01 100644 --- a/src/typing/type_env.ml +++ b/src/typing/type_env.ml @@ -692,8 +692,7 @@ let local_scope_entry_exists cx loc = not (is_global_var cx loc) let get_var_declared_type ?(lookup_mode = ForValue) ?(is_declared_function = false) cx name loc = match (name, lookup_mode) with - | ((OrdinaryName _ | InternalModuleName _), ForType) - | (InternalModuleName _, ForValue) -> + | (OrdinaryName _, ForType) -> (match checked_find_loc_env_write_opt cx Env_api.OrdinaryNameLoc loc with | Some t -> t | None -> diff --git a/src/typing/type_operation_utils.ml b/src/typing/type_operation_utils.ml index da856e308d1..e6b176f340e 100644 --- a/src/typing/type_operation_utils.ml +++ b/src/typing/type_operation_utils.ml @@ -56,8 +56,7 @@ module Import_export = struct let module_t = match Context.find_require cx mref with | Ok t -> t - | Error m_name -> - Flow_js_utils.lookup_builtin_module_error cx (uninternal_name m_name) reason + | Error m_name -> Flow_js_utils.lookup_builtin_module_error cx m_name reason in ( if perform_platform_validation && Files.multi_platform Context.((metadata cx).file_options) then diff --git a/src/typing/type_sig_merge.ml b/src/typing/type_sig_merge.ml index 98d2ed8d00a..6a785dc6d01 100644 --- a/src/typing/type_sig_merge.ml +++ b/src/typing/type_sig_merge.ml @@ -2307,7 +2307,7 @@ let merge_builtins in let map_module_ref s : Context.resolved_require Lazy.t = match SMap.find_opt s dependencies_map with - | None -> lazy (Error (Reason.InternalModuleName s)) + | None -> lazy (Error s) | Some lazy_t -> Lazy.map (fun t -> Ok t) lazy_t in ( {