Skip to content

Commit d8db731

Browse files
arora-amanJoshua Nelson
authored and
Joshua Nelson
committed
Document CGU partioning in case of generic and inline functions
1 parent d117002 commit d8db731

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/backend/monomorph.md

+20
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,28 @@ The monomorphization collector is run just before MIR lowering and codegen.
5555
collection and then partitions them into [codegen
5656
units](../appendix/glossary.md#codegen-unit).
5757

58+
## Codegen Unit (CGU) partitioning
59+
60+
For better incremental build times, the CGU partitioner creates two CGU for each source level
61+
modules. One is for "stable" i.e. non-generic code and the other is more volatile code i.e.
62+
monoporphized/specialized instances.
63+
64+
For depenencies, consider Crate A and Crate B, such that Crate B depends on Crate A.
65+
The following table lists different scenarios for a function in Crate A that might be used by one
66+
or more modules in Crate B.
67+
68+
| Crate A function | Behavior |
69+
| - | - |
70+
| Non-generic function | Crate A function doesn't appear in any codegen units of Crate B |
71+
| Non-generic `#[inline]` function | Crate A function appears with in a single CGU of Crate B, and exists even after post-inlining stage|
72+
| Generic function | Regardless of inlining, all monoporphized (specialized) functions <br> from Crate A appear within a single codegen unit for Crate B. <br> The codegen unit exists even after the post inlining stage.|
73+
| Generic `#[inline]` function | - same - |
74+
75+
For more details about the partitioner read the module level [documentation].
76+
5877
[mono]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/monomorphize/partitioning/fn.collect_and_partition_mono_items.html
5978
[codegen1]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/base/fn.codegen_crate.html
79+
[documentation]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/monomorphize/partitioning/index.html
6080

6181
## Polymorphization
6282

0 commit comments

Comments
 (0)