diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index b7135de08ba84..765f0e4784eef 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -1,9 +1,15 @@ -// Finds items that are externally reachable, to determine which items -// need to have their metadata (and possibly their AST) serialized. -// All items that can be referred to through an exported name are -// reachable, and when a reachable thing is inline or generic, it -// makes all other generics or inline functions that it references -// reachable as well. +//! Finds local items that are externally reachable, to determine which items +//! need to have their metadata (and possibly their AST) serialized. +//! +//! This set is *not* transitively closed, i.e., in general the set only contains definitions that +//! can be reached *directly* via an exported name, not private functions that can only be reached +//! transitively. +//! +//! However, there's a catch: if an item is generic or cross-crate inlinable, then it will have its +//! code generated by some downstream crate. Now if that item calls private monomorphic +//! non-cross-crate-inlinable items, then those can be reached by the code generated by the +//! downstream create! Therefore, when a reachable thing is cross-crate inlinable or generic, it +//! makes all other functions that it references reachable as well. use hir::def_id::LocalDefIdSet; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -394,6 +400,7 @@ fn has_custom_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) } +/// See module-level doc comment above. fn reachable_set(tcx: TyCtxt<'_>, (): ()) -> LocalDefIdSet { let effective_visibilities = &tcx.effective_visibilities(());