Skip to content

Commit

Permalink
Do not export Flow_js.lookup_builtin functions
Browse files Browse the repository at this point in the history
Summary:
The calls to `lookup_builtin_*` functions of merge_service.ml and new_check_service.ml
can be handled without creating any new constraints, ie from flow_js_utils.ml, instead
of flow_js.ml.

Reviewed By: samwgoldman

Differential Revision: D28659924

fbshipit-source-id: 507442171533cf0ec35316b55e8aaca0e8a56c09
  • Loading branch information
panagosg7 authored and facebook-github-bot committed Jun 2, 2021
1 parent 36edf0c commit f3206ba
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/services/inference/merge_service.ml
Expand Up @@ -104,7 +104,7 @@ let merge_context ~options ~reader master_cx component =
let builtin_name = Reason.internal_module_name (Modulename.to_string mname) in
fun loc ->
let reason = Reason.mk_reason desc loc in
Flow_js.lookup_builtin_strict cx builtin_name reason
Flow_js_utils.lookup_builtin_strict cx builtin_name reason
in
let mk_resource_module_t cx filename loc = Import_export.mk_resource_module_t cx loc filename in
let mk_cyclic_module_t component_rec i _loc =
Expand All @@ -123,7 +123,7 @@ let merge_context ~options ~reader master_cx component =
fun loc ->
let reason = Reason.(mk_reason desc loc) in
let default = Type.(AnyT (reason, Untyped)) in
Flow_js.lookup_builtin_with_default cx builtin_name default
Flow_js_utils.lookup_builtin_with_default cx builtin_name default
in
let file_dependency component_rec cx file_key mref =
let open Module_heaps in
Expand Down
4 changes: 2 additions & 2 deletions src/services/inference/new_check_service.ml
Expand Up @@ -171,7 +171,7 @@ let unknown_module_t cx mref provider =
if react_server_module_err then
Flow_js.add_output cx (Error_message.EImportInternalReactServerModule loc);
let reason = Reason.mk_reason desc loc in
Flow_js.lookup_builtin_strict cx m_name reason
Flow_js_utils.lookup_builtin_strict cx m_name reason

let resource_module_t cx f loc = Import_export.mk_resource_module_t cx loc f

Expand All @@ -181,7 +181,7 @@ let unchecked_module_t cx mref =
fun loc ->
let reason = Reason.mk_reason desc loc in
let default = Type.(AnyT (reason, Untyped)) in
Flow_js.lookup_builtin_with_default cx m_name default
Flow_js_utils.lookup_builtin_with_default cx m_name default

let get_lint_severities metadata options =
let lint_severities = Options.lint_severities options in
Expand Down
3 changes: 1 addition & 2 deletions src/typing/flow_js.ml
Expand Up @@ -9765,8 +9765,7 @@ struct
* Does not add an entry that requires a
* write later. *)
and lookup_builtin_with_default cx x default =
let builtins = Context.builtins cx in
let builtin = Builtins.get_builtin builtins x ~on_missing:(fun () -> default) in
let builtin = Flow_js_utils.lookup_builtin_with_default cx x default in
Tvar.mk_where cx (reason_of_t default) (fun t -> flow_t cx (builtin, t))

and get_builtin_typeapp cx ?trace reason x targs =
Expand Down
4 changes: 0 additions & 4 deletions src/typing/flow_js.mli
Expand Up @@ -108,10 +108,6 @@ val add_output : Context.t -> ?trace:Type.trace -> Error_message.t -> unit

val get_builtin : Context.t -> ?trace:Type.trace -> name -> reason -> Type.t

val lookup_builtin_strict : Context.t -> name -> reason -> Type.t

val lookup_builtin_with_default : Context.t -> name -> Type.t -> Type.t

val get_builtin_type : Context.t -> ?trace:Type.trace -> reason -> ?use_desc:bool -> name -> Type.t

val set_builtin : Context.t -> ?trace:Type.trace -> name -> Type.t -> unit
Expand Down
4 changes: 4 additions & 0 deletions src/typing/flow_js_utils.ml
Expand Up @@ -682,6 +682,10 @@ let lookup_builtin_strict cx x reason =
add_output cx (Error_message.EBuiltinLookupFailed { reason; name = Some x });
AnyT.error_of_kind UnresolvedName reason)

let lookup_builtin_with_default cx x default =
let builtins = Context.builtins cx in
Builtins.get_builtin builtins x ~on_missing:(fun () -> default)

let lookup_builtin_typeapp cx reason x targs =
let t = lookup_builtin_strict cx x reason in
typeapp reason t targs
Expand Down
2 changes: 1 addition & 1 deletion src/typing/merge_js.ml
Expand Up @@ -136,7 +136,7 @@ let explicit_unchecked_require cx (m, loc) =
let reason = Reason.(mk_reason (RUntypedModule m) loc) in
let m_name = Reason.internal_module_name m in
let default_t = Type.AnyT (reason, Type.Untyped) in
let from_t = Flow_js.lookup_builtin_with_default cx m_name default_t in
let from_t = Flow_js_utils.lookup_builtin_with_default cx m_name default_t in

(* flow the declared module type to importing context *)
let to_t = Context.find_require cx loc in
Expand Down

0 comments on commit f3206ba

Please sign in to comment.