From a8cf5972c0bdb96190c32c259588578d38d447ce Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sat, 27 Mar 2021 21:22:16 -0700 Subject: [PATCH 1/3] cmt files as input and output proposal Signed-off-by: Rudi Grinberg --- rfcs/cmt_input.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 rfcs/cmt_input.md diff --git a/rfcs/cmt_input.md b/rfcs/cmt_input.md new file mode 100644 index 0000000..b6e95f8 --- /dev/null +++ b/rfcs/cmt_input.md @@ -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 bundle +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. From 489caa694a2a03659a68daa3de1614bdbeace78d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 28 Mar 2021 15:47:39 -0700 Subject: [PATCH 2/3] change command line according to @dra27 Signed-off-by: Rudi Grinberg --- rfcs/cmt_input.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rfcs/cmt_input.md b/rfcs/cmt_input.md index b6e95f8..6d84cc6 100644 --- a/rfcs/cmt_input.md +++ b/rfcs/cmt_input.md @@ -7,14 +7,14 @@ them. The first request is to type check compilation units and produce `.cmt` files: ``` -$ ocamlc -c foo.ml -o foo.cmt +$ ocamlc -c foo.ml -output-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 +$ ocamlc -c foo.cmt +$ ocamlopt -c foo.cmt ``` How does this help? The motivation is mainly to simplify some rough edges of From c1e0aec98847222a8952f872916d9ddc7ed8686d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 28 Mar 2021 15:48:47 -0700 Subject: [PATCH 3/3] Remove conjecturing about type check bottlenecks Signed-off-by: Rudi Grinberg --- rfcs/cmt_input.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rfcs/cmt_input.md b/rfcs/cmt_input.md index 6d84cc6..ef8e348 100644 --- a/rfcs/cmt_input.md +++ b/rfcs/cmt_input.md @@ -39,9 +39,9 @@ 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. +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