@@ -65,12 +65,6 @@ impl<'a, 'tcx> QueryResult<'a, &'tcx GlobalCtxt<'tcx>> {
65
65
}
66
66
}
67
67
68
- impl < T > Default for Query < T > {
69
- fn default ( ) -> Self {
70
- Query { result : RefCell :: new ( None ) }
71
- }
72
- }
73
-
74
68
pub struct Queries < ' tcx > {
75
69
compiler : & ' tcx Compiler ,
76
70
gcx_cell : OnceLock < GlobalCtxt < ' tcx > > ,
@@ -90,8 +84,8 @@ impl<'tcx> Queries<'tcx> {
90
84
gcx_cell : OnceLock :: new ( ) ,
91
85
arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
92
86
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 ) } ,
95
89
}
96
90
}
97
91
@@ -116,23 +110,6 @@ impl<'tcx> Queries<'tcx> {
116
110
)
117
111
} )
118
112
}
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
- }
136
113
}
137
114
138
115
pub struct Linker {
@@ -144,6 +121,36 @@ pub struct Linker {
144
121
}
145
122
146
123
impl 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
+
147
154
pub fn link ( self , sess : & Session , codegen_backend : & dyn CodegenBackend ) -> Result < ( ) > {
148
155
let ( codegen_results, work_products) =
149
156
codegen_backend. join_codegen ( self . ongoing_codegen , sess, & self . output_filenames ) ;
@@ -197,7 +204,7 @@ impl Compiler {
197
204
F : for < ' tcx > FnOnce ( & ' tcx Queries < ' tcx > ) -> T ,
198
205
{
199
206
// Must declare `_timer` first so that it is dropped after `queries`.
200
- let mut _timer = None ;
207
+ let _timer;
201
208
let queries = Queries :: new ( self ) ;
202
209
let ret = f ( & queries) ;
203
210
@@ -220,7 +227,7 @@ impl Compiler {
220
227
221
228
// The timer's lifetime spans the dropping of `queries`, which contains
222
229
// the global context.
223
- _timer = Some ( self . sess . timer ( "free_global_ctxt" ) ) ;
230
+ _timer = self . sess . timer ( "free_global_ctxt" ) ;
224
231
if let Err ( ( path, error) ) = queries. finish ( ) {
225
232
self . sess . dcx ( ) . emit_fatal ( errors:: FailedWritingFile { path : & path, error } ) ;
226
233
}
0 commit comments