Skip to content

Commit f173347

Browse files
authored
Getting started (#1040)
* Use ocamlformat 0.26.2 * Update eslint setting * Update contributing docs
1 parent fd91104 commit f173347

13 files changed

+93
-90
lines changed

.ocamlformat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
profile = default
2-
version = 0.26.1
2+
version = 0.26.2
33

44
field-space = tight-decl
55
break-cases = toplevel

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"typescript.tsc.autoDetect": "off",
55
"typescript.preferences.quoteStyle": "single",
66
"editor.codeActionsOnSave": {
7-
"source.fixAll.eslint": true
7+
"source.fixAll.eslint": "explicit"
88
},
99
"ocaml.sandbox": {
1010
"kind": "opam",

CONTRIBUTING.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ At the root:
4242

4343
```sh
4444
# If you haven't created the switch, do it. OPAM(https://opam.ocaml.org)
45-
opam switch 4.14.0 # can also create local switch with opam switch create . 4.14.0
45+
opam switch 5.2.0 # can also create local switch with opam switch create . 5.2.0
4646

4747
# Install dev dependencies from OPAM
4848
opam install . --deps-only
@@ -51,6 +51,9 @@ opam install . --deps-only
5151
opam install ocaml-lsp-server ocamlformat
5252
```
5353

54+
You need `dune` to build the OCaml source code, if it is not available in your shell try running `eval $(opam env)`.
55+
If `dune` is present, run `make build` to build the OCaml projects and copy the binaries to the root.
56+
5457
## Build & Run
5558

5659
- `npm run compile`. You don't need this if you're developing this repo in VSCode. The compilation happens automatically in the background.

analysis/reanalyze/src/Arnold.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,10 @@ module Compile = struct
813813
| _ ->
814814
Stats.logHygieneNamedArgValue ~label ~loc;
815815
raise ArgError
816-
[@@raises ArgError]
816+
[@@raises ArgError]
817817
in
818818
functionArg ()
819-
[@@raises ArgError]
819+
[@@raises ArgError]
820820
in
821821
let functionArgsOpt =
822822
try Some (functionDefinition.kind |> List.map getFunctionArg)
@@ -1320,15 +1320,15 @@ let traverseAst ~valueBindingsTable =
13201320
progressFunctionsFromAttributes valueBinding.vb_attributes
13211321
with
13221322
| None -> (progressFunctions, functionsToAnalyze)
1323-
| Some newProgressFunctions -> (
1323+
| Some newProgressFunctions ->
13241324
( StringSet.union
13251325
(StringSet.of_list newProgressFunctions)
13261326
progressFunctions,
13271327
match valueBinding.vb_pat.pat_desc with
13281328
| Tpat_var (id, _) ->
13291329
(Ident.name id, valueBinding.vb_expr.exp_loc)
13301330
:: functionsToAnalyze
1331-
| _ -> functionsToAnalyze )))
1331+
| _ -> functionsToAnalyze ))
13321332
(StringSet.empty, [])
13331333
in
13341334
(progressFunctions0, functionsToAnalyze0 |> List.rev)

analysis/reanalyze/src/DeadValue.ml

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ let collectValueBinding super self (vb : Typedtree.value_binding) =
4545
| _ -> false
4646
in
4747
(if (not exists) && not isFirstClassModule then
48-
(* This is never toplevel currently *)
49-
let isToplevel = oldLastBinding = Location.none in
50-
let sideEffects = SideEffects.checkExpr vb.vb_expr in
51-
name
52-
|> addValueDeclaration ~isToplevel ~loc ~moduleLoc:currentModulePath.loc
53-
~optionalArgs ~path ~sideEffects);
48+
(* This is never toplevel currently *)
49+
let isToplevel = oldLastBinding = Location.none in
50+
let sideEffects = SideEffects.checkExpr vb.vb_expr in
51+
name
52+
|> addValueDeclaration ~isToplevel ~loc
53+
~moduleLoc:currentModulePath.loc ~optionalArgs ~path ~sideEffects);
5454
(match PosHash.find_opt decls loc_start with
5555
| None -> ()
5656
| Some decl ->

analysis/reanalyze/src/Exception.ml

+27-27
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,20 @@ module Event = struct
138138
if !Common.Cli.debug then Log_.item "%a@." print ev;
139139
let nestedExceptions = loop Exceptions.empty nestedEvents in
140140
(if Exceptions.isEmpty nestedExceptions (* catch-all *) then
141-
let name =
142-
match nestedEvents with
143-
| {kind = Call {callee}} :: _ -> callee |> Common.Path.toName
144-
| _ -> "expression" |> Name.create
145-
in
146-
Log_.warning ~loc
147-
(Common.ExceptionAnalysis
148-
{
149-
message =
150-
Format.asprintf
151-
"@{<info>%s@} does not raise and is annotated with \
152-
redundant @doesNotRaise"
153-
(name |> Name.toString);
154-
}));
141+
let name =
142+
match nestedEvents with
143+
| {kind = Call {callee}} :: _ -> callee |> Common.Path.toName
144+
| _ -> "expression" |> Name.create
145+
in
146+
Log_.warning ~loc
147+
(Common.ExceptionAnalysis
148+
{
149+
message =
150+
Format.asprintf
151+
"@{<info>%s@} does not raise and is annotated with \
152+
redundant @doesNotRaise"
153+
(name |> Name.toString);
154+
}));
155155
loop exnSet rest
156156
| ({kind = Catches nestedEvents; exceptions} as ev) :: rest ->
157157
if !Common.Cli.debug then Log_.item "%a@." print ev;
@@ -192,11 +192,11 @@ module Checks = struct
192192
let missingAnnotations = Exceptions.diff raiseSet exceptions in
193193
let redundantAnnotations = Exceptions.diff exceptions raiseSet in
194194
(if not (Exceptions.isEmpty missingAnnotations) then
195-
let description =
196-
Common.ExceptionAnalysisMissing
197-
{exnName; exnTable; raiseSet; missingAnnotations; locFull}
198-
in
199-
Log_.warning ~loc description);
195+
let description =
196+
Common.ExceptionAnalysisMissing
197+
{exnName; exnTable; raiseSet; missingAnnotations; locFull}
198+
in
199+
Log_.warning ~loc description);
200200
if not (Exceptions.isEmpty redundantAnnotations) then
201201
Log_.warning ~loc
202202
(Common.ExceptionAnalysis
@@ -356,14 +356,14 @@ let traverseAst () =
356356
cases |> iterCases self
357357
| _ -> super.expr self expr |> ignore);
358358
(if isDoesNoRaise then
359-
let nestedEvents = !currentEvents in
360-
currentEvents :=
361-
{
362-
Event.exceptions = Exceptions.empty;
363-
loc;
364-
kind = DoesNotRaise nestedEvents;
365-
}
366-
:: oldEvents);
359+
let nestedEvents = !currentEvents in
360+
currentEvents :=
361+
{
362+
Event.exceptions = Exceptions.empty;
363+
loc;
364+
kind = DoesNotRaise nestedEvents;
365+
}
366+
:: oldEvents);
367367
expr
368368
in
369369
let getExceptionsFromAnnotations attributes =

analysis/reanalyze/src/Log_.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ module Loc = struct
7575
pos_cnum = char;
7676
pos_fname =
7777
(let open Filename in
78-
match is_implicit pos.pos_fname with
79-
| _ when !Cli.ci -> basename pos.pos_fname
80-
| true -> concat (Sys.getcwd ()) pos.pos_fname
81-
| false -> pos.pos_fname);
78+
match is_implicit pos.pos_fname with
79+
| _ when !Cli.ci -> basename pos.pos_fname
80+
| true -> concat (Sys.getcwd ()) pos.pos_fname
81+
| false -> pos.pos_fname);
8282
}
8383
in
8484
Location.print_loc ppf

analysis/reanalyze/src/Reanalyze.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ let cli () =
110110
let versionAndExit () =
111111
print_endline usage;
112112
exit 0
113-
[@@raises exit]
113+
[@@raises exit]
114114
in
115115
let rec setAll cmtRoot =
116116
RunConfig.all ();
@@ -216,7 +216,7 @@ let cli () =
216216
if !analysisKindSet = false then setConfig ();
217217
let cmtRoot = !cmtRootRef in
218218
runAnalysisAndReport ~cmtRoot
219-
[@@raises exit]
219+
[@@raises exit]
220220

221221
module RunConfig = RunConfig
222222
module Log_ = Log_

analysis/reanalyze/src/WriteDeadAnnotations.ml

+31-31
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,33 @@ let rec lineToString_ {original; declarations} =
4242
{
4343
original =
4444
(if String.length original >= col && col > 0 then
45-
let original1, original2 =
46-
try
47-
( String.sub original 0 col,
48-
String.sub original col (originalLen - col) )
49-
with Invalid_argument _ -> (original, "")
50-
in
51-
if language = Res && declKind = VariantCase then
52-
if
53-
String.length original2 >= 2
54-
&& (String.sub [@doesNotRaise]) original2 0 2 = "| "
55-
then
56-
original1 ^ "| " ^ annotationStr
57-
^ (String.sub [@doesNotRaise]) original2 2
58-
(String.length original2 - 2)
59-
else if
60-
String.length original2 >= 1
61-
&& (String.sub [@doesNotRaise]) original2 0 1 = "|"
62-
then
63-
original1 ^ "|" ^ annotationStr
64-
^ (String.sub [@doesNotRaise]) original2 1
65-
(String.length original2 - 1)
66-
else original1 ^ "| " ^ annotationStr ^ original2
67-
else original1 ^ annotationStr ^ original2
68-
else
69-
match language = Ml with
70-
| true -> original ^ annotationStr
71-
| false -> annotationStr ^ original);
45+
let original1, original2 =
46+
try
47+
( String.sub original 0 col,
48+
String.sub original col (originalLen - col) )
49+
with Invalid_argument _ -> (original, "")
50+
in
51+
if language = Res && declKind = VariantCase then
52+
if
53+
String.length original2 >= 2
54+
&& (String.sub [@doesNotRaise]) original2 0 2 = "| "
55+
then
56+
original1 ^ "| " ^ annotationStr
57+
^ (String.sub [@doesNotRaise]) original2 2
58+
(String.length original2 - 2)
59+
else if
60+
String.length original2 >= 1
61+
&& (String.sub [@doesNotRaise]) original2 0 1 = "|"
62+
then
63+
original1 ^ "|" ^ annotationStr
64+
^ (String.sub [@doesNotRaise]) original2 1
65+
(String.length original2 - 1)
66+
else original1 ^ "| " ^ annotationStr ^ original2
67+
else original1 ^ annotationStr ^ original2
68+
else
69+
match language = Ml with
70+
| true -> original ^ annotationStr
71+
| false -> annotationStr ^ original);
7272
declarations = nextDeclarations;
7373
}
7474
|> lineToString_
@@ -91,7 +91,7 @@ let readFile fileName =
9191
let line = {original = input_line channel; declarations = []} in
9292
lines := line :: !lines;
9393
loop ()
94-
[@@raises End_of_file]
94+
[@@raises End_of_file]
9595
in
9696
try loop ()
9797
with End_of_file ->
@@ -122,9 +122,9 @@ let getLineAnnotation ~decl ~line =
122122
posAnnotation.pos_cnum - posAnnotation.pos_bol + offset )
123123
~text:
124124
(if decl.posAdjustment = FirstVariant then
125-
(* avoid syntax error *)
126-
"| @dead "
127-
else "@dead ")
125+
(* avoid syntax error *)
126+
"| @dead "
127+
else "@dead ")
128128
~action:"Suppress dead code warning"
129129
else
130130
Format.asprintf "@. <-- line %d@. %s" decl.pos.pos_lnum

analysis/src/ProcessExtra.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ let addReference ~extra stamp loc =
99
(loc
1010
::
1111
(if Hashtbl.mem extra.internalReferences stamp then
12-
Hashtbl.find extra.internalReferences stamp
13-
else []))
12+
Hashtbl.find extra.internalReferences stamp
13+
else []))
1414

1515
let extraForFile ~(file : File.t) =
1616
let extra = initExtra () in
@@ -66,8 +66,8 @@ let addExternalReference ~extra moduleName path tip loc =
6666
((path, tip, loc)
6767
::
6868
(if Hashtbl.mem extra.externalReferences moduleName then
69-
Hashtbl.find extra.externalReferences moduleName
70-
else []))
69+
Hashtbl.find extra.externalReferences moduleName
70+
else []))
7171

7272
let addFileReference ~extra moduleName loc =
7373
let newLocs =

analysis/src/References.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let getLocItem ~full ~pos ~debug =
6666
| [
6767
({locType = Typed (_, _, LocalReference _)} as li1);
6868
({locType = Typed (_, _, GlobalReference ("Js_OO", ["unsafe_downgrade"], _))}
69-
as li2);
69+
as li2);
7070
li3;
7171
]
7272
(* For older compiler 9.0 or earlier *)

analysis/src/Scope.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let itemToString item =
1414
| Module (s, loc) -> "Module " ^ s ^ " " ^ Loc.toString loc
1515
| Value (s, loc, _, _) -> "Value " ^ s ^ " " ^ Loc.toString loc
1616
| Type (s, loc) -> "Type " ^ s ^ " " ^ Loc.toString loc
17-
[@@live]
17+
[@@live]
1818

1919
let create () : t = []
2020
let addConstructor ~name ~loc x = Constructor (name, loc) :: x
@@ -24,12 +24,12 @@ let addOpen ~lid x = Open (Utils.flattenLongIdent lid @ ["place holder"]) :: x
2424
let addValue ~name ~loc ?contextPath x =
2525
let showDebug = !Cfg.debugFollowCtxPath in
2626
(if showDebug then
27-
match contextPath with
28-
| None -> Printf.printf "adding value '%s', no ctxPath\n" name
29-
| Some contextPath ->
30-
if showDebug then
31-
Printf.printf "adding value '%s' with ctxPath: %s\n" name
32-
(SharedTypes.Completable.contextPathToString contextPath));
27+
match contextPath with
28+
| None -> Printf.printf "adding value '%s', no ctxPath\n" name
29+
| Some contextPath ->
30+
if showDebug then
31+
Printf.printf "adding value '%s' with ctxPath: %s\n" name
32+
(SharedTypes.Completable.contextPathToString contextPath));
3333
Value (name, loc, contextPath, x) :: x
3434
let addType ~name ~loc x = Type (name, loc) :: x
3535

tools/bin/version.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
let version = "0.6.4"
1+
let version = "0.6.4"

0 commit comments

Comments
 (0)