Skip to content

Commit f122db3

Browse files
SamChou19815facebook-github-bot
authored andcommitted
[flow][cleanup] Thoroughly cleanup remains of declare global support
Summary: D70270290 doesn't cleanup everything. This diff finishes the job. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D70497028 fbshipit-source-id: c5efbdec966f43f06c304fa2eace8bf96149b6c8
1 parent e3fbc37 commit f122db3

File tree

15 files changed

+308
-727
lines changed

15 files changed

+308
-727
lines changed

src/parser_utils/exports/exports.ml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ module ESM = struct
314314
export_keys;
315315
type_stars;
316316
stars;
317-
module_globals = _;
318317
strict = _;
319318
platform_availability_set = _;
320319
}
@@ -410,15 +409,8 @@ module CJS = struct
410409
NamedType name :: acc
411410

412411
let exports type_sig type_exports exports info =
413-
let (CJSModuleInfo
414-
{
415-
type_export_keys;
416-
type_stars;
417-
module_globals = _;
418-
strict = _;
419-
platform_availability_set = _;
420-
}
421-
) =
412+
let (CJSModuleInfo { type_export_keys; type_stars; strict = _; platform_availability_set = _ })
413+
=
422414
info
423415
in
424416
let acc =

src/parser_utils/type_sig/__tests__/type_sig_tests.ml

Lines changed: 271 additions & 456 deletions
Large diffs are not rendered by default.

src/parser_utils/type_sig/type_sig_mark.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,9 @@ let mark_star (loc, mref) =
239239
let mark_exports
240240
~locs_to_dirtify
241241
file_loc
242-
(P.Exports { kind; types; type_stars; global_types; strict = _; platform_availability_set = _ })
243-
=
242+
(P.Exports { kind; types; type_stars; strict = _; platform_availability_set = _ }) =
244243
SMap.iter (fun _ t -> mark_export_type ~locs_to_dirtify t) types;
245244
List.iter mark_star type_stars;
246-
SMap.iter (fun _ -> mark_binding ~locs_to_dirtify) global_types;
247245
match kind with
248246
| P.UnknownModule -> ()
249247
| P.CJSModule t -> mark_parsed ~locs_to_dirtify ~visit_loc:ignore t

src/parser_utils/type_sig/type_sig_pack.ml

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,10 @@ type 'loc type_export =
162162
| ExportTypeFrom of Remote_refs.index
163163
[@@deriving map, show { with_path = false }]
164164

165-
type module_globals =
166-
| ModuleGlobals of {
167-
global_types: Local_defs.index array;
168-
global_types_keys: string array;
169-
}
170-
[@@deriving show { with_path = false }]
171-
172165
type 'loc cjs_module_info =
173166
| CJSModuleInfo of {
174167
type_export_keys: string array;
175168
type_stars: ('loc * Module_refs.index) list;
176-
module_globals: module_globals;
177169
strict: bool;
178170
platform_availability_set: Platform_set.t option;
179171
}
@@ -185,7 +177,6 @@ type 'loc es_module_info =
185177
type_stars: ('loc * Module_refs.index) list;
186178
export_keys: string array;
187179
stars: ('loc * Module_refs.index) list;
188-
module_globals: module_globals;
189180
strict: bool;
190181
platform_availability_set: Platform_set.t option;
191182
}
@@ -436,24 +427,16 @@ and pack_exports
436427
cx
437428
file_loc
438429
module_name
439-
(P.Exports { kind; types; type_stars; global_types; strict; platform_availability_set }) =
430+
(P.Exports { kind; types; type_stars; strict; platform_availability_set }) =
440431
let (type_export_keys, type_exports) = pack_smap pack_type_export types in
441432
let type_stars = List.map pack_star type_stars in
442433
match kind with
443434
| P.UnknownModule ->
444-
let module_globals = pack_module_globals global_types in
445-
let info =
446-
CJSModuleInfo
447-
{ type_export_keys; type_stars; module_globals; strict; platform_availability_set }
448-
in
435+
let info = CJSModuleInfo { type_export_keys; type_stars; strict; platform_availability_set } in
449436
CJSModule { type_exports; exports = None; info }
450437
| P.CJSModule t ->
451438
let exports = Some (pack_parsed cx t) in
452-
let module_globals = pack_module_globals global_types in
453-
let info =
454-
CJSModuleInfo
455-
{ type_export_keys; type_stars; module_globals; strict; platform_availability_set }
456-
in
439+
let info = CJSModuleInfo { type_export_keys; type_stars; strict; platform_availability_set } in
457440
CJSModule { type_exports; exports; info }
458441
| P.CJSModuleProps props ->
459442
let file_loc = pack_loc file_loc in
@@ -466,11 +449,7 @@ and pack_exports
466449
props
467450
in
468451
let exports = Some (Value (ObjLit { loc = file_loc; frozen = true; proto = None; props })) in
469-
let module_globals = pack_module_globals global_types in
470-
let info =
471-
CJSModuleInfo
472-
{ type_export_keys; type_stars; module_globals; strict; platform_availability_set }
473-
in
452+
let info = CJSModuleInfo { type_export_keys; type_stars; strict; platform_availability_set } in
474453
CJSModule { type_exports; exports; info }
475454
| P.CJSDeclareModule props ->
476455
let file_loc = pack_loc file_loc in
@@ -485,27 +464,14 @@ and pack_exports
485464
let exports =
486465
Some (Value (DeclareModuleImplicitlyExportedObject { loc = file_loc; module_name; props }))
487466
in
488-
let module_globals = pack_module_globals global_types in
489-
let info =
490-
CJSModuleInfo
491-
{ type_export_keys; type_stars; module_globals; strict; platform_availability_set }
492-
in
467+
let info = CJSModuleInfo { type_export_keys; type_stars; strict; platform_availability_set } in
493468
CJSModule { type_exports; exports; info }
494469
| P.ESModule { names; stars } ->
495470
let (export_keys, exports) = pack_smap (pack_export cx) names in
496471
let stars = List.map pack_star stars in
497-
let module_globals = pack_module_globals global_types in
498472
let info =
499473
ESModuleInfo
500-
{
501-
type_export_keys;
502-
type_stars;
503-
export_keys;
504-
stars;
505-
module_globals;
506-
strict;
507-
platform_availability_set;
508-
}
474+
{ type_export_keys; type_stars; export_keys; stars; strict; platform_availability_set }
509475
in
510476
ESModule { type_exports; exports; info }
511477

@@ -563,10 +529,6 @@ and pack_builtin = function
563529
| P.LocalBinding b -> Local_defs.index_exn b
564530
| P.RemoteBinding _ -> failwith "unexpected remote builtin"
565531

566-
and pack_module_globals global_types =
567-
let (global_types_keys, global_types) = pack_smap pack_builtin global_types in
568-
ModuleGlobals { global_types_keys; global_types }
569-
570532
and pack_builtin_module cx name (loc, exports) =
571533
let module_kind = pack_exports cx loc name exports in
572534
let loc = pack_loc loc in

src/parser_utils/type_sig/type_sig_parse.ml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ and 'loc exports =
127127
mutable kind: 'loc module_kind;
128128
mutable types: 'loc export_type smap;
129129
mutable type_stars: ('loc loc_node * module_ref_node) list;
130-
mutable global_types: 'loc binding_node SMap.t;
131130
strict: bool;
132131
platform_availability_set: Platform_set.t option;
133132
}
@@ -424,7 +423,6 @@ module Exports = struct
424423
kind = UnknownModule;
425424
types = SMap.empty;
426425
type_stars = [];
427-
global_types = SMap.empty;
428426
strict;
429427
platform_availability_set;
430428
}
@@ -672,19 +670,12 @@ module Scope = struct
672670
(match lookup_scope name values types with
673671
| Some binding -> Some (binding, scope)
674672
| None -> lookup_type parent name)
675-
| Module { values; types; exports = Exports { global_types; _ }; _ } ->
676-
Base.Option.map
677-
~f:(fun binding -> (binding, scope))
678-
(match lookup_scope name values types with
679-
| Some result -> Some result
680-
| None -> lookup_scope name SMap.empty global_types)
681-
| DeclareModule { parent; values; types; exports = Exports { global_types; _ }; _ } ->
673+
| Module { values; types; _ } ->
674+
Base.Option.map ~f:(fun binding -> (binding, scope)) (lookup_scope name values types)
675+
| DeclareModule { parent; values; types; _ } ->
682676
(match lookup_scope name values types with
683677
| Some binding -> Some (binding, scope)
684-
| None ->
685-
(match lookup_scope name SMap.empty global_types with
686-
| Some binding -> Some (binding, scope)
687-
| None -> lookup_type parent name))
678+
| None -> lookup_type parent name)
688679

689680
let rec find_host scope b =
690681
match scope with

src/services/inference/check_service.ml

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -173,31 +173,9 @@ let mk_check_file ~reader ~options ~master_cx ~cache () =
173173
|> Merge.merge_export (Lazy.force file_rec)
174174
)
175175
in
176-
let global_types_map =
177-
let local n index =
178-
lazy
179-
(let { Merge.local_defs; cx; _ } = Lazy.force file_rec in
180-
let global_builtins = Context.global_builtins cx in
181-
let (loc, _, (lazy t), _) = Local_defs.get local_defs index |> Lazy.force in
182-
(match Builtins.get_builtin_type_opt global_builtins n with
183-
| Some (def_loc, _) -> ConsGen.error_on_bad_global_shadow cx n ~loc ~def_loc
184-
| None -> ());
185-
(loc, t)
186-
)
187-
in
188-
let f acc name i = SMap.add name (local name i) acc in
189-
Base.Array.fold2_exn ~init:SMap.empty ~f
190-
in
191176
let cjs_module buf pos =
192-
let (Pack.CJSModuleInfo
193-
{
194-
type_export_keys;
195-
type_stars;
196-
module_globals = Pack.ModuleGlobals { global_types; global_types_keys };
197-
strict;
198-
platform_availability_set;
199-
}
200-
) =
177+
let (Pack.CJSModuleInfo { type_export_keys; type_stars; strict; platform_availability_set })
178+
=
201179
Bin.cjs_module_info buf pos
202180
|> Bin.read_hashed Bin.read_cjs_info buf
203181
|> Pack.map_cjs_module_info aloc
@@ -208,9 +186,8 @@ let mk_check_file ~reader ~options ~master_cx ~cache () =
208186
let f acc name export = SMap.add name export acc in
209187
Base.Array.fold2_exn ~init:SMap.empty ~f type_export_keys type_exports
210188
in
211-
let global_types = global_types_map global_types_keys global_types in
212189
Type_sig_merge.CJSExports
213-
{ type_exports; exports; type_stars; global_types; strict; platform_availability_set }
190+
{ type_exports; exports; type_stars; strict; platform_availability_set }
214191
in
215192
let es_module buf pos =
216193
let (Pack.ESModuleInfo
@@ -219,7 +196,6 @@ let mk_check_file ~reader ~options ~master_cx ~cache () =
219196
export_keys;
220197
type_stars;
221198
stars;
222-
module_globals = Pack.ModuleGlobals { global_types; global_types_keys };
223199
strict;
224200
platform_availability_set;
225201
}
@@ -238,17 +214,8 @@ let mk_check_file ~reader ~options ~master_cx ~cache () =
238214
let f acc name export = SMap.add name export acc in
239215
Base.Array.fold2_exn ~init:SMap.empty ~f export_keys exports
240216
in
241-
let global_types = global_types_map global_types_keys global_types in
242217
Type_sig_merge.ESExports
243-
{
244-
type_exports;
245-
exports;
246-
type_stars;
247-
stars;
248-
global_types;
249-
strict;
250-
platform_availability_set;
251-
}
218+
{ type_exports; exports; type_stars; stars; strict; platform_availability_set }
252219
in
253220
Type.Constraint.ForcingState.of_lazy_module
254221
( reason,

src/services/inference/merge_service.ml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ let sig_hash ~check_dirty_set ~root =
7373
let filename = Fun.const (hash_file_key file_key) in
7474
let info_pos = Bin.cjs_module_info buf pos in
7575
let (P.CJSModuleInfo
76-
{
77-
type_export_keys;
78-
type_stars = _;
79-
module_globals = _;
80-
strict = _;
81-
platform_availability_set = _;
82-
}
76+
{ type_export_keys; type_stars = _; strict = _; platform_availability_set = _ }
8377
) =
8478
Bin.read_hashed Bin.read_cjs_info buf info_pos
8579
in
@@ -101,7 +95,6 @@ let sig_hash ~check_dirty_set ~root =
10195
export_keys;
10296
type_stars = _;
10397
stars = _;
104-
module_globals = _;
10598
strict = _;
10699
platform_availability_set = _;
107100
}
@@ -164,13 +157,7 @@ let sig_hash ~check_dirty_set ~root =
164157
let info_pos = Bin.cjs_module_info buf pos in
165158
let init_hash = Bin.read_hashed Bin.hash_serialized buf info_pos in
166159
let (P.CJSModuleInfo
167-
{
168-
type_export_keys;
169-
type_stars;
170-
module_globals = _;
171-
strict = _;
172-
platform_availability_set = _;
173-
}
160+
{ type_export_keys; type_stars; strict = _; platform_availability_set = _ }
174161
) =
175162
Bin.read_hashed Bin.read_cjs_info buf info_pos
176163
in
@@ -203,7 +190,6 @@ let sig_hash ~check_dirty_set ~root =
203190
export_keys;
204191
type_stars;
205192
stars;
206-
module_globals = _;
207193
strict = _;
208194
platform_availability_set = _;
209195
}

src/typing/context.ml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ type t = {
242242
mutable refined_locations: ALocSet.t ALocMap.t;
243243
mutable aggressively_invalidated_locations: Refinement_invalidation.t ALocMap.t;
244244
node_cache: Node_cache.t;
245-
mutable local_builtins: Builtins.t Lazy.t option;
246245
}
247246

248247
and resolve_require = string -> resolved_require
@@ -434,7 +433,6 @@ let make ccx metadata file aloc_table resolve_require mk_builtins =
434433
node_cache = Node_cache.mk_empty ();
435434
refined_locations = ALocMap.empty;
436435
aggressively_invalidated_locations = ALocMap.empty;
437-
local_builtins = None;
438436
}
439437
in
440438
ccx.builtins <- lazy (mk_builtins cx);
@@ -460,13 +458,7 @@ let global_builtins cx = Lazy.force cx.ccx.builtins
460458

461459
let builtin_value_opt cx = Builtins.get_builtin_value_opt (global_builtins cx)
462460

463-
let builtin_type_opt cx n =
464-
match cx.local_builtins with
465-
| Some (lazy b) ->
466-
(match Builtins.get_builtin_type_opt b n with
467-
| Some v -> Some v
468-
| None -> Builtins.get_builtin_type_opt (global_builtins cx) n)
469-
| None -> Builtins.get_builtin_type_opt (global_builtins cx) n
461+
let builtin_type_opt cx n = Builtins.get_builtin_type_opt (global_builtins cx) n
470462

471463
let builtin_module_opt cx = Builtins.get_builtin_module_opt (global_builtins cx)
472464

@@ -789,8 +781,6 @@ let add_inferred_component_return cx loc t =
789781
in
790782
cx.ccx.inferred_component_return <- ALocFuzzyMap.add loc bounds inferred_component_return
791783

792-
let extend_local_builtins cx local_builtins = cx.local_builtins <- Some local_builtins
793-
794784
let set_evaluated cx evaluated = cx.ccx.sig_cx <- { cx.ccx.sig_cx with evaluated }
795785

796786
let set_graph cx graph = cx.ccx.sig_cx <- { cx.ccx.sig_cx with graph }

src/typing/context.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,6 @@ val add_refined_location : t -> ALoc.t -> ALocSet.t -> unit
391391

392392
val add_aggressively_invalidated_location : t -> ALoc.t -> Refinement_invalidation.t -> unit
393393

394-
val extend_local_builtins : t -> Builtins.t Lazy.t -> unit
395-
396394
val set_evaluated : t -> Type.t Type.Eval.Map.t -> unit
397395

398396
val set_graph : t -> Type.Constraint.graph -> unit

0 commit comments

Comments
 (0)