@@ -66,7 +66,7 @@ use hir::def_id::CrateNum;
66
66
use session;
67
67
use session:: config;
68
68
use ty:: TyCtxt ;
69
- use middle:: cstore:: DepKind ;
69
+ use middle:: cstore:: { CrateStore , DepKind } ;
70
70
use middle:: cstore:: LinkagePreference :: { self , RequireStatic , RequireDynamic } ;
71
71
use util:: nodemap:: FxHashMap ;
72
72
use rustc_back:: PanicStrategy ;
@@ -132,12 +132,12 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
132
132
if let Some ( v) = attempt_static ( tcx) {
133
133
return v;
134
134
}
135
- for cnum in sess . cstore . crates ( ) {
136
- if sess . cstore . dep_kind ( cnum) . macros_only ( ) { continue }
137
- let src = sess . cstore . used_crate_source ( cnum) ;
135
+ for cnum in tcx . cstore ( ) . crates ( ) {
136
+ if tcx . cstore ( ) . dep_kind ( cnum) . macros_only ( ) { continue }
137
+ let src = tcx . cstore ( ) . used_crate_source ( cnum) ;
138
138
if src. rlib . is_some ( ) { continue }
139
139
sess. err ( & format ! ( "dependency `{}` not found in rlib format" ,
140
- sess . cstore. crate_name( cnum) ) ) ;
140
+ tcx . cstore( ) . crate_name( cnum) ) ) ;
141
141
}
142
142
return Vec :: new ( ) ;
143
143
}
@@ -165,24 +165,24 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
165
165
// Sweep all crates for found dylibs. Add all dylibs, as well as their
166
166
// dependencies, ensuring there are no conflicts. The only valid case for a
167
167
// dependency to be relied upon twice is for both cases to rely on a dylib.
168
- for cnum in sess . cstore . crates ( ) {
169
- if sess . cstore . dep_kind ( cnum) . macros_only ( ) { continue }
170
- let name = sess . cstore . crate_name ( cnum) ;
171
- let src = sess . cstore . used_crate_source ( cnum) ;
168
+ for cnum in tcx . cstore ( ) . crates ( ) {
169
+ if tcx . cstore ( ) . dep_kind ( cnum) . macros_only ( ) { continue }
170
+ let name = tcx . cstore ( ) . crate_name ( cnum) ;
171
+ let src = tcx . cstore ( ) . used_crate_source ( cnum) ;
172
172
if src. dylib . is_some ( ) {
173
173
info ! ( "adding dylib: {}" , name) ;
174
- add_library ( sess, cnum, RequireDynamic , & mut formats) ;
174
+ add_library ( sess, tcx . cstore ( ) , cnum, RequireDynamic , & mut formats) ;
175
175
let deps = tcx. dylib_dependency_formats ( cnum. as_def_id ( ) ) ;
176
176
for & ( depnum, style) in deps. iter ( ) {
177
177
info ! ( "adding {:?}: {}" , style,
178
- sess . cstore. crate_name( depnum) ) ;
179
- add_library ( sess, depnum, style, & mut formats) ;
178
+ tcx . cstore( ) . crate_name( depnum) ) ;
179
+ add_library ( sess, tcx . cstore ( ) , depnum, style, & mut formats) ;
180
180
}
181
181
}
182
182
}
183
183
184
184
// Collect what we've got so far in the return vector.
185
- let last_crate = sess . cstore . crates ( ) . len ( ) ;
185
+ let last_crate = tcx . cstore ( ) . crates ( ) . len ( ) ;
186
186
let mut ret = ( 1 ..last_crate+1 ) . map ( |cnum| {
187
187
match formats. get ( & CrateNum :: new ( cnum) ) {
188
188
Some ( & RequireDynamic ) => Linkage :: Dynamic ,
@@ -196,14 +196,14 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
196
196
//
197
197
// If the crate hasn't been included yet and it's not actually required
198
198
// (e.g. it's an allocator) then we skip it here as well.
199
- for cnum in sess . cstore . crates ( ) {
200
- let src = sess . cstore . used_crate_source ( cnum) ;
199
+ for cnum in tcx . cstore ( ) . crates ( ) {
200
+ let src = tcx . cstore ( ) . used_crate_source ( cnum) ;
201
201
if src. dylib . is_none ( ) &&
202
202
!formats. contains_key ( & cnum) &&
203
- sess . cstore . dep_kind ( cnum) == DepKind :: Explicit {
203
+ tcx . cstore ( ) . dep_kind ( cnum) == DepKind :: Explicit {
204
204
assert ! ( src. rlib. is_some( ) || src. rmeta. is_some( ) ) ;
205
- info ! ( "adding staticlib: {}" , sess . cstore. crate_name( cnum) ) ;
206
- add_library ( sess, cnum, RequireStatic , & mut formats) ;
205
+ info ! ( "adding staticlib: {}" , tcx . cstore( ) . crate_name( cnum) ) ;
206
+ add_library ( sess, tcx . cstore ( ) , cnum, RequireStatic , & mut formats) ;
207
207
ret[ cnum. as_usize ( ) - 1 ] = Linkage :: Static ;
208
208
}
209
209
}
@@ -226,7 +226,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
226
226
// making sure that everything is available in the requested format.
227
227
for ( cnum, kind) in ret. iter ( ) . enumerate ( ) {
228
228
let cnum = CrateNum :: new ( cnum + 1 ) ;
229
- let src = sess . cstore . used_crate_source ( cnum) ;
229
+ let src = tcx . cstore ( ) . used_crate_source ( cnum) ;
230
230
match * kind {
231
231
Linkage :: NotLinked |
232
232
Linkage :: IncludedFromDylib => { }
@@ -237,7 +237,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
237
237
Linkage :: Static => "rlib" ,
238
238
_ => "dylib" ,
239
239
} ;
240
- let name = sess . cstore . crate_name ( cnum) ;
240
+ let name = tcx . cstore ( ) . crate_name ( cnum) ;
241
241
sess. err ( & format ! ( "crate `{}` required to be available in {}, \
242
242
but it was not available in this form",
243
243
name, kind) ) ;
@@ -249,6 +249,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
249
249
}
250
250
251
251
fn add_library ( sess : & session:: Session ,
252
+ cstore : & CrateStore ,
252
253
cnum : CrateNum ,
253
254
link : LinkagePreference ,
254
255
m : & mut FxHashMap < CrateNum , LinkagePreference > ) {
@@ -263,7 +264,7 @@ fn add_library(sess: &session::Session,
263
264
// can be refined over time.
264
265
if link2 != link || link == RequireStatic {
265
266
sess. struct_err ( & format ! ( "cannot satisfy dependencies so `{}` only \
266
- shows up once", sess . cstore. crate_name( cnum) ) )
267
+ shows up once", cstore. crate_name( cnum) ) )
267
268
. help ( "having upstream crates all available in one format \
268
269
will likely make this go away")
269
270
. emit ( ) ;
@@ -275,16 +276,16 @@ fn add_library(sess: &session::Session,
275
276
276
277
fn attempt_static < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) -> Option < DependencyList > {
277
278
let sess = & tcx. sess ;
278
- let crates = sess . cstore . used_crates ( RequireStatic ) ;
279
+ let crates = tcx . cstore ( ) . used_crates ( RequireStatic ) ;
279
280
if !crates. iter ( ) . by_ref ( ) . all ( |& ( _, ref p) | p. is_some ( ) ) {
280
281
return None
281
282
}
282
283
283
284
// All crates are available in an rlib format, so we're just going to link
284
285
// everything in explicitly so long as it's actually required.
285
- let last_crate = sess . cstore . crates ( ) . len ( ) ;
286
+ let last_crate = tcx . cstore ( ) . crates ( ) . len ( ) ;
286
287
let mut ret = ( 1 ..last_crate+1 ) . map ( |cnum| {
287
- if sess . cstore . dep_kind ( CrateNum :: new ( cnum) ) == DepKind :: Explicit {
288
+ if tcx . cstore ( ) . dep_kind ( CrateNum :: new ( cnum) ) == DepKind :: Explicit {
288
289
Linkage :: Static
289
290
} else {
290
291
Linkage :: NotLinked
@@ -357,13 +358,13 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
357
358
358
359
if tcx. is_panic_runtime ( cnum. as_def_id ( ) ) {
359
360
if let Some ( ( prev, _) ) = panic_runtime {
360
- let prev_name = sess . cstore . crate_name ( prev) ;
361
- let cur_name = sess . cstore . crate_name ( cnum) ;
361
+ let prev_name = tcx . cstore ( ) . crate_name ( prev) ;
362
+ let cur_name = tcx . cstore ( ) . crate_name ( cnum) ;
362
363
sess. err ( & format ! ( "cannot link together two \
363
364
panic runtimes: {} and {}",
364
365
prev_name, cur_name) ) ;
365
366
}
366
- panic_runtime = Some ( ( cnum, sess . cstore . panic_strategy ( cnum) ) ) ;
367
+ panic_runtime = Some ( ( cnum, tcx . cstore ( ) . panic_strategy ( cnum) ) ) ;
367
368
}
368
369
}
369
370
@@ -379,7 +380,7 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
379
380
sess. err ( & format ! ( "the linked panic runtime `{}` is \
380
381
not compiled with this crate's \
381
382
panic strategy `{}`",
382
- sess . cstore. crate_name( cnum) ,
383
+ tcx . cstore( ) . crate_name( cnum) ,
383
384
desired_strategy. desc( ) ) ) ;
384
385
}
385
386
@@ -395,8 +396,8 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
395
396
continue
396
397
}
397
398
let cnum = CrateNum :: new ( i + 1 ) ;
398
- let found_strategy = sess . cstore . panic_strategy ( cnum) ;
399
- let is_compiler_builtins = sess . cstore . is_compiler_builtins ( cnum) ;
399
+ let found_strategy = tcx . cstore ( ) . panic_strategy ( cnum) ;
400
+ let is_compiler_builtins = tcx . cstore ( ) . is_compiler_builtins ( cnum) ;
400
401
if is_compiler_builtins || desired_strategy == found_strategy {
401
402
continue
402
403
}
@@ -405,7 +406,7 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
405
406
panic strategy `{}` which is \
406
407
incompatible with this crate's \
407
408
strategy of `{}`",
408
- sess . cstore. crate_name( cnum) ,
409
+ tcx . cstore( ) . crate_name( cnum) ,
409
410
found_strategy. desc( ) ,
410
411
desired_strategy. desc( ) ) ) ;
411
412
}
0 commit comments