mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
On-demandify extern_crate
This commit is contained in:
parent
b0f05d4bc5
commit
48356987c1
@ -254,7 +254,6 @@ pub trait CrateStore {
|
||||
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool;
|
||||
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool;
|
||||
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy;
|
||||
fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate>;
|
||||
/// The name of the crate as it is referred to in source code of the current
|
||||
/// crate.
|
||||
fn crate_name(&self, cnum: CrateNum) -> Symbol;
|
||||
@ -374,7 +373,6 @@ impl CrateStore for DummyCrateStore {
|
||||
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {
|
||||
bug!("panic_strategy")
|
||||
}
|
||||
fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate> { bug!("extern_crate") }
|
||||
fn crate_name(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
|
||||
fn original_crate_name(&self, cnum: CrateNum) -> Symbol {
|
||||
bug!("original_crate_name")
|
||||
|
@ -100,7 +100,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
//
|
||||
// Returns `None` for the local crate.
|
||||
if cnum != LOCAL_CRATE {
|
||||
let opt_extern_crate = self.sess.cstore.extern_crate(cnum);
|
||||
let opt_extern_crate = self.extern_crate(cnum);
|
||||
let opt_extern_crate = opt_extern_crate.and_then(|extern_crate| {
|
||||
if extern_crate.direct {
|
||||
Some(extern_crate.def_id)
|
||||
@ -136,8 +136,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
// If `cur_def` is a direct or injected extern crate, push the path to the crate
|
||||
// followed by the path to the item within the crate and return.
|
||||
if cur_def.index == CRATE_DEF_INDEX {
|
||||
match self.sess.cstore.extern_crate(cur_def.krate) {
|
||||
Some(extern_crate) if extern_crate.direct => {
|
||||
match *self.extern_crate(cur_def.krate) {
|
||||
Some(ref extern_crate) if extern_crate.direct => {
|
||||
self.push_item_path(buffer, extern_crate.def_id);
|
||||
cur_path.iter().rev().map(|segment| buffer.push(&segment.as_str())).count();
|
||||
return true;
|
||||
|
@ -13,7 +13,7 @@ use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
|
||||
use hir::def::Def;
|
||||
use hir;
|
||||
use middle::const_val;
|
||||
use middle::cstore::LinkagePreference;
|
||||
use middle::cstore::{ExternCrate, LinkagePreference};
|
||||
use middle::privacy::AccessLevels;
|
||||
use middle::region::RegionMaps;
|
||||
use mir;
|
||||
@ -501,6 +501,12 @@ impl<'tcx> QueryDescription for queries::is_panic_runtime<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> QueryDescription for queries::extern_crate<'tcx> {
|
||||
fn describe(_: TyCtxt, _: CrateNum) -> String {
|
||||
"getting crate's ExternCrateData".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! define_maps {
|
||||
(<$tcx:tt>
|
||||
$($(#[$attr:meta])*
|
||||
@ -963,6 +969,8 @@ define_maps! { <'tcx>
|
||||
|
||||
[] is_allocator: MetaDataByCrateNum(CrateNum) -> bool,
|
||||
[] is_panic_runtime: MetaDataByCrateNum(CrateNum) -> bool,
|
||||
|
||||
[] extern_crate: MetaDataByCrateNum(CrateNum) -> Rc<Option<ExternCrate>>,
|
||||
}
|
||||
|
||||
fn type_param_predicates((item_id, param_id): (DefId, DefId)) -> DepConstructor {
|
||||
|
@ -14,7 +14,7 @@ use schema;
|
||||
|
||||
use rustc::dep_graph::DepTrackingMapConfig;
|
||||
use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind,
|
||||
ExternCrate, NativeLibrary, MetadataLoader, LinkMeta,
|
||||
NativeLibrary, MetadataLoader, LinkMeta,
|
||||
LinkagePreference, LoadedMacro, EncodedMetadata};
|
||||
use rustc::hir::def;
|
||||
use rustc::middle::lang_items;
|
||||
@ -156,6 +156,7 @@ provide! { <'tcx> tcx, def_id, cdata, cnum,
|
||||
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats(&tcx.dep_graph)) }
|
||||
is_allocator => { cdata.is_allocator(&tcx.dep_graph) }
|
||||
is_panic_runtime => { cdata.is_panic_runtime(&tcx.dep_graph) }
|
||||
extern_crate => { Rc::new(cdata.extern_crate.get()) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,11 +284,6 @@ impl CrateStore for cstore::CStore {
|
||||
self.get_crate_data(cnum).name()
|
||||
}
|
||||
|
||||
fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate>
|
||||
{
|
||||
self.get_crate_data(cnum).extern_crate.get()
|
||||
}
|
||||
|
||||
fn crate_hash(&self, cnum: CrateNum) -> Svh
|
||||
{
|
||||
self.get_crate_hash(cnum)
|
||||
|
@ -107,7 +107,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||
let mut result = Vec::new();
|
||||
|
||||
for n in self.tcx.sess.cstore.crates() {
|
||||
let span = match self.tcx.sess.cstore.extern_crate(n) {
|
||||
let span = match *self.tcx.extern_crate(n) {
|
||||
Some(ref c) => c.span,
|
||||
None => {
|
||||
debug!("Skipping crate {}, no data", n);
|
||||
|
Loading…
Reference in New Issue
Block a user