Description
Currently ThinLTO is not compatible with incremental compilation, unfortunately. This is due to the fact that the codegen of an object file is actually dependent on all object files rather than just the one object file, which means we can rarely reuse anything!
ThinLTO, however, is explicitly designed with incrementality in mind. We're just not currently taking advantage of any of it! Last I remember checking in on this there's a good bit of nontrivial work that the incremental ThinLTO requires. Currently the ThinLTO support in rustc is largely a duplicate of that file (so far a duplicate of what we need) which helps us conform to our own requirements and integration better. This would likely best be implemented by tweaking the upstream interfaces to be more what we in rustc desire so we can directly use LLVM's support in this regard.
In any case, I realized we didn't have a tracking issue for this so I wanted to open one! At a high level I'd expect this to be tackled by:
- Create a separate query/codepath in codegen which only emits bytecode, not object files (aka the optimization passes for one module)
- When ThinLTO is enabled with incremental compilation we use this query instead of the previous "give me all the object files" query.
- After all bytecode is loaded/optimized, we then transition to the ThinLTO-owned incremental phase. This'd probably reserve a special directory in the normal incremental directory for exclusive ownership by ThinLTO itself.
- Once the ThinLTO passes have finished we've now got a bunch of object files so we can proceed as usual