Switch CrateNum queries to DefId

This commit is contained in:
Taylor Cramer 2017-06-14 22:49:07 -07:00
parent 48356987c1
commit c98ca953b0
8 changed files with 96 additions and 116 deletions

View File

@ -305,7 +305,6 @@ define_dep_nodes!(
// Represents the metadata for a given HIR node, typically found
// in an extern crate.
MetaData(DefId),
MetaDataByCrateNum(CrateNum),
// Represents some artifact that we save to disk. Note that these
// do not have a def-id as part of their identifier.

View File

@ -58,6 +58,8 @@ impl CrateNum {
pub fn as_u32(&self) -> u32 {
self.0
}
pub fn as_def_id(&self) -> DefId { DefId { krate: *self, index: CRATE_DEF_INDEX } }
}
impl fmt::Display for CrateNum {

View File

@ -172,7 +172,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if src.dylib.is_some() {
info!("adding dylib: {}", name);
add_library(sess, cnum, RequireDynamic, &mut formats);
let deps = tcx.dylib_dependency_formats(cnum);
let deps = tcx.dylib_dependency_formats(cnum.as_def_id());
for &(depnum, style) in deps.iter() {
info!("adding {:?}: {}", style,
sess.cstore.crate_name(depnum));
@ -215,9 +215,9 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// Things like allocators and panic runtimes may not have been activated
// quite yet, so do so here.
activate_injected_dep(sess.injected_allocator.get(), &mut ret,
&|cnum| tcx.is_allocator(cnum));
&|cnum| tcx.is_allocator(cnum.as_def_id()));
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
&|cnum| tcx.is_panic_runtime(cnum));
&|cnum| tcx.is_panic_runtime(cnum.as_def_id()));
// When dylib B links to dylib A, then when using B we must also link to A.
// It could be the case, however, that the rlib for A is present (hence we
@ -296,9 +296,9 @@ fn attempt_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<DependencyLis
// explicitly linked, which is the case for any injected dependency. Handle
// that here and activate them.
activate_injected_dep(sess.injected_allocator.get(), &mut ret,
&|cnum| tcx.is_allocator(cnum));
&|cnum| tcx.is_allocator(cnum.as_def_id()));
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
&|cnum| tcx.is_panic_runtime(cnum));
&|cnum| tcx.is_panic_runtime(cnum.as_def_id()));
Some(ret)
}
@ -345,7 +345,7 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
continue
}
let cnum = CrateNum::new(i + 1);
if tcx.is_allocator(cnum) {
if tcx.is_allocator(cnum.as_def_id()) {
if let Some(prev) = allocator {
let prev_name = sess.cstore.crate_name(prev);
let cur_name = sess.cstore.crate_name(cnum);
@ -356,7 +356,7 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
allocator = Some(cnum);
}
if tcx.is_panic_runtime(cnum) {
if tcx.is_panic_runtime(cnum.as_def_id()) {
if let Some((prev, _)) = panic_runtime {
let prev_name = sess.cstore.crate_name(prev);
let cur_name = sess.cstore.crate_name(cnum);

View File

@ -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.extern_crate(cnum);
let opt_extern_crate = self.extern_crate(cnum.as_def_id());
let opt_extern_crate = opt_extern_crate.and_then(|extern_crate| {
if extern_crate.direct {
Some(extern_crate.def_id)
@ -136,7 +136,7 @@ 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.extern_crate(cur_def.krate) {
match *self.extern_crate(cur_def) {
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();

View File

@ -484,25 +484,25 @@ impl<'tcx> QueryDescription for queries::is_const_fn<'tcx> {
}
impl<'tcx> QueryDescription for queries::dylib_dependency_formats<'tcx> {
fn describe(_: TyCtxt, _: CrateNum) -> String {
fn describe(_: TyCtxt, _: DefId) -> String {
"dylib dependency formats of crate".to_string()
}
}
impl<'tcx> QueryDescription for queries::is_allocator<'tcx> {
fn describe(_: TyCtxt, _: CrateNum) -> String {
fn describe(_: TyCtxt, _: DefId) -> String {
"checking if the crate is_allocator".to_string()
}
}
impl<'tcx> QueryDescription for queries::is_panic_runtime<'tcx> {
fn describe(_: TyCtxt, _: CrateNum) -> String {
fn describe(_: TyCtxt, _: DefId) -> String {
"checking if the crate is_panic_runtime".to_string()
}
}
impl<'tcx> QueryDescription for queries::extern_crate<'tcx> {
fn describe(_: TyCtxt, _: CrateNum) -> String {
fn describe(_: TyCtxt, _: DefId) -> String {
"getting crate's ExternCrateData".to_string()
}
}
@ -964,13 +964,13 @@ define_maps! { <'tcx>
[] layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
-> Result<&'tcx Layout, LayoutError<'tcx>>,
[] dylib_dependency_formats: MetaDataByCrateNum(CrateNum)
[] dylib_dependency_formats: MetaData(DefId)
-> Rc<Vec<(CrateNum, LinkagePreference)>>,
[] is_allocator: MetaDataByCrateNum(CrateNum) -> bool,
[] is_panic_runtime: MetaDataByCrateNum(CrateNum) -> bool,
[] is_allocator: MetaData(DefId) -> bool,
[] is_panic_runtime: MetaData(DefId) -> bool,
[] extern_crate: MetaDataByCrateNum(CrateNum) -> Rc<Option<ExternCrate>>,
[] extern_crate: MetaData(DefId) -> Rc<Option<ExternCrate>>,
}
fn type_param_predicates((item_id, param_id): (DefId, DefId)) -> DepConstructor {

View File

@ -40,17 +40,10 @@ use rustc::hir::svh::Svh;
use rustc::hir;
macro_rules! provide {
(<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident, $cnum:ident,
ByDefId {
$($cdata_fn_name:ident => $cdata_fn_compute:block)*
}
ByCrateNum {
$($cnum_fn_name:ident => $cnum_fn_compute:block)*
}
)=> {
(<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident, $($name:ident => $compute:block)*) => {
pub fn provide<$lt>(providers: &mut Providers<$lt>) {
$(fn $cdata_fn_name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
-> <ty::queries::$cdata_fn_name<$lt> as
$(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
-> <ty::queries::$name<$lt> as
DepTrackingMapConfig>::Value {
assert!(!$def_id.is_local());
@ -62,29 +55,18 @@ macro_rules! provide {
let $cdata = $tcx.sess.cstore.crate_data_as_rc_any($def_id.krate);
let $cdata = $cdata.downcast_ref::<cstore::CrateMetadata>()
.expect("CrateStore crated ata is not a CrateMetadata");
$cdata_fn_compute
})*
$(fn $cnum_fn_name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $cnum: CrateNum)
-> <ty::queries::$cnum_fn_name<$lt> as
DepTrackingMapConfig>::Value {
let $cdata = $tcx.sess.cstore.crate_data_as_rc_any($cnum);
let $cdata = $cdata.downcast_ref::<cstore::CrateMetadata>()
.expect("CrateStore crated ata is not a CrateMetadata");
$cnum_fn_compute
$compute
})*
*providers = Providers {
$($cdata_fn_name,)*
$($cnum_fn_name,)*
$($name,)*
..*providers
};
}
}
}
provide! { <'tcx> tcx, def_id, cdata, cnum,
ByDefId {
provide! { <'tcx> tcx, def_id, cdata,
type_of => { cdata.get_type(def_id.index, tcx) }
generics_of => { tcx.alloc_generics(cdata.get_generics(def_id.index)) }
predicates_of => { cdata.get_predicates(def_id.index, tcx) }
@ -150,14 +132,11 @@ provide! { <'tcx> tcx, def_id, cdata, cnum,
cdata.const_is_rvalue_promotable_to_static(def_id.index)
}
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
}
ByCrateNum {
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()) }
}
}
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {

View File

@ -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.extern_crate(n) {
let span = match *self.tcx.extern_crate(n.as_def_id()) {
Some(ref c) => c.span,
None => {
debug!("Skipping crate {}, no data", n);

View File

@ -92,8 +92,8 @@ impl ExportedSymbols {
// Down below we'll hardwire all of the symbols to the `Rust` export
// level instead.
let special_runtime_crate =
scx.tcx().is_allocator(cnum) ||
scx.tcx().is_panic_runtime(cnum) ||
scx.tcx().is_allocator(cnum.as_def_id()) ||
scx.tcx().is_panic_runtime(cnum.as_def_id()) ||
scx.sess().cstore.is_compiler_builtins(cnum);
let crate_exports = scx