Skip to content

Commit 1ced671

Browse files
committed
Refactor: remove unused opens in extra.
1 parent 2491e17 commit 1ced671

File tree

2 files changed

+23
-37
lines changed

2 files changed

+23
-37
lines changed

analysis/src/ProcessExtra.ml

+23-32
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,7 @@ let structure_item ~env ~extra (iter : Tast_iterator.iterator) item =
327327
| Tstr_module {mb_expr} -> handle_module_expr ~env ~extra mb_expr.mod_desc
328328
| Tstr_open {open_path; open_txt = {txt; loc}} ->
329329
(* Log.log("Have an open here"); *)
330-
addForLongident ~env ~extra None open_path txt loc;
331-
Hashtbl.replace extra.opens loc ()
330+
addForLongident ~env ~extra None open_path txt loc
332331
| _ -> ());
333332
Tast_iterator.default_iterator.structure_item iter item
334333

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

390389
let expr ~env ~(extra : extra) (iter : Tast_iterator.iterator)
391390
(expression : Typedtree.expression) =
392-
(expression.exp_extra
393-
|> List.iter (fun (e, eloc, _) ->
394-
match e with
395-
| Typedtree.Texp_open (_, _path, _ident, _) ->
396-
Hashtbl.add extra.opens eloc ()
397-
| _ -> ());
398-
match expression.exp_desc with
399-
| Texp_ident (path, {txt; loc}, _) when not (JsxHacks.pathIsFragment path) ->
400-
addForLongident ~env ~extra
401-
(Some (expression.exp_type, Value))
402-
path txt loc
403-
| Texp_record {fields} ->
404-
addForRecord ~env ~extra ~recordType:expression.exp_type
405-
(fields |> Array.to_list
406-
|> Utils.filterMap (fun (desc, item) ->
407-
match item with
408-
| Typedtree.Overridden (loc, _) -> Some (loc, desc, ())
409-
| _ -> None))
410-
| Texp_constant constant ->
411-
addLocItem extra expression.exp_loc (Constant constant)
412-
(* Skip unit and list literals *)
413-
| Texp_construct ({txt = Lident ("()" | "::"); loc}, _, _args)
414-
when loc.loc_end.pos_cnum - loc.loc_start.pos_cnum <> 2 ->
415-
()
416-
| Texp_construct (lident, constructor, _args) ->
417-
addForConstructor ~env ~extra expression.exp_type lident constructor
418-
| Texp_field (inner, lident, _label_description) ->
419-
addForField ~env ~extra ~recordType:inner.exp_type
420-
~fieldType:expression.exp_type lident
421-
| _ -> ());
391+
(match expression.exp_desc with
392+
| Texp_ident (path, {txt; loc}, _) when not (JsxHacks.pathIsFragment path) ->
393+
addForLongident ~env ~extra (Some (expression.exp_type, Value)) path txt loc
394+
| Texp_record {fields} ->
395+
addForRecord ~env ~extra ~recordType:expression.exp_type
396+
(fields |> Array.to_list
397+
|> Utils.filterMap (fun (desc, item) ->
398+
match item with
399+
| Typedtree.Overridden (loc, _) -> Some (loc, desc, ())
400+
| _ -> None))
401+
| Texp_constant constant ->
402+
addLocItem extra expression.exp_loc (Constant constant)
403+
(* Skip unit and list literals *)
404+
| Texp_construct ({txt = Lident ("()" | "::"); loc}, _, _args)
405+
when loc.loc_end.pos_cnum - loc.loc_start.pos_cnum <> 2 ->
406+
()
407+
| Texp_construct (lident, constructor, _args) ->
408+
addForConstructor ~env ~extra expression.exp_type lident constructor
409+
| Texp_field (inner, lident, _label_description) ->
410+
addForField ~env ~extra ~recordType:inner.exp_type
411+
~fieldType:expression.exp_type lident
412+
| _ -> ());
422413
Tast_iterator.default_iterator.expr iter expression
423414

424415
let getExtra ~file ~infos =

analysis/src/SharedTypes.ml

-5
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,6 @@ type extra = {
355355
(string, (string list * Tip.t * Location.t) list) Hashtbl.t;
356356
fileReferences: (string, LocationSet.t) Hashtbl.t;
357357
mutable locItems: locItem list;
358-
(* This is the "open location", like the location...
359-
or maybe the >> location of the open ident maybe *)
360-
(* OPTIMIZE: using a stack to come up with this would cut the computation time of this considerably. *)
361-
opens: (Location.t, unit) Hashtbl.t;
362358
}
363359

364360
type file = string
@@ -382,7 +378,6 @@ let initExtra () =
382378
externalReferences = Hashtbl.create 10;
383379
fileReferences = Hashtbl.create 10;
384380
locItems = [];
385-
opens = Hashtbl.create 10;
386381
}
387382

388383
type state = {

0 commit comments

Comments
 (0)