From 4d7c0b68cf2df93158747180bef0c7c6724e4dd3 Mon Sep 17 00:00:00 2001 From: achernyak Date: Wed, 3 May 2017 08:17:54 -0500 Subject: [PATCH 01/10] all queries use dep nodes --- src/librustc/dep_graph/dep_node.rs | 6 ++++++ src/librustc/ty/maps.rs | 10 +++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 37b8a56d9166b..1c71079e94b27 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -154,6 +154,9 @@ pub enum DepNode { DefSpan(D), Stability(D), Deprecation(D), + ItemBodyNestedBodies(D), + ConstIsRvaluePromotableToStatic(D), + IsMirAvailable(D), } impl DepNode { @@ -264,6 +267,9 @@ impl DepNode { DefSpan(ref d) => op(d).map(DefSpan), Stability(ref d) => op(d).map(Stability), Deprecation(ref d) => op(d).map(Deprecation), + ItemBodyNestedBodies(ref d) => op(d).map(ItemBodyNestedBodies), + ConstIsRvaluePromotableToStatic(ref d) => op(d).map(ConstIsRvaluePromotableToStatic), + IsMirAvailable(ref d) => op(d).map(IsMirAvailable), } } } diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 66df8dc050a24..513240a4ec345 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -783,9 +783,9 @@ define_maps! { <'tcx> [] def_span: DefSpan(DefId) -> Span, [] stability: Stability(DefId) -> Option, [] deprecation: Deprecation(DefId) -> Option, - [] item_body_nested_bodies: metadata_dep_node(DefId) -> Rc>, - [] const_is_rvalue_promotable_to_static: metadata_dep_node(DefId) -> bool, - [] is_mir_available: metadata_dep_node(DefId) -> bool, + [] item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> Rc>, + [] const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool, + [] is_mir_available: IsMirAvailable(DefId) -> bool, } fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode { @@ -800,10 +800,6 @@ fn reachability_dep_node(_: CrateNum) -> DepNode { DepNode::Reachability } -fn metadata_dep_node(def_id: DefId) -> DepNode { - DepNode::MetaData(def_id) -} - fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepNode { instance.dep_node() } From a12a55f519baea94c049fcda6d14dcd56110f39d Mon Sep 17 00:00:00 2001 From: achernyak Date: Wed, 3 May 2017 08:40:32 -0500 Subject: [PATCH 02/10] item_attrs --- src/librustc/dep_graph/dep_node.rs | 2 ++ src/librustc/middle/cstore.rs | 2 -- src/librustc/ty/maps.rs | 8 ++++++++ src/librustc/ty/mod.rs | 2 +- src/librustc_metadata/cstore_impl.rs | 7 +------ 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 1c71079e94b27..fb8678ce93eae 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -157,6 +157,7 @@ pub enum DepNode { ItemBodyNestedBodies(D), ConstIsRvaluePromotableToStatic(D), IsMirAvailable(D), + ItemAttrs(D), } impl DepNode { @@ -267,6 +268,7 @@ impl DepNode { DefSpan(ref d) => op(d).map(DefSpan), Stability(ref d) => op(d).map(Stability), Deprecation(ref d) => op(d).map(Deprecation), + ItemAttrs(ref d) => op(d).map(ItemAttrs), ItemBodyNestedBodies(ref d) => op(d).map(ItemBodyNestedBodies), ConstIsRvaluePromotableToStatic(ref d) => op(d).map(ConstIsRvaluePromotableToStatic), IsMirAvailable(ref d) => op(d).map(IsMirAvailable), diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 303c5059e7cf3..e30b4b2818e5e 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -182,7 +182,6 @@ pub trait CrateStore { fn visibility(&self, def: DefId) -> ty::Visibility; fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap>; fn item_generics_cloned(&self, def: DefId) -> ty::Generics; - fn item_attrs(&self, def_id: DefId) -> Rc<[ast::Attribute]>; fn fn_arg_names(&self, did: DefId) -> Vec; // trait info @@ -309,7 +308,6 @@ impl CrateStore for DummyCrateStore { } fn item_generics_cloned(&self, def: DefId) -> ty::Generics { bug!("item_generics_cloned") } - fn item_attrs(&self, def_id: DefId) -> Rc<[ast::Attribute]> { bug!("item_attrs") } fn fn_arg_names(&self, did: DefId) -> Vec { bug!("fn_arg_names") } // trait info diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 513240a4ec345..948df61786751 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -34,6 +34,7 @@ use std::ops::Deref; use std::rc::Rc; use syntax_pos::{Span, DUMMY_SP}; use syntax::attr; +use syntax::ast; use syntax::symbol::Symbol; pub trait Key: Clone + Hash + Eq + Debug { @@ -334,6 +335,12 @@ impl<'tcx> QueryDescription for queries::deprecation<'tcx> { } } +impl<'tcx> QueryDescription for queries::item_attrs<'tcx> { + fn describe(_: TyCtxt, _: DefId) -> String { + bug!("item_attrs") + } +} + impl<'tcx> QueryDescription for queries::item_body_nested_bodies<'tcx> { fn describe(tcx: TyCtxt, def_id: DefId) -> String { format!("nested item bodies of `{}`", tcx.item_path_str(def_id)) @@ -783,6 +790,7 @@ define_maps! { <'tcx> [] def_span: DefSpan(DefId) -> Span, [] stability: Stability(DefId) -> Option, [] deprecation: Deprecation(DefId) -> Option, + [] item_attrs: ItemAttrs(DefId) -> Rc<[ast::Attribute]>, [] item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> Rc>, [] const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool, [] is_mir_available: IsMirAvailable(DefId) -> bool, diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 55466b1f36dac..3cc250f0814ef 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2357,7 +2357,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { if let Some(id) = self.hir.as_local_node_id(did) { Attributes::Borrowed(self.hir.attrs(id)) } else { - Attributes::Owned(self.sess.cstore.item_attrs(did)) + Attributes::Owned(self.item_attrs(did)) } } diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index a1794ec2d82ca..c7a52922e2a09 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -113,6 +113,7 @@ provide! { <'tcx> tcx, def_id, cdata 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) } item_body_nested_bodies => { let map: BTreeMap<_, _> = cdata.entry(def_id.index).ast.into_iter().flat_map(|ast| { ast.decode(cdata).nested_bodies.decode(cdata).map(|body| (body.id(), body)) @@ -145,12 +146,6 @@ impl CrateStore for cstore::CStore { self.get_crate_data(def.krate).get_generics(def.index) } - fn item_attrs(&self, def_id: DefId) -> Rc<[ast::Attribute]> - { - self.dep_graph.read(DepNode::MetaData(def_id)); - self.get_crate_data(def_id.krate).get_item_attrs(def_id.index) - } - fn fn_arg_names(&self, did: DefId) -> Vec { // FIXME(#38501) We've skipped a `read` on the `HirBody` of From c72a16b8e2e1febb300cab5b97fc3265a463e775 Mon Sep 17 00:00:00 2001 From: achernyak Date: Wed, 3 May 2017 09:01:49 -0500 Subject: [PATCH 03/10] fn_arg_names --- src/librustc/dep_graph/dep_node.rs | 2 ++ src/librustc/middle/cstore.rs | 2 -- src/librustc/ty/maps.rs | 7 +++++++ src/librustc_metadata/cstore_impl.rs | 15 +++++---------- src/librustdoc/clean/mod.rs | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index fb8678ce93eae..591c128a16559 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -158,6 +158,7 @@ pub enum DepNode { ConstIsRvaluePromotableToStatic(D), IsMirAvailable(D), ItemAttrs(D), + FnArgNames(D), } impl DepNode { @@ -269,6 +270,7 @@ impl DepNode { Stability(ref d) => op(d).map(Stability), Deprecation(ref d) => op(d).map(Deprecation), ItemAttrs(ref d) => op(d).map(ItemAttrs), + FnArgNames(ref d) => op(d).map(FnArgNames), ItemBodyNestedBodies(ref d) => op(d).map(ItemBodyNestedBodies), ConstIsRvaluePromotableToStatic(ref d) => op(d).map(ConstIsRvaluePromotableToStatic), IsMirAvailable(ref d) => op(d).map(IsMirAvailable), diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index e30b4b2818e5e..00904f5406172 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -182,7 +182,6 @@ pub trait CrateStore { fn visibility(&self, def: DefId) -> ty::Visibility; fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap>; fn item_generics_cloned(&self, def: DefId) -> ty::Generics; - fn fn_arg_names(&self, did: DefId) -> Vec; // trait info fn implementations_of_trait(&self, filter: Option) -> Vec; @@ -308,7 +307,6 @@ impl CrateStore for DummyCrateStore { } fn item_generics_cloned(&self, def: DefId) -> ty::Generics { bug!("item_generics_cloned") } - fn fn_arg_names(&self, did: DefId) -> Vec { bug!("fn_arg_names") } // trait info fn implementations_of_trait(&self, filter: Option) -> Vec { vec![] } diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 948df61786751..43f6c94b8b095 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -341,6 +341,12 @@ impl<'tcx> QueryDescription for queries::item_attrs<'tcx> { } } +impl<'tcx> QueryDescription for queries::fn_arg_names<'tcx> { + fn describe(_: TyCtxt, _: DefId) -> String { + bug!("fn_arg_names") + } +} + impl<'tcx> QueryDescription for queries::item_body_nested_bodies<'tcx> { fn describe(tcx: TyCtxt, def_id: DefId) -> String { format!("nested item bodies of `{}`", tcx.item_path_str(def_id)) @@ -791,6 +797,7 @@ define_maps! { <'tcx> [] stability: Stability(DefId) -> Option, [] deprecation: Deprecation(DefId) -> Option, [] item_attrs: ItemAttrs(DefId) -> Rc<[ast::Attribute]>, + [] fn_arg_names: FnArgNames(DefId) -> Vec, [] item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> Rc>, [] const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool, [] is_mir_available: IsMirAvailable(DefId) -> bool, diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index c7a52922e2a09..325ba14da9c8a 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -114,6 +114,11 @@ provide! { <'tcx> tcx, def_id, cdata stability => { cdata.get_stability(def_id.index) } deprecation => { cdata.get_deprecation(def_id.index) } item_attrs => { cdata.get_item_attrs(def_id.index) } + // 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) } item_body_nested_bodies => { let map: BTreeMap<_, _> = cdata.entry(def_id.index).ast.into_iter().flat_map(|ast| { ast.decode(cdata).nested_bodies.decode(cdata).map(|body| (body.id(), body)) @@ -146,16 +151,6 @@ impl CrateStore for cstore::CStore { self.get_crate_data(def.krate).get_generics(def.index) } - fn fn_arg_names(&self, did: DefId) -> Vec - { - // 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. - assert!(!self.dep_graph.is_fully_enabled()); - self.get_crate_data(did.krate).get_fn_arg_names(did.index) - } - fn implementations_of_trait(&self, filter: Option) -> Vec { if let Some(def_id) = filter { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0a74848724432..78b96e1833b6d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1179,7 +1179,7 @@ impl<'a, 'tcx> Clean for (DefId, ty::PolyFnSig<'tcx>) { let mut names = if cx.tcx.hir.as_local_node_id(did).is_some() { vec![].into_iter() } else { - cx.tcx.sess.cstore.fn_arg_names(did).into_iter() + cx.tcx.fn_arg_names(did).into_iter() }.peekable(); FnDecl { output: Return(sig.skip_binder().output().clean(cx)), From aa5a5320466d4a6ac7125cb01956307e63d9918b Mon Sep 17 00:00:00 2001 From: achernyak Date: Thu, 4 May 2017 08:27:48 -0500 Subject: [PATCH 04/10] trait_of_item --- src/librustc/dep_graph/dep_node.rs | 2 ++ src/librustc/middle/cstore.rs | 2 -- src/librustc/ty/maps.rs | 7 ++++++ src/librustc/ty/mod.rs | 34 +++++++++++++++------------- src/librustc_const_eval/eval.rs | 2 +- src/librustc_metadata/cstore_impl.rs | 6 +---- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 591c128a16559..0e462b95d820e 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -156,6 +156,7 @@ pub enum DepNode { Deprecation(D), ItemBodyNestedBodies(D), ConstIsRvaluePromotableToStatic(D), + TraitOfItem(D), IsMirAvailable(D), ItemAttrs(D), FnArgNames(D), @@ -271,6 +272,7 @@ impl DepNode { Deprecation(ref d) => op(d).map(Deprecation), ItemAttrs(ref d) => op(d).map(ItemAttrs), FnArgNames(ref d) => op(d).map(FnArgNames), + TraitOfItem(ref d) => op(d).map(TraitOfItem), ItemBodyNestedBodies(ref d) => op(d).map(ItemBodyNestedBodies), ConstIsRvaluePromotableToStatic(ref d) => op(d).map(ConstIsRvaluePromotableToStatic), IsMirAvailable(ref d) => op(d).map(IsMirAvailable), diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 00904f5406172..11a2dfc6685a1 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -191,7 +191,6 @@ pub trait CrateStore { fn impl_parent(&self, impl_def_id: DefId) -> Option; // trait/impl-item info - fn trait_of_item(&self, def_id: DefId) -> Option; fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem; // flags @@ -316,7 +315,6 @@ impl CrateStore for DummyCrateStore { fn impl_parent(&self, def: DefId) -> Option { bug!("impl_parent") } // trait/impl-item info - fn trait_of_item(&self, def_id: DefId) -> Option { bug!("trait_of_item") } fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem { bug!("associated_item_cloned") } diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 43f6c94b8b095..5d1b16c3d2e1c 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -347,6 +347,12 @@ impl<'tcx> QueryDescription for queries::fn_arg_names<'tcx> { } } +impl<'tcx> QueryDescription for queries::trait_of_item<'tcx> { + fn describe(_: TyCtxt, _: DefId) -> String { + bug!("trait_of_item") + } +} + impl<'tcx> QueryDescription for queries::item_body_nested_bodies<'tcx> { fn describe(tcx: TyCtxt, def_id: DefId) -> String { format!("nested item bodies of `{}`", tcx.item_path_str(def_id)) @@ -798,6 +804,7 @@ define_maps! { <'tcx> [] deprecation: Deprecation(DefId) -> Option, [] item_attrs: ItemAttrs(DefId) -> Rc<[ast::Attribute]>, [] fn_arg_names: FnArgNames(DefId) -> Vec, + [] trait_of_item: TraitOfItem(DefId) -> Option, [] item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> Rc>, [] const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool, [] is_mir_available: IsMirAvailable(DefId) -> bool, diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 3cc250f0814ef..00f81c9dcf7bc 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2430,22 +2430,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } - /// If the given def ID describes an item belonging to a trait, - /// return the ID of the trait that the trait item belongs to. - /// Otherwise, return `None`. - pub fn trait_of_item(self, def_id: DefId) -> Option { - if def_id.krate != LOCAL_CRATE { - return self.sess.cstore.trait_of_item(def_id); - } - self.opt_associated_item(def_id) - .and_then(|associated_item| { - match associated_item.container { - TraitContainer(def_id) => Some(def_id), - ImplContainer(_) => None - } - }) - } - /// Construct a parameter environment suitable for static contexts or other contexts where there /// are no free type/lifetime parameters in scope. pub fn empty_parameter_environment(self) -> ParameterEnvironment<'tcx> { @@ -2693,6 +2677,23 @@ fn def_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Span { tcx.hir.span_if_local(def_id).unwrap() } +/// If the given def ID describes an item belonging to a trait, +/// return the ID of the trait that the trait item belongs to. +/// Otherwise, return `None`. +fn trait_of_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Option { + if def_id.krate != LOCAL_CRATE { + return None + } + tcx.opt_associated_item(def_id) + .and_then(|associated_item| { + match associated_item.container { + TraitContainer(def_id) => Some(def_id), + ImplContainer(_) => None + } + }) +} + + pub fn provide(providers: &mut ty::maps::Providers) { *providers = ty::maps::Providers { associated_item, @@ -2700,6 +2701,7 @@ pub fn provide(providers: &mut ty::maps::Providers) { adt_sized_constraint, adt_dtorck_constraint, def_span, + trait_of_item, ..*providers }; } diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index 8b1aa0708807b..e79f23aee1145 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -74,7 +74,7 @@ pub fn lookup_const_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // constants, we only try to find the expression for a // trait-associated const if the caller gives us the // substitutions for the reference to it. - if tcx.sess.cstore.trait_of_item(def_id).is_some() { + if tcx.trait_of_item(def_id).is_some() { resolve_trait_associated_const(tcx, def_id, substs) } else { Some((def_id, substs)) diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 325ba14da9c8a..b07dd1ec7b0b8 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -119,6 +119,7 @@ provide! { <'tcx> tcx, def_id, cdata // 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) } + trait_of_item => { cdata.get_trait_of_item(def_id.index) } item_body_nested_bodies => { let map: BTreeMap<_, _> = cdata.entry(def_id.index).ast.into_iter().flat_map(|ast| { ast.decode(cdata).nested_bodies.decode(cdata).map(|body| (body.id(), body)) @@ -174,11 +175,6 @@ impl CrateStore for cstore::CStore { self.get_crate_data(impl_def.krate).get_parent_impl(impl_def.index) } - fn trait_of_item(&self, def_id: DefId) -> Option { - self.dep_graph.read(DepNode::MetaData(def_id)); - self.get_crate_data(def_id.krate).get_trait_of_item(def_id.index) - } - fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem { self.dep_graph.read(DepNode::MetaData(def)); From 03fe10d91d3361144ab5c8a142daf63bc0ff143e Mon Sep 17 00:00:00 2001 From: achernyak Date: Thu, 4 May 2017 09:37:34 -0500 Subject: [PATCH 05/10] impl_parent --- src/librustc/dep_graph/dep_node.rs | 2 ++ src/librustc/middle/cstore.rs | 2 -- src/librustc/ty/maps.rs | 7 +++++++ src/librustc/ty/mod.rs | 2 +- src/librustc_metadata/cstore_impl.rs | 6 +----- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 0e462b95d820e..de1531bbd54d3 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -156,6 +156,7 @@ pub enum DepNode { Deprecation(D), ItemBodyNestedBodies(D), ConstIsRvaluePromotableToStatic(D), + ImplParent(D), TraitOfItem(D), IsMirAvailable(D), ItemAttrs(D), @@ -272,6 +273,7 @@ impl DepNode { Deprecation(ref d) => op(d).map(Deprecation), ItemAttrs(ref d) => op(d).map(ItemAttrs), FnArgNames(ref d) => op(d).map(FnArgNames), + ImplParent(ref d) => op(d).map(ImplParent), TraitOfItem(ref d) => op(d).map(TraitOfItem), ItemBodyNestedBodies(ref d) => op(d).map(ItemBodyNestedBodies), ConstIsRvaluePromotableToStatic(ref d) => op(d).map(ConstIsRvaluePromotableToStatic), diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 11a2dfc6685a1..e50072043d5f7 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -188,7 +188,6 @@ pub trait CrateStore { // impl info fn impl_defaultness(&self, def: DefId) -> hir::Defaultness; - fn impl_parent(&self, impl_def_id: DefId) -> Option; // trait/impl-item info fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem; @@ -312,7 +311,6 @@ impl CrateStore for DummyCrateStore { // impl info fn impl_defaultness(&self, def: DefId) -> hir::Defaultness { bug!("impl_defaultness") } - fn impl_parent(&self, def: DefId) -> Option { bug!("impl_parent") } // trait/impl-item info fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 5d1b16c3d2e1c..1dfd7bc976082 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -347,6 +347,12 @@ impl<'tcx> QueryDescription for queries::fn_arg_names<'tcx> { } } +impl<'tcx> QueryDescription for queries::impl_parent<'tcx> { + fn describe(_: TyCtxt, _: DefId) -> String { + bug!("impl_parent") + } +} + impl<'tcx> QueryDescription for queries::trait_of_item<'tcx> { fn describe(_: TyCtxt, _: DefId) -> String { bug!("trait_of_item") @@ -804,6 +810,7 @@ define_maps! { <'tcx> [] deprecation: Deprecation(DefId) -> Option, [] item_attrs: ItemAttrs(DefId) -> Rc<[ast::Attribute]>, [] fn_arg_names: FnArgNames(DefId) -> Vec, + [] impl_parent: ImplParent(DefId) -> Option, [] trait_of_item: TraitOfItem(DefId) -> Option, [] item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> Rc>, [] const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool, diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 00f81c9dcf7bc..1c3e74d4fb965 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2393,7 +2393,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let trait_ref = self.impl_trait_ref(impl_def_id).unwrap(); // Record the trait->implementation mapping. - let parent = self.sess.cstore.impl_parent(impl_def_id).unwrap_or(trait_id); + let parent = self.impl_parent(impl_def_id).unwrap_or(trait_id); def.record_remote_impl(self, impl_def_id, trait_ref, parent); } diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index b07dd1ec7b0b8..b54db55c0e12a 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -119,6 +119,7 @@ provide! { <'tcx> tcx, def_id, cdata // 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) } item_body_nested_bodies => { let map: BTreeMap<_, _> = cdata.entry(def_id.index).ast.into_iter().flat_map(|ast| { @@ -170,11 +171,6 @@ impl CrateStore for cstore::CStore { self.get_crate_data(def.krate).get_impl_defaultness(def.index) } - fn impl_parent(&self, impl_def: DefId) -> Option { - self.dep_graph.read(DepNode::MetaData(impl_def)); - self.get_crate_data(impl_def.krate).get_parent_impl(impl_def.index) - } - fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem { self.dep_graph.read(DepNode::MetaData(def)); From 5b71d769ffe751399b538fb0fdb51ec88345061b Mon Sep 17 00:00:00 2001 From: achernyak Date: Thu, 4 May 2017 12:45:56 -0500 Subject: [PATCH 06/10] moved metadata provider impls to decoder --- src/librustc_metadata/cstore_impl.rs | 18 +++--------------- src/librustc_metadata/decoder.rs | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index b54db55c0e12a..a0c887e95d6c7 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -41,8 +41,6 @@ use rustc::hir::svh::Svh; use rustc_back::target::Target; use rustc::hir; -use std::collections::BTreeMap; - macro_rules! provide { (<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident $($name:ident => $compute:block)*) => { pub fn provide<$lt>(providers: &mut Providers<$lt>) { @@ -121,21 +119,11 @@ provide! { <'tcx> tcx, def_id, cdata 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) } - item_body_nested_bodies => { - let map: BTreeMap<_, _> = cdata.entry(def_id.index).ast.into_iter().flat_map(|ast| { - ast.decode(cdata).nested_bodies.decode(cdata).map(|body| (body.id(), body)) - }).collect(); - - Rc::new(map) - } + item_body_nested_bodies => { Rc::new(cdata.item_body_nested_bodies(def_id.index)) } const_is_rvalue_promotable_to_static => { - cdata.entry(def_id.index).ast.expect("const item missing `ast`") - .decode(cdata).rvalue_promotable_to_static - } - is_mir_available => { - !cdata.is_proc_macro(def_id.index) && - cdata.maybe_entry(def_id.index).and_then(|item| item.decode(cdata).mir).is_some() + cdata.const_is_rvalue_promotable_to_static(def_id.index) } + is_mir_available => { cdata.is_item_mir_available(def_id.index) } } impl CrateStore for cstore::CStore { diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index ae755adcf5fbb..b89b5181e7bb7 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -29,6 +29,7 @@ use rustc::mir::Mir; use std::borrow::Cow; use std::cell::Ref; +use std::collections::BTreeMap; use std::io; use std::mem; use std::rc::Rc; @@ -448,16 +449,16 @@ impl<'tcx> EntryKind<'tcx> { } impl<'a, 'tcx> CrateMetadata { - pub fn is_proc_macro(&self, id: DefIndex) -> bool { + fn is_proc_macro(&self, id: DefIndex) -> bool { self.proc_macros.is_some() && id != CRATE_DEF_INDEX } - pub fn maybe_entry(&self, item_id: DefIndex) -> Option>> { + fn maybe_entry(&self, item_id: DefIndex) -> Option>> { assert!(!self.is_proc_macro(item_id)); self.root.index.lookup(self.blob.raw_bytes(), item_id) } - pub fn entry(&self, item_id: DefIndex) -> Entry<'tcx> { + fn entry(&self, item_id: DefIndex) -> Entry<'tcx> { match self.maybe_entry(item_id) { None => { bug!("entry: id not found: {:?} in crate {:?} with number {}", @@ -779,6 +780,22 @@ impl<'a, 'tcx> CrateMetadata { tcx.alloc_tables(ast.tables.decode((self, tcx))) } + pub fn item_body_nested_bodies(&self, id: DefIndex) -> BTreeMap { + self.entry(id).ast.into_iter().flat_map(|ast| { + ast.decode(self).nested_bodies.decode(self).map(|body| (body.id(), body)) + }).collect() + } + + pub fn const_is_rvalue_promotable_to_static(&self, id: DefIndex) -> bool { + self.entry(id).ast.expect("const item missing `ast`") + .decode(self).rvalue_promotable_to_static + } + + pub fn is_item_mir_available(&self, id: DefIndex) -> bool { + !self.is_proc_macro(id) && + self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some() + } + pub fn maybe_get_optimized_mir(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefIndex) From 5a7946df703f2d9149adc0ca5c7e0b116e82a98d Mon Sep 17 00:00:00 2001 From: achernyak Date: Fri, 5 May 2017 08:15:08 -0500 Subject: [PATCH 07/10] is_foreign_item --- src/librustc/middle/cstore.rs | 2 -- src/librustc/middle/effect.rs | 2 +- src/librustc_metadata/cstore_impl.rs | 4 ---- src/librustc_trans/back/symbol_names.rs | 2 +- src/librustc_trans/collector.rs | 2 +- src/librustc_trans/consts.rs | 2 +- 6 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index e50072043d5f7..d9ce40a0d7de2 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -195,7 +195,6 @@ pub trait CrateStore { // flags fn is_const_fn(&self, did: DefId) -> bool; fn is_default_impl(&self, impl_did: DefId) -> bool; - fn is_foreign_item(&self, did: DefId) -> bool; fn is_dllimport_foreign_item(&self, def: DefId) -> bool; fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool; fn is_exported_symbol(&self, def_id: DefId) -> bool; @@ -319,7 +318,6 @@ impl CrateStore for DummyCrateStore { // flags fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") } fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") } - fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") } fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false } fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false } fn is_exported_symbol(&self, def_id: DefId) -> bool { false } diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index d2b8ed8c29707..4bbf37b21edbf 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -205,7 +205,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> { } else if match self.tcx.hir.get_if_local(def_id) { Some(hir::map::NodeForeignItem(..)) => true, Some(..) => false, - None => self.tcx.sess.cstore.is_foreign_item(def_id), + None => self.tcx.is_foreign_item(def_id), } { self.require_unsafe_ext(expr.id, expr.span, "use of extern static", true); } diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index a0c887e95d6c7..7bd431ff44621 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -176,10 +176,6 @@ impl CrateStore for cstore::CStore { self.get_crate_data(impl_did.krate).is_default_impl(impl_did.index) } - fn is_foreign_item(&self, did: DefId) -> bool { - self.get_crate_data(did.krate).is_foreign_item(did.index) - } - fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { self.do_is_statically_included_foreign_item(def_id) diff --git a/src/librustc_trans/back/symbol_names.rs b/src/librustc_trans/back/symbol_names.rs index aef9140ba4556..1aed293294802 100644 --- a/src/librustc_trans/back/symbol_names.rs +++ b/src/librustc_trans/back/symbol_names.rs @@ -223,7 +223,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance _ => false } } else { - tcx.sess.cstore.is_foreign_item(def_id) + tcx.is_foreign_item(def_id) }; if let Some(name) = weak_lang_items::link_name(&attrs) { diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index 6d7d95f548721..f0be0941ccf36 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -653,7 +653,7 @@ fn should_trans_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: &Instan Some(_) => true, None => { if tcx.sess.cstore.is_exported_symbol(def_id) || - tcx.sess.cstore.is_foreign_item(def_id) + tcx.is_foreign_item(def_id) { // We can link to the item in question, no instance needed // in this crate diff --git a/src/librustc_trans/consts.rs b/src/librustc_trans/consts.rs index 6afb340107d66..eac0a06256719 100644 --- a/src/librustc_trans/consts.rs +++ b/src/librustc_trans/consts.rs @@ -186,7 +186,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef { llvm::set_thread_local(g, true); } } - if ccx.use_dll_storage_attrs() && !ccx.sess().cstore.is_foreign_item(def_id) { + if ccx.use_dll_storage_attrs() && !ccx.tcx().is_foreign_item(def_id) { // This item is external but not foreign, i.e. it originates from an external Rust // crate. Since we don't know whether this crate will be linked dynamically or // statically in the final application, we always mark such symbols as 'dllimport'. From d561d4c9eb808cbca28fd641934825fdf96fb762 Mon Sep 17 00:00:00 2001 From: achernyak Date: Fri, 5 May 2017 14:40:26 -0500 Subject: [PATCH 08/10] propper trait of item impl --- src/librustc/ty/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 1c3e74d4fb965..9f43ed9bf5bb5 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2682,7 +2682,7 @@ fn def_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Span { /// Otherwise, return `None`. fn trait_of_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Option { if def_id.krate != LOCAL_CRATE { - return None + return tcx.trait_of_item(def_id) } tcx.opt_associated_item(def_id) .and_then(|associated_item| { From 1f532bfed5e0a80bf145f5db504601dc037367a1 Mon Sep 17 00:00:00 2001 From: achernyak Date: Sun, 7 May 2017 21:05:31 -0500 Subject: [PATCH 09/10] is_exported_symbol --- src/librustc/dep_graph/dep_node.rs | 2 ++ src/librustc/middle/cstore.rs | 2 -- src/librustc/ty/maps.rs | 7 +++++++ src/librustc_metadata/cstore_impl.rs | 5 +---- src/librustc_trans/collector.rs | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index de1531bbd54d3..712ada4ec65bb 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -158,6 +158,7 @@ pub enum DepNode { ConstIsRvaluePromotableToStatic(D), ImplParent(D), TraitOfItem(D), + IsExportedSymbol(D), IsMirAvailable(D), ItemAttrs(D), FnArgNames(D), @@ -275,6 +276,7 @@ impl DepNode { FnArgNames(ref d) => op(d).map(FnArgNames), ImplParent(ref d) => op(d).map(ImplParent), TraitOfItem(ref d) => op(d).map(TraitOfItem), + IsExportedSymbol(ref d) => op(d).map(IsExportedSymbol), ItemBodyNestedBodies(ref d) => op(d).map(ItemBodyNestedBodies), ConstIsRvaluePromotableToStatic(ref d) => op(d).map(ConstIsRvaluePromotableToStatic), IsMirAvailable(ref d) => op(d).map(IsMirAvailable), diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index d9ce40a0d7de2..6f0a990ca4126 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -197,7 +197,6 @@ pub trait CrateStore { fn is_default_impl(&self, impl_did: DefId) -> bool; fn is_dllimport_foreign_item(&self, def: DefId) -> bool; fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool; - fn is_exported_symbol(&self, def_id: DefId) -> bool; // crate metadata fn dylib_dependency_formats(&self, cnum: CrateNum) @@ -320,7 +319,6 @@ impl CrateStore for DummyCrateStore { fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") } fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false } fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false } - fn is_exported_symbol(&self, def_id: DefId) -> bool { false } // crate metadata fn dylib_dependency_formats(&self, cnum: CrateNum) diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 1dfd7bc976082..80783a547bf42 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -341,6 +341,12 @@ impl<'tcx> QueryDescription for queries::item_attrs<'tcx> { } } +impl<'tcx> QueryDescription for queries::is_exported_symbol<'tcx> { + fn describe(_: TyCtxt, _: DefId) -> String { + bug!("is_exported_symbol") + } +} + impl<'tcx> QueryDescription for queries::fn_arg_names<'tcx> { fn describe(_: TyCtxt, _: DefId) -> String { bug!("fn_arg_names") @@ -812,6 +818,7 @@ define_maps! { <'tcx> [] fn_arg_names: FnArgNames(DefId) -> Vec, [] impl_parent: ImplParent(DefId) -> Option, [] trait_of_item: TraitOfItem(DefId) -> Option, + [] is_exported_symbol: IsExportedSymbol(DefId) -> bool, [] item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> Rc>, [] const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool, [] is_mir_available: IsMirAvailable(DefId) -> bool, diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 7bd431ff44621..d29fa8f081497 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -119,6 +119,7 @@ provide! { <'tcx> tcx, def_id, cdata 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 => { cdata.exported_symbols.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) @@ -181,10 +182,6 @@ impl CrateStore for cstore::CStore { self.do_is_statically_included_foreign_item(def_id) } - fn is_exported_symbol(&self, def_id: DefId) -> bool { - self.get_crate_data(def_id.krate).exported_symbols.contains(&def_id.index) - } - fn is_dllimport_foreign_item(&self, def_id: DefId) -> bool { if def_id.krate == LOCAL_CRATE { self.dllimport_foreign_items.borrow().contains(&def_id.index) diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index f0be0941ccf36..5f8b79a994a55 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -652,7 +652,7 @@ fn should_trans_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: &Instan } Some(_) => true, None => { - if tcx.sess.cstore.is_exported_symbol(def_id) || + if tcx.is_exported_symbol(def_id) || tcx.is_foreign_item(def_id) { // We can link to the item in question, no instance needed From dfb740f83ca1d6f2056f5cf8de1adbe81b973438 Mon Sep 17 00:00:00 2001 From: achernyak Date: Mon, 8 May 2017 14:30:30 -0500 Subject: [PATCH 10/10] removed unnecessary if --- src/librustc/ty/mod.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 9f43ed9bf5bb5..a065dd6a592f2 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2681,9 +2681,6 @@ fn def_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Span { /// return the ID of the trait that the trait item belongs to. /// Otherwise, return `None`. fn trait_of_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Option { - if def_id.krate != LOCAL_CRATE { - return tcx.trait_of_item(def_id) - } tcx.opt_associated_item(def_id) .and_then(|associated_item| { match associated_item.container {