Skip to content

Refactor: remove unused opens in extra. #615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 23 additions & 32 deletions analysis/src/ProcessExtra.ml
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ let structure_item ~env ~extra (iter : Tast_iterator.iterator) item =
| Tstr_module {mb_expr} -> handle_module_expr ~env ~extra mb_expr.mod_desc
| Tstr_open {open_path; open_txt = {txt; loc}} ->
(* Log.log("Have an open here"); *)
addForLongident ~env ~extra None open_path txt loc;
Hashtbl.replace extra.opens loc ()
addForLongident ~env ~extra None open_path txt loc
| _ -> ());
Tast_iterator.default_iterator.structure_item iter item

Expand Down Expand Up @@ -389,36 +388,28 @@ let pat ~(file : File.t) ~env ~extra (iter : Tast_iterator.iterator)

let expr ~env ~(extra : extra) (iter : Tast_iterator.iterator)
(expression : Typedtree.expression) =
(expression.exp_extra
|> List.iter (fun (e, eloc, _) ->
match e with
| Typedtree.Texp_open (_, _path, _ident, _) ->
Hashtbl.add extra.opens eloc ()
| _ -> ());
match expression.exp_desc with
| Texp_ident (path, {txt; loc}, _) when not (JsxHacks.pathIsFragment path) ->
addForLongident ~env ~extra
(Some (expression.exp_type, Value))
path txt loc
| Texp_record {fields} ->
addForRecord ~env ~extra ~recordType:expression.exp_type
(fields |> Array.to_list
|> Utils.filterMap (fun (desc, item) ->
match item with
| Typedtree.Overridden (loc, _) -> Some (loc, desc, ())
| _ -> None))
| Texp_constant constant ->
addLocItem extra expression.exp_loc (Constant constant)
(* Skip unit and list literals *)
| Texp_construct ({txt = Lident ("()" | "::"); loc}, _, _args)
when loc.loc_end.pos_cnum - loc.loc_start.pos_cnum <> 2 ->
()
| Texp_construct (lident, constructor, _args) ->
addForConstructor ~env ~extra expression.exp_type lident constructor
| Texp_field (inner, lident, _label_description) ->
addForField ~env ~extra ~recordType:inner.exp_type
~fieldType:expression.exp_type lident
| _ -> ());
(match expression.exp_desc with
| Texp_ident (path, {txt; loc}, _) when not (JsxHacks.pathIsFragment path) ->
addForLongident ~env ~extra (Some (expression.exp_type, Value)) path txt loc
| Texp_record {fields} ->
addForRecord ~env ~extra ~recordType:expression.exp_type
(fields |> Array.to_list
|> Utils.filterMap (fun (desc, item) ->
match item with
| Typedtree.Overridden (loc, _) -> Some (loc, desc, ())
| _ -> None))
| Texp_constant constant ->
addLocItem extra expression.exp_loc (Constant constant)
(* Skip unit and list literals *)
| Texp_construct ({txt = Lident ("()" | "::"); loc}, _, _args)
when loc.loc_end.pos_cnum - loc.loc_start.pos_cnum <> 2 ->
()
| Texp_construct (lident, constructor, _args) ->
addForConstructor ~env ~extra expression.exp_type lident constructor
| Texp_field (inner, lident, _label_description) ->
addForField ~env ~extra ~recordType:inner.exp_type
~fieldType:expression.exp_type lident
| _ -> ());
Tast_iterator.default_iterator.expr iter expression

let getExtra ~file ~infos =
Expand Down
5 changes: 0 additions & 5 deletions analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,6 @@ type extra = {
(string, (string list * Tip.t * Location.t) list) Hashtbl.t;
fileReferences: (string, LocationSet.t) Hashtbl.t;
mutable locItems: locItem list;
(* This is the "open location", like the location...
or maybe the >> location of the open ident maybe *)
(* OPTIMIZE: using a stack to come up with this would cut the computation time of this considerably. *)
opens: (Location.t, unit) Hashtbl.t;
}

type file = string
Expand All @@ -382,7 +378,6 @@ let initExtra () =
externalReferences = Hashtbl.create 10;
fileReferences = Hashtbl.create 10;
locItems = [];
opens = Hashtbl.create 10;
}

type state = {
Expand Down