@@ -19,6 +19,7 @@ use rustc_target::spec::SymbolVisibility;
19
19
use tracing:: debug;
20
20
21
21
use crate :: dep_graph:: { DepNode , WorkProduct , WorkProductId } ;
22
+ use crate :: query:: Providers ;
22
23
use crate :: ty:: { GenericArgs , Instance , InstanceKind , SymbolName , TyCtxt } ;
23
24
24
25
/// Describes how a monomorphization will be instantiated in object files.
@@ -46,7 +47,7 @@ pub enum InstantiationMode {
46
47
LocalCopy ,
47
48
}
48
49
49
- #[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash , HashStable ) ]
50
+ #[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash , HashStable , TyEncodable , TyDecodable ) ]
50
51
pub enum MonoItem < ' tcx > {
51
52
Fn ( Instance < ' tcx > ) ,
52
53
Static ( DefId ) ,
@@ -62,30 +63,6 @@ impl<'tcx> MonoItem<'tcx> {
62
63
}
63
64
}
64
65
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
-
89
66
pub fn is_generic_fn ( & self ) -> bool {
90
67
match self {
91
68
MonoItem :: Fn ( instance) => instance. args . non_erasable_generics ( ) . next ( ) . is_some ( ) ,
@@ -556,3 +533,49 @@ impl<'tcx> CodegenUnitNameBuilder<'tcx> {
556
533
Symbol :: intern ( & cgu_name)
557
534
}
558
535
}
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