@@ -65,6 +65,7 @@ use hir::def_id::CrateNum;
65
65
66
66
use session;
67
67
use session:: config;
68
+ use ty:: TyCtxt ;
68
69
use middle:: cstore:: DepKind ;
69
70
use middle:: cstore:: LinkagePreference :: { self , RequireStatic , RequireDynamic } ;
70
71
use util:: nodemap:: FxHashMap ;
@@ -91,18 +92,22 @@ pub enum Linkage {
91
92
Dynamic ,
92
93
}
93
94
94
- pub fn calculate ( sess : & session:: Session ) {
95
+ pub fn calculate < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) {
96
+ let sess = & tcx. sess ;
95
97
let mut fmts = sess. dependency_formats . borrow_mut ( ) ;
96
98
for & ty in sess. crate_types . borrow ( ) . iter ( ) {
97
- let linkage = calculate_type ( sess , ty) ;
98
- verify_ok ( sess , & linkage) ;
99
+ let linkage = calculate_type ( tcx , ty) ;
100
+ verify_ok ( tcx , & linkage) ;
99
101
fmts. insert ( ty, linkage) ;
100
102
}
101
103
sess. abort_if_errors ( ) ;
102
104
}
103
105
104
- fn calculate_type ( sess : & session:: Session ,
105
- ty : config:: CrateType ) -> DependencyList {
106
+ fn calculate_type < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
107
+ ty : config:: CrateType ) -> DependencyList {
108
+
109
+ let sess = & tcx. sess ;
110
+
106
111
if !sess. opts . output_types . should_trans ( ) {
107
112
return Vec :: new ( ) ;
108
113
}
@@ -111,7 +116,7 @@ fn calculate_type(sess: &session::Session,
111
116
// If the global prefer_dynamic switch is turned off, first attempt
112
117
// static linkage (this can fail).
113
118
config:: CrateTypeExecutable if !sess. opts . cg . prefer_dynamic => {
114
- if let Some ( v) = attempt_static ( sess ) {
119
+ if let Some ( v) = attempt_static ( tcx ) {
115
120
return v;
116
121
}
117
122
}
@@ -124,7 +129,7 @@ fn calculate_type(sess: &session::Session,
124
129
// to be found, we generate some nice pretty errors.
125
130
config:: CrateTypeStaticlib |
126
131
config:: CrateTypeCdylib => {
127
- if let Some ( v) = attempt_static ( sess ) {
132
+ if let Some ( v) = attempt_static ( tcx ) {
128
133
return v;
129
134
}
130
135
for cnum in sess. cstore . crates ( ) {
@@ -141,7 +146,7 @@ fn calculate_type(sess: &session::Session,
141
146
// to try to eagerly statically link all dependencies. This is normally
142
147
// done for end-product dylibs, not intermediate products.
143
148
config:: CrateTypeDylib if !sess. opts . cg . prefer_dynamic => {
144
- if let Some ( v) = attempt_static ( sess ) {
149
+ if let Some ( v) = attempt_static ( tcx ) {
145
150
return v;
146
151
}
147
152
}
@@ -167,8 +172,8 @@ fn calculate_type(sess: &session::Session,
167
172
if src. dylib . is_some ( ) {
168
173
info ! ( "adding dylib: {}" , name) ;
169
174
add_library ( sess, cnum, RequireDynamic , & mut formats) ;
170
- let deps = sess . cstore . dylib_dependency_formats ( cnum) ;
171
- for & ( depnum, style) in & deps {
175
+ let deps = tcx . dylib_dependency_formats ( cnum. as_def_id ( ) ) ;
176
+ for & ( depnum, style) in deps. iter ( ) {
172
177
info ! ( "adding {:?}: {}" , style,
173
178
sess. cstore. crate_name( depnum) ) ;
174
179
add_library ( sess, depnum, style, & mut formats) ;
@@ -210,9 +215,9 @@ fn calculate_type(sess: &session::Session,
210
215
// Things like allocators and panic runtimes may not have been activated
211
216
// quite yet, so do so here.
212
217
activate_injected_dep ( sess. injected_allocator . get ( ) , & mut ret,
213
- & |cnum| sess . cstore . is_allocator ( cnum) ) ;
218
+ & |cnum| tcx . is_allocator ( cnum. as_def_id ( ) ) ) ;
214
219
activate_injected_dep ( sess. injected_panic_runtime . get ( ) , & mut ret,
215
- & |cnum| sess . cstore . is_panic_runtime ( cnum) ) ;
220
+ & |cnum| tcx . is_panic_runtime ( cnum. as_def_id ( ) ) ) ;
216
221
217
222
// When dylib B links to dylib A, then when using B we must also link to A.
218
223
// It could be the case, however, that the rlib for A is present (hence we
@@ -269,7 +274,8 @@ fn add_library(sess: &session::Session,
269
274
}
270
275
}
271
276
272
- fn attempt_static ( sess : & session:: Session ) -> Option < DependencyList > {
277
+ fn attempt_static < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) -> Option < DependencyList > {
278
+ let sess = & tcx. sess ;
273
279
let crates = sess. cstore . used_crates ( RequireStatic ) ;
274
280
if !crates. iter ( ) . by_ref ( ) . all ( |& ( _, ref p) | p. is_some ( ) ) {
275
281
return None
@@ -290,9 +296,9 @@ fn attempt_static(sess: &session::Session) -> Option<DependencyList> {
290
296
// explicitly linked, which is the case for any injected dependency. Handle
291
297
// that here and activate them.
292
298
activate_injected_dep ( sess. injected_allocator . get ( ) , & mut ret,
293
- & |cnum| sess . cstore . is_allocator ( cnum) ) ;
299
+ & |cnum| tcx . is_allocator ( cnum. as_def_id ( ) ) ) ;
294
300
activate_injected_dep ( sess. injected_panic_runtime . get ( ) , & mut ret,
295
- & |cnum| sess . cstore . is_panic_runtime ( cnum) ) ;
301
+ & |cnum| tcx . is_panic_runtime ( cnum. as_def_id ( ) ) ) ;
296
302
297
303
Some ( ret)
298
304
}
@@ -327,7 +333,8 @@ fn activate_injected_dep(injected: Option<CrateNum>,
327
333
328
334
// After the linkage for a crate has been determined we need to verify that
329
335
// there's only going to be one allocator in the output.
330
- fn verify_ok ( sess : & session:: Session , list : & [ Linkage ] ) {
336
+ fn verify_ok < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , list : & [ Linkage ] ) {
337
+ let sess = & tcx. sess ;
331
338
if list. len ( ) == 0 {
332
339
return
333
340
}
@@ -338,7 +345,7 @@ fn verify_ok(sess: &session::Session, list: &[Linkage]) {
338
345
continue
339
346
}
340
347
let cnum = CrateNum :: new ( i + 1 ) ;
341
- if sess . cstore . is_allocator ( cnum) {
348
+ if tcx . is_allocator ( cnum. as_def_id ( ) ) {
342
349
if let Some ( prev) = allocator {
343
350
let prev_name = sess. cstore . crate_name ( prev) ;
344
351
let cur_name = sess. cstore . crate_name ( cnum) ;
@@ -349,7 +356,7 @@ fn verify_ok(sess: &session::Session, list: &[Linkage]) {
349
356
allocator = Some ( cnum) ;
350
357
}
351
358
352
- if sess . cstore . is_panic_runtime ( cnum) {
359
+ if tcx . is_panic_runtime ( cnum. as_def_id ( ) ) {
353
360
if let Some ( ( prev, _) ) = panic_runtime {
354
361
let prev_name = sess. cstore . crate_name ( prev) ;
355
362
let cur_name = sess. cstore . crate_name ( cnum) ;
0 commit comments