|
| 1 | +# Cmt files - both as input and output |
| 2 | + |
| 3 | +This RFC asks for two separate additions to the compiler front end. They are |
| 4 | +technically independent, but mostly useful together. So I decided to bundled |
| 5 | +them. |
| 6 | + |
| 7 | +The first request is to type check compilation units and produce `.cmt` files: |
| 8 | + |
| 9 | +``` |
| 10 | +$ ocamlc -c foo.ml -o foo.cmt |
| 11 | +``` |
| 12 | + |
| 13 | +The second request is to take `.cmt` files as input to produce object files: |
| 14 | + |
| 15 | +``` |
| 16 | +$ ocamlc -c foo.cmt -o foo.cmo |
| 17 | +$ ocamlopt -c foo.cmt -o foo.cmx |
| 18 | +``` |
| 19 | + |
| 20 | +How does this help? The motivation is mainly to simplify some rough edges of |
| 21 | +build tools and improve compilation speed in some use cases. Some concrete |
| 22 | +examples where this is useful: |
| 23 | + |
| 24 | +## Fast "check" mode |
| 25 | + |
| 26 | +Dune's check mode (`$ dune build @check`) attempts to verify the user's code |
| 27 | +type checks in the fastest way possible. Currently, this is done by building all |
| 28 | +`.cmi`, `.cmt`, `.cmti` targets. Unnecessary targets such as .cma, .cmx, .cmxa, |
| 29 | +files are omitted. Obviously producing `.cmt` files requires building bytecode, |
| 30 | +which slows things down somewhat. |
| 31 | + |
| 32 | +## Duplicate warnings |
| 33 | + |
| 34 | +When a project is built in both bytecode and native mode concurrently, |
| 35 | +compilation warnings are displayed twice (once per mode). This is bad user |
| 36 | +experience. Build systems such as dune need to add hacks to filter duplicate |
| 37 | +errors to make things more bearable. A separate type checking phase would now be |
| 38 | +responsible for these errors and such warnings would only appear once. |
| 39 | + |
| 40 | +## Speed up compilation when type checking is a bottle neck |
| 41 | + |
| 42 | +This likely doesn't occur very often, but there are cases where type checking is |
| 43 | +slow. This proposal should improve compilation speed in such projects, because |
| 44 | +type checking will be done only once per compilation unit. |
| 45 | + |
| 46 | +## More flexible build rules for users |
| 47 | + |
| 48 | +This one is kind of dune specific, but I'm sure it would help other build |
| 49 | +systems as well. Since dune uses bytecode targets to produce `.cmt` files, users |
| 50 | +cannot have full editor integration (since it requires `.cmt` files) and disable |
| 51 | +bytecode builds. It could be argued that dune can be improved to produce `.cmt` |
| 52 | +files via the native rules, but this a needless complication. |
0 commit comments