@@ -19,6 +19,7 @@ use rustc_target::spec::SymbolVisibility;
1919use tracing:: debug;
2020
2121use crate :: dep_graph:: { DepNode , WorkProduct , WorkProductId } ;
22+ use crate :: query:: Providers ;
2223use crate :: ty:: { GenericArgs , Instance , InstanceKind , SymbolName , TyCtxt } ;
2324
2425/// Describes how a monomorphization will be instantiated in object files.
@@ -46,7 +47,7 @@ pub enum InstantiationMode {
4647 LocalCopy ,
4748}
4849
49- #[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash , HashStable ) ]
50+ #[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash , HashStable , TyEncodable , TyDecodable ) ]
5051pub enum MonoItem < ' tcx > {
5152 Fn ( Instance < ' tcx > ) ,
5253 Static ( DefId ) ,
@@ -62,30 +63,6 @@ impl<'tcx> MonoItem<'tcx> {
6263 }
6364 }
6465
65- // Note: if you change how item size estimates work, you might need to
66- // change NON_INCR_MIN_CGU_SIZE as well.
67- pub fn size_estimate ( & self , tcx : TyCtxt < ' tcx > ) -> usize {
68- match * self {
69- MonoItem :: Fn ( instance) => {
70- match instance. def {
71- // "Normal" functions size estimate: the number of
72- // statements, plus one for the terminator.
73- InstanceKind :: Item ( ..)
74- | InstanceKind :: DropGlue ( ..)
75- | InstanceKind :: AsyncDropGlueCtorShim ( ..) => {
76- let mir = tcx. instance_mir ( instance. def ) ;
77- mir. basic_blocks . iter ( ) . map ( |bb| bb. statements . len ( ) + 1 ) . sum ( )
78- }
79- // Other compiler-generated shims size estimate: 1
80- _ => 1 ,
81- }
82- }
83- // Conservatively estimate the size of a static declaration or
84- // assembly item to be 1.
85- MonoItem :: Static ( _) | MonoItem :: GlobalAsm ( _) => 1 ,
86- }
87- }
88-
8966 pub fn is_generic_fn ( & self ) -> bool {
9067 match self {
9168 MonoItem :: Fn ( instance) => instance. args . non_erasable_generics ( ) . next ( ) . is_some ( ) ,
@@ -556,3 +533,49 @@ impl<'tcx> CodegenUnitNameBuilder<'tcx> {
556533 Symbol :: intern ( & cgu_name)
557534 }
558535}
536+
537+ /// See module-level docs on some contect for "mentioned" items.
538+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , HashStable ) ]
539+ pub enum CollectionMode {
540+ /// Collect items that are used, i.e., actually needed for codegen.
541+ ///
542+ /// Which items are used can depend on optimization levels, as MIR optimizations can remove
543+ /// uses.
544+ UsedItems ,
545+ /// Collect items that are mentioned. The goal of this mode is that it is independent of
546+ /// optimizations: the set of "mentioned" items is computed before optimizations are run.
547+ ///
548+ /// The exact contents of this set are *not* a stable guarantee. (For instance, it is currently
549+ /// computed after drop-elaboration. If we ever do some optimizations even in debug builds, we
550+ /// might decide to run them before computing mentioned items.) The key property of this set is
551+ /// that it is optimization-independent.
552+ MentionedItems ,
553+ }
554+
555+ // Note: if you change how item size estimates work, you might need to
556+ // change NON_INCR_MIN_CGU_SIZE as well.
557+ fn size_estimate < ' tcx > ( tcx : TyCtxt < ' tcx > , item : MonoItem < ' tcx > ) -> usize {
558+ match item {
559+ MonoItem :: Fn ( instance) => {
560+ match instance. def {
561+ // "Normal" functions size estimate: the number of
562+ // statements, plus one for the terminator.
563+ InstanceKind :: Item ( ..)
564+ | InstanceKind :: DropGlue ( ..)
565+ | InstanceKind :: AsyncDropGlueCtorShim ( ..) => {
566+ let mir = tcx. instance_mir ( instance. def ) ;
567+ mir. basic_blocks . iter ( ) . map ( |bb| bb. statements . len ( ) + 1 ) . sum ( )
568+ }
569+ // Other compiler-generated shims size estimate: 1
570+ _ => 1 ,
571+ }
572+ }
573+ // Conservatively estimate the size of a static declaration or
574+ // assembly item to be 1.
575+ MonoItem :: Static ( _) | MonoItem :: GlobalAsm ( _) => 1 ,
576+ }
577+ }
578+
579+ pub fn provide ( providers : & mut Providers ) {
580+ providers. size_estimate = size_estimate;
581+ }
0 commit comments