Skip to content

[WIP] HirId-ification #57578

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

Closed
Prev Previous commit
Next Next commit
codegen: HirId-ify
  • Loading branch information
ljedrz committed Jan 30, 2019
commit 69de4e43a4fdeb4f5eaff1d6971367f9041d11bd
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {

let mut flags = DIFlags::FlagPrototyped;

let local_id = self.tcx().hir().as_local_node_id(def_id);
let local_id = self.tcx().hir().as_local_hir_id(def_id);
if let Some((id, _, _)) = *self.sess().entry_fn.borrow() {
if local_id == Some(id) {
flags |= DIFlags::FlagMainSubprogram;
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

let mut reachable_non_generics: DefIdMap<_> = tcx.reachable_set(LOCAL_CRATE).0
.iter()
.filter_map(|&node_id| {
.filter_map(|&hir_id| {
// We want to ignore some FFI functions that are not exposed from
// this crate. Reachable FFI functions can be lumped into two
// categories:
Expand All @@ -83,9 +83,9 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
//
// As a result, if this id is an FFI item (foreign item) then we only
// let it through if it's included statically.
match tcx.hir().get(node_id) {
match tcx.hir().get_by_hir_id(hir_id) {
Node::ForeignItem(..) => {
let def_id = tcx.hir().local_def_id(node_id);
let def_id = tcx.hir().local_def_id_from_hir_id(hir_id);
if tcx.is_statically_included_foreign_item(def_id) {
Some(def_id)
} else {
Expand All @@ -105,7 +105,7 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
node: hir::ImplItemKind::Method(..),
..
}) => {
let def_id = tcx.hir().local_def_id(node_id);
let def_id = tcx.hir().local_def_id_from_hir_id(hir_id);
let generics = tcx.generics_of(def_id);
if !generics.requires_monomorphization(tcx) &&
// Functions marked with #[inline] are only ever codegened
Expand Down Expand Up @@ -343,8 +343,8 @@ fn upstream_monomorphizations_for_provider<'a, 'tcx>(
}

fn is_unreachable_local_definition_provider(tcx: TyCtxt, def_id: DefId) -> bool {
if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
!tcx.reachable_set(LOCAL_CRATE).0.contains(&node_id)
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
!tcx.reachable_set(LOCAL_CRATE).0.contains(&hir_id)
} else {
bug!("is_unreachable_local_definition called with non-local DefId: {:?}",
def_id)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
) {
let (main_def_id, span) = match *cx.sess().entry_fn.borrow() {
Some((id, span, _)) => {
(cx.tcx().hir().local_def_id(id), span)
(cx.tcx().hir().local_def_id_from_hir_id(id), span)
}
None => return,
};
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/mono_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub trait MonoItemExt<'a, 'tcx: 'a>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {
};
cx.codegen_static(def_id, is_mutable);
}
MonoItem::GlobalAsm(node_id) => {
let item = cx.tcx().hir().expect_item(node_id);
MonoItem::GlobalAsm(hir_id) => {
let item = cx.tcx().hir().expect_item_by_hir_id(hir_id);
if let hir::ItemKind::GlobalAsm(ref ga) = item.node {
cx.codegen_global_asm(ga);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_utils/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub mod symbol_names_test;
/// reporting an error.
pub fn check_for_rustc_errors_attr(tcx: TyCtxt) {
if let Some((id, span, _)) = *tcx.sess.entry_fn.borrow() {
let main_def_id = tcx.hir().local_def_id(id);
let main_def_id = tcx.hir().local_def_id_from_hir_id(id);

if tcx.has_attr(main_def_id, "rustc_error") {
tcx.sess.span_fatal(span, "compilation successful");
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_utils/symbol_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance

debug!("symbol_name(def_id={:?}, substs={:?})", def_id, substs);

let node_id = tcx.hir().as_local_node_id(def_id);
let hir_id = tcx.hir().as_local_hir_id(def_id);

if def_id.is_local() {
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) {
Expand All @@ -254,8 +254,8 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
}

// FIXME(eddyb) Precompute a custom symbol name based on attributes.
let is_foreign = if let Some(id) = node_id {
match tcx.hir().get(id) {
let is_foreign = if let Some(id) = hir_id {
match tcx.hir().get_by_hir_id(id) {
Node::ForeignItem(_) => true,
_ => false,
}
Expand Down
11 changes: 5 additions & 6 deletions src/librustc_codegen_utils/symbol_names_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use rustc::hir;
use rustc::ty::TyCtxt;
use syntax::ast;

use rustc_mir::monomorphize::Instance;

Expand All @@ -33,9 +32,9 @@ struct SymbolNamesTest<'a, 'tcx:'a> {

impl<'a, 'tcx> SymbolNamesTest<'a, 'tcx> {
fn process_attrs(&mut self,
node_id: ast::NodeId) {
hir_id: hir::HirId) {
let tcx = self.tcx;
let def_id = tcx.hir().local_def_id(node_id);
let def_id = self.tcx.hir().local_def_id_from_hir_id(hir_id);
for attr in tcx.get_attrs(def_id).iter() {
if attr.check_name(SYMBOL_NAME) {
// for now, can only use on monomorphic names
Expand All @@ -56,14 +55,14 @@ impl<'a, 'tcx> SymbolNamesTest<'a, 'tcx> {

impl<'a, 'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'a, 'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item) {
self.process_attrs(item.id);
self.process_attrs(item.hir_id);
}

fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
self.process_attrs(trait_item.id);
self.process_attrs(trait_item.hir_id);
}

fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
self.process_attrs(impl_item.id);
self.process_attrs(impl_item.hir_id);
}
}