@@ -21,7 +21,6 @@ use rustc_session::config::{self, CrateType, OutputFilenames, OutputType};
21
21
use rustc_session:: cstore:: Untracked ;
22
22
use rustc_session:: { output:: find_crate_name, Session } ;
23
23
use rustc_span:: symbol:: sym;
24
- use rustc_span:: Symbol ;
25
24
use std:: any:: Any ;
26
25
use std:: cell:: { RefCell , RefMut } ;
27
26
use std:: sync:: Arc ;
@@ -85,6 +84,7 @@ pub struct Queries<'tcx> {
85
84
arena : WorkerLocal < Arena < ' tcx > > ,
86
85
hir_arena : WorkerLocal < rustc_hir:: Arena < ' tcx > > ,
87
86
87
+ dep_graph_future : Query < Option < DepGraphFuture > > ,
88
88
parse : Query < ast:: Crate > ,
89
89
pre_configure : Query < ( ast:: Crate , ast:: AttrVec ) > ,
90
90
// This just points to what's in `gcx_cell`.
@@ -98,6 +98,7 @@ impl<'tcx> Queries<'tcx> {
98
98
gcx_cell : OnceLock :: new ( ) ,
99
99
arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
100
100
hir_arena : WorkerLocal :: new ( |_| rustc_hir:: Arena :: default ( ) ) ,
101
+ dep_graph_future : Default :: default ( ) ,
101
102
parse : Default :: default ( ) ,
102
103
pre_configure : Default :: default ( ) ,
103
104
gcx : Default :: default ( ) ,
@@ -112,8 +113,13 @@ impl<'tcx> Queries<'tcx> {
112
113
}
113
114
114
115
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
+ } )
117
123
}
118
124
119
125
pub fn pre_configure ( & self ) -> Result < QueryResult < ' _ , ( ast:: Crate , ast:: AttrVec ) > > {
@@ -133,41 +139,41 @@ impl<'tcx> Queries<'tcx> {
133
139
} )
134
140
}
135
141
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
+ }
158
161
159
- Ok ( res)
162
+ Ok ( res)
163
+ } )
160
164
}
161
165
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 ( )
164
170
. and_then ( |future| {
165
171
let sess = self . session ( ) ;
166
172
let ( prev_graph, prev_work_products) =
167
173
sess. time ( "blocked_on_dep_graph_loading" , || future. open ( ) . open ( sess) ) ;
168
174
rustc_incremental:: build_dep_graph ( sess, prev_graph, prev_work_products)
169
175
} )
170
- . unwrap_or_else ( DepGraph :: new_disabled)
176
+ . unwrap_or_else ( DepGraph :: new_disabled) )
171
177
}
172
178
173
179
pub fn global_ctxt ( & ' tcx self ) -> Result < QueryResult < ' _ , & ' tcx GlobalCtxt < ' tcx > > > {
@@ -185,10 +191,6 @@ impl<'tcx> Queries<'tcx> {
185
191
sess. cfg_version ,
186
192
) ;
187
193
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
-
192
194
let lint_store = Lrc :: new ( passes:: create_lint_store (
193
195
sess,
194
196
& * self . codegen_backend ( ) . metadata_loader ( ) ,
@@ -210,7 +212,7 @@ impl<'tcx> Queries<'tcx> {
210
212
crate_types,
211
213
stable_crate_id,
212
214
lint_store,
213
- self . dep_graph ( dep_graph_future ) ,
215
+ self . dep_graph ( ) ? ,
214
216
untracked,
215
217
& self . gcx_cell ,
216
218
& self . arena ,
0 commit comments