Skip to content

Commit

Permalink
HirIdification: replace NodeId method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Mar 7, 2019
1 parent 88f755f commit cd06038
Show file tree
Hide file tree
Showing 69 changed files with 336 additions and 339 deletions.
22 changes: 11 additions & 11 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -501,10 +501,10 @@ impl<'hir> Map<'hir> {
}

/// Given a body owner's id, returns the `BodyId` associated with it.
pub fn body_owned_by(&self, id: NodeId) -> BodyId {
self.maybe_body_owned_by(id).unwrap_or_else(|| {
span_bug!(self.span(id), "body_owned_by: {} has no associated body",
self.node_to_string(id));
pub fn body_owned_by(&self, id: HirId) -> BodyId {
self.maybe_body_owned_by_by_hir_id(id).unwrap_or_else(|| {
span_bug!(self.span_by_hir_id(id), "body_owned_by: {} has no associated body",
self.hir_to_string(id));
})
}

Expand Down Expand Up @@ -539,19 +539,19 @@ impl<'hir> Map<'hir> {
self.body_owner_kind(node_id)
}

pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
match self.get(id) {
pub fn ty_param_owner(&self, id: HirId) -> HirId {
match self.get_by_hir_id(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => id,
Node::GenericParam(_) => self.get_parent_node(id),
_ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id))
Node::GenericParam(_) => self.get_parent_node_by_hir_id(id),
_ => bug!("ty_param_owner: {} not a type parameter", self.hir_to_string(id))
}
}

pub fn ty_param_name(&self, id: NodeId) -> Name {
match self.get(id) {
pub fn ty_param_name(&self, id: HirId) -> Name {
match self.get_by_hir_id(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => keywords::SelfUpper.name(),
Node::GenericParam(param) => param.name.ident().name,
_ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)),
_ => bug!("ty_param_name: {} not a type parameter", self.hir_to_string(id)),
}
}

Expand Down
30 changes: 15 additions & 15 deletions src/librustc/infer/opaque_types/mod.rs
Expand Up @@ -4,7 +4,6 @@ use crate::hir::Node;
use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin};
use crate::infer::outlives::free_region_map::FreeRegionRelations;
use rustc_data_structures::fx::FxHashMap;
use syntax::ast;
use crate::traits::{self, PredicateObligation};
use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind};
use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder};
Expand Down Expand Up @@ -686,13 +685,14 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
// let x = || foo(); // returns the Opaque assoc with `foo`
// }
// ```
if let Some(opaque_node_id) = tcx.hir().as_local_node_id(def_id) {
if let Some(opaque_hir_id) = tcx.hir().as_local_hir_id(def_id) {
let parent_def_id = self.parent_def_id;
let def_scope_default = || {
let opaque_parent_node_id = tcx.hir().get_parent(opaque_node_id);
parent_def_id == tcx.hir().local_def_id(opaque_parent_node_id)
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
parent_def_id == tcx.hir()
.local_def_id_from_hir_id(opaque_parent_hir_id)
};
let in_definition_scope = match tcx.hir().find(opaque_node_id) {
let in_definition_scope = match tcx.hir().find_by_hir_id(opaque_hir_id) {
Some(Node::Item(item)) => match item.node {
// impl trait
hir::ItemKind::Existential(hir::ExistTy {
Expand All @@ -706,21 +706,21 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
}) => may_define_existential_type(
tcx,
self.parent_def_id,
opaque_node_id,
opaque_hir_id,
),
_ => def_scope_default(),
},
Some(Node::ImplItem(item)) => match item.node {
hir::ImplItemKind::Existential(_) => may_define_existential_type(
tcx,
self.parent_def_id,
opaque_node_id,
opaque_hir_id,
),
_ => def_scope_default(),
},
_ => bug!(
"expected (impl) item, found {}",
tcx.hir().node_to_string(opaque_node_id),
tcx.hir().hir_to_string(opaque_hir_id),
),
};
if in_definition_scope {
Expand Down Expand Up @@ -839,20 +839,20 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
pub fn may_define_existential_type(
tcx: TyCtxt<'_, '_, '_>,
def_id: DefId,
opaque_node_id: ast::NodeId,
opaque_hir_id: hir::HirId,
) -> bool {
let mut node_id = tcx
let mut hir_id = tcx
.hir()
.as_local_node_id(def_id)
.as_local_hir_id(def_id)
.unwrap();
// named existential types can be defined by any siblings or
// children of siblings
let mod_id = tcx.hir().get_parent(opaque_node_id);
let mod_id = tcx.hir().get_parent_item(opaque_hir_id);
// so we walk up the node tree until we hit the root or the parent
// of the opaque type
while node_id != mod_id && node_id != ast::CRATE_NODE_ID {
node_id = tcx.hir().get_parent(node_id);
while hir_id != mod_id && hir_id != hir::CRATE_HIR_ID {
hir_id = tcx.hir().get_parent_item(hir_id);
}
// syntactically we are allowed to define the concrete type
node_id == mod_id
hir_id == mod_id
}
5 changes: 2 additions & 3 deletions src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -918,9 +918,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) {
debug!("walk_captures({:?})", closure_expr);

let closure_node_id = self.tcx().hir().hir_to_node_id(closure_expr.hir_id);
let closure_def_id = self.tcx().hir().local_def_id(closure_node_id);
self.tcx().with_freevars(closure_node_id, |freevars| {
let closure_def_id = self.tcx().hir().local_def_id_from_hir_id(closure_expr.hir_id);
self.tcx().with_freevars(closure_expr.hir_id, |freevars| {
for freevar in freevars {
let var_hir_id = self.tcx().hir().node_to_hir_id(freevar.var_id());
let upvar_id = ty::UpvarId {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/liveness.rs
Expand Up @@ -476,8 +476,7 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
// in better error messages than just pointing at the closure
// construction site.
let mut call_caps = Vec::new();
let node_id = ir.tcx.hir().hir_to_node_id(expr.hir_id);
ir.tcx.with_freevars(node_id, |freevars| {
ir.tcx.with_freevars(expr.hir_id, |freevars| {
call_caps.extend(freevars.iter().filter_map(|fv| {
if let Def::Local(rv) = fv.def {
let fv_ln = ir.add_live_node(FreeVarNode(fv.span));
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/reachable.rs
Expand Up @@ -51,8 +51,8 @@ fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) {
return true
}
if let Some(impl_node_id) = tcx.hir().as_local_node_id(impl_src) {
match tcx.hir().find(impl_node_id) {
if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_src) {
match tcx.hir().find_by_hir_id(impl_hir_id) {
Some(Node::Item(item)) =>
item_might_be_inlined(tcx, &item, codegen_fn_attrs),
Some(..) | None =>
Expand Down Expand Up @@ -141,12 +141,12 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
// Returns true if the given def ID represents a local item that is
// eligible for inlining and false otherwise.
fn def_id_represents_local_inlined_item(&self, def_id: DefId) -> bool {
let node_id = match self.tcx.hir().as_local_node_id(def_id) {
Some(node_id) => node_id,
let hir_id = match self.tcx.hir().as_local_hir_id(def_id) {
Some(hir_id) => hir_id,
None => { return false; }
};

match self.tcx.hir().find(node_id) {
match self.tcx.hir().find_by_hir_id(hir_id) {
Some(Node::Item(item)) => {
match item.node {
hir::ItemKind::Fn(..) =>
Expand All @@ -173,7 +173,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
} else {
let impl_did = self.tcx
.hir()
.get_parent_did(node_id);
.get_parent_did_by_hir_id(hir_id);
// Check the impl. If the generics on the self
// type of the impl require inlining, this method
// does too.
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/middle/region.rs
Expand Up @@ -223,7 +223,7 @@ pub struct ScopeTree {
/// The parent of the root body owner, if the latter is an
/// an associated const or method, as impls/traits can also
/// have lifetime parameters free in this body.
root_parent: Option<ast::NodeId>,
root_parent: Option<hir::HirId>,

/// `parent_map` maps from a scope ID to the enclosing scope id;
/// this is usually corresponding to the lexical nesting, though
Expand Down Expand Up @@ -650,8 +650,8 @@ impl<'tcx> ScopeTree {
-> Scope {
let param_owner = tcx.parent_def_id(br.def_id).unwrap();

let param_owner_id = tcx.hir().as_local_node_id(param_owner).unwrap();
let scope = tcx.hir().maybe_body_owned_by(param_owner_id).map(|body_id| {
let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap();
let scope = tcx.hir().maybe_body_owned_by_by_hir_id(param_owner_id).map(|body_id| {
tcx.hir().body(body_id).value.hir_id.local_id
}).unwrap_or_else(|| {
// The lifetime was defined on node that doesn't own a body,
Expand All @@ -661,7 +661,7 @@ impl<'tcx> ScopeTree {
"free_scope: {:?} not recognized by the \
region scope tree for {:?} / {:?}",
param_owner,
self.root_parent.map(|id| tcx.hir().local_def_id(id)),
self.root_parent.map(|id| tcx.hir().local_def_id_from_hir_id(id)),
self.root_body.map(|hir_id| DefId::local(hir_id.owner)));

// The trait/impl lifetime is in scope for the method's body.
Expand All @@ -686,7 +686,7 @@ impl<'tcx> ScopeTree {
// on the same function that they ended up being freed in.
assert_eq!(param_owner, fr.scope);

let param_owner_id = tcx.hir().as_local_node_id(param_owner).unwrap();
let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap();
let body_id = tcx.hir().body_owned_by(param_owner_id);
Scope { id: tcx.hir().body(body_id).value.hir_id.local_id, data: ScopeData::CallSite }
}
Expand Down Expand Up @@ -1328,8 +1328,8 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
return tcx.region_scope_tree(closure_base_def_id);
}

let id = tcx.hir().as_local_node_id(def_id).unwrap();
let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) {
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by_by_hir_id(id) {
let mut visitor = RegionResolutionVisitor {
tcx,
scope_tree: ScopeTree::default(),
Expand All @@ -1348,10 +1348,10 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
// If the item is an associated const or a method,
// record its impl/trait parent, as it can also have
// lifetime parameters free in this body.
match tcx.hir().get(id) {
match tcx.hir().get_by_hir_id(id) {
Node::ImplItem(_) |
Node::TraitItem(_) => {
visitor.scope_tree.root_parent = Some(tcx.hir().get_parent(id));
visitor.scope_tree.root_parent = Some(tcx.hir().get_parent_item(id));
}
_ => {}
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -1585,9 +1585,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {

match lifetimeuseset {
Some(LifetimeUseSet::One(lifetime)) => {
let node_id = self.tcx.hir().as_local_node_id(def_id).unwrap();
debug!("node id first={:?}", node_id);
if let Some((id, span, name)) = match self.tcx.hir().get(node_id) {
let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
debug!("hir id first={:?}", hir_id);
if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) {
Node::Lifetime(hir_lifetime) => Some((
hir_lifetime.hir_id,
hir_lifetime.span,
Expand Down Expand Up @@ -1626,8 +1626,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
debug!("Not one use lifetime");
}
None => {
let node_id = self.tcx.hir().as_local_node_id(def_id).unwrap();
if let Some((id, span, name)) = match self.tcx.hir().get(node_id) {
let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) {
Node::Lifetime(hir_lifetime) => Some((
hir_lifetime.hir_id,
hir_lifetime.span,
Expand Down
15 changes: 8 additions & 7 deletions src/librustc/mir/mod.rs
Expand Up @@ -2411,15 +2411,15 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}

AggregateKind::Closure(def_id, _) => ty::tls::with(|tcx| {
if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
format!("[closure@{:?}]", node_id)
format!("[closure@{:?}]", hir_id)
} else {
format!("[closure@{:?}]", tcx.hir().span(node_id))
format!("[closure@{:?}]", tcx.hir().span_by_hir_id(hir_id))
};
let mut struct_fmt = fmt.debug_struct(&name);

tcx.with_freevars(node_id, |freevars| {
tcx.with_freevars(hir_id, |freevars| {
for (freevar, place) in freevars.iter().zip(places) {
let var_name = tcx.hir().name(freevar.var_id());
struct_fmt.field(&var_name.as_str(), place);
Expand All @@ -2433,11 +2433,12 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}),

AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
let name = format!("[generator@{:?}]", tcx.hir().span(node_id));
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
let name = format!("[generator@{:?}]",
tcx.hir().span_by_hir_id(hir_id));
let mut struct_fmt = fmt.debug_struct(&name);

tcx.with_freevars(node_id, |freevars| {
tcx.with_freevars(hir_id, |freevars| {
for (freevar, place) in freevars.iter().zip(places) {
let var_name = tcx.hir().name(freevar.var_id());
struct_fmt.field(&var_name.as_str(), place);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/mono.rs
@@ -1,5 +1,5 @@
use crate::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
use syntax::ast::NodeId;
use crate::hir::HirId;
use syntax::symbol::{Symbol, InternedString};
use crate::ty::{Instance, TyCtxt};
use crate::util::nodemap::FxHashMap;
Expand All @@ -14,7 +14,7 @@ use std::hash::Hash;
pub enum MonoItem<'tcx> {
Fn(Instance<'tcx>),
Static(DefId),
GlobalAsm(NodeId),
GlobalAsm(HirId),
}

impl<'tcx> MonoItem<'tcx> {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/traits/error_reporting.rs
Expand Up @@ -761,7 +761,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
let found_kind = self.closure_kind(closure_def_id, closure_substs).unwrap();
let closure_span = self.tcx.sess.source_map()
.def_span(self.tcx.hir().span_if_local(closure_def_id).unwrap());
let node_id = self.tcx.hir().as_local_node_id(closure_def_id).unwrap();
let hir_id = self.tcx.hir().as_local_hir_id(closure_def_id).unwrap();
let mut err = struct_span_err!(
self.tcx.sess, closure_span, E0525,
"expected a closure that implements the `{}` trait, \
Expand All @@ -780,8 +780,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// a particular trait.
if let Some(tables) = self.in_progress_tables {
let tables = tables.borrow();
let closure_hir_id = self.tcx.hir().node_to_hir_id(node_id);
match (found_kind, tables.closure_kind_origins().get(closure_hir_id)) {
match (found_kind, tables.closure_kind_origins().get(hir_id)) {
(ty::ClosureKind::FnOnce, Some((span, name))) => {
err.span_label(*span, format!(
"closure is `FnOnce` because it moves the \
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/constness.rs
Expand Up @@ -67,10 +67,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
/// only checks whether the function has a `const` modifier
fn is_const_fn_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
let node_id = tcx.hir().as_local_node_id(def_id)
.expect("Non-local call to local provider is_const_fn");
let hir_id = tcx.hir().as_local_hir_id(def_id)
.expect("Non-local call to local provider is_const_fn");

if let Some(fn_like) = FnLikeNode::from_node(tcx.hir().get(node_id)) {
if let Some(fn_like) = FnLikeNode::from_node(tcx.hir().get_by_hir_id(hir_id)) {
fn_like.constness() == hir::Constness::Const
} else {
false
Expand Down

0 comments on commit cd06038

Please sign in to comment.