Skip to content

Commit c98ca95

Browse files
committed
Switch CrateNum queries to DefId
1 parent 4835698 commit c98ca95

File tree

8 files changed

+96
-116
lines changed

8 files changed

+96
-116
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ define_dep_nodes!(
305305
// Represents the metadata for a given HIR node, typically found
306306
// in an extern crate.
307307
MetaData(DefId),
308-
MetaDataByCrateNum(CrateNum),
309308

310309
// Represents some artifact that we save to disk. Note that these
311310
// do not have a def-id as part of their identifier.

src/librustc/hir/def_id.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ impl CrateNum {
5858
pub fn as_u32(&self) -> u32 {
5959
self.0
6060
}
61+
62+
pub fn as_def_id(&self) -> DefId { DefId { krate: *self, index: CRATE_DEF_INDEX } }
6163
}
6264

6365
impl fmt::Display for CrateNum {

src/librustc/middle/dependency_format.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
172172
if src.dylib.is_some() {
173173
info!("adding dylib: {}", name);
174174
add_library(sess, cnum, RequireDynamic, &mut formats);
175-
let deps = tcx.dylib_dependency_formats(cnum);
175+
let deps = tcx.dylib_dependency_formats(cnum.as_def_id());
176176
for &(depnum, style) in deps.iter() {
177177
info!("adding {:?}: {}", style,
178178
sess.cstore.crate_name(depnum));
@@ -215,9 +215,9 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
215215
// Things like allocators and panic runtimes may not have been activated
216216
// quite yet, so do so here.
217217
activate_injected_dep(sess.injected_allocator.get(), &mut ret,
218-
&|cnum| tcx.is_allocator(cnum));
218+
&|cnum| tcx.is_allocator(cnum.as_def_id()));
219219
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
220-
&|cnum| tcx.is_panic_runtime(cnum));
220+
&|cnum| tcx.is_panic_runtime(cnum.as_def_id()));
221221

222222
// When dylib B links to dylib A, then when using B we must also link to A.
223223
// 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
296296
// explicitly linked, which is the case for any injected dependency. Handle
297297
// that here and activate them.
298298
activate_injected_dep(sess.injected_allocator.get(), &mut ret,
299-
&|cnum| tcx.is_allocator(cnum));
299+
&|cnum| tcx.is_allocator(cnum.as_def_id()));
300300
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
301-
&|cnum| tcx.is_panic_runtime(cnum));
301+
&|cnum| tcx.is_panic_runtime(cnum.as_def_id()));
302302

303303
Some(ret)
304304
}
@@ -345,7 +345,7 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
345345
continue
346346
}
347347
let cnum = CrateNum::new(i + 1);
348-
if tcx.is_allocator(cnum) {
348+
if tcx.is_allocator(cnum.as_def_id()) {
349349
if let Some(prev) = allocator {
350350
let prev_name = sess.cstore.crate_name(prev);
351351
let cur_name = sess.cstore.crate_name(cnum);
@@ -356,7 +356,7 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
356356
allocator = Some(cnum);
357357
}
358358

359-
if tcx.is_panic_runtime(cnum) {
359+
if tcx.is_panic_runtime(cnum.as_def_id()) {
360360
if let Some((prev, _)) = panic_runtime {
361361
let prev_name = sess.cstore.crate_name(prev);
362362
let cur_name = sess.cstore.crate_name(cnum);

src/librustc/ty/item_path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
100100
//
101101
// Returns `None` for the local crate.
102102
if cnum != LOCAL_CRATE {
103-
let opt_extern_crate = self.extern_crate(cnum);
103+
let opt_extern_crate = self.extern_crate(cnum.as_def_id());
104104
let opt_extern_crate = opt_extern_crate.and_then(|extern_crate| {
105105
if extern_crate.direct {
106106
Some(extern_crate.def_id)
@@ -136,7 +136,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
136136
// If `cur_def` is a direct or injected extern crate, push the path to the crate
137137
// followed by the path to the item within the crate and return.
138138
if cur_def.index == CRATE_DEF_INDEX {
139-
match *self.extern_crate(cur_def.krate) {
139+
match *self.extern_crate(cur_def) {
140140
Some(ref extern_crate) if extern_crate.direct => {
141141
self.push_item_path(buffer, extern_crate.def_id);
142142
cur_path.iter().rev().map(|segment| buffer.push(&segment.as_str())).count();

src/librustc/ty/maps.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,25 +484,25 @@ impl<'tcx> QueryDescription for queries::is_const_fn<'tcx> {
484484
}
485485

486486
impl<'tcx> QueryDescription for queries::dylib_dependency_formats<'tcx> {
487-
fn describe(_: TyCtxt, _: CrateNum) -> String {
487+
fn describe(_: TyCtxt, _: DefId) -> String {
488488
"dylib dependency formats of crate".to_string()
489489
}
490490
}
491491

492492
impl<'tcx> QueryDescription for queries::is_allocator<'tcx> {
493-
fn describe(_: TyCtxt, _: CrateNum) -> String {
493+
fn describe(_: TyCtxt, _: DefId) -> String {
494494
"checking if the crate is_allocator".to_string()
495495
}
496496
}
497497

498498
impl<'tcx> QueryDescription for queries::is_panic_runtime<'tcx> {
499-
fn describe(_: TyCtxt, _: CrateNum) -> String {
499+
fn describe(_: TyCtxt, _: DefId) -> String {
500500
"checking if the crate is_panic_runtime".to_string()
501501
}
502502
}
503503

504504
impl<'tcx> QueryDescription for queries::extern_crate<'tcx> {
505-
fn describe(_: TyCtxt, _: CrateNum) -> String {
505+
fn describe(_: TyCtxt, _: DefId) -> String {
506506
"getting crate's ExternCrateData".to_string()
507507
}
508508
}
@@ -964,13 +964,13 @@ define_maps! { <'tcx>
964964
[] layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
965965
-> Result<&'tcx Layout, LayoutError<'tcx>>,
966966

967-
[] dylib_dependency_formats: MetaDataByCrateNum(CrateNum)
967+
[] dylib_dependency_formats: MetaData(DefId)
968968
-> Rc<Vec<(CrateNum, LinkagePreference)>>,
969969

970-
[] is_allocator: MetaDataByCrateNum(CrateNum) -> bool,
971-
[] is_panic_runtime: MetaDataByCrateNum(CrateNum) -> bool,
970+
[] is_allocator: MetaData(DefId) -> bool,
971+
[] is_panic_runtime: MetaData(DefId) -> bool,
972972

973-
[] extern_crate: MetaDataByCrateNum(CrateNum) -> Rc<Option<ExternCrate>>,
973+
[] extern_crate: MetaData(DefId) -> Rc<Option<ExternCrate>>,
974974
}
975975

976976
fn type_param_predicates((item_id, param_id): (DefId, DefId)) -> DepConstructor {

src/librustc_metadata/cstore_impl.rs

Lines changed: 74 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,10 @@ use rustc::hir::svh::Svh;
4040
use rustc::hir;
4141

4242
macro_rules! provide {
43-
(<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident, $cnum:ident,
44-
ByDefId {
45-
$($cdata_fn_name:ident => $cdata_fn_compute:block)*
46-
}
47-
ByCrateNum {
48-
$($cnum_fn_name:ident => $cnum_fn_compute:block)*
49-
}
50-
)=> {
43+
(<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident, $($name:ident => $compute:block)*) => {
5144
pub fn provide<$lt>(providers: &mut Providers<$lt>) {
52-
$(fn $cdata_fn_name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
53-
-> <ty::queries::$cdata_fn_name<$lt> as
45+
$(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
46+
-> <ty::queries::$name<$lt> as
5447
DepTrackingMapConfig>::Value {
5548
assert!(!$def_id.is_local());
5649

@@ -62,102 +55,88 @@ macro_rules! provide {
6255
let $cdata = $tcx.sess.cstore.crate_data_as_rc_any($def_id.krate);
6356
let $cdata = $cdata.downcast_ref::<cstore::CrateMetadata>()
6457
.expect("CrateStore crated ata is not a CrateMetadata");
65-
$cdata_fn_compute
66-
})*
67-
68-
$(fn $cnum_fn_name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $cnum: CrateNum)
69-
-> <ty::queries::$cnum_fn_name<$lt> as
70-
DepTrackingMapConfig>::Value {
71-
let $cdata = $tcx.sess.cstore.crate_data_as_rc_any($cnum);
72-
let $cdata = $cdata.downcast_ref::<cstore::CrateMetadata>()
73-
.expect("CrateStore crated ata is not a CrateMetadata");
74-
$cnum_fn_compute
58+
$compute
7559
})*
7660

7761
*providers = Providers {
78-
$($cdata_fn_name,)*
79-
$($cnum_fn_name,)*
62+
$($name,)*
8063
..*providers
8164
};
8265
}
8366
}
8467
}
8568

86-
provide! { <'tcx> tcx, def_id, cdata, cnum,
87-
ByDefId {
88-
type_of => { cdata.get_type(def_id.index, tcx) }
89-
generics_of => { tcx.alloc_generics(cdata.get_generics(def_id.index)) }
90-
predicates_of => { cdata.get_predicates(def_id.index, tcx) }
91-
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
92-
trait_def => {
93-
tcx.alloc_trait_def(cdata.get_trait_def(def_id.index))
94-
}
95-
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
96-
adt_destructor => {
97-
let _ = cdata;
98-
tcx.calculate_dtor(def_id, &mut |_,_| Ok(()))
99-
}
100-
variances_of => { Rc::new(cdata.get_item_variances(def_id.index)) }
101-
associated_item_def_ids => {
102-
let mut result = vec![];
103-
cdata.each_child_of_item(def_id.index,
104-
|child| result.push(child.def.def_id()), tcx.sess);
105-
Rc::new(result)
106-
}
107-
associated_item => { cdata.get_associated_item(def_id.index) }
108-
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
109-
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
110-
coerce_unsized_info => {
111-
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
112-
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
113-
})
114-
}
115-
optimized_mir => {
116-
let mir = cdata.maybe_get_optimized_mir(tcx, def_id.index).unwrap_or_else(|| {
117-
bug!("get_optimized_mir: missing MIR for `{:?}`", def_id)
118-
});
119-
120-
let mir = tcx.alloc_mir(mir);
121-
122-
mir
123-
}
124-
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
125-
typeck_tables_of => { cdata.item_body_tables(def_id.index, tcx) }
126-
closure_kind => { cdata.closure_kind(def_id.index) }
127-
closure_type => { cdata.closure_ty(def_id.index, tcx) }
128-
inherent_impls => { Rc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
129-
is_const_fn => { cdata.is_const_fn(def_id.index) }
130-
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
131-
is_default_impl => { cdata.is_default_impl(def_id.index) }
132-
describe_def => { cdata.get_def(def_id.index) }
133-
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
134-
stability => { cdata.get_stability(def_id.index) }
135-
deprecation => { cdata.get_deprecation(def_id.index) }
136-
item_attrs => { cdata.get_item_attrs(def_id.index, &tcx.dep_graph) }
137-
// FIXME(#38501) We've skipped a `read` on the `HirBody` of
138-
// a `fn` when encoding, so the dep-tracking wouldn't work.
139-
// This is only used by rustdoc anyway, which shouldn't have
140-
// incremental recompilation ever enabled.
141-
fn_arg_names => { cdata.get_fn_arg_names(def_id.index) }
142-
impl_parent => { cdata.get_parent_impl(def_id.index) }
143-
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
144-
is_exported_symbol => {
145-
let dep_node = cdata.metadata_dep_node(GlobalMetaDataKind::ExportedSymbols);
146-
cdata.exported_symbols.get(&tcx.dep_graph, dep_node).contains(&def_id.index)
147-
}
148-
item_body_nested_bodies => { Rc::new(cdata.item_body_nested_bodies(def_id.index)) }
149-
const_is_rvalue_promotable_to_static => {
150-
cdata.const_is_rvalue_promotable_to_static(def_id.index)
151-
}
152-
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
69+
provide! { <'tcx> tcx, def_id, cdata,
70+
type_of => { cdata.get_type(def_id.index, tcx) }
71+
generics_of => { tcx.alloc_generics(cdata.get_generics(def_id.index)) }
72+
predicates_of => { cdata.get_predicates(def_id.index, tcx) }
73+
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
74+
trait_def => {
75+
tcx.alloc_trait_def(cdata.get_trait_def(def_id.index))
76+
}
77+
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
78+
adt_destructor => {
79+
let _ = cdata;
80+
tcx.calculate_dtor(def_id, &mut |_,_| Ok(()))
81+
}
82+
variances_of => { Rc::new(cdata.get_item_variances(def_id.index)) }
83+
associated_item_def_ids => {
84+
let mut result = vec![];
85+
cdata.each_child_of_item(def_id.index,
86+
|child| result.push(child.def.def_id()), tcx.sess);
87+
Rc::new(result)
88+
}
89+
associated_item => { cdata.get_associated_item(def_id.index) }
90+
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
91+
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
92+
coerce_unsized_info => {
93+
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
94+
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
95+
})
15396
}
97+
optimized_mir => {
98+
let mir = cdata.maybe_get_optimized_mir(tcx, def_id.index).unwrap_or_else(|| {
99+
bug!("get_optimized_mir: missing MIR for `{:?}`", def_id)
100+
});
154101

155-
ByCrateNum {
156-
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats(&tcx.dep_graph)) }
157-
is_allocator => { cdata.is_allocator(&tcx.dep_graph) }
158-
is_panic_runtime => { cdata.is_panic_runtime(&tcx.dep_graph) }
159-
extern_crate => { Rc::new(cdata.extern_crate.get()) }
160-
}
102+
let mir = tcx.alloc_mir(mir);
103+
104+
mir
105+
}
106+
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
107+
typeck_tables_of => { cdata.item_body_tables(def_id.index, tcx) }
108+
closure_kind => { cdata.closure_kind(def_id.index) }
109+
closure_type => { cdata.closure_ty(def_id.index, tcx) }
110+
inherent_impls => { Rc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
111+
is_const_fn => { cdata.is_const_fn(def_id.index) }
112+
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
113+
is_default_impl => { cdata.is_default_impl(def_id.index) }
114+
describe_def => { cdata.get_def(def_id.index) }
115+
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
116+
stability => { cdata.get_stability(def_id.index) }
117+
deprecation => { cdata.get_deprecation(def_id.index) }
118+
item_attrs => { cdata.get_item_attrs(def_id.index, &tcx.dep_graph) }
119+
// FIXME(#38501) We've skipped a `read` on the `HirBody` of
120+
// a `fn` when encoding, so the dep-tracking wouldn't work.
121+
// This is only used by rustdoc anyway, which shouldn't have
122+
// incremental recompilation ever enabled.
123+
fn_arg_names => { cdata.get_fn_arg_names(def_id.index) }
124+
impl_parent => { cdata.get_parent_impl(def_id.index) }
125+
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
126+
is_exported_symbol => {
127+
let dep_node = cdata.metadata_dep_node(GlobalMetaDataKind::ExportedSymbols);
128+
cdata.exported_symbols.get(&tcx.dep_graph, dep_node).contains(&def_id.index)
129+
}
130+
item_body_nested_bodies => { Rc::new(cdata.item_body_nested_bodies(def_id.index)) }
131+
const_is_rvalue_promotable_to_static => {
132+
cdata.const_is_rvalue_promotable_to_static(def_id.index)
133+
}
134+
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
135+
136+
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats(&tcx.dep_graph)) }
137+
is_allocator => { cdata.is_allocator(&tcx.dep_graph) }
138+
is_panic_runtime => { cdata.is_panic_runtime(&tcx.dep_graph) }
139+
extern_crate => { Rc::new(cdata.extern_crate.get()) }
161140
}
162141

163142
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {

src/librustc_save_analysis/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
107107
let mut result = Vec::new();
108108

109109
for n in self.tcx.sess.cstore.crates() {
110-
let span = match *self.tcx.extern_crate(n) {
110+
let span = match *self.tcx.extern_crate(n.as_def_id()) {
111111
Some(ref c) => c.span,
112112
None => {
113113
debug!("Skipping crate {}, no data", n);

src/librustc_trans/back/symbol_export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ impl ExportedSymbols {
9292
// Down below we'll hardwire all of the symbols to the `Rust` export
9393
// level instead.
9494
let special_runtime_crate =
95-
scx.tcx().is_allocator(cnum) ||
96-
scx.tcx().is_panic_runtime(cnum) ||
95+
scx.tcx().is_allocator(cnum.as_def_id()) ||
96+
scx.tcx().is_panic_runtime(cnum.as_def_id()) ||
9797
scx.sess().cstore.is_compiler_builtins(cnum);
9898

9999
let crate_exports = scx

0 commit comments

Comments
 (0)