@@ -46,7 +46,7 @@ pub enum InstantiationMode {
4646 LocalCopy ,
4747}
4848
49- #[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash , HashStable ) ]
49+ #[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash , HashStable , TyEncodable , TyDecodable ) ]
5050pub enum MonoItem < ' tcx > {
5151 Fn ( Instance < ' tcx > ) ,
5252 Static ( DefId ) ,
@@ -66,20 +66,7 @@ impl<'tcx> MonoItem<'tcx> {
6666 // change NON_INCR_MIN_CGU_SIZE as well.
6767 pub fn size_estimate ( & self , tcx : TyCtxt < ' tcx > ) -> usize {
6868 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- }
69+ MonoItem :: Fn ( instance) => tcx. size_estimate ( instance) ,
8370 // Conservatively estimate the size of a static declaration or
8471 // assembly item to be 1.
8572 MonoItem :: Static ( _) | MonoItem :: GlobalAsm ( _) => 1 ,
@@ -556,3 +543,21 @@ impl<'tcx> CodegenUnitNameBuilder<'tcx> {
556543 Symbol :: intern ( & cgu_name)
557544 }
558545}
546+
547+ /// See module-level docs of `rustc_monomorphize::collector` on some context for "mentioned" items.
548+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , HashStable ) ]
549+ pub enum CollectionMode {
550+ /// Collect items that are used, i.e., actually needed for codegen.
551+ ///
552+ /// Which items are used can depend on optimization levels, as MIR optimizations can remove
553+ /// uses.
554+ UsedItems ,
555+ /// Collect items that are mentioned. The goal of this mode is that it is independent of
556+ /// optimizations: the set of "mentioned" items is computed before optimizations are run.
557+ ///
558+ /// The exact contents of this set are *not* a stable guarantee. (For instance, it is currently
559+ /// computed after drop-elaboration. If we ever do some optimizations even in debug builds, we
560+ /// might decide to run them before computing mentioned items.) The key property of this set is
561+ /// that it is optimization-independent.
562+ MentionedItems ,
563+ }
0 commit comments