@@ -65,12 +65,6 @@ impl<'a, 'tcx> QueryResult<'a, &'tcx GlobalCtxt<'tcx>> {
6565 }
6666}
6767
68- impl < T > Default for Query < T > {
69- fn default ( ) -> Self {
70- Query { result : RefCell :: new ( None ) }
71- }
72- }
73-
7468pub struct Queries < ' tcx > {
7569 compiler : & ' tcx Compiler ,
7670 gcx_cell : OnceLock < GlobalCtxt < ' tcx > > ,
@@ -90,8 +84,8 @@ impl<'tcx> Queries<'tcx> {
9084 gcx_cell : OnceLock :: new ( ) ,
9185 arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
9286 hir_arena : WorkerLocal :: new ( |_| rustc_hir:: Arena :: default ( ) ) ,
93- parse : Default :: default ( ) ,
94- gcx : Default :: default ( ) ,
87+ parse : Query { result : RefCell :: new ( None ) } ,
88+ gcx : Query { result : RefCell :: new ( None ) } ,
9589 }
9690 }
9791
@@ -116,23 +110,6 @@ impl<'tcx> Queries<'tcx> {
116110 )
117111 } )
118112 }
119-
120- pub fn codegen_and_build_linker ( & ' tcx self ) -> Result < Linker > {
121- self . global_ctxt ( ) ?. enter ( |tcx| {
122- let ongoing_codegen = passes:: start_codegen ( & * self . compiler . codegen_backend , tcx) ?;
123-
124- Ok ( Linker {
125- dep_graph : tcx. dep_graph . clone ( ) ,
126- output_filenames : tcx. output_filenames ( ( ) ) . clone ( ) ,
127- crate_hash : if tcx. needs_crate_hash ( ) {
128- Some ( tcx. crate_hash ( LOCAL_CRATE ) )
129- } else {
130- None
131- } ,
132- ongoing_codegen,
133- } )
134- } )
135- }
136113}
137114
138115pub struct Linker {
@@ -144,6 +121,36 @@ pub struct Linker {
144121}
145122
146123impl Linker {
124+ pub fn codegen_and_build_linker (
125+ tcx : TyCtxt < ' _ > ,
126+ codegen_backend : & dyn CodegenBackend ,
127+ ) -> Result < Linker > {
128+ let ongoing_codegen = passes:: start_codegen ( codegen_backend, tcx) ?;
129+
130+ // This must run after monomorphization so that all generic types
131+ // have been instantiated.
132+ if tcx. sess . opts . unstable_opts . print_type_sizes {
133+ tcx. sess . code_stats . print_type_sizes ( ) ;
134+ }
135+
136+ if tcx. sess . opts . unstable_opts . print_vtable_sizes {
137+ let crate_name = tcx. crate_name ( LOCAL_CRATE ) ;
138+
139+ tcx. sess . code_stats . print_vtable_sizes ( crate_name) ;
140+ }
141+
142+ Ok ( Linker {
143+ dep_graph : tcx. dep_graph . clone ( ) ,
144+ output_filenames : tcx. output_filenames ( ( ) ) . clone ( ) ,
145+ crate_hash : if tcx. needs_crate_hash ( ) {
146+ Some ( tcx. crate_hash ( LOCAL_CRATE ) )
147+ } else {
148+ None
149+ } ,
150+ ongoing_codegen,
151+ } )
152+ }
153+
147154 pub fn link ( self , sess : & Session , codegen_backend : & dyn CodegenBackend ) -> Result < ( ) > {
148155 let ( codegen_results, work_products) =
149156 codegen_backend. join_codegen ( self . ongoing_codegen , sess, & self . output_filenames ) ;
@@ -197,7 +204,7 @@ impl Compiler {
197204 F : for < ' tcx > FnOnce ( & ' tcx Queries < ' tcx > ) -> T ,
198205 {
199206 // Must declare `_timer` first so that it is dropped after `queries`.
200- let mut _timer = None ;
207+ let _timer;
201208 let queries = Queries :: new ( self ) ;
202209 let ret = f ( & queries) ;
203210
@@ -220,7 +227,7 @@ impl Compiler {
220227
221228 // The timer's lifetime spans the dropping of `queries`, which contains
222229 // the global context.
223- _timer = Some ( self . sess . timer ( "free_global_ctxt" ) ) ;
230+ _timer = self . sess . timer ( "free_global_ctxt" ) ;
224231 if let Err ( ( path, error) ) = queries. finish ( ) {
225232 self . sess . dcx ( ) . emit_fatal ( errors:: FailedWritingFile { path : & path, error } ) ;
226233 }
0 commit comments