3 ms·
Rust has a great compromise between crate and file: module. I wonder why that's not the compilation unit?
by bryanlarsen 2y ago
Rust has a great compromise between crate and file: module. I wonder why that's not the compilation unit?
- lmkg 2y agoPer a reddit comment, modules are allowed to have circular dependencies while crates are not.
- colonial 2y agoI think it's due to the fact that (unlike crates) cyclic dependencies are allowed between modules without any extra ceremony (e.x. forward declarations in C.)
- dathinab 2y ago- cyclic dependencies - some subtleties related to (proc-)macros - better optimizations (potentially, not always, sometimes not at all) - how generics and compilation units interact (reduces the benefit of making each module a compilation unit) - a lot of unclearity about how rust will develop in the future when this decision was made Also when people speak about rust compiling slow and splitting helping it's most times related to better caching of repeated builds (unrelated to the incremental build feature) and not the specific issue here. But there is definitely potential to improve on it to make humongous single crates work better (like instead of just 16/256 internal splits you could factor in the crate size, maybe add a attribute to hint code unit splits etc.), but so far no one has deemed it important enough to invest their time into fixing it. I mean splitting crates is often easy so you do that once are good forever or at lest a long time.