Switch CrateNum queries to DefId
This commit is contained in:
parent
48356987c1
commit
c98ca953b0
@ -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.
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
@ -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,102 +55,88 @@ 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 {
|
||||
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) }
|
||||
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
|
||||
trait_def => {
|
||||
tcx.alloc_trait_def(cdata.get_trait_def(def_id.index))
|
||||
}
|
||||
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
|
||||
adt_destructor => {
|
||||
let _ = cdata;
|
||||
tcx.calculate_dtor(def_id, &mut |_,_| Ok(()))
|
||||
}
|
||||
variances_of => { Rc::new(cdata.get_item_variances(def_id.index)) }
|
||||
associated_item_def_ids => {
|
||||
let mut result = vec![];
|
||||
cdata.each_child_of_item(def_id.index,
|
||||
|child| result.push(child.def.def_id()), tcx.sess);
|
||||
Rc::new(result)
|
||||
}
|
||||
associated_item => { cdata.get_associated_item(def_id.index) }
|
||||
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
|
||||
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
|
||||
coerce_unsized_info => {
|
||||
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
|
||||
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
|
||||
})
|
||||
}
|
||||
optimized_mir => {
|
||||
let mir = cdata.maybe_get_optimized_mir(tcx, def_id.index).unwrap_or_else(|| {
|
||||
bug!("get_optimized_mir: missing MIR for `{:?}`", def_id)
|
||||
});
|
||||
|
||||
let mir = tcx.alloc_mir(mir);
|
||||
|
||||
mir
|
||||
}
|
||||
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
|
||||
typeck_tables_of => { cdata.item_body_tables(def_id.index, tcx) }
|
||||
closure_kind => { cdata.closure_kind(def_id.index) }
|
||||
closure_type => { cdata.closure_ty(def_id.index, tcx) }
|
||||
inherent_impls => { Rc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
|
||||
is_const_fn => { cdata.is_const_fn(def_id.index) }
|
||||
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
||||
is_default_impl => { cdata.is_default_impl(def_id.index) }
|
||||
describe_def => { cdata.get_def(def_id.index) }
|
||||
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
|
||||
stability => { cdata.get_stability(def_id.index) }
|
||||
deprecation => { cdata.get_deprecation(def_id.index) }
|
||||
item_attrs => { cdata.get_item_attrs(def_id.index, &tcx.dep_graph) }
|
||||
// FIXME(#38501) We've skipped a `read` on the `HirBody` of
|
||||
// a `fn` when encoding, so the dep-tracking wouldn't work.
|
||||
// This is only used by rustdoc anyway, which shouldn't have
|
||||
// incremental recompilation ever enabled.
|
||||
fn_arg_names => { cdata.get_fn_arg_names(def_id.index) }
|
||||
impl_parent => { cdata.get_parent_impl(def_id.index) }
|
||||
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
|
||||
is_exported_symbol => {
|
||||
let dep_node = cdata.metadata_dep_node(GlobalMetaDataKind::ExportedSymbols);
|
||||
cdata.exported_symbols.get(&tcx.dep_graph, dep_node).contains(&def_id.index)
|
||||
}
|
||||
item_body_nested_bodies => { Rc::new(cdata.item_body_nested_bodies(def_id.index)) }
|
||||
const_is_rvalue_promotable_to_static => {
|
||||
cdata.const_is_rvalue_promotable_to_static(def_id.index)
|
||||
}
|
||||
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
|
||||
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) }
|
||||
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
|
||||
trait_def => {
|
||||
tcx.alloc_trait_def(cdata.get_trait_def(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()) }
|
||||
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
|
||||
adt_destructor => {
|
||||
let _ = cdata;
|
||||
tcx.calculate_dtor(def_id, &mut |_,_| Ok(()))
|
||||
}
|
||||
variances_of => { Rc::new(cdata.get_item_variances(def_id.index)) }
|
||||
associated_item_def_ids => {
|
||||
let mut result = vec![];
|
||||
cdata.each_child_of_item(def_id.index,
|
||||
|child| result.push(child.def.def_id()), tcx.sess);
|
||||
Rc::new(result)
|
||||
}
|
||||
associated_item => { cdata.get_associated_item(def_id.index) }
|
||||
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
|
||||
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
|
||||
coerce_unsized_info => {
|
||||
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
|
||||
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
|
||||
})
|
||||
}
|
||||
optimized_mir => {
|
||||
let mir = cdata.maybe_get_optimized_mir(tcx, def_id.index).unwrap_or_else(|| {
|
||||
bug!("get_optimized_mir: missing MIR for `{:?}`", def_id)
|
||||
});
|
||||
|
||||
let mir = tcx.alloc_mir(mir);
|
||||
|
||||
mir
|
||||
}
|
||||
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
|
||||
typeck_tables_of => { cdata.item_body_tables(def_id.index, tcx) }
|
||||
closure_kind => { cdata.closure_kind(def_id.index) }
|
||||
closure_type => { cdata.closure_ty(def_id.index, tcx) }
|
||||
inherent_impls => { Rc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
|
||||
is_const_fn => { cdata.is_const_fn(def_id.index) }
|
||||
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
|
||||
is_default_impl => { cdata.is_default_impl(def_id.index) }
|
||||
describe_def => { cdata.get_def(def_id.index) }
|
||||
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
|
||||
stability => { cdata.get_stability(def_id.index) }
|
||||
deprecation => { cdata.get_deprecation(def_id.index) }
|
||||
item_attrs => { cdata.get_item_attrs(def_id.index, &tcx.dep_graph) }
|
||||
// FIXME(#38501) We've skipped a `read` on the `HirBody` of
|
||||
// a `fn` when encoding, so the dep-tracking wouldn't work.
|
||||
// This is only used by rustdoc anyway, which shouldn't have
|
||||
// incremental recompilation ever enabled.
|
||||
fn_arg_names => { cdata.get_fn_arg_names(def_id.index) }
|
||||
impl_parent => { cdata.get_parent_impl(def_id.index) }
|
||||
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
|
||||
is_exported_symbol => {
|
||||
let dep_node = cdata.metadata_dep_node(GlobalMetaDataKind::ExportedSymbols);
|
||||
cdata.exported_symbols.get(&tcx.dep_graph, dep_node).contains(&def_id.index)
|
||||
}
|
||||
item_body_nested_bodies => { Rc::new(cdata.item_body_nested_bodies(def_id.index)) }
|
||||
const_is_rvalue_promotable_to_static => {
|
||||
cdata.const_is_rvalue_promotable_to_static(def_id.index)
|
||||
}
|
||||
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
|
||||
|
||||
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>) {
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user