Skip to content

Commit

Permalink
rustc: rename TyCtxt's map field to hir.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jan 26, 2017
1 parent 2f0463a commit 45c8c56
Show file tree
Hide file tree
Showing 111 changed files with 761 additions and 761 deletions.
6 changes: 3 additions & 3 deletions src/librustc/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// Find the function this expression is from.
let mut node_id = body.id;
loop {
let node = tcx.map.get(node_id);
let node = tcx.hir.get(node_id);
if hir::map::blocks::FnLikeNode::from_node(node).is_some() {
break;
}
let parent = tcx.map.get_parent_node(node_id);
let parent = tcx.hir.get_parent_node(node_id);
assert!(node_id != parent);
node_id = parent;
}

let mut cfg_builder = CFGBuilder {
tcx: tcx,
tables: tcx.item_tables(tcx.map.local_def_id(node_id)),
tables: tcx.item_tables(tcx.hir.local_def_id(node_id)),
graph: graph,
fn_exit: fn_exit,
loop_scopes: Vec::new()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ pub enum DepNode<D: Clone + Debug> {
// Represents the `Krate` as a whole (the `hir::Krate` value) (as
// distinct from the krate module). This is basically a hash of
// the entire krate, so if you read from `Krate` (e.g., by calling
// `tcx.map.krate()`), we will have to assume that any change
// `tcx.hir.krate()`), we will have to assume that any change
// means that you need to be recompiled. This is because the
// `Krate` value gives you access to all other items. To avoid
// this fate, do not call `tcx.map.krate()`; instead, prefer
// this fate, do not call `tcx.hir.krate()`; instead, prefer
// wrappers like `tcx.visit_all_items_in_krate()`. If there is no
// suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain
// access to the krate, but you must remember to add suitable
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/dep_tracking_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<M: DepTrackingMapConfig> MemoizationMap for RefCell<DepTrackingMap<M>> {
///
/// ```
/// fn type_of_item(..., item: &hir::Item) -> Ty<'tcx> {
/// let item_def_id = ccx.tcx.map.local_def_id(it.id);
/// let item_def_id = ccx.tcx.hir.local_def_id(it.id);
/// ccx.tcx.item_types.memoized(item_def_id, || {
/// ccx.tcx.dep_graph.read(DepNode::Hir(item_def_id)); // (*)
/// compute_type_of_item(ccx, item)
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/dep_graph/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn visit_all_item_likes_in_krate<'a, 'tcx, V, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>
where F: FnMut(DefId) -> DepNode<DefId>, V: ItemLikeVisitor<'tcx>
{
fn visit_item(&mut self, i: &'tcx hir::Item) {
let item_def_id = self.tcx.map.local_def_id(i.id);
let item_def_id = self.tcx.hir.local_def_id(i.id);
let task_id = (self.dep_node_fn)(item_def_id);
let _task = self.tcx.dep_graph.in_task(task_id.clone());
debug!("Started task {:?}", task_id);
Expand All @@ -46,7 +46,7 @@ pub fn visit_all_item_likes_in_krate<'a, 'tcx, V, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>
}

fn visit_trait_item(&mut self, i: &'tcx hir::TraitItem) {
let trait_item_def_id = self.tcx.map.local_def_id(i.id);
let trait_item_def_id = self.tcx.hir.local_def_id(i.id);
let task_id = (self.dep_node_fn)(trait_item_def_id);
let _task = self.tcx.dep_graph.in_task(task_id.clone());
debug!("Started task {:?}", task_id);
Expand All @@ -56,7 +56,7 @@ pub fn visit_all_item_likes_in_krate<'a, 'tcx, V, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>
}

fn visit_impl_item(&mut self, i: &'tcx hir::ImplItem) {
let impl_item_def_id = self.tcx.map.local_def_id(i.id);
let impl_item_def_id = self.tcx.hir.local_def_id(i.id);
let task_id = (self.dep_node_fn)(impl_item_def_id);
let _task = self.tcx.dep_graph.in_task(task_id.clone());
debug!("Started task {:?}", task_id);
Expand All @@ -66,7 +66,7 @@ pub fn visit_all_item_likes_in_krate<'a, 'tcx, V, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>
}
}

let krate = tcx.dep_graph.with_ignore(|| tcx.map.krate());
let krate = tcx.dep_graph.with_ignore(|| tcx.hir.krate());
let mut tracking_visitor = TrackingVisitor {
tcx: tcx,
dep_node_fn: &mut dep_node_fn,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/itemlikevisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use super::intravisit::Visitor;
/// - How: Implement `intravisit::Visitor` and override the
/// `visit_nested_map()` methods to return
/// `NestedVisitorMap::All`. Walk your crate with
/// `intravisit::walk_crate()` invoked on `tcx.map.krate()`.
/// `intravisit::walk_crate()` invoked on `tcx.hir.krate()`.
/// - Pro: Visitor methods for any kind of HIR node, not just item-like things.
/// - Pro: Preserves nesting information
/// - Con: Does not integrate well into dependency tracking.
Expand Down
32 changes: 16 additions & 16 deletions src/librustc/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
format!("{}unknown scope: {:?}{}. Please report a bug.",
prefix, scope, suffix)
};
let span = match scope.span(&self.region_maps, &self.map) {
let span = match scope.span(&self.region_maps, &self.hir) {
Some(s) => s,
None => {
err.note(&unknown_scope());
return;
}
};
let tag = match self.map.find(scope.node_id(&self.region_maps)) {
let tag = match self.hir.find(scope.node_id(&self.region_maps)) {
Some(ast_map::NodeBlock(_)) => "block",
Some(ast_map::NodeExpr(expr)) => match expr.node {
hir::ExprCall(..) => "call",
Expand Down Expand Up @@ -206,7 +206,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

let node = fr.scope.node_id(&self.region_maps);
let unknown;
let tag = match self.map.find(node) {
let tag = match self.hir.find(node) {
Some(ast_map::NodeBlock(_)) |
Some(ast_map::NodeExpr(_)) => "body",
Some(ast_map::NodeItem(it)) => item_scope_tag(&it),
Expand All @@ -218,7 +218,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
Some(_) => {
unknown = format!("unexpected node ({}) for scope {:?}. \
Please report a bug.",
self.map.node_to_string(node), fr.scope);
self.hir.node_to_string(node), fr.scope);
&unknown
}
None => {
Expand All @@ -227,7 +227,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
&unknown
}
};
let (msg, opt_span) = explain_span(self, tag, self.map.span(node));
let (msg, opt_span) = explain_span(self, tag, self.hir.span(node));
(format!("{} {}", prefix, msg), opt_span)
}

Expand Down Expand Up @@ -467,8 +467,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
},
_ => return None
};
let parent = tcx.map.get_parent(scope_id);
let parent_node = tcx.map.find(parent);
let parent = tcx.hir.get_parent(scope_id);
let parent_node = tcx.hir.find(parent);
match parent_node {
Some(node) => match node {
ast_map::NodeItem(item) => match item.node {
Expand Down Expand Up @@ -1068,8 +1068,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

fn give_suggestion(&self, err: &mut DiagnosticBuilder, same_regions: &[SameRegions]) {
let scope_id = same_regions[0].scope_id;
let parent = self.tcx.map.get_parent(scope_id);
let parent_node = self.tcx.map.find(parent);
let parent = self.tcx.hir.get_parent(scope_id);
let parent_node = self.tcx.hir.find(parent);
let taken = lifetimes_in_scope(self.tcx, scope_id);
let life_giver = LifeGiver::with_taken(&taken[..]);
let node_inner = match parent_node {
Expand All @@ -1083,8 +1083,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}
}
ast_map::NodeImplItem(item) => {
let id = self.tcx.map.get_parent(item.id);
if let Some(ast_map::NodeItem(parent_scope)) = self.tcx.map.find(id) {
let id = self.tcx.hir.get_parent(item.id);
if let Some(ast_map::NodeItem(parent_scope)) = self.tcx.hir.find(id) {
if let hir::ItemImpl(_, _, _, None, _, _) = parent_scope.node {
// this impl scope implements a trait, do not recomend
// using explicit lifetimes (#37363)
Expand Down Expand Up @@ -1654,7 +1654,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
generics: &hir::Generics,
span: Span,
body: hir::BodyId) {
let s = hir::print::to_string(&self.tcx.map, |s| {
let s = hir::print::to_string(&self.tcx.hir, |s| {
use syntax::abi::Abi;
use syntax::print::pprust::PrintState;

Expand Down Expand Up @@ -1891,8 +1891,8 @@ fn lifetimes_in_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
scope_id: ast::NodeId)
-> Vec<hir::LifetimeDef> {
let mut taken = Vec::new();
let parent = tcx.map.get_parent(scope_id);
let method_id_opt = match tcx.map.find(parent) {
let parent = tcx.hir.get_parent(scope_id);
let method_id_opt = match tcx.hir.find(parent) {
Some(node) => match node {
ast_map::NodeItem(item) => match item.node {
hir::ItemFn(.., ref gen, _) => {
Expand All @@ -1915,8 +1915,8 @@ fn lifetimes_in_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
None => None
};
if let Some(method_id) = method_id_opt {
let parent = tcx.map.get_parent(method_id);
if let Some(node) = tcx.map.find(parent) {
let parent = tcx.hir.get_parent(method_id);
if let Some(node) = tcx.hir.find(parent) {
match node {
ast_map::NodeItem(item) => match item.node {
hir::ItemImpl(_, _, ref gen, ..) => {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ impl<'a, 'tcx> InferEnv<'a, 'tcx> for hir::BodyId {
-> (Option<&'a ty::TypeckTables<'tcx>>,
Option<ty::TypeckTables<'tcx>>,
Option<ty::ParameterEnvironment<'tcx>>) {
let item_id = tcx.map.body_owner(self);
(Some(tcx.item_tables(tcx.map.local_def_id(item_id))),
let item_id = tcx.hir.body_owner(self);
(Some(tcx.item_tables(tcx.hir.local_def_id(item_id))),
None,
Some(ty::ParameterEnvironment::for_item(tcx, item_id)))
}
Expand Down Expand Up @@ -1269,7 +1269,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
self.tcx.types.err,
None => {
bug!("no type for node {}: {} in fcx",
id, self.tcx.map.node_to_string(id));
id, self.tcx.hir.node_to_string(id));
}
}
}
Expand Down Expand Up @@ -1639,7 +1639,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
-> Option<ty::ClosureKind>
{
if let InferTables::InProgress(tables) = self.tables {
if let Some(id) = self.tcx.map.as_local_node_id(def_id) {
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
return tables.borrow().closure_kinds.get(&id).cloned();
}
}
Expand All @@ -1657,7 +1657,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
-> ty::ClosureTy<'tcx>
{
if let InferTables::InProgress(tables) = self.tables {
if let Some(id) = self.tcx.map.as_local_node_id(def_id) {
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
if let Some(ty) = tables.borrow().closure_tys.get(&id) {
return ty.subst(self.tcx, substs.substs);
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
/// items in the context of the outer item, so enable
/// deep-walking.
fn nested_visit_map<'this>(&'this mut self) -> hir_visit::NestedVisitorMap<'this, 'tcx> {
hir_visit::NestedVisitorMap::All(&self.tcx.map)
hir_visit::NestedVisitorMap::All(&self.tcx.hir)
}

// Output any lints that were previously added to the session.
Expand All @@ -784,7 +784,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_tables = self.tables;
self.tables = self.tcx.body_tables(body);
let body = self.tcx.map.body(body);
let body = self.tcx.hir.body(body);
self.visit_body(body);
self.tables = old_tables;
}
Expand Down Expand Up @@ -834,7 +834,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
// in order for `check_fn` to be able to use them.
let old_tables = self.tables;
self.tables = self.tcx.body_tables(body_id);
let body = self.tcx.map.body(body_id);
let body = self.tcx.hir.body(body_id);
run_lints!(self, check_fn, late_passes, fk, decl, body, span, id);
hir_visit::walk_fn(self, fk, decl, body_id, span, id);
run_lints!(self, check_fn_post, late_passes, fk, decl, body, span, id);
Expand Down Expand Up @@ -1206,7 +1206,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
access_levels: &AccessLevels) {
let _task = tcx.dep_graph.in_task(DepNode::LateLintCheck);

let krate = tcx.map.krate();
let krate = tcx.hir.krate();

// We want to own the lint store, so move it out of the session.
let lint_store = mem::replace(&mut *tcx.sess.lint_store.borrow_mut(), LintStore::new());
Expand Down Expand Up @@ -1236,7 +1236,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
for early_lint in v {
span_bug!(early_lint.diagnostic.span.clone(),
"unprocessed lint {:?} at {}",
early_lint, tcx.map.node_to_string(*id));
early_lint, tcx.hir.node_to_string(*id));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {

impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O> {
fn nested(&self, state: &mut pprust::State, nested: pprust::Nested) -> io::Result<()> {
pprust::PpAnn::nested(&self.tcx.map, state, nested)
pprust::PpAnn::nested(&self.tcx.hir, state, nested)
}
fn pre(&self,
ps: &mut pprust::State,
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use syntax_pos;
// may need to be marked as live.
fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
node_id: ast::NodeId) -> bool {
match tcx.map.find(node_id) {
match tcx.hir.find(node_id) {
Some(ast_map::NodeItem(..)) |
Some(ast_map::NodeImplItem(..)) |
Some(ast_map::NodeForeignItem(..)) |
Expand All @@ -59,7 +59,7 @@ struct MarkSymbolVisitor<'a, 'tcx: 'a> {

impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
fn check_def_id(&mut self, def_id: DefId) {
if let Some(node_id) = self.tcx.map.as_local_node_id(def_id) {
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
if should_explore(self.tcx, node_id) {
self.worklist.push(node_id);
}
Expand All @@ -68,7 +68,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}

fn insert_def_id(&mut self, def_id: DefId) {
if let Some(node_id) = self.tcx.map.as_local_node_id(def_id) {
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
debug_assert!(!should_explore(self.tcx, node_id));
self.live_symbols.insert(node_id);
}
Expand Down Expand Up @@ -143,7 +143,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}
scanned.insert(id);

if let Some(ref node) = self.tcx.map.find(id) {
if let Some(ref node) = self.tcx.hir.find(id) {
self.live_symbols.insert(id);
self.visit_node(node);
}
Expand Down Expand Up @@ -203,7 +203,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_tables = self.tables;
self.tables = self.tcx.body_tables(body);
let body = self.tcx.map.body(body);
let body = self.tcx.hir.body(body);
self.visit_body(body);
self.tables = old_tables;
}
Expand Down Expand Up @@ -434,7 +434,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
}

fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool {
let field_type = self.tcx.item_type(self.tcx.map.local_def_id(field.id));
let field_type = self.tcx.item_type(self.tcx.hir.local_def_id(field.id));
let is_marker_field = match field_type.ty_to_def_id() {
Some(def_id) => self.tcx.lang_items.items().iter().any(|item| *item == Some(def_id)),
_ => false
Expand Down Expand Up @@ -478,10 +478,10 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
// method of a private type is used, but the type itself is never
// called directly.
if let Some(impl_list) =
self.tcx.inherent_impls.borrow().get(&self.tcx.map.local_def_id(id)) {
self.tcx.inherent_impls.borrow().get(&self.tcx.hir.local_def_id(id)) {
for &impl_did in impl_list.iter() {
for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] {
if let Some(item_node_id) = self.tcx.map.as_local_node_id(item_did) {
if let Some(item_node_id) = self.tcx.hir.as_local_node_id(item_did) {
if self.live_symbols.contains(&item_node_id) {
return true;
}
Expand Down Expand Up @@ -514,7 +514,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
/// an error. We could do this also by checking the parents, but
/// this is how the code is setup and it seems harmless enough.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::All(&self.tcx.map)
NestedVisitorMap::All(&self.tcx.hir)
}

fn visit_item(&mut self, item: &'tcx hir::Item) {
Expand Down Expand Up @@ -596,7 +596,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
access_levels: &privacy::AccessLevels) {
let _task = tcx.dep_graph.in_task(DepNode::DeadCheck);
let krate = tcx.map.krate();
let krate = tcx.hir.krate();
let live_symbols = find_live(tcx, access_levels, krate);
let mut visitor = DeadVisitor { tcx: tcx, live_symbols: live_symbols };
intravisit::walk_crate(&mut visitor, krate);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_tables = self.tables;
self.tables = self.tcx.body_tables(body);
let body = self.tcx.map.body(body);
let body = self.tcx.hir.body(body);
self.visit_body(body);
self.tables = old_tables;
}
Expand Down Expand Up @@ -203,7 +203,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
if let Def::Static(def_id, mutbl) = path.def {
if mutbl {
self.require_unsafe(expr.span, "use of mutable static");
} else if match self.tcx.map.get_if_local(def_id) {
} 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),
Expand Down Expand Up @@ -249,5 +249,5 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
unsafe_context: UnsafeContext::new(SafeContext),
};

tcx.map.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
tcx.hir.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
}

0 comments on commit 45c8c56

Please sign in to comment.