This gist provides a certain amount of background material towards the meta goal here of allowing us to skip type-checking during incremental compilation. Type-checking a particular item with def-id X is done by the typeck_tables_of(X) query, which is used in a number of places in the compiler. The idea is to ensure that we never (or rarely) execute typeck_tables_of(X) unless the function X has really changed. This can be achieved by strategically serializing other bits of data within the graph -- as a simple example, consider generating LLVM IR. If we have to generate LLVM IR, we do that based on the MIR for a function, which in turn is generated based on the typeck_tables_of. But if we have a .o file we can re-use, then we can skip generating LLVM IR, which in turn means we never demand the MIR, which in turn means we never demand typeck_tables_of. So type-checking would not need to be preformed.
Saving .o files already works, of course. The problem here is that there are other paths which wind up executing typeck_tables_of(X): so our goal is to isolate those paths so that they also do not execute unless the function X has changed.
There is an alternative way to achieve the same end. In particular, we could serialize the results of the typeck_tables_of(X) query and re-load those results if the inputs have not changed. This always remains an option, but it'd be nice to avoid that path for now for a number of reasons:
- serializing
typeck_tables_ofmay involve complications; it's a complex data structure - even if we are re-loading from disk, that still means we are spending time deserializing and memory to store the loaded data
- if we can skip the query entirely, we are doing none of that
- disk-space usage can already be a problem in some cases, serializing this query will require yet more space
- if we move later to storing incremental state in RAM for e.g. the RLS, this would translate to memory usage
In short, it may just not be a good trade-off.