Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postpone HirIdification until HirId functions are optimized #58376

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
@@ -934,9 +934,7 @@ impl<'hir> Map<'hir> {
}
}

pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData {
let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible

pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData {
match self.find(id) {
Some(Node::Item(i)) => {
match i.node {
@@ -951,9 +949,7 @@ impl<'hir> Map<'hir> {
}
}

pub fn expect_variant(&self, id: HirId) -> &'hir Variant {
let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible

pub fn expect_variant(&self, id: NodeId) -> &'hir Variant {
match self.find(id) {
Some(Node::Variant(variant)) => variant,
_ => bug!("expected variant, found {}", self.node_to_string(id)),
18 changes: 10 additions & 8 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ use crate::hir::def_id::DefId;
use crate::hir::Node;
use crate::middle::region;
use std::{cmp, fmt};
use syntax::ast::DUMMY_NODE_ID;
use syntax_pos::{Pos, Span};
use crate::traits::{ObligationCause, ObligationCauseCode};
use crate::ty::error::TypeError;
@@ -181,8 +182,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let cm = self.sess.source_map();

let scope = region.free_region_binding_scope(self);
let node = self.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
let tag = match self.hir().find_by_hir_id(node) {
let node = self.hir().as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID);
let tag = match self.hir().find(node) {
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
Some(Node::Item(it)) => Self::item_scope_tag(&it),
Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it),
@@ -191,7 +192,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
};
let (prefix, span) = match *region {
ty::ReEarlyBound(ref br) => {
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
let mut sp = cm.def_span(self.hir().span(node));
if let Some(param) = self.hir()
.get_generics(scope)
.and_then(|generics| generics.get_named(&br.name))
@@ -204,7 +205,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
bound_region: ty::BoundRegion::BrNamed(_, ref name),
..
}) => {
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
let mut sp = cm.def_span(self.hir().span(node));
if let Some(param) = self.hir()
.get_generics(scope)
.and_then(|generics| generics.get_named(&name))
@@ -216,15 +217,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
ty::ReFree(ref fr) => match fr.bound_region {
ty::BrAnon(idx) => (
format!("the anonymous lifetime #{} defined on", idx + 1),
self.hir().span_by_hir_id(node),
self.hir().span(node),
),
ty::BrFresh(_) => (
"an anonymous lifetime defined on".to_owned(),
self.hir().span_by_hir_id(node),
self.hir().span(node),
),
_ => (
format!("the lifetime {} as defined on", fr.bound_region),
cm.def_span(self.hir().span_by_hir_id(node)),
cm.def_span(self.hir().span(node)),
),
},
_ => bug!(),
@@ -1450,7 +1451,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
format!(" for lifetime parameter `{}` in coherence check", name)
}
infer::UpvarRegion(ref upvar_id, _) => {
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id);
let var_name = self.tcx.hir().name(var_node_id);
format!(" for capture of `{}` by closure", var_name)
}
infer::NLL(..) => bug!("NLL variable found in lexical phase"),
6 changes: 4 additions & 2 deletions src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
@@ -31,7 +31,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
"...so that reference does not outlive borrowed content");
}
infer::ReborrowUpvar(span, ref upvar_id) => {
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id);
let var_name = self.tcx.hir().name(var_node_id);
err.span_note(span,
&format!("...so that closure can access `{}`", var_name));
}
@@ -163,7 +164,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err
}
infer::ReborrowUpvar(span, ref upvar_id) => {
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id);
let var_name = self.tcx.hir().name(var_node_id);
let mut err = struct_span_err!(self.tcx.sess,
span,
E0313,
4 changes: 2 additions & 2 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
@@ -177,8 +177,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
// Check the impl. If the generics on the self
// type of the impl require inlining, this method
// does too.
let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did).unwrap();
match self.tcx.hir().expect_item_by_hir_id(impl_hir_id).node {
let impl_node_id = self.tcx.hir().as_local_node_id(impl_did).unwrap();
match self.tcx.hir().expect_item(impl_node_id).node {
hir::ItemKind::Impl(..) => {
let generics = self.tcx.generics_of(impl_did);
generics.requires_monomorphization(self.tcx)
8 changes: 4 additions & 4 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
@@ -1248,12 +1248,12 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {
} => {
// FIXME (#24278): non-hygienic comparison
if let Some(def) = lifetimes.get(&hir::ParamName::Plain(label.modern())) {
let hir_id = tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap();
let node_id = tcx.hir().as_local_node_id(def.id().unwrap()).unwrap();

signal_shadowing_problem(
tcx,
label.name,
original_lifetime(tcx.hir().span_by_hir_id(hir_id)),
original_lifetime(tcx.hir().span(node_id)),
shadower_label(label.span),
);
return;
@@ -2593,12 +2593,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
ref lifetimes, s, ..
} => {
if let Some(&def) = lifetimes.get(&param.name.modern()) {
let hir_id = self.tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap();
let node_id = self.tcx.hir().as_local_node_id(def.id().unwrap()).unwrap();

signal_shadowing_problem(
self.tcx,
param.name.ident().name,
original_lifetime(self.tcx.hir().span_by_hir_id(hir_id)),
original_lifetime(self.tcx.hir().span(node_id)),
shadower_lifetime(&param),
);
return;
3 changes: 1 addition & 2 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
@@ -1035,8 +1035,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
).collect::<Vec<_>>())
}
Node::StructCtor(ref variant_data) => {
(self.tcx.sess.source_map().def_span(
self.tcx.hir().span_by_hir_id(variant_data.hir_id())),
(self.tcx.sess.source_map().def_span(self.tcx.hir().span(variant_data.id())),
vec![ArgKind::empty(); variant_data.fields().len()])
}
_ => panic!("non-FnLike node found: {:?}", node),
6 changes: 3 additions & 3 deletions src/librustc/traits/util.rs
Original file line number Diff line number Diff line change
@@ -525,9 +525,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}

pub fn impl_is_default(self, node_item_def_id: DefId) -> bool {
match self.hir().as_local_hir_id(node_item_def_id) {
Some(hir_id) => {
let item = self.hir().expect_item_by_hir_id(hir_id);
match self.hir().as_local_node_id(node_item_def_id) {
Some(node_id) => {
let item = self.hir().expect_item(node_id);
if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.node {
defaultness.is_default()
} else {
4 changes: 2 additions & 2 deletions src/librustc/ty/item_path.rs
Original file line number Diff line number Diff line change
@@ -462,8 +462,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// only occur very early in the compiler pipeline.
let parent_def_id = self.parent_def_id(impl_def_id).unwrap();
self.push_item_path(buffer, parent_def_id, pushed_prelude_crate);
let hir_id = self.hir().as_local_hir_id(impl_def_id).unwrap();
let item = self.hir().expect_item_by_hir_id(hir_id);
let node_id = self.hir().as_local_node_id(impl_def_id).unwrap();
let item = self.hir().expect_item(node_id);
let span_str = self.sess.source_map().span_to_string(item.span);
buffer.push(&format!("<impl at {}>", span_str));
}
12 changes: 6 additions & 6 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -2939,8 +2939,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

/// Get the attributes of a definition.
pub fn get_attrs(self, did: DefId) -> Attributes<'gcx> {
if let Some(id) = self.hir().as_local_hir_id(did) {
Attributes::Borrowed(self.hir().attrs_by_hir_id(id))
if let Some(id) = self.hir().as_local_node_id(did) {
Attributes::Borrowed(self.hir().attrs(id))
} else {
Attributes::Owned(self.item_attrs(did))
}
@@ -2991,8 +2991,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
/// with the name of the crate containing the impl.
pub fn span_of_impl(self, impl_did: DefId) -> Result<Span, Symbol> {
if impl_did.is_local() {
let hir_id = self.hir().as_local_hir_id(impl_did).unwrap();
Ok(self.hir().span_by_hir_id(hir_id))
let node_id = self.hir().as_local_node_id(impl_did).unwrap();
Ok(self.hir().span(node_id))
} else {
Err(self.crate_name(impl_did.krate))
}
@@ -3110,8 +3110,8 @@ fn adt_sized_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId)
-> Lrc<Vec<DefId>> {
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let item = tcx.hir().expect_item_by_hir_id(id);
let id = tcx.hir().as_local_node_id(def_id).unwrap();
let item = tcx.hir().expect_item(id);
let vec: Vec<_> = match item.node {
hir::ItemKind::Trait(.., ref trait_item_refs) => {
trait_item_refs.iter()
2 changes: 1 addition & 1 deletion src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
@@ -802,7 +802,7 @@ impl fmt::Debug for ty::UpvarId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "UpvarId({:?};`{}`;{:?})",
self.var_path.hir_id,
ty::tls::with(|tcx| tcx.hir().name_by_hir_id(self.var_path.hir_id)),
ty::tls::with(|tcx| tcx.hir().name(tcx.hir().hir_to_node_id(self.var_path.hir_id))),
self.closure_expr_id)
}
}
2 changes: 1 addition & 1 deletion src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
@@ -674,7 +674,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
let def_id = field.did;
debug!("IsolatedEncoder::encode_field({:?})", def_id);

let variant_id = tcx.hir().as_local_hir_id(variant.did).unwrap();
let variant_id = tcx.hir().as_local_node_id(variant.did).unwrap();
let variant_data = tcx.hir().expect_variant_data(variant_id);

Entry {
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
@@ -833,13 +833,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
format!("`{}` would have to be valid for `{}`...", name, region_name),
);

if let Some(fn_hir_id) = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id) {
if let Some(fn_node_id) = self.infcx.tcx.hir().as_local_node_id(self.mir_def_id) {
err.span_label(
drop_span,
format!(
"...but `{}` will be dropped here, when the function `{}` returns",
name,
self.infcx.tcx.hir().name_by_hir_id(fn_hir_id),
self.infcx.tcx.hir().name(fn_node_id),
),
);

5 changes: 3 additions & 2 deletions src/librustc_mir/borrow_check/move_errors.rs
Original file line number Diff line number Diff line change
@@ -308,8 +308,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
let upvar_decl = &self.mir.upvar_decls[field.index()];
let upvar_hir_id =
upvar_decl.var_hir_id.assert_crate_local();
let upvar_span = self.infcx.tcx.hir().span_by_hir_id(
upvar_hir_id);
let upvar_node_id =
self.infcx.tcx.hir().hir_to_node_id(upvar_hir_id);
let upvar_span = self.infcx.tcx.hir().span(upvar_node_id);
diag.span_label(upvar_span, "captured outer variable");
break;
}
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ use rustc::ty::subst::{Substs, UnpackedKind};
use rustc::ty::{self, RegionKind, RegionVid, Ty, TyCtxt};
use rustc::util::ppaux::RegionHighlightMode;
use rustc_errors::DiagnosticBuilder;
use syntax::ast::Name;
use syntax::ast::{Name, DUMMY_NODE_ID};
use syntax::symbol::keywords;
use syntax_pos::Span;
use syntax_pos::symbol::InternedString;
@@ -293,9 +293,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
name: &InternedString,
) -> Span {
let scope = error_region.free_region_binding_scope(tcx);
let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
let node = tcx.hir().as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID);

let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(node));
let span = tcx.sess.source_map().def_span(tcx.hir().span(node));
if let Some(param) = tcx.hir()
.get_generics(scope)
.and_then(|generics| generics.get_named(name))
Original file line number Diff line number Diff line change
@@ -71,10 +71,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
upvar_index: usize,
) -> (Symbol, Span) {
let upvar_hir_id = mir.upvar_decls[upvar_index].var_hir_id.assert_crate_local();
debug!("get_upvar_name_and_span_for_region: upvar_hir_id={:?}", upvar_hir_id);
let upvar_node_id = tcx.hir().hir_to_node_id(upvar_hir_id);
debug!("get_upvar_name_and_span_for_region: upvar_node_id={:?}", upvar_node_id);

let upvar_name = tcx.hir().name_by_hir_id(upvar_hir_id);
let upvar_span = tcx.hir().span_by_hir_id(upvar_hir_id);
let upvar_name = tcx.hir().name(upvar_node_id);
let upvar_span = tcx.hir().span(upvar_node_id);
debug!("get_upvar_name_and_span_for_region: upvar_name={:?} upvar_span={:?}",
upvar_name, upvar_span);

5 changes: 3 additions & 2 deletions src/librustc_mir/borrow_check/nll/universal_regions.rs
Original file line number Diff line number Diff line change
@@ -771,8 +771,9 @@ fn for_each_late_bound_region_defined_on<'tcx>(
owner: fn_def_id.index,
local_id: *late_bound,
};
let name = tcx.hir().name_by_hir_id(hir_id).as_interned_str();
let region_def_id = tcx.hir().local_def_id_from_hir_id(hir_id);
let region_node_id = tcx.hir().hir_to_node_id(hir_id);
let name = tcx.hir().name(region_node_id).as_interned_str();
let region_def_id = tcx.hir().local_def_id(region_node_id);
let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion {
scope: fn_def_id,
bound_region: ty::BoundRegion::BrNamed(region_def_id, name),
6 changes: 3 additions & 3 deletions src/librustc_mir/build/mod.rs
Original file line number Diff line number Diff line change
@@ -64,8 +64,8 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
) => {
(*body_id, ty.span)
}
Node::AnonConst(hir::AnonConst { body, hir_id, .. }) => {
(*body, tcx.hir().span_by_hir_id(*hir_id))
Node::AnonConst(hir::AnonConst { body, id, .. }) => {
(*body, tcx.hir().span(*id))
}

_ => span_bug!(tcx.hir().span(id), "can't build MIR for {:?}", def_id),
@@ -114,7 +114,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
let self_arg;
if let Some(ref fn_decl) = tcx.hir().fn_decl(owner_id) {
let ty_hir_id = fn_decl.inputs[index].hir_id;
let ty_span = tcx.hir().span_by_hir_id(ty_hir_id);
let ty_span = tcx.hir().span(tcx.hir().hir_to_node_id(ty_hir_id));
opt_ty_info = Some(ty_span);
self_arg = if index == 0 && fn_decl.implicit_self.has_implicit_self() {
match fn_decl.implicit_self {
2 changes: 1 addition & 1 deletion src/librustc_mir/hair/cx/block.rs
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
for (index, stmt) in stmts.iter().enumerate() {
let hir_id = stmt.hir_id;
let opt_dxn_ext = cx.region_scope_tree.opt_destruction_scope(hir_id.local_id);
let stmt_span = StatementSpan(cx.tcx.hir().span_by_hir_id(hir_id));
let stmt_span = StatementSpan(cx.tcx.hir().span(stmt.id));
match stmt.node {
hir::StmtKind::Expr(ref expr) |
hir::StmtKind::Semi(ref expr) => {
8 changes: 4 additions & 4 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
@@ -450,8 +450,8 @@ fn check_recursion_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if recursion_depth > *tcx.sess.recursion_limit.get() {
let error = format!("reached the recursion limit while instantiating `{}`",
instance);
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
tcx.sess.span_fatal(tcx.hir().span_by_hir_id(hir_id), &error);
if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
tcx.sess.span_fatal(tcx.hir().span(node_id), &error);
} else {
tcx.sess.fatal(&error);
}
@@ -482,8 +482,8 @@ fn check_type_length_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let instance_name = instance.to_string();
let msg = format!("reached the type-length limit while instantiating `{:.64}...`",
instance_name);
let mut diag = if let Some(hir_id) = tcx.hir().as_local_hir_id(instance.def_id()) {
tcx.sess.struct_span_fatal(tcx.hir().span_by_hir_id(hir_id), &msg)
let mut diag = if let Some(node_id) = tcx.hir().as_local_node_id(instance.def_id()) {
tcx.sess.struct_span_fatal(tcx.hir().span(node_id), &msg)
} else {
tcx.sess.struct_fatal(&msg)
};
Loading