Skip to content

Add project-level format. #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
SHELL = /bin/bash

build:
make -C analysis build

clean:
make -C analysis clean

clean-deep:
make -C analysis clean-deep

test:
make -C analysis test

.DEFAULT_GOAL := build

.PHONY: build clean clean-deep test
2 changes: 2 additions & 0 deletions analysis/.ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/compiler-libs-406/*
vendor/res_outcome_printer/*
5 changes: 4 additions & 1 deletion analysis/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ build: build-analysis-binary build-reanalyze build-tests
dce: build-analysis-binary
opam exec reanalyze.exe -- -dce-cmt _build -suppress vendor

format:
dune build @fmt --auto-promote

test-analysis-binary: build-analysis-binary
make -C tests test

Expand All @@ -35,4 +38,4 @@ clean-deep:

.DEFAULT_GOAL := build

.PHONY: build-analysis-binary build-reanalyze build-tests dce clean clean-deep test
.PHONY: build-analysis-binary build-reanalyze build-tests dce clean clean-deep format test
2 changes: 1 addition & 1 deletion analysis/reanalyze/dune
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(dirs src)
(dirs src)
2 changes: 0 additions & 2 deletions analysis/reanalyze/src/Annotation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ type attributePayload =
| UnrecognizedPayload

let tagIsGenType s = s = "genType" || s = "gentype"

let tagIsGenTypeImport s = s = "genType.import" || s = "gentype.import"

let tagIsGenTypeOpaque s = s = "genType.opaque" || s = "gentype.opaque"

let tagIsOneOfTheGenTypeAnnotations s =
Expand Down
22 changes: 0 additions & 22 deletions analysis/reanalyze/src/Arnold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ end

module FunctionArgs = struct
type arg = {label : string; functionName : FunctionName.t}

type t = arg list

let empty = []

let argToString {label; functionName} = label ^ ":" ^ functionName

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

module Stats = struct
let nCacheChecks = ref 0

let nCacheHits = ref 0

let nFiles = ref 0

let nFunctions = ref 0

let nHygieneErrors = ref 0

let nInfiniteLoops = ref 0

let nRecursiveBlocks = ref 0

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

let dump ~ppf = Format.fprintf ppf "%a@." print ()

let newFile () = incr nFiles

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

let some = Toption Rsome

let none = Toption Rnone

let retOptionToString r =
Expand All @@ -273,21 +263,15 @@ module Values : sig
type t

val getNone : t -> Progress.t option

val getSome : t -> Progress.t option

val nd : t -> t -> t

val none : progress:Progress.t -> t

val some : progress:Progress.t -> t

val toString : t -> string
end = struct
type t = {none : Progress.t option; some : Progress.t option}

let getNone {none} = none

let getSome {some} = some

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

let none ~progress = {none = Some progress; some = None}

let some ~progress = {none = None; some = Some progress}

let nd (v1 : t) (v2 : t) : t =
Expand Down Expand Up @@ -384,7 +367,6 @@ end

module Command = struct
type progress = Progress.t

type retOption = Trace.retOption

type t =
Expand Down Expand Up @@ -450,7 +432,6 @@ end

module Kind = struct
type t = entry list

and entry = {label : string; k : t}

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

let dump tbl = Format.fprintf Format.std_formatter "%a@." print tbl

let initialFunctionDefinition () = {kind = Kind.empty; body = None}

let getFunctionDefinition ~functionName (tbl : t) =
Expand Down Expand Up @@ -1034,7 +1014,6 @@ end

module CallStack = struct
type frame = {frameNumber : int; pos : Lexing.position}

type t = {tbl : (FunctionCall.t, frame) Hashtbl.t; mutable size : int}

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

module Eval = struct
type progress = Progress.t

type cache = (FunctionCall.t, State.t) Hashtbl.t

let createCache () : cache = Hashtbl.create 1
Expand Down
9 changes: 0 additions & 9 deletions analysis/reanalyze/src/Common.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
let currentSrc = ref ""

let currentModule = ref ""

let currentModuleName = ref ("" |> Name.create)

let runConfig = RunConfig.runConfig

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

module Cli = struct
let debug = ref false

let ci = ref false

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

let experimental = ref false

let json = ref false

let write = ref false

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

let hash (x : t) = Hashtbl.hash x

let equal (x : t) y = x = y
end)
end
Expand Down Expand Up @@ -167,7 +160,6 @@ module OptionalArgs = struct
y.alwaysUsed <- alwaysUsed

let iterUnused f x = StringSet.iter f x.unused

let iterAlwaysUsed f x = StringSet.iter (fun s -> f s x.count) x.alwaysUsed
end

Expand Down Expand Up @@ -222,7 +214,6 @@ type missingRaiseInfo = {
}

type severity = Warning | Error

type deadOptional = WarningUnusedArgument | WarningRedundantOptionalArgument

type termination =
Expand Down
9 changes: 0 additions & 9 deletions analysis/reanalyze/src/DeadCommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@ end)
module Config = struct
(* Turn on type analysis *)
let analyzeTypes = ref true

let analyzeExternals = ref false

let reportUnderscore = false

let reportTypesDeadOnlyInInterface = false

let recursiveDebug = false

let warnOnCircularDependencies = false
end

module Current = struct
let bindings = ref PosSet.empty

let lastBinding = ref Location.none

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

let add posTo posFrom = PosHash.addSet table posTo posFrom

let find pos = PosHash.findSet table pos
end

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

let add posTo posFrom = PosHash.addSet table posTo posFrom

let find pos = PosHash.findSet table pos
end

Expand Down Expand Up @@ -195,7 +187,6 @@ module ProcessDeadAnnotations = struct
type annotatedAs = GenType | Dead | Live

let positionsAnnotated = PosHash.create 1

let isAnnotatedDead pos = PosHash.find_opt positionsAnnotated pos = Some Dead

let isAnnotatedGenTypeOrLive pos =
Expand Down
1 change: 0 additions & 1 deletion analysis/reanalyze/src/DeadException.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open Common
type item = {exceptionPath : Path.t; locFrom : Location.t}

let delayedItems = ref []

let declarations = Hashtbl.create 1

let add ~path ~loc ~(strLoc : Location.t) name =
Expand Down
1 change: 0 additions & 1 deletion analysis/reanalyze/src/DeadModules.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
let active () = true

let table = Hashtbl.create 1

let markDead ~isType ~loc path =
Expand Down
1 change: 0 additions & 1 deletion analysis/reanalyze/src/DeadOptionalArgs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type item = {
}

let delayedItems = (ref [] : item list ref)

let functionReferences = (ref [] : (Lexing.position * Lexing.position) list ref)

let addFunctionReference ~(locFrom : Location.t) ~(locTo : Location.t) =
Expand Down
4 changes: 0 additions & 4 deletions analysis/reanalyze/src/DeadType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ module TypeLabels = struct
(* map from type path (for record/variant label) to its location *)

let table = (Hashtbl.create 256 : (Path.t, Location.t) Hashtbl.t)

let add path loc = Hashtbl.replace table path loc

let find path = Hashtbl.find_opt table path
end

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

module TypeDependencies = struct
let delayedItems = ref []

let add loc1 loc2 = delayedItems := (loc1, loc2) :: !delayedItems

let clear () = delayedItems := []

let processTypeDependency
Expand Down
2 changes: 1 addition & 1 deletion analysis/reanalyze/src/DeadValue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ let rec collectExpr super self (e : Typedtree.expression) =
~locTo ~path
| Texp_let
( (* generated for functions with optional args *)
Nonrecursive,
Nonrecursive,
[
{
vb_pat = {pat_desc = Tpat_var (idArg, _)};
Expand Down
3 changes: 0 additions & 3 deletions analysis/reanalyze/src/EmitJson.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
let items = ref 0

let start () = Format.fprintf Format.std_formatter "["

let finish () = Format.fprintf Format.std_formatter "\n]@."

let emitClose () = "\n}"

let emitItem ~ppf ~name ~kind ~file ~range ~message =
Expand Down
3 changes: 2 additions & 1 deletion analysis/reanalyze/src/Exception.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ module Event = struct
type kind =
| Catches of t list (* with | E => ... *)
| Call of {callee : Common.Path.t; modulePath : Common.Path.t} (* foo() *)
| DoesNotRaise of t list (* DoesNotRaise(events) where events come from an expression *)
| DoesNotRaise of
t list (* DoesNotRaise(events) where events come from an expression *)
| Raises (** raise E *)

and t = {exceptions : Exceptions.t; kind : kind; loc : Location.t}
Expand Down
7 changes: 0 additions & 7 deletions analysis/reanalyze/src/Exceptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@ open Common
type t = ExnSet.t

let add = ExnSet.add

let diff = ExnSet.diff

let empty = ExnSet.empty

let fromList = ExnSet.of_list

let toList = ExnSet.elements

let isEmpty = ExnSet.is_empty

let iter = ExnSet.iter

let union = ExnSet.union

let pp ~exnTable ppf exceptions =
Expand Down
18 changes: 1 addition & 17 deletions analysis/reanalyze/src/Exn.ml
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
type t = string

let compare = String.compare

let decodeError = "DecodeError"

let assertFailure = "Assert_failure"

let divisionByZero = "Division_by_zero"

let endOfFile = "End_of_file"

let exit = "exit"

let failure = "Failure"

let invalidArgument = "Invalid_argument"

let jsExnError = "Js.Exn.Error"

let matchFailure = "Match_failure"

let notFound = "Not_found"

let sysError = "Sys_error"

let fromLid lid = lid |> Longident.flatten |> String.concat "."

let fromString s = s

let toString s = s

let yojsonJsonError = "Yojson.Json_error"

let yojsonTypeError = "Yojson.Basic.Util.Type_error"
let yojsonTypeError = "Yojson.Basic.Util.Type_error"
2 changes: 1 addition & 1 deletion analysis/reanalyze/src/Exn.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ val notFound : t
val sysError : t
val toString : t -> string
val yojsonJsonError : t
val yojsonTypeError : t
val yojsonTypeError : t
Loading