TL;DR: Could the compiler typecheck, borrowcheck, … all the code sections, even those which are cfg’ed away and will not make it into the final binary?
State of the art
The compiler parses all the code, however as far as I know it only performs type unification, borrow checking, etc… on the code that will make it into the final binary.
This is trivially demonstrated by using a #[cfg(test)] section: cargo build will not report errors in the test, cargo test will.
The problem
When writing platform specific code, this code is only verified when compiling for the specific platform. When writing featured code, this code is only verified when compiling with the specific feature enabled.
This means that simply checking that all the bits of code are correct (as far as the compiler is concerned) requires compiling for all variations of platforms and featured code.
The question
Could the compiler perform all the type checking, borrow checking, etc… on all the code?
This would of course introduce some overhead, however:
- this would only introduce overhead for those hacking on projects which use
cfg, and only in direct proportion to the size of cfg’ed code,
- this overhead is less than independent invocations of the compiler for each combination of platform and feature,
- it is my understanding that type checking and borrow checking are not the bottleneck in the compilation process anyway.
Note: it might even solve the issue of double-reporting of errors when invoking cargo test…
Thus, would it possible? And if possible, does anyone else find it desirable?