@@ -21,7 +21,6 @@ use rustc_session::config::{self, CrateType, OutputFilenames, OutputType};
2121use rustc_session:: cstore:: Untracked ;
2222use rustc_session:: { output:: find_crate_name, Session } ;
2323use rustc_span:: symbol:: sym;
24- use rustc_span:: Symbol ;
2524use std:: any:: Any ;
2625use std:: cell:: { RefCell , RefMut } ;
2726use std:: sync:: Arc ;
@@ -85,6 +84,7 @@ pub struct Queries<'tcx> {
8584 arena : WorkerLocal < Arena < ' tcx > > ,
8685 hir_arena : WorkerLocal < rustc_hir:: Arena < ' tcx > > ,
8786
87+ dep_graph_future : Query < Option < DepGraphFuture > > ,
8888 parse : Query < ast:: Crate > ,
8989 pre_configure : Query < ( ast:: Crate , ast:: AttrVec ) > ,
9090 // This just points to what's in `gcx_cell`.
@@ -98,6 +98,7 @@ impl<'tcx> Queries<'tcx> {
9898 gcx_cell : OnceLock :: new ( ) ,
9999 arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
100100 hir_arena : WorkerLocal :: new ( |_| rustc_hir:: Arena :: default ( ) ) ,
101+ dep_graph_future : Default :: default ( ) ,
101102 parse : Default :: default ( ) ,
102103 pre_configure : Default :: default ( ) ,
103104 gcx : Default :: default ( ) ,
@@ -112,8 +113,13 @@ impl<'tcx> Queries<'tcx> {
112113 }
113114
114115 pub fn parse ( & self ) -> Result < QueryResult < ' _ , ast:: Crate > > {
115- self . parse
116- . compute ( || passes:: parse ( self . session ( ) ) . map_err ( |mut parse_error| parse_error. emit ( ) ) )
116+ self . parse . compute ( || {
117+ // Compute the dependency graph (in the background). We want to do this as early as
118+ // possible, to give the DepGraph maximum time to load before `dep_graph` is called.
119+ self . dep_graph_future ( ) ?;
120+
121+ passes:: parse ( self . session ( ) ) . map_err ( |mut parse_error| parse_error. emit ( ) )
122+ } )
117123 }
118124
119125 pub fn pre_configure ( & self ) -> Result < QueryResult < ' _ , ( ast:: Crate , ast:: AttrVec ) > > {
@@ -133,41 +139,41 @@ impl<'tcx> Queries<'tcx> {
133139 } )
134140 }
135141
136- fn dep_graph_future (
137- & self ,
138- crate_name : Symbol ,
139- stable_crate_id : StableCrateId ,
140- ) -> Result < Option < DepGraphFuture > > {
141- let sess = self . session ( ) ;
142-
143- // `load_dep_graph` can only be called after `prepare_session_directory`.
144- rustc_incremental:: prepare_session_directory ( sess, crate_name, stable_crate_id) ?;
145- let res = sess. opts . build_dep_graph ( ) . then ( || rustc_incremental:: load_dep_graph ( sess) ) ;
146-
147- if sess. opts . incremental . is_some ( ) {
148- sess. time ( "incr_comp_garbage_collect_session_directories" , || {
149- if let Err ( e) = rustc_incremental:: garbage_collect_session_directories ( sess) {
150- warn ! (
151- "Error while trying to garbage collect incremental \
152- compilation cache directory: {}",
153- e
154- ) ;
155- }
156- } ) ;
157- }
142+ fn dep_graph_future ( & self ) -> Result < QueryResult < ' _ , Option < DepGraphFuture > > > {
143+ self . dep_graph_future . compute ( || {
144+ let sess = self . session ( ) ;
145+
146+ // `load_dep_graph` can only be called after `prepare_session_directory`.
147+ rustc_incremental:: prepare_session_directory ( sess) ?;
148+ let res = sess. opts . build_dep_graph ( ) . then ( || rustc_incremental:: load_dep_graph ( sess) ) ;
149+
150+ if sess. opts . incremental . is_some ( ) {
151+ sess. time ( "incr_comp_garbage_collect_session_directories" , || {
152+ if let Err ( e) = rustc_incremental:: garbage_collect_session_directories ( sess) {
153+ warn ! (
154+ "Error while trying to garbage collect incremental \
155+ compilation cache directory: {}",
156+ e
157+ ) ;
158+ }
159+ } ) ;
160+ }
158161
159- Ok ( res)
162+ Ok ( res)
163+ } )
160164 }
161165
162- fn dep_graph ( & self , dep_graph_future : Option < DepGraphFuture > ) -> DepGraph {
163- dep_graph_future
166+ fn dep_graph ( & self ) -> Result < DepGraph > {
167+ Ok ( self
168+ . dep_graph_future ( ) ?
169+ . steal ( )
164170 . and_then ( |future| {
165171 let sess = self . session ( ) ;
166172 let ( prev_graph, prev_work_products) =
167173 sess. time ( "blocked_on_dep_graph_loading" , || future. open ( ) . open ( sess) ) ;
168174 rustc_incremental:: build_dep_graph ( sess, prev_graph, prev_work_products)
169175 } )
170- . unwrap_or_else ( DepGraph :: new_disabled)
176+ . unwrap_or_else ( DepGraph :: new_disabled) )
171177 }
172178
173179 pub fn global_ctxt ( & ' tcx self ) -> Result < QueryResult < ' _ , & ' tcx GlobalCtxt < ' tcx > > > {
@@ -185,10 +191,6 @@ impl<'tcx> Queries<'tcx> {
185191 sess. cfg_version ,
186192 ) ;
187193
188- // Compute the dependency graph (in the background). We want to do this as early as
189- // possible, to give the DepGraph maximum time to load before `dep_graph` is called.
190- let dep_graph_future = self . dep_graph_future ( crate_name, stable_crate_id) ?;
191-
192194 let lint_store = Lrc :: new ( passes:: create_lint_store (
193195 sess,
194196 & * self . codegen_backend ( ) . metadata_loader ( ) ,
@@ -210,7 +212,7 @@ impl<'tcx> Queries<'tcx> {
210212 crate_types,
211213 stable_crate_id,
212214 lint_store,
213- self . dep_graph ( dep_graph_future ) ,
215+ self . dep_graph ( ) ? ,
214216 untracked,
215217 & self . gcx_cell ,
216218 & self . arena ,
0 commit comments