Skip to content

Commit 7ab2d23

Browse files
committed
Remove unused code related to open tracker.
1 parent c3a19db commit 7ab2d23

File tree

3 files changed

+9
-97
lines changed

3 files changed

+9
-97
lines changed

analysis/src/ProcessCmt.ml

Lines changed: 8 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -609,32 +609,6 @@ let extraForFile ~(file : File.t) =
609609
| _ -> ());
610610
extra
611611

612-
let rec relative ident path =
613-
match (ident, path) with
614-
| Longident.Lident name, Path.Pdot (path, pname, _) when pname = name ->
615-
Some path
616-
| Longident.Ldot (ident, name), Path.Pdot (path, pname, _) when pname = name
617-
->
618-
relative ident path
619-
(* | (Ldot(Lident("*predef*" | "exn"), _), Pident(_)) => None *)
620-
| _ -> None
621-
622-
let findClosestMatchingOpen opens path ident loc =
623-
match relative ident path with
624-
| None -> None
625-
| Some openNeedle -> (
626-
let matching =
627-
Hashtbl.fold
628-
(fun _ op res ->
629-
if Utils.locWithinLoc loc op.extent && Path.same op.path openNeedle
630-
then op :: res
631-
else res)
632-
opens []
633-
|> List.sort (fun (a : SharedTypes.openTracker) b ->
634-
b.loc.loc_start.pos_cnum - a.loc.loc_start.pos_cnum)
635-
in
636-
match matching with [] -> None | first :: _ -> Some first)
637-
638612
let rec joinPaths modulePath path =
639613
match modulePath with
640614
| Path.Pident ident -> (ident.stamp, ident.name, path)
@@ -698,26 +672,6 @@ end) =
698672
struct
699673
let extra = Collector.extra
700674

701-
let makeRelativePath basePath otherPath =
702-
let rec loop base other tip =
703-
if Path.same base other then Some tip
704-
else
705-
match other with
706-
| Pdot (inner, name, _) -> loop basePath inner (Nested (name, tip))
707-
| _ -> None
708-
in
709-
match otherPath with
710-
| Path.Pdot (inner, name, _) -> loop basePath inner (Tip name)
711-
| _ -> None
712-
713-
let maybeAddUse path ident loc tip =
714-
match findClosestMatchingOpen extra.opens path ident loc with
715-
| None -> ()
716-
| Some tracker -> (
717-
match makeRelativePath tracker.path path with
718-
| None -> ()
719-
| Some relpath -> tracker.used <- (relpath, tip, loc) :: tracker.used)
720-
721675
let addReference stamp loc =
722676
Hashtbl.replace extra.internalReferences stamp
723677
(loc
@@ -746,7 +700,6 @@ struct
746700
let env = QueryEnv.fromFile Collector.file
747701

748702
let addForPath path lident loc typ tip =
749-
maybeAddUse path lident loc tip;
750703
let identName = Longident.last lident in
751704
let identLoc = Utils.endOfLocation loc (String.length identName) in
752705
let locType =
@@ -815,26 +768,18 @@ struct
815768
| Some declaredType -> `Local declaredType
816769
| None -> `Not_found)
817770

818-
let handleConstructor path txt =
819-
let typeName =
820-
match path with
821-
| Path.Pdot (_path, typename, _) -> typename
822-
| Pident ident -> Ident.name ident
823-
| _ -> assert false
824-
in
825-
let open Longident in
771+
let handleConstructor txt =
826772
match txt with
827-
| Longident.Lident name -> (name, Lident typeName)
828-
| Ldot (left, name) -> (name, Ldot (left, typeName))
773+
| Longident.Lident name -> name
774+
| Ldot (_left, name) -> name
829775
| Lapply (_, _) -> assert false
830776

831777
let addForField recordType item {Asttypes.txt; loc} =
832778
match (Shared.dig recordType).desc with
833779
| Tconstr (path, _args, _memo) ->
834780
let t = getTypeAtPath ~env path in
835781
let {Types.lbl_res} = item in
836-
let name, typeLident = handleConstructor path txt in
837-
maybeAddUse path typeLident loc (Field name);
782+
let name = handleConstructor txt in
838783
let nameLoc = Utils.endOfLocation loc (String.length name) in
839784
let locType =
840785
match t with
@@ -859,8 +804,7 @@ struct
859804
items
860805
|> List.iter (fun ({Asttypes.txt; loc}, {Types.lbl_res}, _) ->
861806
(* let name = Longident.last(txt); *)
862-
let name, typeLident = handleConstructor path txt in
863-
maybeAddUse path typeLident loc (Field name);
807+
let name = handleConstructor txt in
864808
let nameLoc = Utils.endOfLocation loc (String.length name) in
865809
let locType =
866810
match t with
@@ -883,8 +827,7 @@ struct
883827
let addForConstructor constructorType {Asttypes.txt; loc} {Types.cstr_name} =
884828
match (Shared.dig constructorType).desc with
885829
| Tconstr (path, _args, _memo) ->
886-
let name, typeLident = handleConstructor path txt in
887-
maybeAddUse path typeLident loc (Constructor name);
830+
let name = handleConstructor txt in
888831
let nameLoc = Utils.endOfLocation loc (String.length name) in
889832
let t = getTypeAtPath ~env path in
890833
let locType =
@@ -944,7 +887,6 @@ struct
944887
| Tmod_constraint (expr, _, _, _) -> handle_module_expr expr.mod_desc
945888
| Tmod_ident (path, {txt; loc}) ->
946889
Log.log ("Ident!! " ^ String.concat "." (Longident.flatten txt));
947-
maybeAddUse path txt loc Module;
948890
addForLongident None path txt loc
949891
| Tmod_functor (_ident, _argName, _maybeType, resultExpr) ->
950892
handle_module_expr resultExpr.mod_desc
@@ -961,22 +903,8 @@ struct
961903
| Tstr_module {mb_expr} -> handle_module_expr mb_expr.mod_desc
962904
| Tstr_open {open_path; open_txt = {txt; loc}} ->
963905
(* Log.log("Have an open here"); *)
964-
maybeAddUse open_path txt loc Module;
965-
let tracker =
966-
{
967-
path = open_path;
968-
loc;
969-
used = [];
970-
extent =
971-
{
972-
loc_ghost = true;
973-
loc_start = loc.loc_end;
974-
loc_end = (currentScopeExtent ()).loc_end;
975-
};
976-
}
977-
in
978906
addForLongident None open_path txt loc;
979-
Hashtbl.replace Collector.extra.opens loc tracker
907+
Hashtbl.replace Collector.extra.opens loc ()
980908
| _ -> ()
981909

982910
let enter_structure {str_items} =
@@ -1058,9 +986,7 @@ struct
1058986
expression.exp_extra
1059987
|> List.iter (fun (e, eloc, _) ->
1060988
match e with
1061-
| Texp_open (_, path, _ident, _) ->
1062-
Hashtbl.add extra.opens eloc
1063-
{path; loc = eloc; extent = expression.exp_loc; used = []}
989+
| Texp_open (_, _path, _ident, _) -> Hashtbl.add extra.opens eloc ()
1064990
| _ -> ());
1065991
match expression.exp_desc with
1066992
| Texp_ident (path, {txt; loc}, {val_type}) ->

analysis/src/SharedTypes.ml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ let tipToString tip =
177177
| Constructor a -> "Constructor(" ^ a ^ ")"
178178
| Module -> "Module"
179179

180-
type path = Tip of string | Nested of string * path
181-
182180
let pathToString path = path |> String.concat "."
183181

184182
type locKind =
@@ -196,13 +194,6 @@ type locType =
196194

197195
type locItem = {loc : Location.t; locType : locType}
198196

199-
type openTracker = {
200-
path : Path.t;
201-
loc : Location.t;
202-
extent : Location.t;
203-
mutable used : (path * tip * Location.t) list;
204-
}
205-
206197
module LocationSet = Set.Make (struct
207198
include Location
208199

@@ -220,7 +211,7 @@ type extra = {
220211
(* This is the "open location", like the location...
221212
or maybe the >> location of the open ident maybe *)
222213
(* OPTIMIZE: using a stack to come up with this would cut the computation time of this considerably. *)
223-
opens : (Location.t, openTracker) Hashtbl.t;
214+
opens : (Location.t, unit) Hashtbl.t;
224215
}
225216

226217
type file = string

analysis/src/Utils.ml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ let cmtPosToPosition {Lexing.pos_lnum; pos_cnum; pos_bol} =
2121
let cmtLocToRange {Location.loc_start; loc_end} =
2222
Protocol.{start = cmtPosToPosition loc_start; end_ = cmtPosToPosition loc_end}
2323

24-
let locWithinLoc inner outer =
25-
let open Location in
26-
inner.loc_start.pos_cnum >= outer.loc_start.pos_cnum
27-
&& inner.loc_end.pos_cnum <= outer.loc_end.pos_cnum
28-
2924
let endOfLocation loc length =
3025
let open Location in
3126
{

0 commit comments

Comments
 (0)