2 ms·
From a cursory look at the documentation this interests me, but with one huge caveat: does this support incremental compilation? The documentation goes on at s
by comex 9y ago
From a cursory look at the documentation this interests me, but with one huge caveat: does this support incremental compilation?
The documentation goes on at some length about how the C2 compiler parses and analyzes all source files at once, before generating code. Supposedly this improves compilation speed because:
The code generation (and optimization) steps require a lot of time. So if you have 100 C source files and the 99th file has a syntax error, the compiler has to go through a lot of work before showing the diagnostic. In C2 it only takes very little time. So during development, developers never have to wait for diagnostic messages.
Except that during development of C programs, in practice, most changes will only require recompiling one or two files. The rest of the files have already been compiled and don’t have to be examined at all until the link step, which is relatively fast.
Admittedly, C is simple enough, and the header file and process-per-source-file models inefficient enough, that the C2 compiler might be able to parse and typecheck 100 files in an amount of time similar to what make and clang take to build two. I haven’t tested it, but let’s assume so. Then if I have an error, I indeed wouldn’t have to “wait for diagnostic messages” (for too long, anyway). And it would be nice that the same speed could be achieved regardless of what I change, whereas in C touching a common header file may well require rebuilding everything. Then again, this fundamentally doesn’t scale well.
But what if I don’t have an error? With an incremental C build, I don’t have to wait to run and test my code, either. If the C2 compiler doesn’t support incremental compilation, it’ll have to redo code generation for everything, using the same backend (LLVM) as my C compiler. Thus, the ‘feature’ of compiling everything at once becomes an antifeature.
It is possible to implement incremental compilation in a compiler more ‘natively’ than C’s file-based approach, and this can turn module-at-once compilation from a mixed bag for performance to a pure win. If the C2 compiler has done so, I shouldn’t be complaining! But since it’s not mentioned in the documentation pages I looked at, I’m guessing it hasn’t.