Skip to content

Commit 532a08b

Browse files
committed
Add CrateNum-taking ability to the provide macro
1 parent 9f71053 commit 532a08b

File tree

2 files changed

+92
-68
lines changed

2 files changed

+92
-68
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ 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),
308309

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

src/librustc_metadata/cstore_impl.rs

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

4242
macro_rules! provide {
43-
(<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident $($name:ident => $compute:block)*) => {
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+
)=> {
4451
pub fn provide<$lt>(providers: &mut Providers<$lt>) {
45-
$(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
46-
-> <ty::queries::$name<$lt> as
52+
$(fn $cdata_fn_name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
53+
-> <ty::queries::$cdata_fn_name<$lt> as
4754
DepTrackingMapConfig>::Value {
4855
assert!(!$def_id.is_local());
4956

@@ -55,82 +62,98 @@ macro_rules! provide {
5562
let $cdata = $tcx.sess.cstore.crate_data_as_rc_any($def_id.krate);
5663
let $cdata = $cdata.downcast_ref::<cstore::CrateMetadata>()
5764
.expect("CrateStore crated ata is not a CrateMetadata");
58-
$compute
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
5975
})*
6076

6177
*providers = Providers {
62-
$($name,)*
78+
$($cdata_fn_name,)*
79+
$($cnum_fn_name,)*
6380
..*providers
6481
};
6582
}
6683
}
6784
}
6885

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, |child| result.push(child.def.def_id()), tcx.sess);
86-
Rc::new(result)
87-
}
88-
associated_item => { cdata.get_associated_item(def_id.index) }
89-
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
90-
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
91-
coerce_unsized_info => {
92-
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
93-
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
94-
})
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) }
95153
}
96-
optimized_mir => {
97-
let mir = cdata.maybe_get_optimized_mir(tcx, def_id.index).unwrap_or_else(|| {
98-
bug!("get_optimized_mir: missing MIR for `{:?}`", def_id)
99-
});
100154

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

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

0 commit comments

Comments
 (0)