Skip to content

Commit d63aea1

Browse files
committed
reanalyze: remove global exception decl table (pure)
Stop using global mutable exception declaration state during AST processing. Instead, derive a pure exception lookup from merged Declarations and use it when processing CrossFileItems exception refs. Signed-Off-By: Cristiano Calcagno <cristiano.calcagno@gmail.com>
1 parent da9ba2f commit d63aea1

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

analysis/reanalyze/src/DeadException.ml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
open DeadCommon
22

3-
let declarations = Hashtbl.create 1
3+
module PathMap = Map.Make (struct
4+
type t = DcePath.t
5+
6+
let compare = Stdlib.compare
7+
end)
8+
9+
let find_exception_from_decls (decls : Declarations.t) :
10+
DcePath.t -> Location.t option =
11+
let index =
12+
Declarations.fold
13+
(fun _pos (decl : Decl.t) acc ->
14+
match decl.Decl.declKind with
15+
| Exception ->
16+
(* Use raw decl positions: reference graph keys are raw positions. *)
17+
let loc : Location.t =
18+
{
19+
Location.loc_start = decl.pos;
20+
loc_end = decl.posEnd;
21+
loc_ghost = false;
22+
}
23+
in
24+
PathMap.add decl.path loc acc
25+
| _ -> acc)
26+
decls PathMap.empty
27+
in
28+
fun path -> PathMap.find_opt path index
429

530
let add ~config ~decls ~file ~path ~loc ~(strLoc : Location.t)
631
~(moduleLoc : Location.t) name =
7-
let exceptionPath = name :: path in
8-
Hashtbl.add declarations exceptionPath loc;
32+
addDeclaration_ ~config ~decls ~file ~posEnd:strLoc.loc_end
33+
~posStart:strLoc.loc_start ~declKind:Exception ~moduleLoc ~path ~loc name;
934
name
10-
|> addDeclaration_ ~config ~decls ~file ~posEnd:strLoc.loc_end
11-
~posStart:strLoc.loc_start ~declKind:Exception ~moduleLoc ~path ~loc
12-
13-
let find_exception path = Hashtbl.find_opt declarations path
1435

1536
let markAsUsed ~config ~refs ~file_deps ~cross_file ~(binding : Location.t)
1637
~(locFrom : Location.t) ~(locTo : Location.t) path_ =
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
open DeadCommon
2+
3+
val find_exception_from_decls : Declarations.t -> DcePath.t -> Location.t option
4+
5+
val add :
6+
config:DceConfig.t ->
7+
decls:Declarations.builder ->
8+
file:FileContext.t ->
9+
path:DcePath.t ->
10+
loc:Location.t ->
11+
strLoc:Location.t ->
12+
moduleLoc:Location.t ->
13+
Name.t ->
14+
Name.t
15+
16+
val markAsUsed :
17+
config:DceConfig.t ->
18+
refs:References.builder ->
19+
file_deps:FileDeps.builder ->
20+
cross_file:CrossFileItems.builder ->
21+
binding:Location.t ->
22+
locFrom:Location.t ->
23+
locTo:Location.t ->
24+
Path.t ->
25+
unit

analysis/reanalyze/src/Reanalyze.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ let runAnalysis ~dce_config ~cmtRoot =
167167
(* Compute type-label dependencies after merge (no global TypeLabels table during traversal) *)
168168
DeadType.process_type_label_dependencies ~config:dce_config ~decls
169169
~refs:refs_builder;
170+
let find_exception = DeadException.find_exception_from_decls decls in
170171
(* Process cross-file exception refs - they write to refs_builder and file_deps_builder *)
171172
CrossFileItems.process_exception_refs cross_file ~refs:refs_builder
172-
~file_deps:file_deps_builder ~find_exception:DeadException.find_exception
173-
~config:dce_config;
173+
~file_deps:file_deps_builder ~find_exception ~config:dce_config;
174174
(* Now freeze refs and file_deps for solver *)
175175
let refs = References.freeze_builder refs_builder in
176176
let file_deps = FileDeps.freeze_builder file_deps_builder in

0 commit comments

Comments
 (0)