On-demandify extern_crate

This commit is contained in:
Taylor Cramer 2017-06-12 00:59:22 -07:00
parent b0f05d4bc5
commit 48356987c1
5 changed files with 15 additions and 13 deletions

View File

@ -254,7 +254,6 @@ pub trait CrateStore {
fn is_compiler_builtins(&self, cnum: CrateNum) -> bool; fn is_compiler_builtins(&self, cnum: CrateNum) -> bool;
fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool; fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool;
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy; 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 /// The name of the crate as it is referred to in source code of the current
/// crate. /// crate.
fn crate_name(&self, cnum: CrateNum) -> Symbol; fn crate_name(&self, cnum: CrateNum) -> Symbol;
@ -374,7 +373,6 @@ fn is_sanitizer_runtime(&self, cnum: CrateNum) -> bool { bug!("is_sanitizer_runt
fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy { fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {
bug!("panic_strategy") 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 crate_name(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
fn original_crate_name(&self, cnum: CrateNum) -> Symbol { fn original_crate_name(&self, cnum: CrateNum) -> Symbol {
bug!("original_crate_name") bug!("original_crate_name")

View File

@ -100,7 +100,7 @@ pub fn push_krate_path<T>(self, buffer: &mut T, cnum: CrateNum)
// //
// Returns `None` for the local crate. // Returns `None` for the local crate.
if cnum != 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| { let opt_extern_crate = opt_extern_crate.and_then(|extern_crate| {
if extern_crate.direct { if extern_crate.direct {
Some(extern_crate.def_id) Some(extern_crate.def_id)
@ -136,8 +136,8 @@ pub fn try_push_visible_item_path<T>(self, buffer: &mut T, external_def_id: DefI
// If `cur_def` is a direct or injected extern crate, push the path to the crate // 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. // followed by the path to the item within the crate and return.
if cur_def.index == CRATE_DEF_INDEX { if cur_def.index == CRATE_DEF_INDEX {
match self.sess.cstore.extern_crate(cur_def.krate) { match *self.extern_crate(cur_def.krate) {
Some(extern_crate) if extern_crate.direct => { Some(ref extern_crate) if extern_crate.direct => {
self.push_item_path(buffer, extern_crate.def_id); self.push_item_path(buffer, extern_crate.def_id);
cur_path.iter().rev().map(|segment| buffer.push(&segment.as_str())).count(); cur_path.iter().rev().map(|segment| buffer.push(&segment.as_str())).count();
return true; return true;

View File

@ -13,7 +13,7 @@
use hir::def::Def; use hir::def::Def;
use hir; use hir;
use middle::const_val; use middle::const_val;
use middle::cstore::LinkagePreference; use middle::cstore::{ExternCrate, LinkagePreference};
use middle::privacy::AccessLevels; use middle::privacy::AccessLevels;
use middle::region::RegionMaps; use middle::region::RegionMaps;
use mir; use mir;
@ -501,6 +501,12 @@ fn describe(_: TyCtxt, _: CrateNum) -> String {
} }
} }
impl<'tcx> QueryDescription for queries::extern_crate<'tcx> {
fn describe(_: TyCtxt, _: CrateNum) -> String {
"getting crate's ExternCrateData".to_string()
}
}
macro_rules! define_maps { macro_rules! define_maps {
(<$tcx:tt> (<$tcx:tt>
$($(#[$attr:meta])* $($(#[$attr:meta])*
@ -963,6 +969,8 @@ fn default() -> Self {
[] is_allocator: MetaDataByCrateNum(CrateNum) -> bool, [] is_allocator: MetaDataByCrateNum(CrateNum) -> bool,
[] is_panic_runtime: 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 { fn type_param_predicates((item_id, param_id): (DefId, DefId)) -> DepConstructor {

View File

@ -14,7 +14,7 @@
use rustc::dep_graph::DepTrackingMapConfig; use rustc::dep_graph::DepTrackingMapConfig;
use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind, use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind,
ExternCrate, NativeLibrary, MetadataLoader, LinkMeta, NativeLibrary, MetadataLoader, LinkMeta,
LinkagePreference, LoadedMacro, EncodedMetadata}; LinkagePreference, LoadedMacro, EncodedMetadata};
use rustc::hir::def; use rustc::hir::def;
use rustc::middle::lang_items; use rustc::middle::lang_items;
@ -156,6 +156,7 @@ pub fn provide<$lt>(providers: &mut Providers<$lt>) {
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats(&tcx.dep_graph)) } dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats(&tcx.dep_graph)) }
is_allocator => { cdata.is_allocator(&tcx.dep_graph) } is_allocator => { cdata.is_allocator(&tcx.dep_graph) }
is_panic_runtime => { cdata.is_panic_runtime(&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 @@ fn original_crate_name(&self, cnum: CrateNum) -> Symbol
self.get_crate_data(cnum).name() 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 fn crate_hash(&self, cnum: CrateNum) -> Svh
{ {
self.get_crate_hash(cnum) self.get_crate_hash(cnum)

View File

@ -107,7 +107,7 @@ pub fn get_external_crates(&self) -> Vec<CrateData> {
let mut result = Vec::new(); let mut result = Vec::new();
for n in self.tcx.sess.cstore.crates() { 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, Some(ref c) => c.span,
None => { None => {
debug!("Skipping crate {}, no data", n); debug!("Skipping crate {}, no data", n);