@@ -46,7 +46,7 @@ pub enum InstantiationMode {
46
46
LocalCopy ,
47
47
}
48
48
49
- #[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash , HashStable ) ]
49
+ #[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash , HashStable , TyEncodable , TyDecodable ) ]
50
50
pub enum MonoItem < ' tcx > {
51
51
Fn ( Instance < ' tcx > ) ,
52
52
Static ( DefId ) ,
@@ -66,20 +66,7 @@ impl<'tcx> MonoItem<'tcx> {
66
66
// change NON_INCR_MIN_CGU_SIZE as well.
67
67
pub fn size_estimate ( & self , tcx : TyCtxt < ' tcx > ) -> usize {
68
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
- }
69
+ MonoItem :: Fn ( instance) => tcx. size_estimate ( instance) ,
83
70
// Conservatively estimate the size of a static declaration or
84
71
// assembly item to be 1.
85
72
MonoItem :: Static ( _) | MonoItem :: GlobalAsm ( _) => 1 ,
@@ -556,3 +543,21 @@ impl<'tcx> CodegenUnitNameBuilder<'tcx> {
556
543
Symbol :: intern ( & cgu_name)
557
544
}
558
545
}
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