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

HirId-ify hir::BodyId #58167

Merged
merged 1 commit into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
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
29 changes: 24 additions & 5 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ impl<'hir> Entry<'hir> {
}
}

fn is_body_owner(self, node_id: NodeId) -> bool {
fn is_body_owner(self, hir_id: HirId) -> bool {
match self.associated_body() {
Some(b) => b.node_id == node_id,
Some(b) => b.hir_id == hir_id,
None => false,
}
}
Expand Down Expand Up @@ -438,7 +438,7 @@ impl<'hir> Map<'hir> {
}

pub fn body(&self, id: BodyId) -> &'hir Body {
self.read(id.node_id);
self.read_by_hir_id(id.hir_id);

// N.B., intentionally bypass `self.forest.krate()` so that we
// do not trigger a read of the whole krate here
Expand All @@ -462,9 +462,10 @@ impl<'hir> Map<'hir> {
/// Returns the `NodeId` that corresponds to the definition of
/// which this is the body of, i.e., a `fn`, `const` or `static`
/// item (possibly associated), a closure, or a `hir::AnonConst`.
pub fn body_owner(&self, BodyId { node_id }: BodyId) -> NodeId {
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> NodeId {
let node_id = self.hir_to_node_id(hir_id);
let parent = self.get_parent_node(node_id);
assert!(self.map[parent.as_usize()].map_or(false, |e| e.is_body_owner(node_id)));
assert!(self.map[parent.as_usize()].map_or(false, |e| e.is_body_owner(hir_id)));
parent
}

Expand All @@ -488,6 +489,12 @@ impl<'hir> Map<'hir> {
}
}

// FIXME(@ljedrz): replace the NodeId variant
pub fn maybe_body_owned_by_by_hir_id(&self, id: HirId) -> Option<BodyId> {
let node_id = self.hir_to_node_id(id);
self.maybe_body_owned_by(node_id)
}

/// 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(|| {
Expand Down Expand Up @@ -521,6 +528,12 @@ impl<'hir> Map<'hir> {
}
}

// FIXME(@ljedrz): replace the NodeId variant
pub fn body_owner_kind_by_hir_id(&self, id: HirId) -> BodyOwnerKind {
let node_id = self.hir_to_node_id(id);
self.body_owner_kind(node_id)
}

pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
match self.get(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => id,
Expand Down Expand Up @@ -837,6 +850,12 @@ impl<'hir> Map<'hir> {
self.local_def_id(self.get_module_parent_node(id))
}

// FIXME(@ljedrz): replace the NodeId variant
pub fn get_module_parent_by_hir_id(&self, id: HirId) -> DefId {
let node_id = self.hir_to_node_id(id);
self.get_module_parent(node_id)
}

/// Returns the `NodeId` of `id`'s nearest module parent, or `id` itself if no
/// module parent is in this map.
pub fn get_module_parent_node(&self, id: NodeId) -> NodeId {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub mod print;
/// the `local_id` part of the `HirId` changing, which is a very useful property in
/// incremental compilation where we have to persist things through changes to
/// the code base.
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
pub struct HirId {
pub owner: DefIndex,
pub local_id: ItemLocalId,
Expand Down Expand Up @@ -1234,7 +1234,7 @@ pub enum UnsafeSource {

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct BodyId {
pub node_id: NodeId,
pub hir_id: HirId,
}

/// The body of a function, closure, or constant value. In the case of
Expand Down Expand Up @@ -1268,7 +1268,7 @@ pub struct Body {
impl Body {
pub fn id(&self) -> BodyId {
BodyId {
node_id: self.value.id
hir_id: self.value.hir_id,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,8 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::BodyId {
fn to_stable_hash_key(&self,
hcx: &StableHashingContext<'a>)
-> (DefPathHash, hir::ItemLocalId) {
let hir::BodyId { node_id } = *self;
node_id.to_stable_hash_key(hcx)
let hir::BodyId { hir_id } = *self;
hir_id.to_stable_hash_key(hcx)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
};

if let Some(body_id) = body_id {
let expr = self.tcx.hir().expect_expr(body_id.node_id);
let expr = self.tcx.hir().expect_expr_by_hir_id(body_id.hir_id);
local_visitor.visit_expr(expr);
}

Expand Down
5 changes: 3 additions & 2 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub use self::SubregionOrigin::*;
pub use self::ValuePairs::*;
pub use crate::ty::IntVarValue;

use crate::hir;
use crate::hir::def_id::DefId;
use crate::infer::canonical::{Canonical, CanonicalVarValues};
use crate::middle::free_region::RegionRelations;
Expand Down Expand Up @@ -203,7 +204,7 @@ pub struct InferCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
// for each body-id in this map, which will process the
// obligations within. This is expected to be done 'late enough'
// that all type inference variables have been bound and so forth.
pub region_obligations: RefCell<Vec<(ast::NodeId, RegionObligation<'tcx>)>>,
pub region_obligations: RefCell<Vec<(hir::HirId, RegionObligation<'tcx>)>>,

/// What is the innermost universe we have created? Starts out as
/// `UniverseIndex::root()` but grows from there as we enter
Expand Down Expand Up @@ -1433,7 +1434,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
pub fn partially_normalize_associated_types_in<T>(
&self,
span: Span,
body_id: ast::NodeId,
body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
value: &T,
) -> InferOk<'tcx, T>
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
pub fn instantiate_opaque_types<T: TypeFoldable<'tcx>>(
&self,
parent_def_id: DefId,
body_id: ast::NodeId,
body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
value: &T,
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> {
Expand Down Expand Up @@ -632,7 +632,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx>
struct Instantiator<'a, 'gcx: 'tcx, 'tcx: 'a> {
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
parent_def_id: DefId,
body_id: ast::NodeId,
body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
opaque_types: OpaqueTypeMap<'tcx>,
obligations: Vec<PredicateObligation<'tcx>>,
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/infer/outlives/env.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::infer::outlives::free_region_map::FreeRegionMap;
use crate::infer::{GenericKind, InferCtxt};
use crate::hir;
use rustc_data_structures::fx::FxHashMap;
use syntax::ast;
use syntax_pos::Span;
use crate::traits::query::outlives_bounds::{self, OutlivesBound};
use crate::ty::{self, Ty};
Expand Down Expand Up @@ -55,7 +55,7 @@ pub struct OutlivesEnvironment<'tcx> {
// results when proving outlives obligations like `T: 'x` later
// (e.g., if `T: 'x` must be proven within the body B1, then we
// know it is true if either `'a: 'x` or `'b: 'x`).
region_bound_pairs_map: FxHashMap<ast::NodeId, RegionBoundPairs<'tcx>>,
region_bound_pairs_map: FxHashMap<hir::HirId, RegionBoundPairs<'tcx>>,

// Used to compute `region_bound_pairs_map`: contains the set of
// in-scope region-bound pairs thus far.
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> {
}

/// Borrows current value of the `region_bound_pairs`.
pub fn region_bound_pairs_map(&self) -> &FxHashMap<ast::NodeId, RegionBoundPairs<'tcx>> {
pub fn region_bound_pairs_map(&self) -> &FxHashMap<hir::HirId, RegionBoundPairs<'tcx>> {
&self.region_bound_pairs_map
}

Expand Down Expand Up @@ -162,7 +162,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> {
&mut self,
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
fn_sig_tys: &[Ty<'tcx>],
body_id: ast::NodeId,
body_id: hir::HirId,
span: Span,
) {
debug!("add_implied_bounds()");
Expand All @@ -176,7 +176,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> {
}

/// Save the current set of region-bound pairs under the given `body_id`.
pub fn save_implied_bounds(&mut self, body_id: ast::NodeId) {
pub fn save_implied_bounds(&mut self, body_id: hir::HirId) {
let old = self.region_bound_pairs_map.insert(
body_id,
self.region_bound_pairs_accum.clone(),
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use crate::infer::outlives::env::RegionBoundPairs;
use crate::infer::outlives::verify::VerifyBoundCx;
use crate::infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound};
use rustc_data_structures::fx::FxHashMap;
use syntax::ast;
use crate::hir;
use crate::traits::ObligationCause;
use crate::ty::outlives::Component;
use crate::ty::{self, Region, Ty, TyCtxt, TypeFoldable};
Expand All @@ -76,7 +76,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
/// information).
pub fn register_region_obligation(
&self,
body_id: ast::NodeId,
body_id: hir::HirId,
obligation: RegionObligation<'tcx>,
) {
debug!(
Expand Down Expand Up @@ -110,7 +110,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
}

/// Trait queries just want to pass back type obligations "as is"
pub fn take_registered_region_obligations(&self) -> Vec<(ast::NodeId, RegionObligation<'tcx>)> {
pub fn take_registered_region_obligations(&self) -> Vec<(hir::HirId, RegionObligation<'tcx>)> {
::std::mem::replace(&mut *self.region_obligations.borrow_mut(), vec![])
}

Expand Down Expand Up @@ -149,7 +149,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
/// processed.
pub fn process_registered_region_obligations(
&self,
region_bound_pairs_map: &FxHashMap<ast::NodeId, RegionBoundPairs<'tcx>>,
region_bound_pairs_map: &FxHashMap<hir::HirId, RegionBoundPairs<'tcx>>,
implicit_region_bound: Option<ty::Region<'tcx>>,
param_env: ty::ParamEnv<'tcx>,
) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
full_env,
ty,
trait_did,
ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID),
ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID),
);
fulfill.select_all_or_error(&infcx).unwrap_or_else(|e| {
panic!(
Expand Down Expand Up @@ -315,7 +315,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
user_env.caller_bounds.iter().cloned().collect();

let mut new_env = param_env.clone();
let dummy_cause = ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID);
let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);

while let Some(pred) = predicates.pop_front() {
infcx.clear_caches();
Expand Down Expand Up @@ -669,7 +669,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
select: &mut SelectionContext<'c, 'd, 'cx>,
only_projections: bool,
) -> bool {
let dummy_cause = ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID);
let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);

for (obligation, mut predicate) in nested
.map(|o| (o.clone(), o.predicate.clone()))
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub struct ObligationCause<'tcx> {
/// (in particular, closures can add new assumptions). See the
/// field `region_obligations` of the `FulfillmentContext` for more
/// information.
pub body_id: ast::NodeId,
pub body_id: hir::HirId,

pub code: ObligationCauseCode<'tcx>
}
Expand Down Expand Up @@ -654,7 +654,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'gcx, 'tcx>(
};
let obligation = Obligation {
param_env,
cause: ObligationCause::misc(span, ast::DUMMY_NODE_ID),
cause: ObligationCause::misc(span, hir::DUMMY_HIR_ID),
recursion_depth: 0,
predicate: trait_ref.to_predicate(),
};
Expand All @@ -677,7 +677,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'gcx, 'tcx>(
// We can use a dummy node-id here because we won't pay any mind
// to region obligations that arise (there shouldn't really be any
// anyhow).
let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);
let cause = ObligationCause::misc(span, hir::DUMMY_HIR_ID);

fulfill_cx.register_bound(infcx, param_env, ty, def_id, cause);

Expand Down Expand Up @@ -1057,7 +1057,7 @@ impl<'tcx,O> Obligation<'tcx,O> {
}

pub fn misc(span: Span,
body_id: ast::NodeId,
body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
trait_ref: O)
-> Obligation<'tcx, O> {
Expand All @@ -1075,18 +1075,18 @@ impl<'tcx,O> Obligation<'tcx,O> {
impl<'tcx> ObligationCause<'tcx> {
#[inline]
pub fn new(span: Span,
body_id: ast::NodeId,
body_id: hir::HirId,
code: ObligationCauseCode<'tcx>)
-> ObligationCause<'tcx> {
ObligationCause { span: span, body_id: body_id, code: code }
ObligationCause { span, body_id, code }
}

pub fn misc(span: Span, body_id: ast::NodeId) -> ObligationCause<'tcx> {
ObligationCause { span: span, body_id: body_id, code: MiscObligation }
pub fn misc(span: Span, body_id: hir::HirId) -> ObligationCause<'tcx> {
ObligationCause { span, body_id, code: MiscObligation }
}

pub fn dummy() -> ObligationCause<'tcx> {
ObligationCause { span: DUMMY_SP, body_id: ast::CRATE_NODE_ID, code: MiscObligation }
ObligationCause { span: DUMMY_SP, body_id: hir::CRATE_HIR_ID, code: MiscObligation }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/query/outlives_bounds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::infer::InferCtxt;
use crate::infer::canonical::OriginalQueryValues;
use syntax::ast;
use crate::hir;
use syntax::source_map::Span;
use crate::traits::{FulfillmentContext, ObligationCause, TraitEngine, TraitEngineExt};
use crate::traits::query::NoSolution;
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
pub fn implied_outlives_bounds(
&self,
param_env: ty::ParamEnv<'tcx>,
body_id: ast::NodeId,
body_id: hir::HirId,
ty: Ty<'tcx>,
span: Span,
) -> Vec<OutlivesBound<'tcx>> {
Expand Down
Loading