Skip to content

Commit

Permalink
cmt files as input and output proposal
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Mar 28, 2021
1 parent 2ab45a2 commit 8a23ae1
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions rfcs/cmt_input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Cmt files - both as input and output

This RFC asks for two separate additions to the compiler front end. They are
technically independent, but mostly useful together. So I decided to bundled
them.

The first request is to type check compilation units and produce `.cmt` files:

```
$ ocamlc -c foo.ml -o foo.cmt
```

The second request is to take `.cmt` files as input to produce object files:

```
$ ocamlc -c foo.cmt -o foo.cmo
$ ocamlopt -c foo.cmt -o foo.cmx
```

How does this help? The motivation is mainly to simplify some rough edges of
build tools and improve compilation speed in some use cases. Some concrete
examples where this is useful:

## Fast "check" mode

Dune's check mode (`$ dune build @check`) attempts to verify the user's code
type checks in the fastest way possible. Currently, this is done by building all
`.cmi`, `.cmt`, `.cmti` targets. Targets such as `.cma`, `.cmx`, `.cmxa`, files
are omitted as an optimization. Obviously producing `.cmt` files requires
building bytecode, which slows things down somewhat.

## Duplicate warnings

When a project is built in both bytecode and native mode concurrently,
compilation warnings are displayed twice (once per mode). This is bad user
experience. Build systems such as dune need to add hacks to filter duplicate
errors to make things more bearable. A separate type checking phase would now be
responsible for these errors and such warnings would only appear once.

## Speed up compilation when type checking is a bottle neck

This likely doesn't occur very often, but there are cases where type checking is
slow. This proposal should improve compilation speed in such projects, because
type checking will be done only once per compilation unit.

## More flexible build rules for users

This one is kind of dune specific, but I'm sure it would help other build
systems as well. Since dune uses bytecode targets to produce `.cmt` files, users
cannot have full editor integration (since it requires `.cmt` files) and disable
bytecode builds. It could be argued that dune can be improved to produce `.cmt`
files via the native rules, but this a needless complication.

0 comments on commit 8a23ae1

Please sign in to comment.