提交 7e277d96 编写于 作者: L ljedrz

middle & privacy: partially HirIdify

上级 d987b46b
......@@ -14,10 +14,9 @@
use crate::ty::query::Providers;
use crate::middle::privacy;
use crate::session::config;
use crate::util::nodemap::{NodeSet, FxHashSet};
use crate::util::nodemap::{HirIdSet, FxHashSet};
use rustc_target::spec::abi::Abi;
use syntax::ast;
use crate::hir;
use crate::hir::def_id::LOCAL_CRATE;
use crate::hir::intravisit::{Visitor, NestedVisitorMap};
......@@ -70,10 +69,10 @@ struct ReachableContext<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
tables: &'a ty::TypeckTables<'tcx>,
// The set of items which must be exported in the linkage sense.
reachable_symbols: NodeSet,
reachable_symbols: HirIdSet,
// A worklist of item IDs. Each item ID in this worklist will be inlined
// and will be scanned for further references.
worklist: Vec<ast::NodeId>,
worklist: Vec<hir::HirId>,
// Whether any output of this compilation is a library
any_library: bool,
}
......@@ -104,27 +103,28 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
match def {
Some(Def::Local(node_id)) | Some(Def::Upvar(node_id, ..)) => {
self.reachable_symbols.insert(node_id);
let hir_id = self.tcx.hir().node_to_hir_id(node_id);
self.reachable_symbols.insert(hir_id);
}
Some(def) => {
if let Some((node_id, def_id)) = def.opt_def_id().and_then(|def_id| {
self.tcx.hir().as_local_node_id(def_id).map(|node_id| (node_id, def_id))
if let Some((hir_id, def_id)) = def.opt_def_id().and_then(|def_id| {
self.tcx.hir().as_local_hir_id(def_id).map(|hir_id| (hir_id, def_id))
}) {
if self.def_id_represents_local_inlined_item(def_id) {
self.worklist.push(node_id);
self.worklist.push(hir_id);
} else {
match def {
// If this path leads to a constant, then we need to
// recurse into the constant to continue finding
// items that are reachable.
Def::Const(..) | Def::AssociatedConst(..) => {
self.worklist.push(node_id);
self.worklist.push(hir_id);
}
// If this wasn't a static, then the destination is
// surely reachable.
_ => {
self.reachable_symbols.insert(node_id);
self.reachable_symbols.insert(hir_id);
}
}
}
......@@ -204,14 +204,14 @@ fn propagate(&mut self) {
continue
}
if let Some(ref item) = self.tcx.hir().find(search_item) {
if let Some(ref item) = self.tcx.hir().find_by_hir_id(search_item) {
self.propagate_node(item, search_item);
}
}
}
fn propagate_node(&mut self, node: &Node<'tcx>,
search_item: ast::NodeId) {
search_item: hir::HirId) {
if !self.any_library {
// If we are building an executable, only explicitly extern
// types need to be exported.
......@@ -221,7 +221,7 @@ fn propagate_node(&mut self, node: &Node<'tcx>,
} else {
false
};
let def_id = self.tcx.hir().local_def_id(item.id);
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
let is_extern = codegen_attrs.contains_extern_indicator();
let std_internal = codegen_attrs.flags.contains(
......@@ -242,7 +242,7 @@ fn propagate_node(&mut self, node: &Node<'tcx>,
Node::Item(item) => {
match item.node {
hir::ItemKind::Fn(.., body) => {
let def_id = self.tcx.hir().local_def_id(item.id);
let def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
if item_might_be_inlined(self.tcx,
&item,
self.tcx.codegen_fn_attrs(def_id)) {
......@@ -295,7 +295,7 @@ fn propagate_node(&mut self, node: &Node<'tcx>,
self.visit_nested_body(body);
}
hir::ImplItemKind::Method(_, body) => {
let did = self.tcx.hir().get_parent_did(search_item);
let did = self.tcx.hir().get_parent_did_by_hir_id(search_item);
if method_might_be_inlined(self.tcx, impl_item, did) {
self.visit_nested_body(body)
}
......@@ -317,7 +317,7 @@ fn propagate_node(&mut self, node: &Node<'tcx>,
_ => {
bug!(
"found unexpected node kind in worklist: {} ({:?})",
self.tcx.hir().node_to_string(search_item),
self.tcx.hir().hir_to_string(search_item),
node,
);
}
......@@ -336,7 +336,7 @@ fn propagate_node(&mut self, node: &Node<'tcx>,
struct CollectPrivateImplItemsVisitor<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
access_levels: &'a privacy::AccessLevels,
worklist: &'a mut Vec<ast::NodeId>,
worklist: &'a mut Vec<hir::HirId>,
}
impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx> {
......@@ -348,13 +348,18 @@ fn visit_item(&mut self, item: &hir::Item) {
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
if codegen_attrs.contains_extern_indicator() ||
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) {
self.worklist.push(item.id);
self.worklist.push(item.hir_id);
}
// We need only trait impls here, not inherent impls, and only non-exported ones
if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node {
if !self.access_levels.is_reachable(item.id) {
self.worklist.extend(impl_item_refs.iter().map(|r| r.id.node_id));
let node_id = self.tcx.hir().hir_to_node_id(item.hir_id);
if !self.access_levels.is_reachable(node_id) {
// FIXME(@ljedrz): rework back to a nice extend when item Ids contain HirId
for impl_item_ref in impl_item_refs {
let hir_id = self.tcx.hir().node_to_hir_id(impl_item_ref.id.node_id);
self.worklist.push(hir_id);
}
let trait_def_id = match trait_ref.path.def {
Def::Trait(def_id) => def_id,
......@@ -368,11 +373,11 @@ fn visit_item(&mut self, item: &hir::Item) {
let provided_trait_methods = self.tcx.provided_trait_methods(trait_def_id);
self.worklist.reserve(provided_trait_methods.len());
for default_method in provided_trait_methods {
let node_id = self.tcx
.hir()
.as_local_node_id(default_method.def_id)
.unwrap();
self.worklist.push(node_id);
let hir_id = self.tcx
.hir()
.as_local_hir_id(default_method.def_id)
.unwrap();
self.worklist.push(hir_id);
}
}
}
......@@ -388,7 +393,7 @@ fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
// We introduce a new-type here, so we can have a specialized HashStable
// implementation for it.
#[derive(Clone)]
pub struct ReachableSet(pub Lrc<NodeSet>);
pub struct ReachableSet(pub Lrc<HirIdSet>);
fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> ReachableSet {
debug_assert!(crate_num == LOCAL_CRATE);
......@@ -412,11 +417,12 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) ->
// If other crates link to us, they're going to expect to be able to
// use the lang items, so we need to be sure to mark them as
// exported.
reachable_context.worklist.extend(access_levels.map.iter().map(|(id, _)| *id));
reachable_context.worklist.extend(
access_levels.map.iter().map(|(id, _)| tcx.hir().node_to_hir_id(*id)));
for item in tcx.lang_items().items().iter() {
if let Some(did) = *item {
if let Some(node_id) = tcx.hir().as_local_node_id(did) {
reachable_context.worklist.push(node_id);
if let Some(hir_id) = tcx.hir().as_local_hir_id(did) {
reachable_context.worklist.push(hir_id);
}
}
}
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册