From 532a08b94726a399a4203b54536e63f7b634d36d Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Sun, 11 Jun 2017 21:58:12 -0700 Subject: [PATCH] Add CrateNum-taking ability to the provide macro --- src/librustc/dep_graph/dep_node.rs | 1 + src/librustc_metadata/cstore_impl.rs | 155 +++++++++++++++------------ 2 files changed, 90 insertions(+), 66 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index c987a37c420..6c4c90585b3 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -305,6 +305,7 @@ 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. diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 00c1fdb177d..6314ffd3020 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -40,10 +40,17 @@ use rustc::hir::svh::Svh; use rustc::hir; macro_rules! provide { - (<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident $($name:ident => $compute:block)*) => { + (<$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)* + } + )=> { pub fn provide<$lt>(providers: &mut Providers<$lt>) { - $(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId) - -> as + $(fn $cdata_fn_name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId) + -> as DepTrackingMapConfig>::Value { assert!(!$def_id.is_local()); @@ -55,82 +62,98 @@ macro_rules! provide { let $cdata = $tcx.sess.cstore.crate_data_as_rc_any($def_id.krate); let $cdata = $cdata.downcast_ref::() .expect("CrateStore crated ata is not a CrateMetadata"); - $compute + $cdata_fn_compute + })* + + $(fn $cnum_fn_name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $cnum: CrateNum) + -> as + DepTrackingMapConfig>::Value { + let $cdata = $tcx.sess.cstore.crate_data_as_rc_any($cnum); + let $cdata = $cdata.downcast_ref::() + .expect("CrateStore crated ata is not a CrateMetadata"); + $cnum_fn_compute })* *providers = Providers { - $($name,)* + $($cdata_fn_name,)* + $($cnum_fn_name,)* ..*providers }; } } } -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)) - } - 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) - }); +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); + let mir = tcx.alloc_mir(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) } } - 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) + + ByCrateNum { } - 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) } } pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {