Skip to content

Commit b660b86

Browse files
committed
refactor(reanalyze): remove Common.ml kitchen sink module
Extract focused modules from Common.ml: - Cli.ml: CLI option refs - Pos.ml: Position utilities - PosSet.ml, PosHash.ml: Position collections - StringSet.ml, FileSet.ml, FileHash.ml: String/file collections - DcePath.ml: Dead code path type (renamed from Path to avoid shadowing) - Decl.ml: Declaration types (Kind, t, posAdjustment) - Issue.ml: Issue types (severity, deadWarning, description, etc.) - LocSet.ml: Location set - OptionalArgs.ml, OptionalArgsState.ml: Optional args tracking This eliminates the Common.ml 'kitchen sink' that was causing: - Circular dependency issues - Poor code organization - Difficulty understanding module boundaries Each module now has a single responsibility. Signed-Off-By: Cristiano Calcagno
1 parent a9e984b commit b660b86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+527
-644
lines changed

analysis/reanalyze/src/AnalysisResult.ml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
The solver returns this instead of logging directly.
44
All side effects (logging, JSON output) happen in the reporting phase. *)
55

6-
open Common
7-
8-
type t = {issues: issue list}
6+
type t = {issues: Issue.t list}
97
(** Immutable analysis result *)
108

119
let empty = {issues = []}
@@ -20,11 +18,11 @@ let get_issues result = result.issues |> List.rev
2018
let issue_count result = List.length result.issues
2119

2220
(** Create a dead code issue *)
23-
let make_dead_issue ~loc ~deadWarning ~path ~message =
21+
let make_dead_issue ~loc ~deadWarning ~path ~message : Issue.t =
2422
{
25-
name =
23+
Issue.name =
2624
(match deadWarning with
27-
| WarningDeadException -> "Warning Dead Exception"
25+
| Issue.WarningDeadException -> "Warning Dead Exception"
2826
| WarningDeadType -> "Warning Dead Type"
2927
| WarningDeadValue -> "Warning Dead Value"
3028
| WarningDeadValueWithSideEffects ->
@@ -36,9 +34,9 @@ let make_dead_issue ~loc ~deadWarning ~path ~message =
3634
}
3735

3836
(** Create a dead module issue *)
39-
let make_dead_module_issue ~loc ~moduleName =
37+
let make_dead_module_issue ~loc ~moduleName : Issue.t =
4038
{
41-
name = "Warning Dead Module";
39+
Issue.name = "Warning Dead Module";
4240
severity = Warning;
4341
loc;
4442
description =

analysis/reanalyze/src/AnalysisResult.mli

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
The solver returns this instead of logging directly.
44
All side effects (logging, JSON output) happen in the reporting phase. *)
55

6-
open Common
7-
86
type t
97
(** Immutable analysis result *)
108

119
val empty : t
1210
(** Empty result with no issues *)
1311

14-
val add_issue : t -> issue -> t
12+
val add_issue : t -> Issue.t -> t
1513
(** Add a single issue to the result *)
1614

17-
val add_issues : t -> issue list -> t
15+
val add_issues : t -> Issue.t list -> t
1816
(** Add multiple issues to the result *)
1917

20-
val get_issues : t -> issue list
18+
val get_issues : t -> Issue.t list
2119
(** Get all issues in order they were added *)
2220

2321
val issue_count : t -> int
@@ -27,11 +25,11 @@ val issue_count : t -> int
2725

2826
val make_dead_issue :
2927
loc:Location.t ->
30-
deadWarning:deadWarning ->
28+
deadWarning:Issue.deadWarning ->
3129
path:string ->
3230
message:string ->
33-
issue
31+
Issue.t
3432
(** Create a dead code warning issue *)
3533

36-
val make_dead_module_issue : loc:Location.t -> moduleName:Name.t -> issue
34+
val make_dead_module_issue : loc:Location.t -> moduleName:Name.t -> Issue.t
3735
(** Create a dead module warning issue *)

analysis/reanalyze/src/Cli.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(** Command-line interface options for reanalyze.
2+
These refs are set by argument parsing in Reanalyze.ml *)
3+
4+
let debug = ref false
5+
let ci = ref false
6+
7+
(** The command was a -cmt variant (e.g. -exception-cmt) *)
8+
let cmtCommand = ref false
9+
10+
let experimental = ref false
11+
let json = ref false
12+
13+
(* names to be considered live values *)
14+
let liveNames = ref ([] : string list)
15+
16+
(* paths of files where all values are considered live *)
17+
let livePaths = ref ([] : string list)
18+
19+
(* paths of files to exclude from analysis *)
20+
let excludePaths = ref ([] : string list)

analysis/reanalyze/src/Common.ml

Lines changed: 0 additions & 248 deletions
This file was deleted.

analysis/reanalyze/src/CrossFileItems.ml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,9 @@
33
These are references that span file boundaries and need to be resolved
44
after all files are processed. *)
55

6-
open Common
7-
8-
(* Position-keyed hashtable *)
9-
module PosHash = Hashtbl.Make (struct
10-
type t = Lexing.position
11-
12-
let hash x =
13-
let s = Filename.basename x.Lexing.pos_fname in
14-
Hashtbl.hash (x.Lexing.pos_cnum, s)
15-
16-
let equal (x : t) y = x = y
17-
end)
18-
196
(** {2 Item types} *)
207

21-
type exception_ref = {exception_path: Path.t; loc_from: Location.t}
8+
type exception_ref = {exception_path: DcePath.t; loc_from: Location.t}
229

2310
type optional_arg_call = {
2411
pos_to: Lexing.position;

analysis/reanalyze/src/CrossFileItems.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type builder
1818
val create_builder : unit -> builder
1919

2020
val add_exception_ref :
21-
builder -> exception_path:Common.Path.t -> loc_from:Location.t -> unit
21+
builder -> exception_path:DcePath.t -> loc_from:Location.t -> unit
2222
(** Add a cross-file exception reference (defined in another file). *)
2323

2424
val add_optional_arg_call :
@@ -44,14 +44,14 @@ val process_exception_refs :
4444
t ->
4545
refs:References.builder ->
4646
file_deps:FileDeps.builder ->
47-
find_exception:(Common.Path.t -> Location.t option) ->
47+
find_exception:(DcePath.t -> Location.t option) ->
4848
config:DceConfig.t ->
4949
unit
5050
(** Process cross-file exception references. *)
5151

5252
(** {2 Optional Args State} *)
5353

5454
val compute_optional_args_state :
55-
t -> decls:Declarations.t -> Common.OptionalArgsState.t
55+
t -> decls:Declarations.t -> OptionalArgsState.t
5656
(** Compute final optional args state from calls and function references.
5757
Pure function - does not mutate declarations. *)

0 commit comments

Comments
 (0)