11use crate :: errors:: { FailedWritingFile , RustcErrorFatal , RustcErrorUnexpectedAnnotation } ;
22use crate :: interface:: { Compiler , Result } ;
3- use crate :: passes:: { self , BoxedResolver , QueryContext } ;
3+ use crate :: passes:: { self , BoxedResolver } ;
44
55use rustc_ast as ast;
66use rustc_codegen_ssa:: traits:: CodegenBackend ;
@@ -64,7 +64,7 @@ impl<'a, T> std::ops::DerefMut for QueryResult<'a, T> {
6464 }
6565}
6666
67- impl < ' a , ' tcx > QueryResult < ' a , QueryContext < ' tcx > > {
67+ impl < ' a , ' tcx > QueryResult < ' a , & ' tcx GlobalCtxt < ' tcx > > {
6868 pub fn enter < T > ( & mut self , f : impl FnOnce ( TyCtxt < ' tcx > ) -> T ) -> T {
6969 ( * self . 0 ) . get_mut ( ) . enter ( f)
7070 }
@@ -78,7 +78,7 @@ impl<T> Default for Query<T> {
7878
7979pub struct Queries < ' tcx > {
8080 compiler : & ' tcx Compiler ,
81- gcx : OnceCell < GlobalCtxt < ' tcx > > ,
81+ gcx_cell : OnceCell < GlobalCtxt < ' tcx > > ,
8282 queries : OnceCell < TcxQueries < ' tcx > > ,
8383
8484 arena : WorkerLocal < Arena < ' tcx > > ,
@@ -90,15 +90,16 @@ pub struct Queries<'tcx> {
9090 register_plugins : Query < ( ast:: Crate , Lrc < LintStore > ) > ,
9191 expansion : Query < ( Lrc < ast:: Crate > , Rc < RefCell < BoxedResolver > > , Lrc < LintStore > ) > ,
9292 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 > > ,
9495 ongoing_codegen : Query < Box < dyn Any > > ,
9596}
9697
9798impl < ' tcx > Queries < ' tcx > {
9899 pub fn new ( compiler : & ' tcx Compiler ) -> Queries < ' tcx > {
99100 Queries {
100101 compiler,
101- gcx : OnceCell :: new ( ) ,
102+ gcx_cell : OnceCell :: new ( ) ,
102103 queries : OnceCell :: new ( ) ,
103104 arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
104105 hir_arena : WorkerLocal :: new ( |_| rustc_hir:: Arena :: default ( ) ) ,
@@ -108,7 +109,7 @@ impl<'tcx> Queries<'tcx> {
108109 register_plugins : Default :: default ( ) ,
109110 expansion : Default :: default ( ) ,
110111 dep_graph : Default :: default ( ) ,
111- global_ctxt : Default :: default ( ) ,
112+ gcx : Default :: default ( ) ,
112113 ongoing_codegen : Default :: default ( ) ,
113114 }
114115 }
@@ -207,8 +208,8 @@ impl<'tcx> Queries<'tcx> {
207208 } )
208209 }
209210
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 ( || {
212213 let crate_name = * self . crate_name ( ) ?. borrow ( ) ;
213214 let ( krate, resolver, lint_store) = self . expansion ( ) ?. steal ( ) ;
214215
@@ -218,18 +219,18 @@ impl<'tcx> Queries<'tcx> {
218219 ast_lowering : untracked_resolver_for_lowering,
219220 } = BoxedResolver :: to_resolver_outputs ( resolver) ;
220221
221- let mut qcx = passes:: create_global_ctxt (
222+ let gcx = passes:: create_global_ctxt (
222223 self . compiler ,
223224 lint_store,
224225 self . dep_graph ( ) ?. steal ( ) ,
225226 untracked,
226227 & self . queries ,
227- & self . gcx ,
228+ & self . gcx_cell ,
228229 & self . arena ,
229230 & self . hir_arena ,
230231 ) ;
231232
232- qcx . enter ( |tcx| {
233+ gcx . enter ( |tcx| {
233234 let feed = tcx. feed_unit_query ( ) ;
234235 feed. resolver_for_lowering (
235236 tcx. arena . alloc ( Steal :: new ( ( untracked_resolver_for_lowering, krate) ) ) ,
@@ -239,7 +240,7 @@ impl<'tcx> Queries<'tcx> {
239240 let feed = tcx. feed_local_crate ( ) ;
240241 feed. crate_name ( crate_name) ;
241242 } ) ;
242- Ok ( qcx )
243+ Ok ( gcx )
243244 } )
244245 }
245246
@@ -387,7 +388,7 @@ impl Compiler {
387388
388389 // NOTE: intentionally does not compute the global context if it hasn't been built yet,
389390 // 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 ( ) {
391392 let gcx = gcx. get_mut ( ) ;
392393 // We assume that no queries are run past here. If there are new queries
393394 // after this point, they'll show up as "<unknown>" in self-profiling data.
0 commit comments