Skip to content

Commit

Permalink
[flow][cleanup] Kill Reason.InternalModuleName
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Apr 30, 2024
1 parent ec7af26 commit 1b8141c
Show file tree
Hide file tree
Showing 17 changed files with 20 additions and 50 deletions.
20 changes: 3 additions & 17 deletions src/common/reason.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/common/reason.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/flow_dot_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/parser_utils/signature_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 2 additions & 4 deletions src/services/autocomplete/autocompleteService_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
2 changes: 1 addition & 1 deletion src/services/inference/check_service.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/services/inference/init_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/typing/__tests__/type_hint_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/typing/__tests__/typed_ast_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/typing/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/typing/context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 2 additions & 6 deletions src/typing/flow_js_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
[]

Expand Down
3 changes: 1 addition & 2 deletions src/typing/members.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion src/typing/merge_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
3 changes: 1 addition & 2 deletions src/typing/type_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
3 changes: 1 addition & 2 deletions src/typing/type_operation_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/typing/type_sig_merge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
( {
Expand Down

0 comments on commit 1b8141c

Please sign in to comment.