@@ -5,7 +5,6 @@ use crate::{passes, util};
55use rustc_ast as ast;
66use rustc_codegen_ssa:: traits:: CodegenBackend ;
77use rustc_codegen_ssa:: CodegenResults ;
8- use rustc_data_structures:: fx:: FxIndexMap ;
98use rustc_data_structures:: steal:: Steal ;
109use rustc_data_structures:: svh:: Svh ;
1110use rustc_data_structures:: sync:: { AppendOnlyIndexVec , Lrc , OnceCell , RwLock , WorkerLocal } ;
@@ -86,9 +85,6 @@ pub struct Queries<'tcx> {
8685
8786 parse : Query < ast:: Crate > ,
8887 pre_configure : Query < ( ast:: Crate , ast:: AttrVec ) > ,
89- crate_name : Query < Symbol > ,
90- crate_types : Query < Vec < CrateType > > ,
91- stable_crate_id : Query < StableCrateId > ,
9288 // This just points to what's in `gcx_cell`.
9389 gcx : Query < & ' tcx GlobalCtxt < ' tcx > > ,
9490}
@@ -102,9 +98,6 @@ impl<'tcx> Queries<'tcx> {
10298 hir_arena : WorkerLocal :: new ( |_| rustc_hir:: Arena :: default ( ) ) ,
10399 parse : Default :: default ( ) ,
104100 pre_configure : Default :: default ( ) ,
105- crate_name : Default :: default ( ) ,
106- crate_types : Default :: default ( ) ,
107- stable_crate_id : Default :: default ( ) ,
108101 gcx : Default :: default ( ) ,
109102 }
110103 }
@@ -138,39 +131,12 @@ impl<'tcx> Queries<'tcx> {
138131 } )
139132 }
140133
141- fn crate_name ( & self ) -> Result < QueryResult < ' _ , Symbol > > {
142- self . crate_name . compute ( || {
143- let pre_configure_result = self . pre_configure ( ) ?;
144- let ( _, pre_configured_attrs) = & * pre_configure_result. borrow ( ) ;
145- // parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches.
146- Ok ( find_crate_name ( self . session ( ) , pre_configured_attrs) )
147- } )
148- }
149-
150- fn crate_types ( & self ) -> Result < QueryResult < ' _ , Vec < CrateType > > > {
151- self . crate_types . compute ( || {
152- let pre_configure_result = self . pre_configure ( ) ?;
153- let ( _, pre_configured_attrs) = & * pre_configure_result. borrow ( ) ;
154- Ok ( util:: collect_crate_types ( & self . session ( ) , & pre_configured_attrs) )
155- } )
156- }
157-
158- fn stable_crate_id ( & self ) -> Result < QueryResult < ' _ , StableCrateId > > {
159- self . stable_crate_id . compute ( || {
160- let sess = self . session ( ) ;
161- Ok ( StableCrateId :: new (
162- * self . crate_name ( ) ?. borrow ( ) ,
163- self . crate_types ( ) ?. borrow ( ) . contains ( & CrateType :: Executable ) ,
164- sess. opts . cg . metadata . clone ( ) ,
165- sess. cfg_version ,
166- ) )
167- } )
168- }
169-
170- fn dep_graph_future ( & self ) -> Result < Option < DepGraphFuture > > {
134+ fn dep_graph_future (
135+ & self ,
136+ crate_name : Symbol ,
137+ stable_crate_id : StableCrateId ,
138+ ) -> Result < Option < DepGraphFuture > > {
171139 let sess = self . session ( ) ;
172- let crate_name = * self . crate_name ( ) ?. borrow ( ) ;
173- let stable_crate_id = * self . stable_crate_id ( ) ?. borrow ( ) ;
174140
175141 // `load_dep_graph` can only be called after `prepare_session_directory`.
176142 rustc_incremental:: prepare_session_directory ( sess, crate_name, stable_crate_id) ?;
@@ -195,39 +161,42 @@ impl<'tcx> Queries<'tcx> {
195161 dep_graph_future
196162 . and_then ( |future| {
197163 let sess = self . session ( ) ;
198- let ( prev_graph, mut prev_work_products) =
164+ let ( prev_graph, prev_work_products) =
199165 sess. time ( "blocked_on_dep_graph_loading" , || future. open ( ) . open ( sess) ) ;
200- // Convert from UnordMap to FxIndexMap by sorting
201- let prev_work_product_ids =
202- prev_work_products. items ( ) . map ( |x| * x. 0 ) . into_sorted_stable_ord ( ) ;
203- let prev_work_products = prev_work_product_ids
204- . into_iter ( )
205- . map ( |x| ( x, prev_work_products. remove ( & x) . unwrap ( ) ) )
206- . collect :: < FxIndexMap < _ , _ > > ( ) ;
207166 rustc_incremental:: build_dep_graph ( sess, prev_graph, prev_work_products)
208167 } )
209168 . unwrap_or_else ( DepGraph :: new_disabled)
210169 }
211170
212171 pub fn global_ctxt ( & ' tcx self ) -> Result < QueryResult < ' _ , & ' tcx GlobalCtxt < ' tcx > > > {
213172 self . gcx . compute ( || {
173+ let sess = self . session ( ) ;
174+ let ( krate, pre_configured_attrs) = self . pre_configure ( ) ?. steal ( ) ;
175+
176+ // parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches.
177+ let crate_name = find_crate_name ( sess, & pre_configured_attrs) ;
178+ let crate_types = util:: collect_crate_types ( sess, & pre_configured_attrs) ;
179+ let stable_crate_id = StableCrateId :: new (
180+ crate_name,
181+ crate_types. contains ( & CrateType :: Executable ) ,
182+ sess. opts . cg . metadata . clone ( ) ,
183+ sess. cfg_version ,
184+ ) ;
185+
214186 // Compute the dependency graph (in the background). We want to do this as early as
215187 // possible, to give the DepGraph maximum time to load before `dep_graph` is called.
216- let dep_graph_future = self . dep_graph_future ( ) ?;
217-
218- let crate_name = self . crate_name ( ) ?. steal ( ) ;
219- let crate_types = self . crate_types ( ) ?. steal ( ) ;
220- let stable_crate_id = self . stable_crate_id ( ) ?. steal ( ) ;
221- let ( krate, pre_configured_attrs) = self . pre_configure ( ) ?. steal ( ) ;
188+ let dep_graph_future = self . dep_graph_future ( crate_name, stable_crate_id) ?;
222189
223- let sess = self . session ( ) ;
224190 let lint_store = Lrc :: new ( passes:: create_lint_store (
225191 sess,
226192 & * self . codegen_backend ( ) . metadata_loader ( ) ,
227193 self . compiler . register_lints . as_deref ( ) ,
228194 & pre_configured_attrs,
229195 ) ) ;
230- let cstore = RwLock :: new ( Box :: new ( CStore :: new ( stable_crate_id) ) as _ ) ;
196+ let cstore = RwLock :: new ( Box :: new ( CStore :: new (
197+ self . codegen_backend ( ) . metadata_loader ( ) ,
198+ stable_crate_id,
199+ ) ) as _ ) ;
231200 let definitions = RwLock :: new ( Definitions :: new ( stable_crate_id) ) ;
232201 let source_span = AppendOnlyIndexVec :: new ( ) ;
233202 let _id = source_span. push ( krate. spans . inner_span ) ;
@@ -255,9 +224,6 @@ impl<'tcx> Queries<'tcx> {
255224 tcx. arena . alloc ( rustc_expand:: config:: features ( sess, & pre_configured_attrs) ) ,
256225 ) ;
257226 feed. crate_for_resolver ( tcx. arena . alloc ( Steal :: new ( ( krate, pre_configured_attrs) ) ) ) ;
258- feed. metadata_loader (
259- tcx. arena . alloc ( Steal :: new ( self . codegen_backend ( ) . metadata_loader ( ) ) ) ,
260- ) ;
261227 } ) ;
262228 Ok ( qcx)
263229 } )
0 commit comments