I'm very new at rustc development -- I'm wondering if rustc does any cross-crate optimizations, and if it does where do I find the code that serializes/deserializes HIR/MIR for cross-crate inlining. Also, am I right that a crate is one compilation unit, and optimized/code generated as a whole? Thanks.
(I've searched about this but the term "cross" mostly brings cross-compilation related stuff. There's one blog post, but it's published in 2012 so it's probably not too relevant these days)
Our optimizations do not care whether a function is from the same crate or from a different crate. I fact, except for lints the optimizations can't even tell the difference
The (de-)serialization happens completely transparently in the query system
You request the MIR of a function from another crate with the same query that you use for local crates
That said, if you are still interested in metadata serialization and deserialization, the typr you want to look at is
CrateMetadata. Although note that this is just a tiny cog in the metadata (de)serialization scheme.
There may also be a rustc-guide topic about this, I'm not sure, search the guide for "metadata" I guess
Thanks @oli , that's very helpful. I'll check the code and the rustc-guide section.