Skip to content

Commit

Permalink
[flow][cleanup] Thoroughly cleanup remains of declare global support
Browse files Browse the repository at this point in the history
Summary:
D70270290 doesn't cleanup everything. This diff finishes the job.

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D70497028

fbshipit-source-id: c5efbdec966f43f06c304fa2eace8bf96149b6c8
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Mar 3, 2025
1 parent e3fbc37 commit f122db3
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 727 deletions.
12 changes: 2 additions & 10 deletions src/parser_utils/exports/exports.ml
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ module ESM = struct
export_keys;
type_stars;
stars;
module_globals = _;
strict = _;
platform_availability_set = _;
}
Expand Down Expand Up @@ -410,15 +409,8 @@ module CJS = struct
NamedType name :: acc

let exports type_sig type_exports exports info =
let (CJSModuleInfo
{
type_export_keys;
type_stars;
module_globals = _;
strict = _;
platform_availability_set = _;
}
) =
let (CJSModuleInfo { type_export_keys; type_stars; strict = _; platform_availability_set = _ })
=
info
in
let acc =
Expand Down
727 changes: 271 additions & 456 deletions src/parser_utils/type_sig/__tests__/type_sig_tests.ml

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/parser_utils/type_sig/type_sig_mark.ml
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,9 @@ let mark_star (loc, mref) =
let mark_exports
~locs_to_dirtify
file_loc
(P.Exports { kind; types; type_stars; global_types; strict = _; platform_availability_set = _ })
=
(P.Exports { kind; types; type_stars; strict = _; platform_availability_set = _ }) =
SMap.iter (fun _ t -> mark_export_type ~locs_to_dirtify t) types;
List.iter mark_star type_stars;
SMap.iter (fun _ -> mark_binding ~locs_to_dirtify) global_types;
match kind with
| P.UnknownModule -> ()
| P.CJSModule t -> mark_parsed ~locs_to_dirtify ~visit_loc:ignore t
Expand Down
50 changes: 6 additions & 44 deletions src/parser_utils/type_sig/type_sig_pack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,10 @@ type 'loc type_export =
| ExportTypeFrom of Remote_refs.index
[@@deriving map, show { with_path = false }]

type module_globals =
| ModuleGlobals of {
global_types: Local_defs.index array;
global_types_keys: string array;
}
[@@deriving show { with_path = false }]

type 'loc cjs_module_info =
| CJSModuleInfo of {
type_export_keys: string array;
type_stars: ('loc * Module_refs.index) list;
module_globals: module_globals;
strict: bool;
platform_availability_set: Platform_set.t option;
}
Expand All @@ -185,7 +177,6 @@ type 'loc es_module_info =
type_stars: ('loc * Module_refs.index) list;
export_keys: string array;
stars: ('loc * Module_refs.index) list;
module_globals: module_globals;
strict: bool;
platform_availability_set: Platform_set.t option;
}
Expand Down Expand Up @@ -436,24 +427,16 @@ and pack_exports
cx
file_loc
module_name
(P.Exports { kind; types; type_stars; global_types; strict; platform_availability_set }) =
(P.Exports { kind; types; type_stars; strict; platform_availability_set }) =
let (type_export_keys, type_exports) = pack_smap pack_type_export types in
let type_stars = List.map pack_star type_stars in
match kind with
| P.UnknownModule ->
let module_globals = pack_module_globals global_types in
let info =
CJSModuleInfo
{ type_export_keys; type_stars; module_globals; strict; platform_availability_set }
in
let info = CJSModuleInfo { type_export_keys; type_stars; strict; platform_availability_set } in
CJSModule { type_exports; exports = None; info }
| P.CJSModule t ->
let exports = Some (pack_parsed cx t) in
let module_globals = pack_module_globals global_types in
let info =
CJSModuleInfo
{ type_export_keys; type_stars; module_globals; strict; platform_availability_set }
in
let info = CJSModuleInfo { type_export_keys; type_stars; strict; platform_availability_set } in
CJSModule { type_exports; exports; info }
| P.CJSModuleProps props ->
let file_loc = pack_loc file_loc in
Expand All @@ -466,11 +449,7 @@ and pack_exports
props
in
let exports = Some (Value (ObjLit { loc = file_loc; frozen = true; proto = None; props })) in
let module_globals = pack_module_globals global_types in
let info =
CJSModuleInfo
{ type_export_keys; type_stars; module_globals; strict; platform_availability_set }
in
let info = CJSModuleInfo { type_export_keys; type_stars; strict; platform_availability_set } in
CJSModule { type_exports; exports; info }
| P.CJSDeclareModule props ->
let file_loc = pack_loc file_loc in
Expand All @@ -485,27 +464,14 @@ and pack_exports
let exports =
Some (Value (DeclareModuleImplicitlyExportedObject { loc = file_loc; module_name; props }))
in
let module_globals = pack_module_globals global_types in
let info =
CJSModuleInfo
{ type_export_keys; type_stars; module_globals; strict; platform_availability_set }
in
let info = CJSModuleInfo { type_export_keys; type_stars; strict; platform_availability_set } in
CJSModule { type_exports; exports; info }
| P.ESModule { names; stars } ->
let (export_keys, exports) = pack_smap (pack_export cx) names in
let stars = List.map pack_star stars in
let module_globals = pack_module_globals global_types in
let info =
ESModuleInfo
{
type_export_keys;
type_stars;
export_keys;
stars;
module_globals;
strict;
platform_availability_set;
}
{ type_export_keys; type_stars; export_keys; stars; strict; platform_availability_set }
in
ESModule { type_exports; exports; info }

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

and pack_module_globals global_types =
let (global_types_keys, global_types) = pack_smap pack_builtin global_types in
ModuleGlobals { global_types_keys; global_types }

and pack_builtin_module cx name (loc, exports) =
let module_kind = pack_exports cx loc name exports in
let loc = pack_loc loc in
Expand Down
17 changes: 4 additions & 13 deletions src/parser_utils/type_sig/type_sig_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ and 'loc exports =
mutable kind: 'loc module_kind;
mutable types: 'loc export_type smap;
mutable type_stars: ('loc loc_node * module_ref_node) list;
mutable global_types: 'loc binding_node SMap.t;
strict: bool;
platform_availability_set: Platform_set.t option;
}
Expand Down Expand Up @@ -424,7 +423,6 @@ module Exports = struct
kind = UnknownModule;
types = SMap.empty;
type_stars = [];
global_types = SMap.empty;
strict;
platform_availability_set;
}
Expand Down Expand Up @@ -672,19 +670,12 @@ module Scope = struct
(match lookup_scope name values types with
| Some binding -> Some (binding, scope)
| None -> lookup_type parent name)
| Module { values; types; exports = Exports { global_types; _ }; _ } ->
Base.Option.map
~f:(fun binding -> (binding, scope))
(match lookup_scope name values types with
| Some result -> Some result
| None -> lookup_scope name SMap.empty global_types)
| DeclareModule { parent; values; types; exports = Exports { global_types; _ }; _ } ->
| Module { values; types; _ } ->
Base.Option.map ~f:(fun binding -> (binding, scope)) (lookup_scope name values types)
| DeclareModule { parent; values; types; _ } ->
(match lookup_scope name values types with
| Some binding -> Some (binding, scope)
| None ->
(match lookup_scope name SMap.empty global_types with
| Some binding -> Some (binding, scope)
| None -> lookup_type parent name))
| None -> lookup_type parent name)

let rec find_host scope b =
match scope with
Expand Down
41 changes: 4 additions & 37 deletions src/services/inference/check_service.ml
Original file line number Diff line number Diff line change
Expand Up @@ -173,31 +173,9 @@ let mk_check_file ~reader ~options ~master_cx ~cache () =
|> Merge.merge_export (Lazy.force file_rec)
)
in
let global_types_map =
let local n index =
lazy
(let { Merge.local_defs; cx; _ } = Lazy.force file_rec in
let global_builtins = Context.global_builtins cx in
let (loc, _, (lazy t), _) = Local_defs.get local_defs index |> Lazy.force in
(match Builtins.get_builtin_type_opt global_builtins n with
| Some (def_loc, _) -> ConsGen.error_on_bad_global_shadow cx n ~loc ~def_loc
| None -> ());
(loc, t)
)
in
let f acc name i = SMap.add name (local name i) acc in
Base.Array.fold2_exn ~init:SMap.empty ~f
in
let cjs_module buf pos =
let (Pack.CJSModuleInfo
{
type_export_keys;
type_stars;
module_globals = Pack.ModuleGlobals { global_types; global_types_keys };
strict;
platform_availability_set;
}
) =
let (Pack.CJSModuleInfo { type_export_keys; type_stars; strict; platform_availability_set })
=
Bin.cjs_module_info buf pos
|> Bin.read_hashed Bin.read_cjs_info buf
|> Pack.map_cjs_module_info aloc
Expand All @@ -208,9 +186,8 @@ let mk_check_file ~reader ~options ~master_cx ~cache () =
let f acc name export = SMap.add name export acc in
Base.Array.fold2_exn ~init:SMap.empty ~f type_export_keys type_exports
in
let global_types = global_types_map global_types_keys global_types in
Type_sig_merge.CJSExports
{ type_exports; exports; type_stars; global_types; strict; platform_availability_set }
{ type_exports; exports; type_stars; strict; platform_availability_set }
in
let es_module buf pos =
let (Pack.ESModuleInfo
Expand All @@ -219,7 +196,6 @@ let mk_check_file ~reader ~options ~master_cx ~cache () =
export_keys;
type_stars;
stars;
module_globals = Pack.ModuleGlobals { global_types; global_types_keys };
strict;
platform_availability_set;
}
Expand All @@ -238,17 +214,8 @@ let mk_check_file ~reader ~options ~master_cx ~cache () =
let f acc name export = SMap.add name export acc in
Base.Array.fold2_exn ~init:SMap.empty ~f export_keys exports
in
let global_types = global_types_map global_types_keys global_types in
Type_sig_merge.ESExports
{
type_exports;
exports;
type_stars;
stars;
global_types;
strict;
platform_availability_set;
}
{ type_exports; exports; type_stars; stars; strict; platform_availability_set }
in
Type.Constraint.ForcingState.of_lazy_module
( reason,
Expand Down
18 changes: 2 additions & 16 deletions src/services/inference/merge_service.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,7 @@ let sig_hash ~check_dirty_set ~root =
let filename = Fun.const (hash_file_key file_key) in
let info_pos = Bin.cjs_module_info buf pos in
let (P.CJSModuleInfo
{
type_export_keys;
type_stars = _;
module_globals = _;
strict = _;
platform_availability_set = _;
}
{ type_export_keys; type_stars = _; strict = _; platform_availability_set = _ }
) =
Bin.read_hashed Bin.read_cjs_info buf info_pos
in
Expand All @@ -101,7 +95,6 @@ let sig_hash ~check_dirty_set ~root =
export_keys;
type_stars = _;
stars = _;
module_globals = _;
strict = _;
platform_availability_set = _;
}
Expand Down Expand Up @@ -164,13 +157,7 @@ let sig_hash ~check_dirty_set ~root =
let info_pos = Bin.cjs_module_info buf pos in
let init_hash = Bin.read_hashed Bin.hash_serialized buf info_pos in
let (P.CJSModuleInfo
{
type_export_keys;
type_stars;
module_globals = _;
strict = _;
platform_availability_set = _;
}
{ type_export_keys; type_stars; strict = _; platform_availability_set = _ }
) =
Bin.read_hashed Bin.read_cjs_info buf info_pos
in
Expand Down Expand Up @@ -203,7 +190,6 @@ let sig_hash ~check_dirty_set ~root =
export_keys;
type_stars;
stars;
module_globals = _;
strict = _;
platform_availability_set = _;
}
Expand Down
12 changes: 1 addition & 11 deletions src/typing/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ type t = {
mutable refined_locations: ALocSet.t ALocMap.t;
mutable aggressively_invalidated_locations: Refinement_invalidation.t ALocMap.t;
node_cache: Node_cache.t;
mutable local_builtins: Builtins.t Lazy.t option;
}

and resolve_require = string -> resolved_require
Expand Down Expand Up @@ -434,7 +433,6 @@ let make ccx metadata file aloc_table resolve_require mk_builtins =
node_cache = Node_cache.mk_empty ();
refined_locations = ALocMap.empty;
aggressively_invalidated_locations = ALocMap.empty;
local_builtins = None;
}
in
ccx.builtins <- lazy (mk_builtins cx);
Expand All @@ -460,13 +458,7 @@ let global_builtins cx = Lazy.force cx.ccx.builtins

let builtin_value_opt cx = Builtins.get_builtin_value_opt (global_builtins cx)

let builtin_type_opt cx n =
match cx.local_builtins with
| Some (lazy b) ->
(match Builtins.get_builtin_type_opt b n with
| Some v -> Some v
| None -> Builtins.get_builtin_type_opt (global_builtins cx) n)
| None -> Builtins.get_builtin_type_opt (global_builtins cx) n
let builtin_type_opt cx n = Builtins.get_builtin_type_opt (global_builtins cx) n

let builtin_module_opt cx = Builtins.get_builtin_module_opt (global_builtins cx)

Expand Down Expand Up @@ -789,8 +781,6 @@ let add_inferred_component_return cx loc t =
in
cx.ccx.inferred_component_return <- ALocFuzzyMap.add loc bounds inferred_component_return

let extend_local_builtins cx local_builtins = cx.local_builtins <- Some local_builtins

let set_evaluated cx evaluated = cx.ccx.sig_cx <- { cx.ccx.sig_cx with evaluated }

let set_graph cx graph = cx.ccx.sig_cx <- { cx.ccx.sig_cx with graph }
Expand Down
2 changes: 0 additions & 2 deletions src/typing/context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,6 @@ val add_refined_location : t -> ALoc.t -> ALocSet.t -> unit

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

val extend_local_builtins : t -> Builtins.t Lazy.t -> unit

val set_evaluated : t -> Type.t Type.Eval.Map.t -> unit

val set_graph : t -> Type.Constraint.graph -> unit
Expand Down
Loading

0 comments on commit f122db3

Please sign in to comment.