From d8db731a4ab9d1f35b71f7a542a361776eed6ff4 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Thu, 3 Sep 2020 22:46:56 -0400 Subject: [PATCH] Document CGU partioning in case of generic and inline functions --- src/backend/monomorph.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/backend/monomorph.md b/src/backend/monomorph.md index 47b41d4f..e678b4f7 100644 --- a/src/backend/monomorph.md +++ b/src/backend/monomorph.md @@ -55,8 +55,28 @@ The monomorphization collector is run just before MIR lowering and codegen. collection and then partitions them into [codegen units](../appendix/glossary.md#codegen-unit). +## Codegen Unit (CGU) partitioning + +For better incremental build times, the CGU partitioner creates two CGU for each source level +modules. One is for "stable" i.e. non-generic code and the other is more volatile code i.e. +monoporphized/specialized instances. + +For depenencies, consider Crate A and Crate B, such that Crate B depends on Crate A. +The following table lists different scenarios for a function in Crate A that might be used by one +or more modules in Crate B. + +| Crate A function | Behavior | +| - | - | +| Non-generic function | Crate A function doesn't appear in any codegen units of Crate B | +| Non-generic `#[inline]` function | Crate A function appears with in a single CGU of Crate B, and exists even after post-inlining stage| +| Generic function | Regardless of inlining, all monoporphized (specialized) functions
from Crate A appear within a single codegen unit for Crate B.
The codegen unit exists even after the post inlining stage.| +| Generic `#[inline]` function | - same - | + +For more details about the partitioner read the module level [documentation]. + [mono]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/monomorphize/partitioning/fn.collect_and_partition_mono_items.html [codegen1]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/base/fn.codegen_crate.html +[documentation]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/monomorphize/partitioning/index.html ## Polymorphization