1
1
use crate :: errors:: { FailedWritingFile , RustcErrorFatal , RustcErrorUnexpectedAnnotation } ;
2
2
use crate :: interface:: { Compiler , Result } ;
3
- use crate :: passes:: { self , BoxedResolver , QueryContext } ;
3
+ use crate :: passes:: { self , BoxedResolver } ;
4
4
5
5
use rustc_ast as ast;
6
6
use rustc_codegen_ssa:: traits:: CodegenBackend ;
@@ -64,7 +64,7 @@ impl<'a, T> std::ops::DerefMut for QueryResult<'a, T> {
64
64
}
65
65
}
66
66
67
- impl < ' a , ' tcx > QueryResult < ' a , QueryContext < ' tcx > > {
67
+ impl < ' a , ' tcx > QueryResult < ' a , & ' tcx GlobalCtxt < ' tcx > > {
68
68
pub fn enter < T > ( & mut self , f : impl FnOnce ( TyCtxt < ' tcx > ) -> T ) -> T {
69
69
( * self . 0 ) . get_mut ( ) . enter ( f)
70
70
}
@@ -78,7 +78,7 @@ impl<T> Default for Query<T> {
78
78
79
79
pub struct Queries < ' tcx > {
80
80
compiler : & ' tcx Compiler ,
81
- gcx : OnceCell < GlobalCtxt < ' tcx > > ,
81
+ gcx_cell : OnceCell < GlobalCtxt < ' tcx > > ,
82
82
queries : OnceCell < TcxQueries < ' tcx > > ,
83
83
84
84
arena : WorkerLocal < Arena < ' tcx > > ,
@@ -90,15 +90,16 @@ pub struct Queries<'tcx> {
90
90
register_plugins : Query < ( ast:: Crate , Lrc < LintStore > ) > ,
91
91
expansion : Query < ( Lrc < ast:: Crate > , Rc < RefCell < BoxedResolver > > , Lrc < LintStore > ) > ,
92
92
dep_graph : Query < DepGraph > ,
93
- global_ctxt : Query < QueryContext < ' tcx > > ,
93
+ // This just points to what's in `gcx_cell`.
94
+ gcx : Query < & ' tcx GlobalCtxt < ' tcx > > ,
94
95
ongoing_codegen : Query < Box < dyn Any > > ,
95
96
}
96
97
97
98
impl < ' tcx > Queries < ' tcx > {
98
99
pub fn new ( compiler : & ' tcx Compiler ) -> Queries < ' tcx > {
99
100
Queries {
100
101
compiler,
101
- gcx : OnceCell :: new ( ) ,
102
+ gcx_cell : OnceCell :: new ( ) ,
102
103
queries : OnceCell :: new ( ) ,
103
104
arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
104
105
hir_arena : WorkerLocal :: new ( |_| rustc_hir:: Arena :: default ( ) ) ,
@@ -108,7 +109,7 @@ impl<'tcx> Queries<'tcx> {
108
109
register_plugins : Default :: default ( ) ,
109
110
expansion : Default :: default ( ) ,
110
111
dep_graph : Default :: default ( ) ,
111
- global_ctxt : Default :: default ( ) ,
112
+ gcx : Default :: default ( ) ,
112
113
ongoing_codegen : Default :: default ( ) ,
113
114
}
114
115
}
@@ -207,8 +208,8 @@ impl<'tcx> Queries<'tcx> {
207
208
} )
208
209
}
209
210
210
- pub fn global_ctxt ( & ' tcx self ) -> Result < QueryResult < ' _ , QueryContext < ' tcx > > > {
211
- self . global_ctxt . compute ( || {
211
+ pub fn global_ctxt ( & ' tcx self ) -> Result < QueryResult < ' _ , & ' tcx GlobalCtxt < ' tcx > > > {
212
+ self . gcx . compute ( || {
212
213
let crate_name = * self . crate_name ( ) ?. borrow ( ) ;
213
214
let ( krate, resolver, lint_store) = self . expansion ( ) ?. steal ( ) ;
214
215
@@ -218,18 +219,18 @@ impl<'tcx> Queries<'tcx> {
218
219
ast_lowering : untracked_resolver_for_lowering,
219
220
} = BoxedResolver :: to_resolver_outputs ( resolver) ;
220
221
221
- let mut qcx = passes:: create_global_ctxt (
222
+ let gcx = passes:: create_global_ctxt (
222
223
self . compiler ,
223
224
lint_store,
224
225
self . dep_graph ( ) ?. steal ( ) ,
225
226
untracked,
226
227
& self . queries ,
227
- & self . gcx ,
228
+ & self . gcx_cell ,
228
229
& self . arena ,
229
230
& self . hir_arena ,
230
231
) ;
231
232
232
- qcx . enter ( |tcx| {
233
+ gcx . enter ( |tcx| {
233
234
let feed = tcx. feed_unit_query ( ) ;
234
235
feed. resolver_for_lowering (
235
236
tcx. arena . alloc ( Steal :: new ( ( untracked_resolver_for_lowering, krate) ) ) ,
@@ -239,7 +240,7 @@ impl<'tcx> Queries<'tcx> {
239
240
let feed = tcx. feed_local_crate ( ) ;
240
241
feed. crate_name ( crate_name) ;
241
242
} ) ;
242
- Ok ( qcx )
243
+ Ok ( gcx )
243
244
} )
244
245
}
245
246
@@ -387,7 +388,7 @@ impl Compiler {
387
388
388
389
// NOTE: intentionally does not compute the global context if it hasn't been built yet,
389
390
// since that likely means there was a parse error.
390
- if let Some ( Ok ( gcx) ) = & mut * queries. global_ctxt . result . borrow_mut ( ) {
391
+ if let Some ( Ok ( gcx) ) = & mut * queries. gcx . result . borrow_mut ( ) {
391
392
let gcx = gcx. get_mut ( ) ;
392
393
// We assume that no queries are run past here. If there are new queries
393
394
// after this point, they'll show up as "<unknown>" in self-profiling data.
0 commit comments