Skip to content

Commit e3fbc37

Browse files
SamChou19815facebook-github-bot
authored andcommitted
[flow][refactor][EZ] Only return one copy of builtins from Merge_js.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
1 parent 9f2fcb8 commit e3fbc37

File tree

5 files changed

+29
-35
lines changed

5 files changed

+29
-35
lines changed

src/flow_dot_js.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ let load_lib_files files =
8383
locs_to_dirtify = [];
8484
}
8585
in
86-
let (_, _, master_cx) = Merge_js.merge_lib_files ~sig_opts asts in
86+
let (_, master_cx) = Merge_js.merge_lib_files ~sig_opts asts in
8787
master_cx
8888

8989
let stub_metadata ~root ~checked =

src/services/inference/init_js.ml

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,31 @@ let load_lib_files ~ccx ~options ~reader files =
4343
(true, ErrorSet.empty, [])
4444
in
4545
let (builtin_exports, master_cx, cx_opt) =
46-
if ok then
46+
if ok then (
4747
let sig_opts = Type_sig_options.builtin_options options in
48-
let (builtins, builtin_errors, master_cx) = Merge_js.merge_lib_files ~sig_opts ordered_asts in
49-
let cx_opt =
50-
match master_cx with
51-
| Context.EmptyMasterContext -> None
52-
| Context.NonEmptyMasterContext { builtin_leader_file_key; _ } ->
53-
let metadata =
54-
Context.(
55-
let metadata = metadata_of_options options in
56-
{ metadata with checked = false }
57-
)
58-
in
59-
let mk_builtins = Merge_js.mk_builtins metadata master_cx in
60-
let cx =
61-
Context.make
62-
ccx
63-
metadata
64-
builtin_leader_file_key
65-
(lazy (ALoc.empty_table builtin_leader_file_key))
66-
(fun mref -> Context.MissingModule mref)
67-
mk_builtins
68-
in
69-
Context.reset_errors cx builtin_errors;
70-
Some cx
71-
in
72-
(Exports.of_builtins builtins, master_cx, cx_opt)
73-
else
48+
let (builtin_errors, master_cx) = Merge_js.merge_lib_files ~sig_opts ordered_asts in
49+
match master_cx with
50+
| Context.EmptyMasterContext -> (Exports.empty, Context.EmptyMasterContext, None)
51+
| Context.NonEmptyMasterContext { builtin_leader_file_key; builtins; _ } ->
52+
let metadata =
53+
Context.(
54+
let metadata = metadata_of_options options in
55+
{ metadata with checked = false }
56+
)
57+
in
58+
let mk_builtins = Merge_js.mk_builtins metadata master_cx in
59+
let cx =
60+
Context.make
61+
ccx
62+
metadata
63+
builtin_leader_file_key
64+
(lazy (ALoc.empty_table builtin_leader_file_key))
65+
(fun mref -> Context.MissingModule mref)
66+
mk_builtins
67+
in
68+
Context.reset_errors cx builtin_errors;
69+
(Exports.of_builtins builtins, master_cx, Some cx)
70+
) else
7471
(Exports.empty, Context.EmptyMasterContext, None)
7572
in
7673
Lwt.return (ok, master_cx, cx_opt, errors, builtin_exports)

src/typing/__tests__/type_hint_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ end = struct
181181
locs_to_dirtify = [];
182182
}
183183
in
184-
let (_, _, master_cx) = Merge_js.merge_lib_files ~sig_opts asts in
184+
let (_, master_cx) = Merge_js.merge_lib_files ~sig_opts asts in
185185
master_cx
186186

187187
let master_cx_ref = ref None

src/typing/merge_js.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,11 +901,10 @@ let merge_lib_files ~sig_opts ordered_asts =
901901
|> Flow_error.ErrorSet.of_list
902902
in
903903
match ordered_asts with
904-
| [] -> (builtins, builtin_errors, Context.EmptyMasterContext)
904+
| [] -> (builtin_errors, Context.EmptyMasterContext)
905905
| fst_ast :: _ ->
906906
let builtin_leader_file_key = Base.Option.value_exn (fst_ast |> fst |> Loc.source) in
907-
( builtins,
908-
builtin_errors,
907+
( builtin_errors,
909908
Context.NonEmptyMasterContext { builtin_leader_file_key; builtin_locs; builtins }
910909
)
911910

src/typing/merge_js.mli

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ val copy_into :
2828
val merge_lib_files :
2929
sig_opts:Type_sig_options.t ->
3030
(Loc.t, Loc.t) Flow_ast.Program.t list ->
31-
Type_sig_collections.Locs.index Packed_type_sig.Builtins.t
32-
* Flow_error.ErrorSet.t
33-
* Context.master_context
31+
Flow_error.ErrorSet.t * Context.master_context
3432

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

0 commit comments

Comments
 (0)