Skip to content

Commit

Permalink
[flow][refactor][EZ] Only return one copy of builtins from `Merge_js.…
Browse files Browse the repository at this point in the history
…merge_lib_files`

Summary:
In the case of `EmptyMasterContext`, the builtins will be empty any ways, in the case of `NonEmptyMasterContext`, the first returned builtins from `Merge_js.merge_lib_files` will be the same builtins in `NonEmptyMasterContext`.

Therefore, we can alwaus ignore the builtin from the first returned builtins from `Merge_js.merge_lib_files`. Let's just remove that return instead.

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D70495943

fbshipit-source-id: 2d189e13c95da3e9bf1dddc7be0ab2714f230d8f
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Mar 3, 2025
1 parent 9f2fcb8 commit e3fbc37
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/flow_dot_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ let load_lib_files files =
locs_to_dirtify = [];
}
in
let (_, _, master_cx) = Merge_js.merge_lib_files ~sig_opts asts in
let (_, master_cx) = Merge_js.merge_lib_files ~sig_opts asts in
master_cx

let stub_metadata ~root ~checked =
Expand Down
51 changes: 24 additions & 27 deletions src/services/inference/init_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,31 @@ let load_lib_files ~ccx ~options ~reader files =
(true, ErrorSet.empty, [])
in
let (builtin_exports, master_cx, cx_opt) =
if ok then
if ok then (
let sig_opts = Type_sig_options.builtin_options options in
let (builtins, builtin_errors, master_cx) = Merge_js.merge_lib_files ~sig_opts ordered_asts in
let cx_opt =
match master_cx with
| Context.EmptyMasterContext -> None
| Context.NonEmptyMasterContext { builtin_leader_file_key; _ } ->
let metadata =
Context.(
let metadata = metadata_of_options options in
{ metadata with checked = false }
)
in
let mk_builtins = Merge_js.mk_builtins metadata master_cx in
let cx =
Context.make
ccx
metadata
builtin_leader_file_key
(lazy (ALoc.empty_table builtin_leader_file_key))
(fun mref -> Context.MissingModule mref)
mk_builtins
in
Context.reset_errors cx builtin_errors;
Some cx
in
(Exports.of_builtins builtins, master_cx, cx_opt)
else
let (builtin_errors, master_cx) = Merge_js.merge_lib_files ~sig_opts ordered_asts in
match master_cx with
| Context.EmptyMasterContext -> (Exports.empty, Context.EmptyMasterContext, None)
| Context.NonEmptyMasterContext { builtin_leader_file_key; builtins; _ } ->
let metadata =
Context.(
let metadata = metadata_of_options options in
{ metadata with checked = false }
)
in
let mk_builtins = Merge_js.mk_builtins metadata master_cx in
let cx =
Context.make
ccx
metadata
builtin_leader_file_key
(lazy (ALoc.empty_table builtin_leader_file_key))
(fun mref -> Context.MissingModule mref)
mk_builtins
in
Context.reset_errors cx builtin_errors;
(Exports.of_builtins builtins, master_cx, Some cx)
) else
(Exports.empty, Context.EmptyMasterContext, None)
in
Lwt.return (ok, master_cx, cx_opt, errors, builtin_exports)
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 @@ -181,7 +181,7 @@ end = struct
locs_to_dirtify = [];
}
in
let (_, _, master_cx) = Merge_js.merge_lib_files ~sig_opts asts in
let (_, master_cx) = Merge_js.merge_lib_files ~sig_opts asts in
master_cx

let master_cx_ref = ref None
Expand Down
5 changes: 2 additions & 3 deletions src/typing/merge_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -901,11 +901,10 @@ let merge_lib_files ~sig_opts ordered_asts =
|> Flow_error.ErrorSet.of_list
in
match ordered_asts with
| [] -> (builtins, builtin_errors, Context.EmptyMasterContext)
| [] -> (builtin_errors, Context.EmptyMasterContext)
| fst_ast :: _ ->
let builtin_leader_file_key = Base.Option.value_exn (fst_ast |> fst |> Loc.source) in
( builtins,
builtin_errors,
( builtin_errors,
Context.NonEmptyMasterContext { builtin_leader_file_key; builtin_locs; builtins }
)

Expand Down
4 changes: 1 addition & 3 deletions src/typing/merge_js.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ val copy_into :
val merge_lib_files :
sig_opts:Type_sig_options.t ->
(Loc.t, Loc.t) Flow_ast.Program.t list ->
Type_sig_collections.Locs.index Packed_type_sig.Builtins.t
* Flow_error.ErrorSet.t
* Context.master_context
Flow_error.ErrorSet.t * Context.master_context

val mk_builtins : Context.metadata -> Context.master_context -> Context.t -> Builtins.t

0 comments on commit e3fbc37

Please sign in to comment.