Skip to content

Commit ece778e

Browse files
committed
Attempt to pass CrateMetadata flags on creation
1 parent 466fc68 commit ece778e

File tree

3 files changed

+39
-60
lines changed

3 files changed

+39
-60
lines changed

src/librustc_metadata/creader.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! Validates all used crates and extern libraries and loads their metadata
1212
1313
use cstore::{self, CStore, CrateSource, MetadataBlob};
14+
use decoder::Metadata;
1415
use locator::{self, CratePaths};
1516
use schema::CrateRoot;
1617
use rustc_data_structures::sync::{Lrc, RwLock, Lock};
@@ -222,13 +223,24 @@ impl<'a> CrateLoader<'a> {
222223
crate_root.def_path_table.decode((&metadata, self.sess))
223224
});
224225

226+
let crate_entry = crate_root
227+
.index
228+
.lookup(metadata.raw_bytes(), CRATE_DEF_INDEX)
229+
.unwrap()
230+
.decode(&metadata);
231+
232+
let crate_attrs: Vec<ast::Attribute> = crate_entry
233+
.attributes
234+
.decode((&metadata, self.sess))
235+
.collect();
236+
225237
let trait_impls = crate_root
226238
.impls
227239
.decode((&metadata, self.sess))
228240
.map(|trait_impls| (trait_impls.trait_id, trait_impls.impls))
229241
.collect();
230242

231-
let mut cmeta = cstore::CrateMetadata {
243+
let cmeta = cstore::CrateMetadata {
232244
name,
233245
extern_crate: Lock::new(None),
234246
def_path_table: Lrc::new(def_path_table),
@@ -248,17 +260,15 @@ impl<'a> CrateLoader<'a> {
248260
rlib,
249261
rmeta,
250262
},
251-
compiler_builtins: None,
252-
needs_allocator: None,
253-
needs_panic_runtime: None,
254-
no_builtins: None,
255-
panic_runtime: None,
256-
profiler_runtime: None,
257-
sanitizer_runtime: None,
263+
compiler_builtins: attr::contains_name(&crate_attrs, "compiler_builtins"),
264+
needs_allocator: attr::contains_name(&crate_attrs, "needs_allocator"),
265+
needs_panic_runtime: attr::contains_name(&crate_attrs, "needs_panic_runtime"),
266+
no_builtins: attr::contains_name(&crate_attrs, "no_builtins"),
267+
panic_runtime: attr::contains_name(&crate_attrs, "panic_runtime"),
268+
profiler_runtime: attr::contains_name(&crate_attrs, "profiler_runtime"),
269+
sanitizer_runtime: attr::contains_name(&crate_attrs, "sanitizer_runtime"),
258270
};
259271

260-
cmeta.derive_attributes(self.sess);
261-
262272
let cmeta = Lrc::new(cmeta);
263273
self.cstore.set_crate_data(cnum, cmeta.clone());
264274
(cnum, cmeta)
@@ -651,12 +661,12 @@ impl<'a> CrateLoader<'a> {
651661

652662
self.cstore.iter_crate_data(|cnum, data| {
653663
needs_panic_runtime = needs_panic_runtime ||
654-
data.needs_panic_runtime();
655-
if data.is_panic_runtime() {
664+
data.needs_panic_runtime;
665+
if data.panic_runtime {
656666
// Inject a dependency from all #![needs_panic_runtime] to this
657667
// #![panic_runtime] crate.
658668
self.inject_dependency_if(cnum, "a panic runtime",
659-
&|data| data.needs_panic_runtime());
669+
&|data| data.needs_panic_runtime);
660670
runtime_found = runtime_found || *data.dep_kind.lock() == DepKind::Explicit;
661671
}
662672
});
@@ -693,7 +703,7 @@ impl<'a> CrateLoader<'a> {
693703

694704
// Sanity check the loaded crate to ensure it is indeed a panic runtime
695705
// and the panic strategy is indeed what we thought it was.
696-
if !data.is_panic_runtime() {
706+
if !data.panic_runtime {
697707
self.sess.err(&format!("the crate `{}` is not a panic runtime",
698708
name));
699709
}
@@ -705,7 +715,7 @@ impl<'a> CrateLoader<'a> {
705715

706716
self.sess.injected_panic_runtime.set(Some(cnum));
707717
self.inject_dependency_if(cnum, "a panic runtime",
708-
&|data| data.needs_panic_runtime());
718+
&|data| data.needs_panic_runtime);
709719
}
710720

711721
fn inject_sanitizer_runtime(&mut self) {
@@ -800,7 +810,7 @@ impl<'a> CrateLoader<'a> {
800810
PathKind::Crate, dep_kind);
801811

802812
// Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
803-
if !data.is_sanitizer_runtime() {
813+
if !data.sanitizer_runtime {
804814
self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
805815
name));
806816
}
@@ -823,7 +833,7 @@ impl<'a> CrateLoader<'a> {
823833
PathKind::Crate, dep_kind);
824834

825835
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
826-
if !data.is_profiler_runtime() {
836+
if !data.profiler_runtime {
827837
self.sess.err(&format!("the crate `profiler_builtins` is not \
828838
a profiler runtime"));
829839
}
@@ -840,7 +850,7 @@ impl<'a> CrateLoader<'a> {
840850
let mut needs_allocator = attr::contains_name(&krate.attrs,
841851
"needs_allocator");
842852
self.cstore.iter_crate_data(|_, data| {
843-
needs_allocator = needs_allocator || data.needs_allocator();
853+
needs_allocator = needs_allocator || data.needs_allocator;
844854
});
845855
if !needs_allocator {
846856
self.sess.injected_allocator.set(None);

src/librustc_metadata/cstore.rs

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
use schema;
1515

16-
use rustc::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex};
16+
use rustc::hir::def_id::{CrateNum, DefIndex};
1717
use rustc::hir::map::definitions::DefPathTable;
1818
use rustc::hir::svh::Svh;
1919
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
20-
use rustc::session::{CrateDisambiguator, Session};
20+
use rustc::session::CrateDisambiguator;
2121
use rustc_target::spec::PanicStrategy;
2222
use rustc_data_structures::indexed_vec::IndexVec;
2323
use rustc::util::nodemap::{FxHashMap, NodeMap};
@@ -87,13 +87,13 @@ pub struct CrateMetadata {
8787
pub proc_macros: Option<Vec<(ast::Name, Lrc<SyntaxExtension>)>>,
8888

8989
// Booleans derived from attributes
90-
pub compiler_builtins: Option<bool>,
91-
pub needs_allocator: Option<bool>,
92-
pub needs_panic_runtime: Option<bool>,
93-
pub no_builtins: Option<bool>,
94-
pub panic_runtime: Option<bool>,
95-
pub profiler_runtime: Option<bool>,
96-
pub sanitizer_runtime: Option<bool>,
90+
pub compiler_builtins: bool,
91+
pub needs_allocator: bool,
92+
pub needs_panic_runtime: bool,
93+
pub no_builtins: bool,
94+
pub panic_runtime: bool,
95+
pub profiler_runtime: bool,
96+
pub sanitizer_runtime: bool,
9797
}
9898

9999
pub struct CStore {
@@ -190,17 +190,15 @@ impl CrateMetadata {
190190
pub fn name(&self) -> Symbol {
191191
self.root.name
192192
}
193+
193194
pub fn hash(&self) -> Svh {
194195
self.root.hash
195196
}
197+
196198
pub fn disambiguator(&self) -> CrateDisambiguator {
197199
self.root.disambiguator
198200
}
199201

200-
pub fn needs_allocator(&self) -> bool {
201-
self.needs_allocator.unwrap_or(false)
202-
}
203-
204202
pub fn has_global_allocator(&self) -> bool {
205203
self.root.has_global_allocator
206204
}
@@ -209,30 +207,6 @@ impl CrateMetadata {
209207
self.root.has_default_lib_allocator
210208
}
211209

212-
pub fn is_panic_runtime(&self) -> bool {
213-
self.panic_runtime.unwrap_or(false)
214-
}
215-
216-
pub fn needs_panic_runtime(&self) -> bool {
217-
self.needs_panic_runtime.unwrap_or(false)
218-
}
219-
220-
pub fn is_compiler_builtins(&self) -> bool {
221-
self.compiler_builtins.unwrap_or(false)
222-
}
223-
224-
pub fn is_sanitizer_runtime(&self) -> bool {
225-
self.sanitizer_runtime.unwrap_or(false)
226-
}
227-
228-
pub fn is_profiler_runtime(&self) -> bool {
229-
self.profiler_runtime.unwrap_or(false)
230-
}
231-
232-
pub fn is_no_builtins(&self) -> bool {
233-
self.no_builtins.unwrap_or(false)
234-
}
235-
236210
pub fn panic_strategy(&self) -> PanicStrategy {
237211
self.root.panic_strategy.clone()
238212
}

src/librustc_metadata/cstore_impl.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,12 @@ provide! { <'tcx> tcx, def_id, other, cdata,
170170
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
171171

172172
dylib_dependency_formats => { Lrc::new(cdata.get_dylib_dependency_formats()) }
173-
is_panic_runtime => { cdata.is_panic_runtime() }
174-
is_compiler_builtins => { cdata.is_compiler_builtins() }
175173
has_global_allocator => { cdata.has_global_allocator() }
176-
is_sanitizer_runtime => { cdata.is_sanitizer_runtime() }
177-
is_profiler_runtime => { cdata.is_profiler_runtime() }
178174
panic_strategy => { cdata.panic_strategy() }
179175
extern_crate => {
180176
let r = Lrc::new(*cdata.extern_crate.lock());
181177
r
182178
}
183-
is_no_builtins => { cdata.is_no_builtins() }
184179
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
185180
reachable_non_generics => {
186181
let reachable_non_generics = tcx

0 commit comments

Comments
 (0)