From 3166e0857defd02d78f5afe1a64380a429967cc7 Mon Sep 17 00:00:00 2001 From: Mario Carneiro Date: Fri, 2 Apr 2021 09:33:34 -0700 Subject: [PATCH 1/3] Monomorphization doc fix Only public items are monomorphization roots. This can be confirmed by noting that this program compiles: ```rust fn foo() { if true { foo::>() } } fn bar() { foo::<()>() } ``` --- compiler/rustc_mir/src/monomorphize/collector.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_mir/src/monomorphize/collector.rs index fd5dbfb186efd..cadfc85a85879 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_mir/src/monomorphize/collector.rs @@ -59,9 +59,9 @@ //! //! ### Discovering roots //! -//! The roots of the mono item graph correspond to the non-generic +//! The roots of the mono item graph correspond to the public non-generic //! syntactic items in the source code. We find them by walking the HIR of the -//! crate, and whenever we hit upon a function, method, or static item, we +//! crate, and whenever we hit upon a public function, method, or static item, we //! create a mono item consisting of the items DefId and, since we only //! consider non-generic items, an empty type-substitution set. //! From e01c3b82110a3338eab2e2d9cffbb74dc7039bc7 Mon Sep 17 00:00:00 2001 From: Mario Carneiro Date: Fri, 2 Apr 2021 09:55:23 -0700 Subject: [PATCH 2/3] clarify wording --- compiler/rustc_mir/src/monomorphize/collector.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_mir/src/monomorphize/collector.rs index cadfc85a85879..8ecb0a7cdc535 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_mir/src/monomorphize/collector.rs @@ -61,9 +61,12 @@ //! //! The roots of the mono item graph correspond to the public non-generic //! syntactic items in the source code. We find them by walking the HIR of the -//! crate, and whenever we hit upon a public function, method, or static item, we -//! create a mono item consisting of the items DefId and, since we only -//! consider non-generic items, an empty type-substitution set. +//! crate, and whenever we hit upon a public function, method, or static item, +//! we create a mono item consisting of the items DefId and, since we only +//! consider non-generic items, an empty type-substitution set. (In eager +//! collection mode, during incremental compilation, all non-generic functions +//! are considered as roots, as well as when the `-Clink-dead-code` option is +//! specified. Functions marked `#[no_mangle]` also always act as roots.) //! //! ### Finding neighbor nodes //! Given a mono item node, we can discover neighbors by inspecting its From 99f3e889b1dd3fca8a6ac8d32b6bdcc444dd333a Mon Sep 17 00:00:00 2001 From: Mario Carneiro Date: Fri, 2 Apr 2021 10:21:23 -0700 Subject: [PATCH 3/3] fix --- compiler/rustc_mir/src/monomorphize/collector.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_mir/src/monomorphize/collector.rs index 8ecb0a7cdc535..1fda71d74bbf5 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_mir/src/monomorphize/collector.rs @@ -66,7 +66,8 @@ //! consider non-generic items, an empty type-substitution set. (In eager //! collection mode, during incremental compilation, all non-generic functions //! are considered as roots, as well as when the `-Clink-dead-code` option is -//! specified. Functions marked `#[no_mangle]` also always act as roots.) +//! specified. Functions marked `#[no_mangle]` and functions called by inlinable +//! functions also always act as roots.) //! //! ### Finding neighbor nodes //! Given a mono item node, we can discover neighbors by inspecting its