Skip to content

Commit 15e5b7c

Browse files
committed
Add project-level format.
1 parent 85d80d1 commit 15e5b7c

40 files changed

+257
-690
lines changed

analysis/.ocamlformat-ignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/compiler-libs-406/*
2+
vendor/res_outcome_printer/*

analysis/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ build: build-analysis-binary build-reanalyze build-tests
1616
dce: build-analysis-binary
1717
opam exec reanalyze.exe -- -dce-cmt _build -suppress vendor
1818

19+
format:
20+
dune build @fmt --auto-promote
21+
1922
test-analysis-binary: build-analysis-binary
2023
make -C tests test
2124

@@ -35,4 +38,4 @@ clean-deep:
3538

3639
.DEFAULT_GOAL := build
3740

38-
.PHONY: build-analysis-binary build-reanalyze build-tests dce clean clean-deep test
41+
.PHONY: build-analysis-binary build-reanalyze build-tests dce clean clean-deep format test

analysis/reanalyze/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(dirs src)
1+
(dirs src)

analysis/reanalyze/src/Annotation.ml

-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ type attributePayload =
99
| UnrecognizedPayload
1010

1111
let tagIsGenType s = s = "genType" || s = "gentype"
12-
1312
let tagIsGenTypeImport s = s = "genType.import" || s = "gentype.import"
14-
1513
let tagIsGenTypeOpaque s = s = "genType.opaque" || s = "gentype.opaque"
1614

1715
let tagIsOneOfTheGenTypeAnnotations s =

analysis/reanalyze/src/Arnold.ml

-22
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ end
1414

1515
module FunctionArgs = struct
1616
type arg = {label : string; functionName : FunctionName.t}
17-
1817
type t = arg list
1918

2019
let empty = []
21-
2220
let argToString {label; functionName} = label ^ ":" ^ functionName
2321

2422
let toString functionArgs =
@@ -82,17 +80,11 @@ module FunctionCallSet = Set.Make (FunctionCall)
8280

8381
module Stats = struct
8482
let nCacheChecks = ref 0
85-
8683
let nCacheHits = ref 0
87-
8884
let nFiles = ref 0
89-
9085
let nFunctions = ref 0
91-
9286
let nHygieneErrors = ref 0
93-
9487
let nInfiniteLoops = ref 0
95-
9688
let nRecursiveBlocks = ref 0
9789

9890
let print ppf () =
@@ -107,7 +99,6 @@ module Stats = struct
10799
Format.fprintf ppf "@]"
108100

109101
let dump ~ppf = Format.fprintf ppf "%a@." print ()
110-
111102
let newFile () = incr nFiles
112103

113104
let newRecursiveFunctions ~numFunctions =
@@ -246,7 +237,6 @@ module Trace = struct
246237
| _ -> Tseq [t1; t2]
247238

248239
let some = Toption Rsome
249-
250240
let none = Toption Rnone
251241

252242
let retOptionToString r =
@@ -273,21 +263,15 @@ module Values : sig
273263
type t
274264

275265
val getNone : t -> Progress.t option
276-
277266
val getSome : t -> Progress.t option
278-
279267
val nd : t -> t -> t
280-
281268
val none : progress:Progress.t -> t
282-
283269
val some : progress:Progress.t -> t
284-
285270
val toString : t -> string
286271
end = struct
287272
type t = {none : Progress.t option; some : Progress.t option}
288273

289274
let getNone {none} = none
290-
291275
let getSome {some} = some
292276

293277
let toString x =
@@ -299,7 +283,6 @@ end = struct
299283
|> String.concat ", "
300284

301285
let none ~progress = {none = Some progress; some = None}
302-
303286
let some ~progress = {none = None; some = Some progress}
304287

305288
let nd (v1 : t) (v2 : t) : t =
@@ -384,7 +367,6 @@ end
384367

385368
module Command = struct
386369
type progress = Progress.t
387-
388370
type retOption = Trace.retOption
389371

390372
type t =
@@ -450,7 +432,6 @@ end
450432

451433
module Kind = struct
452434
type t = entry list
453-
454435
and entry = {label : string; k : t}
455436

456437
let empty = ([] : t)
@@ -502,7 +483,6 @@ module FunctionTable = struct
502483
Format.fprintf ppf "@]"
503484

504485
let dump tbl = Format.fprintf Format.std_formatter "%a@." print tbl
505-
506486
let initialFunctionDefinition () = {kind = Kind.empty; body = None}
507487

508488
let getFunctionDefinition ~functionName (tbl : t) =
@@ -1034,7 +1014,6 @@ end
10341014

10351015
module CallStack = struct
10361016
type frame = {frameNumber : int; pos : Lexing.position}
1037-
10381017
type t = {tbl : (FunctionCall.t, frame) Hashtbl.t; mutable size : int}
10391018

10401019
let create () = {tbl = Hashtbl.create 1; size = 0}
@@ -1072,7 +1051,6 @@ end
10721051

10731052
module Eval = struct
10741053
type progress = Progress.t
1075-
10761054
type cache = (FunctionCall.t, State.t) Hashtbl.t
10771055

10781056
let createCache () : cache = Hashtbl.create 1

analysis/reanalyze/src/Common.ml

-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
let currentSrc = ref ""
2-
32
let currentModule = ref ""
4-
53
let currentModuleName = ref ("" |> Name.create)
6-
74
let runConfig = RunConfig.runConfig
85

96
(* Location printer: `filename:line: ' *)
@@ -16,16 +13,13 @@ let posToString (pos : Lexing.position) =
1613

1714
module Cli = struct
1815
let debug = ref false
19-
2016
let ci = ref false
2117

2218
(** The command was a -cmt variant (e.g. -exception-cmt) *)
2319
let cmtCommand = ref false
2420

2521
let experimental = ref false
26-
2722
let json = ref false
28-
2923
let write = ref false
3024

3125
(* names to be considered live values *)
@@ -54,7 +48,6 @@ module FileHash = struct
5448
type t = string
5549

5650
let hash (x : t) = Hashtbl.hash x
57-
5851
let equal (x : t) y = x = y
5952
end)
6053
end
@@ -167,7 +160,6 @@ module OptionalArgs = struct
167160
y.alwaysUsed <- alwaysUsed
168161

169162
let iterUnused f x = StringSet.iter f x.unused
170-
171163
let iterAlwaysUsed f x = StringSet.iter (fun s -> f s x.count) x.alwaysUsed
172164
end
173165

@@ -222,7 +214,6 @@ type missingRaiseInfo = {
222214
}
223215

224216
type severity = Warning | Error
225-
226217
type deadOptional = WarningUnusedArgument | WarningRedundantOptionalArgument
227218

228219
type termination =

analysis/reanalyze/src/DeadCommon.ml

-9
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@ end)
1111
module Config = struct
1212
(* Turn on type analysis *)
1313
let analyzeTypes = ref true
14-
1514
let analyzeExternals = ref false
16-
1715
let reportUnderscore = false
18-
1916
let reportTypesDeadOnlyInInterface = false
20-
2117
let recursiveDebug = false
22-
2318
let warnOnCircularDependencies = false
2419
end
2520

2621
module Current = struct
2722
let bindings = ref PosSet.empty
28-
2923
let lastBinding = ref Location.none
3024

3125
(** max end position of a value reported dead *)
@@ -71,7 +65,6 @@ module ValueReferences = struct
7165
let table = (PosHash.create 256 : PosSet.t PosHash.t)
7266

7367
let add posTo posFrom = PosHash.addSet table posTo posFrom
74-
7568
let find pos = PosHash.findSet table pos
7669
end
7770

@@ -80,7 +73,6 @@ module TypeReferences = struct
8073
let table = (PosHash.create 256 : PosSet.t PosHash.t)
8174

8275
let add posTo posFrom = PosHash.addSet table posTo posFrom
83-
8476
let find pos = PosHash.findSet table pos
8577
end
8678

@@ -195,7 +187,6 @@ module ProcessDeadAnnotations = struct
195187
type annotatedAs = GenType | Dead | Live
196188

197189
let positionsAnnotated = PosHash.create 1
198-
199190
let isAnnotatedDead pos = PosHash.find_opt positionsAnnotated pos = Some Dead
200191

201192
let isAnnotatedGenTypeOrLive pos =

analysis/reanalyze/src/DeadException.ml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ open Common
44
type item = {exceptionPath : Path.t; locFrom : Location.t}
55

66
let delayedItems = ref []
7-
87
let declarations = Hashtbl.create 1
98

109
let add ~path ~loc ~(strLoc : Location.t) name =

analysis/reanalyze/src/DeadModules.ml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
let active () = true
2-
32
let table = Hashtbl.create 1
43

54
let markDead ~isType ~loc path =

analysis/reanalyze/src/DeadOptionalArgs.ml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ type item = {
1010
}
1111

1212
let delayedItems = (ref [] : item list ref)
13-
1413
let functionReferences = (ref [] : (Lexing.position * Lexing.position) list ref)
1514

1615
let addFunctionReference ~(locFrom : Location.t) ~(locTo : Location.t) =

analysis/reanalyze/src/DeadType.ml

-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ module TypeLabels = struct
77
(* map from type path (for record/variant label) to its location *)
88

99
let table = (Hashtbl.create 256 : (Path.t, Location.t) Hashtbl.t)
10-
1110
let add path loc = Hashtbl.replace table path loc
12-
1311
let find path = Hashtbl.find_opt table path
1412
end
1513

@@ -21,9 +19,7 @@ let addTypeReference ~posFrom ~posTo =
2119

2220
module TypeDependencies = struct
2321
let delayedItems = ref []
24-
2522
let add loc1 loc2 = delayedItems := (loc1, loc2) :: !delayedItems
26-
2723
let clear () = delayedItems := []
2824

2925
let processTypeDependency

analysis/reanalyze/src/DeadValue.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ let rec collectExpr super self (e : Typedtree.expression) =
137137
~locTo ~path
138138
| Texp_let
139139
( (* generated for functions with optional args *)
140-
Nonrecursive,
140+
Nonrecursive,
141141
[
142142
{
143143
vb_pat = {pat_desc = Tpat_var (idArg, _)};

analysis/reanalyze/src/EmitJson.ml

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
let items = ref 0
2-
32
let start () = Format.fprintf Format.std_formatter "["
4-
53
let finish () = Format.fprintf Format.std_formatter "\n]@."
6-
74
let emitClose () = "\n}"
85

96
let emitItem ~ppf ~name ~kind ~file ~range ~message =

analysis/reanalyze/src/Exception.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ module Event = struct
6666
type kind =
6767
| Catches of t list (* with | E => ... *)
6868
| Call of {callee : Common.Path.t; modulePath : Common.Path.t} (* foo() *)
69-
| DoesNotRaise of t list (* DoesNotRaise(events) where events come from an expression *)
69+
| DoesNotRaise of
70+
t list (* DoesNotRaise(events) where events come from an expression *)
7071
| Raises (** raise E *)
7172

7273
and t = {exceptions : Exceptions.t; kind : kind; loc : Location.t}

analysis/reanalyze/src/Exceptions.ml

-7
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,12 @@ open Common
33
type t = ExnSet.t
44

55
let add = ExnSet.add
6-
76
let diff = ExnSet.diff
8-
97
let empty = ExnSet.empty
10-
118
let fromList = ExnSet.of_list
12-
139
let toList = ExnSet.elements
14-
1510
let isEmpty = ExnSet.is_empty
16-
1711
let iter = ExnSet.iter
18-
1912
let union = ExnSet.union
2013

2114
let pp ~exnTable ppf exceptions =

analysis/reanalyze/src/Exn.ml

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,19 @@
11
type t = string
22

33
let compare = String.compare
4-
54
let decodeError = "DecodeError"
6-
75
let assertFailure = "Assert_failure"
8-
96
let divisionByZero = "Division_by_zero"
10-
117
let endOfFile = "End_of_file"
12-
138
let exit = "exit"
14-
159
let failure = "Failure"
16-
1710
let invalidArgument = "Invalid_argument"
18-
1911
let jsExnError = "Js.Exn.Error"
20-
2112
let matchFailure = "Match_failure"
22-
2313
let notFound = "Not_found"
24-
2514
let sysError = "Sys_error"
26-
2715
let fromLid lid = lid |> Longident.flatten |> String.concat "."
28-
2916
let fromString s = s
30-
3117
let toString s = s
32-
3318
let yojsonJsonError = "Yojson.Json_error"
34-
35-
let yojsonTypeError = "Yojson.Basic.Util.Type_error"
19+
let yojsonTypeError = "Yojson.Basic.Util.Type_error"

analysis/reanalyze/src/Exn.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ val notFound : t
1616
val sysError : t
1717
val toString : t -> string
1818
val yojsonJsonError : t
19-
val yojsonTypeError : t
19+
val yojsonTypeError : t

0 commit comments

Comments
 (0)