-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmt files as input and output proposal
Signed-off-by: Rudi Grinberg <[email protected]>
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |