Skip to content

Commit

Permalink
[police] open IStd automatically
Browse files Browse the repository at this point in the history
Summary:
This should help prevent new modules being created that do not `open! IStd`.

Documented this in CONTRIBUTING.md.

Reviewed By: jberdine

Differential Revision: D5183552

fbshipit-source-id: 0f0a8ce
  • Loading branch information
jvillard authored and facebook-github-bot committed Jun 6, 2017
1 parent 7a1f1d9 commit e24bffe
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
70 changes: 51 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,47 @@ us a line at [email protected]. Thanks!

### OCaml

- Follow the ocp-indent style in infer/.ocpindent for indentation.
- The module IStd (infer/src/base/IStd.ml) is automatically opened in every file. Beware that this
can cause weird errors such as:
```
$ pwd
/somewhere/infer/infer/src
$ cat base/toto.ml
let b = List.mem true [true; false]
$ make
[...]
File "base/toto.ml", line 1, characters 17-21:
Error: This variant expression is expected to have type 'a list
The constructor true does not belong to type list
```

- Spaces around binary operators, e.g., `let x = a + 5`.
If your new module cannot compile with `IStd`, for instance because it's generated code, modify
the line in infer/src/Makefile that adds `-open IStd` so that your module is excluded (see how
it's done for other such modules, eg IStd.ml).

- Spaces around parentheses, no space inside parentheses.
- All modules open `IStd` using `open! IStd`. This is to make that fact more explicit (there's also
the compilation flag mentioned above), and also it helps merlin find the right types. In
particular this also opens `Core.Std`.

- Spaces around braces and brackets, spaces inside braces and brackets.
- Do not add anything to `IStd` unless you have a compelling reason to do so, for instance if you
find some utility function is missing and is not provided by
[`Core`](https://ocaml.janestreet.com/ocaml-core/latest/doc/core/).

- Space after `,` and `;`, e.g. `let (a, b) = ({ foo = 4; }, ())`.
- Polymorphic equality is disabled; use type-specific equality instead, even for primitive types
(e.g., `Int.equal`). However, if your module uses a lot of polymorphic variants with no arguments
you may safely `open! PVariant`.

- Terminate multi-line values such as lists and records with `;` so that it's easy to add new lines
without modifying existing ones. For instance:
```OCaml
let foo = [
value1;
value2;
]
If you try and use polymorphic equality `=` in your code you will get a compilation error, such as:
```
Error: This expression has type int but an expression was expected of type
[ `no_polymorphic_compare ]
```

- All modules open `IStd`, using `open! IStd`. In particular this also opens `Core.Std`. Do not add
anything to `IStd`; if you find some utility function is missing (and not provided by
[`Core`](https://ocaml.janestreet.com/ocaml-core/latest/doc/core/)), add it to `Utils`.
- Alias and use `module L = Logging` for all your logging needs. Refer to its API in Logging.mli for
documentation.

- Polymorphic equality is disabled; use type-specific equality instead, even for primitive types
(e.g., `Int.equal`). However, if your module uses a lot of polymorphic variants you may
`open! PVariant`.
- Check that your code compiles without warnings with `make -j test_build` (this also runs as part
of `make test`).

- Apart from `IStd` and `PVariant`, refrain from globally `open`ing modules. Using local open
instead when it improves readability: `let open MyModule in ...`.
Expand Down Expand Up @@ -129,7 +144,24 @@ module MF = MarkupFormatter

- Use the `_hum` suffix to flag functions that output human-readable strings.

- Check that your code compiles without warnings with `make -j test_build`.
- Follow the ocp-indent style in infer/.ocpindent for indentation.

- Spaces around binary operators, e.g., `let x = a + 5`.

- Spaces around parentheses, no space inside parentheses.

- Spaces around braces and brackets, spaces inside braces and brackets.

- Space after `,` and `;`, e.g. `let (a, b) = ({ foo = 4; }, ())`.

- Terminate multi-line values such as lists and records with `;` so that it's easy to add new lines
without modifying existing ones. For instance:
```OCaml
let foo = [
value1;
value2;
]
```

### Reason

Expand Down
1 change: 1 addition & 0 deletions infer/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ OCAMLBUILD_OPTIONS = \
-cflags -w,$(OCAML_FATAL_WARNINGS)-4-9-32-40-41-42-45-48 \
-tag-line "<*{clang/clang_ast_*,backend/jsonbug_*,checkers/stacktree_*}>: warn(-27-32-34-35-39)" \
-tag-line "<*/{,*/}*.{ml,re}{,i}>: package(ppx_compare)" \
-tag-line "not <**/{IList,IStd,jsonbug_j,clang_ast_j,clang_ast_b,stacktree_j}.*>: open(IStd)" \
-tag thread \
-pkgs ANSITerminal,atdgen,cmdliner,core,extlib,oUnit,parmap,str,unix,xmlm,yojson,zip

Expand Down

0 comments on commit e24bffe

Please sign in to comment.