From e24bffef9885d09db76e413619db5f6b91bf65f8 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 6 Jun 2017 04:17:14 -0700 Subject: [PATCH] [police] open IStd automatically 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 --- CONTRIBUTING.md | 70 +++++++++++++++++++++++++++++++++------------- infer/src/Makefile | 1 + 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 948e54b4d..f02b43232 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -71,32 +71,47 @@ us a line at cla@fb.com. 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 ...`. @@ -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 diff --git a/infer/src/Makefile b/infer/src/Makefile index f75780002..87f0fc751 100644 --- a/infer/src/Makefile +++ b/infer/src/Makefile @@ -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