Open Pauan opened 7 years ago
In order to minimize build times, it might also be useful to keep track of dependencies between Koka statements rather than Koka files. What I mean is, consider these two Koka files:
module foo
val foo = 1
module bar
import foo
val bar = foo + 10
val qux = 20
Under ordinary circumstances, when the foo.kk
file changes, it has to recompile the foo.kk
and bar.kk
files, because bar.kk
imports foo.kk
But if the Koka compiler kept track of statement dependencies, it would know that the bar
statement depends upon the foo
statement, but the qux
statement doesn't depend upon anything, and so it only needs to recompile the bar
statement: it doesn't need to recompile the qux
statement.
This might be relevant for incremental compilation: https://blog.rust-lang.org/2016/09/08/incremental.html
Right now Koka uses Require.js, which is quite outdated. Modern JS uses Webpack or Rollup, which bundles multiple files into a single optimized file.
Both Webpack and Rollup support ES6 modules, and it's recommended to use ES6 modules because it allows Webpack/Rollup to remove unused variables.
Both Webpack and Rollup support a plugin system, which we can use to add in support for Koka. However, I think Webpack's plugin system is more mature and powerful.
Both Webpack and Rollup support a "watch mode" which means that whenever a file changes, it will automatically recompile your project, but it will only recompile the files that changed, so it's much faster than a full compile. However, I've found Rollup's watch mode to be a bit flaky: Webpack's watch mode is rock solid.
Rollup produces extremely small code, because it merges all files into a single function scope, whereas Webpack creates one function per file. However, Webpack 3 will also merge multiple files into a single function scope. This puts Webpack on par with Rollup.
Webpack has many many more features than Rollup, but Rollup is more lightweight.
Webpack is much more maintained than Rollup: the author of Rollup is very sporadic with updates and improvements.
As such, I recommend using Webpack as the official Koka bundler. In order to support watch mode, the Koka compiler will need the ability to recompile a single file which has changed, without recompiling files which haven't changed.
There's various strategies for this, such as placing the compiler artifacts (
.js
and.kki
) into a temporary folder, and then reusing existing artifacts which haven't changed. PureScript uses that strategy.Alternatively, Koka could run as a daemon in the background, so that way it can store the artifacts in memory. Fable uses that strategy.
Using a database to store the artifacts is another possibility, which would allow for transactions. This can result in more correct builds, because the file system is not transactional.