@@ -17,7 +17,7 @@ use rustc::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex};
17
17
use rustc:: hir:: map:: definitions:: DefPathTable ;
18
18
use rustc:: hir:: svh:: Svh ;
19
19
use rustc:: middle:: cstore:: { DepKind , ExternCrate , MetadataLoader } ;
20
- use rustc:: session:: { Session , CrateDisambiguator } ;
20
+ use rustc:: session:: { CrateDisambiguator , Session } ;
21
21
use rustc_target:: spec:: PanicStrategy ;
22
22
use rustc_data_structures:: indexed_vec:: IndexVec ;
23
23
use rustc:: util:: nodemap:: { FxHashMap , NodeMap } ;
@@ -84,6 +84,15 @@ pub struct CrateMetadata {
84
84
pub source : CrateSource ,
85
85
86
86
pub proc_macros : Option < Vec < ( ast:: Name , Lrc < SyntaxExtension > ) > > ,
87
+
88
+ // Booleans derived from attributes
89
+ pub compiler_builtins : Option < bool > ,
90
+ pub needs_allocator : Option < bool > ,
91
+ pub needs_panic_runtime : Option < bool > ,
92
+ pub no_builtins : Option < bool > ,
93
+ pub panic_runtime : Option < bool > ,
94
+ pub profiler_runtime : Option < bool > ,
95
+ pub sanitizer_runtime : Option < bool > ,
87
96
}
88
97
89
98
pub struct CStore {
@@ -187,50 +196,55 @@ impl CrateMetadata {
187
196
self . root . disambiguator
188
197
}
189
198
190
- pub fn needs_allocator ( & self , sess : & Session ) -> bool {
191
- let attrs = self . get_item_attrs ( CRATE_DEF_INDEX , sess) ;
192
- attr:: contains_name ( & attrs, "needs_allocator" )
199
+ pub fn needs_allocator ( & self ) -> bool {
200
+ self . needs_allocator . unwrap_or ( false )
193
201
}
194
202
195
203
pub fn has_global_allocator ( & self ) -> bool {
196
- self . root . has_global_allocator . clone ( )
204
+ self . root . has_global_allocator
197
205
}
198
206
199
207
pub fn has_default_lib_allocator ( & self ) -> bool {
200
- self . root . has_default_lib_allocator . clone ( )
208
+ self . root . has_default_lib_allocator
201
209
}
202
210
203
- pub fn is_panic_runtime ( & self , sess : & Session ) -> bool {
204
- let attrs = self . get_item_attrs ( CRATE_DEF_INDEX , sess) ;
205
- attr:: contains_name ( & attrs, "panic_runtime" )
211
+ pub fn is_panic_runtime ( & self ) -> bool {
212
+ self . panic_runtime . unwrap_or ( false )
206
213
}
207
214
208
- pub fn needs_panic_runtime ( & self , sess : & Session ) -> bool {
209
- let attrs = self . get_item_attrs ( CRATE_DEF_INDEX , sess) ;
210
- attr:: contains_name ( & attrs, "needs_panic_runtime" )
215
+ pub fn needs_panic_runtime ( & self ) -> bool {
216
+ self . needs_panic_runtime . unwrap_or ( false )
211
217
}
212
218
213
- pub fn is_compiler_builtins ( & self , sess : & Session ) -> bool {
214
- let attrs = self . get_item_attrs ( CRATE_DEF_INDEX , sess) ;
215
- attr:: contains_name ( & attrs, "compiler_builtins" )
219
+ pub fn is_compiler_builtins ( & self ) -> bool {
220
+ self . compiler_builtins . unwrap_or ( false )
216
221
}
217
222
218
- pub fn is_sanitizer_runtime ( & self , sess : & Session ) -> bool {
219
- let attrs = self . get_item_attrs ( CRATE_DEF_INDEX , sess) ;
220
- attr:: contains_name ( & attrs, "sanitizer_runtime" )
223
+ pub fn is_sanitizer_runtime ( & self ) -> bool {
224
+ self . sanitizer_runtime . unwrap_or ( false )
221
225
}
222
226
223
- pub fn is_profiler_runtime ( & self , sess : & Session ) -> bool {
224
- let attrs = self . get_item_attrs ( CRATE_DEF_INDEX , sess) ;
225
- attr:: contains_name ( & attrs, "profiler_runtime" )
227
+ pub fn is_profiler_runtime ( & self ) -> bool {
228
+ self . profiler_runtime . unwrap_or ( false )
226
229
}
227
230
228
- pub fn is_no_builtins ( & self , sess : & Session ) -> bool {
229
- let attrs = self . get_item_attrs ( CRATE_DEF_INDEX , sess) ;
230
- attr:: contains_name ( & attrs, "no_builtins" )
231
+ pub fn is_no_builtins ( & self ) -> bool {
232
+ self . no_builtins . unwrap_or ( false )
231
233
}
232
234
233
235
pub fn panic_strategy ( & self ) -> PanicStrategy {
234
236
self . root . panic_strategy . clone ( )
235
237
}
238
+
239
+ pub fn derive_attributes ( & mut self , sess : & Session ) {
240
+ let attrs = self . get_item_attrs ( CRATE_DEF_INDEX , sess) ;
241
+
242
+ self . compiler_builtins = Some ( attr:: contains_name ( & attrs, "compiler_builtins" ) ) ;
243
+ self . needs_allocator = Some ( attr:: contains_name ( & attrs, "needs_allocator" ) ) ;
244
+ self . needs_panic_runtime = Some ( attr:: contains_name ( & attrs, "needs_panic_runtime" ) ) ;
245
+ self . no_builtins = Some ( attr:: contains_name ( & attrs, "no_builtins" ) ) ;
246
+ self . panic_runtime = Some ( attr:: contains_name ( & attrs, "panic_runtime" ) ) ;
247
+ self . profiler_runtime = Some ( attr:: contains_name ( & attrs, "profiler_runtime" ) ) ;
248
+ self . sanitizer_runtime = Some ( attr:: contains_name ( & attrs, "sanitizer_runtime" ) ) ;
249
+ }
236
250
}
0 commit comments