@@ -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.
@@ -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 ( ) ,
@@ -574,3 +551,31 @@ pub enum CollectionMode {
574551 /// that it is optimization-independent.
575552 MentionedItems ,
576553}
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