1
1
# Contribution Guidelines
2
2
3
-
4
3
## Reporting Issues
5
4
6
5
If you encounter a problem when using infer or if you have any questions, please open a
@@ -14,6 +13,7 @@ We welcome contributions via [pull requests on GitHub](https://github.com/facebo
14
13
15
14
You'll want to install a few more dependencies to comfortably hack on the infer codebase;
16
15
in order to do this run ` ./build_infer.sh ` which will allow you to then run:
16
+
17
17
``` sh
18
18
make devsetup
19
19
```
@@ -23,14 +23,11 @@ make devsetup
23
23
- The default build mode ("dev") makes all build warnings * fatal* . If you want the build to ignore
24
24
warnings, for example to be able to test an infer executable before polishing the code to remove
25
25
warnings, you can build in "dev-noerror" mode with ` make BUILD_MODE=dev-noerror ` .
26
-
27
26
- Faster edit/build cycle when working on OCaml code inside infer/src/: build inside infer/src/
28
27
(skips building the models after infer has been built), and build only what is needed for type
29
28
checking with ` make -j -C infer/src check ` . You need to have run ` make -j ` at some point before.
30
-
31
29
- Alternatively, if you want to test your changes on a small example, build in bytecode mode:
32
30
` make -j -C infer/src byte ` .
33
-
34
31
- In general, ` make ` commands from the root of the repository make sure that dependencies are in a
35
32
consistent and up-to-date state (e.g., they rebuild infer and the models before running steps that
36
33
use infer), while running ` make ` commands from within subdirectories generally assumes that
@@ -40,26 +37,23 @@ make devsetup
40
37
necessary before running the test, but running ` make -C infer/tests/codetoanalyze/java/biabduction/ test `
41
38
will just execute the test.
42
39
43
-
44
40
### Debugging OCaml Code
45
41
46
42
- Printf-debug using ` Logging.debug_dev ` . It comes with a warning so
47
43
that you don't accidentally push code with calls to ` debug_dev ` to
48
44
the repo.
49
-
50
45
- Browse the documentation of OCaml modules in your browser with ` make doc `
51
-
52
46
- When using ` ocamldebug ` , and in particular when setting break points
53
47
with ` break @ <module> <line> ` don't forget that an infer module ` M `
54
48
is in reality called ` InferModules__M ` , or ` InferBase__M ` , or
55
49
... See the html documentation of the OCaml modules from ` make doc `
56
50
if you're unsure of a module name.
57
51
58
- ``` console
59
- $ ledit ocamldebug infer/bin/infer.bc.exe
60
- (ocd) break @ InferModules__InferAnalyze 100
61
- Breakpoint 1 at 9409684: file backend/InferAnalyze.ml, line 99, characters 18-78
62
- ```
52
+ ``` console
53
+ $ ledit ocamldebug infer/bin/infer.bc.exe
54
+ (ocd) break @ InferModules__InferAnalyze 100
55
+ Breakpoint 1 at 9409684: file backend/InferAnalyze.ml, line 99, characters 18-78
56
+ ```
63
57
64
58
- To test the infer OCaml code you can use the OCaml toplevel. To
65
59
build the OCaml toplevel with the infer modules pre-loaded, run
@@ -71,7 +65,6 @@ Breakpoint 1 at 9409684: file backend/InferAnalyze.ml, line 99, characters 18-78
71
65
Many operations require the results directory and database to be
72
66
initialized with ` ResultsDir.assert_results_dir "" ` .
73
67
74
-
75
68
## Contributor License Agreement
76
69
77
70
We require contributors to sign our Contributor License Agreement. In
@@ -88,80 +81,71 @@ Thanks!
88
81
### All Languages
89
82
90
83
- Indent with spaces, not tabs.
91
-
92
84
- Line width limit is 100 characters.
93
-
94
85
- In general, follow the style of surrounding code.
95
86
96
87
### OCaml
97
88
98
89
- The module IStd (infer/src/istd/IStd.ml) is automatically opened in every file. Beware that this
99
90
can cause weird errors such as:
100
- ```
101
- $ pwd
102
- /somewhere/infer/infer/src
103
- $ cat base/toto.ml
104
- let b = List.mem true [true; false]
105
- $ make
106
- [...]
107
- File "base/toto.ml", line 1, characters 17-21:
108
- Error: This variant expression is expected to have type 'a list
109
- The constructor true does not belong to type list
110
- ```
91
+
92
+ ``` console
93
+ $ pwd
94
+ /somewhere/infer/infer/src
95
+ $ cat base/toto.ml
96
+ let b = List.mem true [true; false]
97
+ $ make
98
+ [...]
99
+ File "base/toto.ml", line 1, characters 17-21:
100
+ Error: This variant expression is expected to have type 'a list
101
+ The constructor true does not belong to type list
102
+ ```
111
103
112
104
- All modules open ` IStd ` using ` open! IStd ` . This is to make that fact more explicit (there's also
113
105
the compilation flag mentioned above), and also it helps merlin find the right types. In
114
106
particular this also opens ` Core.Std ` .
115
-
116
107
- Do not add anything to ` IStd ` unless you have a compelling reason to do so, for instance if you
117
108
find some utility function is missing and is not provided by
118
109
[ ` Core ` ] ( https://ocaml.janestreet.com/ocaml-core/latest/doc/core/ ) .
119
-
120
110
- Polymorphic equality is disabled; use type-specific equality instead, even for primitive types
121
111
(e.g., ` Int.equal ` ). However, if your module uses a lot of polymorphic variants with no arguments
122
112
you may safely ` open PolyVariantEqual ` .
123
113
124
114
If you try and use polymorphic equality ` = ` in your code you will get a compilation error, such as:
125
- ```
126
- Error: This expression has type int but an expression was expected of type
127
- [ `no_polymorphic_compare ]
128
- ```
115
+
116
+ ``` console
117
+ Error: This expression has type int but an expression was expected of type
118
+ [ `no_polymorphic_compare ]
119
+ ```
129
120
130
121
- Alias and use ` module L = Logging ` for all your logging needs. Refer to its API in Logging.mli for
131
122
documentation.
132
-
133
123
- Check that your code compiles without warnings with ` make -j test_build ` (this also runs as part
134
124
of ` make test ` ).
135
-
136
125
- Apart from ` IStd ` and ` PolyVariantEqual ` , refrain from globally ` open ` ing modules. Using
137
126
local open instead when it improves readability: ` let open MyModule in ... ` .
138
-
139
127
- Avoid the use of module aliases, except for the following commonly-aliased modules. Use
140
128
module aliases consistently (e.g., do not alias ` L ` to a module other than ` Logging ` ).
141
- ``` OCaml
142
- module CLOpt = CommandLineOption
143
- module F = Format
144
- module L = Logging
145
- module MF = MarkupFormatter
146
- ```
129
+
130
+ ``` OCaml
131
+ module CLOpt = CommandLineOption
132
+ module F = Format
133
+ module L = Logging
134
+ module MF = MarkupFormatter
135
+ ```
147
136
148
137
- Use ` [@@deriving compare, equal] ` to write comparison/equality functions whenever possible.
149
138
Watch out for [ this issue] ( https://github.com/ocaml-ppx/ppx_deriving/issues/116 ) when writing
150
139
` type nonrec t = t [@@deriving compare] ` .
151
-
152
140
- Use named arguments whenever the purpose of the argument is not immediately obvious. In
153
141
particular, use named arguments for boolean and integer parameters unless the name of the function
154
142
mentions them explicitly. Also use named arguments to disambiguate between several arguments of
155
143
the same type.
156
-
157
144
- Use named arguments for functions taken as argument; it is common to name a function argument
158
145
` f ` . For instance: ` List.map : 'a list -> f:('a -> 'b) -> 'b list ` .
159
-
160
146
- In modules defining a type ` t ` , functions that take an argument of that type should generally have
161
147
that argument come first, except for optional arguments: ` val f : ?optional:bool -> t -> ... ` .
162
-
163
148
- Use the ` _hum ` suffix to flag functions that output human-readable strings.
164
-
165
149
- Format code with [ ocamlformat] ( https://github.com/ocaml-ppx/ocamlformat ) .
166
150
167
151
### C/C++/Objective-C
@@ -172,20 +156,16 @@ Follow `clang-format` (see ".clang-format" at the root of the repository).
172
156
173
157
- Make sure infer builds: ` make -j test_build ` . Refer to the [ installation
174
158
document] ( https://github.com/facebook/infer/blob/main/INSTALL.md ) for details.
175
-
176
159
- Run the tests: ` make -j 4 test ` (adjust 4 to the number of cores available of your machine). The
177
160
tests (almost) all consist of the same three ingredients:
178
161
1 . Some source code to run infer on.
179
162
2 . An "issues.exp" file where each line represents one item of output of the test. For most tests,
180
163
one line is one issue reported by infer.
181
164
3 . A ` Makefile ` that orchestrates the test, for instance running infer on the source code and
182
165
comparing the results with issues.exp using ` diff ` .
183
-
184
166
- If your changes modified some of the expected outputs and if the changes make sense, you can
185
167
update the expected test results by running ` make test-replace ` .
186
-
187
168
- If relevant, add a test for your change.
188
-
189
169
- To add a test that infer finds (or does not find) a particular issue, add your test in
190
170
"infer/tests/codetoanalyze/{language}/{analyzer}/". Look at the ` Makefile ` in that directory and
191
171
make sure it runs your test. "{analyzer}" is often an infer analyzer (as in
@@ -200,21 +180,18 @@ Follow `clang-format` (see ".clang-format" at the root of the repository).
200
180
- Test procedures documenting current limitations of the analyzer should have the prefix ` FP_ `
201
181
(for "false positive") or ` FN_ ` (for "false negative") and a comment explaining why the analyzer
202
182
gets the wrong answer.
203
-
204
-
205
183
- To add a test that a certain build system integration or a command-line option works in a certain
206
184
way, add a test in "infer/tests/build_systems/".
207
-
208
185
- If you created a new Makefile for your test, add it to the root "Makefile", either to the
209
186
` DIRECT_TESTS ` (first case) or to the ` BUILD_SYSTEMS_TESTS ` variable (second case). Gate the
210
187
test appropriately if it depends on Java or Clang or Xcode (see how other tests do it).
211
-
212
188
- It can be useful to look at the debug HTML output of infer to see the detail of the symbolic
213
189
execution. For instance:
214
- ``` sh
215
- $ infer --debug -- clang -c examples/hello.c
216
- $ firefox infer-out/captured/hello.c.* .html
217
- ```
190
+
191
+ ``` console
192
+ infer --debug -- clang -c examples/hello.c
193
+ firefox infer-out/captured/hello.c.*.html
194
+ ```
218
195
219
196
## Updating infer.opam and infer.opam.locked
220
197
0 commit comments