use crate::dep_graph::{self, DepConstructor};
use crate::hir::exports::Export;
use crate::hir::map as hir_map;
+use crate::hir::map::definitions::Definitions;
use crate::hir::map::{DefPathData, DefPathHash};
use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
};
use crate::traits;
use crate::traits::{Clause, Clauses, Goal, GoalKind, Goals};
-use crate::ty::free_region_map::FreeRegionMap;
use crate::ty::layout::{LayoutDetails, TargetDataLayout, VariantIdx};
use crate::ty::query;
use crate::ty::steal::Steal;
use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
-use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex, LOCAL_CRATE};
+use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE};
use rustc_hir::{HirId, Node, TraitCandidate};
use rustc_hir::{ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet};
use rustc_index::vec::{Idx, IndexVec};
mut_access: bool,
) {
if let Some(local_id_root) = local_id_root {
- if hir_id.owner != local_id_root.index {
+ if hir_id.owner.to_def_id() != local_id_root {
ty::tls::with(|tcx| {
bug!(
"node {} with HirId::owner {:?} cannot be placed in \
TypeckTables with local_id_root {:?}",
tcx.hir().node_to_string(hir_id),
- DefId::local(hir_id.owner),
+ hir_id.owner,
local_id_root
)
});
/// this field will be set to `true`.
pub tainted_by_errors: bool,
- /// Stores the free-region relationships that were deduced from
- /// its where-clauses and parameter types. These are then
- /// read-again by borrowck.
- pub free_region_map: FreeRegionMap<'tcx>,
-
/// All the opaque types that are restricted to concrete types
/// by this function.
pub concrete_opaque_types: FxHashMap<DefId, ResolvedOpaqueTy<'tcx>>,
coercion_casts: Default::default(),
used_trait_imports: Lrc::new(Default::default()),
tainted_by_errors: false,
- free_region_map: Default::default(),
concrete_opaque_types: Default::default(),
upvar_list: Default::default(),
generator_interior_types: Default::default(),
ref used_trait_imports,
tainted_by_errors,
- ref free_region_map,
ref concrete_opaque_types,
ref upvar_list,
ref generator_interior_types,
let local_id_root = local_id_root.expect("trying to hash invalid TypeckTables");
- let var_owner_def_id =
- DefId { krate: local_id_root.krate, index: var_path.hir_id.owner };
+ let var_owner_def_id = DefId {
+ krate: local_id_root.krate,
+ index: var_path.hir_id.owner.local_def_index,
+ };
let closure_def_id =
- DefId { krate: local_id_root.krate, index: closure_expr_id.to_def_id().index };
+ DefId { krate: local_id_root.krate, index: closure_expr_id.local_def_index };
(
hcx.def_path_hash(var_owner_def_id),
var_path.hir_id.local_id,
coercion_casts.hash_stable(hcx, hasher);
used_trait_imports.hash_stable(hcx, hasher);
tainted_by_errors.hash_stable(hcx, hasher);
- free_region_map.hash_stable(hcx, hasher);
concrete_opaque_types.hash_stable(hcx, hasher);
upvar_list.hash_stable(hcx, hasher);
generator_interior_types.hash_stable(hcx, hasher);
interners: CtxtInterners<'tcx>,
- cstore: Box<CrateStoreDyn>,
+ pub(crate) cstore: Box<CrateStoreDyn>,
pub sess: &'tcx Session,
/// Map indicating what traits are in scope for places where this
/// is relevant; generated by resolve.
- trait_map: FxHashMap<DefIndex, FxHashMap<ItemLocalId, StableVec<TraitCandidate>>>,
+ trait_map: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, StableVec<TraitCandidate>>>,
/// Export map produced by name resolution.
export_map: FxHashMap<DefId, Vec<Export<hir::HirId>>>,
- /// This should usually be accessed with the `tcx.hir()` method.
- pub(crate) hir_map: hir_map::Map<'tcx>,
+ pub(crate) untracked_crate: &'tcx hir::Crate<'tcx>,
+ pub(crate) definitions: &'tcx Definitions,
/// A map from `DefPathHash` -> `DefId`. Includes `DefId`s from the local crate
/// as well as all upstream crates. Only populated in incremental mode.
extern_providers: ty::query::Providers<'tcx>,
arena: &'tcx WorkerLocal<Arena<'tcx>>,
resolutions: ty::ResolverOutputs,
- hir: hir_map::Map<'tcx>,
+ krate: &'tcx hir::Crate<'tcx>,
+ definitions: &'tcx Definitions,
+ dep_graph: DepGraph,
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
crate_name: &str,
output_filenames: &OutputFilenames,
let common_types = CommonTypes::new(&interners);
let common_lifetimes = CommonLifetimes::new(&interners);
let common_consts = CommonConsts::new(&interners, &common_types);
- let dep_graph = hir.dep_graph.clone();
let cstore = resolutions.cstore;
let crates = cstore.crates_untracked();
let max_cnum = crates.iter().map(|c| c.as_usize()).max().unwrap_or(0);
let def_path_tables = crates
.iter()
.map(|&cnum| (cnum, cstore.def_path_table(cnum)))
- .chain(iter::once((LOCAL_CRATE, hir.definitions().def_path_table())));
+ .chain(iter::once((LOCAL_CRATE, definitions.def_path_table())));
// Precompute the capacity of the hashmap so we don't have to
// re-allocate when populating it.
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
for (k, v) in resolutions.trait_map {
- let hir_id = hir.node_to_hir_id(k);
+ let hir_id = definitions.node_to_hir_id(k);
let map = trait_map.entry(hir_id.owner).or_default();
let v = v
.into_iter()
- .map(|tc| tc.map_import_ids(|id| hir.definitions().node_to_hir_id(id)))
+ .map(|tc| tc.map_import_ids(|id| definitions.node_to_hir_id(id)))
.collect();
map.insert(hir_id.local_id, StableVec::new(v));
}
.export_map
.into_iter()
.map(|(k, v)| {
- let exports: Vec<_> =
- v.into_iter().map(|e| e.map_id(|id| hir.node_to_hir_id(id))).collect();
+ let exports: Vec<_> = v
+ .into_iter()
+ .map(|e| e.map_id(|id| definitions.node_to_hir_id(id)))
+ .collect();
(k, exports)
})
.collect(),
maybe_unused_trait_imports: resolutions
.maybe_unused_trait_imports
.into_iter()
- .map(|id| hir.local_def_id_from_node_id(id))
+ .map(|id| definitions.local_def_id(id))
.collect(),
maybe_unused_extern_crates: resolutions
.maybe_unused_extern_crates
.into_iter()
- .map(|(id, sp)| (hir.local_def_id_from_node_id(id), sp))
+ .map(|(id, sp)| (definitions.local_def_id(id), sp))
.collect(),
glob_map: resolutions
.glob_map
.into_iter()
- .map(|(id, names)| (hir.local_def_id_from_node_id(id), names))
+ .map(|(id, names)| (definitions.local_def_id(id), names))
.collect(),
extern_prelude: resolutions.extern_prelude,
- hir_map: hir,
+ untracked_crate: krate,
+ definitions,
def_path_hash_to_def_id,
queries: query::Queries::new(providers, extern_providers, on_disk_query_result_cache),
rcache: Default::default(),
}
pub fn def_key(self, id: DefId) -> hir_map::DefKey {
- if id.is_local() { self.hir().def_key(id) } else { self.cstore.def_key(id) }
+ if let Some(id) = id.as_local() { self.hir().def_key(id) } else { self.cstore.def_key(id) }
}
/// Converts a `DefId` into its fully expanded `DefPath` (every
/// Note that if `id` is not local to this crate, the result will
/// be a non-local `DefPath`.
pub fn def_path(self, id: DefId) -> hir_map::DefPath {
- if id.is_local() { self.hir().def_path(id) } else { self.cstore.def_path(id) }
+ if let Some(id) = id.as_local() {
+ self.hir().def_path(id)
+ } else {
+ self.cstore.def_path(id)
+ }
}
/// Returns whether or not the crate with CrateNum 'cnum'
#[inline]
pub fn def_path_hash(self, def_id: DefId) -> hir_map::DefPathHash {
- if def_id.is_local() {
- self.hir().definitions().def_path_hash(def_id.index)
+ if let Some(def_id) = def_id.as_local() {
+ self.definitions.def_path_hash(def_id)
} else {
self.cstore.def_path_hash(def_id)
}
#[inline(always)]
pub fn create_stable_hashing_context(self) -> StableHashingContext<'tcx> {
- let krate = self.gcx.hir_map.untracked_krate();
+ let krate = self.gcx.untracked_crate;
- StableHashingContext::new(self.sess, krate, self.hir().definitions(), &*self.cstore)
+ StableHashingContext::new(self.sess, krate, self.definitions, &*self.cstore)
}
// This method makes sure that we have a DepNode and a Fingerprint for
/// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`).
pub fn article_and_description(&self, def_id: DefId) -> (&'static str, &'static str) {
- match self.def_key(def_id).disambiguated_data.data {
- DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => {
- let kind = self.def_kind(def_id).unwrap();
- (kind.article(), kind.descr(def_id))
- }
- DefPathData::ClosureExpr => match self.generator_kind(def_id) {
- None => ("a", "closure"),
- Some(rustc_hir::GeneratorKind::Async(..)) => ("an", "async closure"),
- Some(rustc_hir::GeneratorKind::Gen) => ("a", "generator"),
- },
- DefPathData::LifetimeNs(..) => ("a", "lifetime"),
- DefPathData::Impl => ("an", "implementation"),
- _ => bug!("article_and_description called on def_id {:?}", def_id),
- }
+ self.def_kind(def_id)
+ .map(|def_kind| (def_kind.article(), def_kind.descr(def_id)))
+ .unwrap_or_else(|| match self.def_key(def_id).disambiguated_data.data {
+ DefPathData::ClosureExpr => match self.generator_kind(def_id) {
+ None => ("a", "closure"),
+ Some(rustc_hir::GeneratorKind::Async(..)) => ("an", "async closure"),
+ Some(rustc_hir::GeneratorKind::Gen) => ("a", "generator"),
+ },
+ DefPathData::LifetimeNs(..) => ("a", "lifetime"),
+ DefPathData::Impl => ("an", "implementation"),
+ DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => {
+ unreachable!()
+ }
+ _ => bug!("article_and_description called on def_id {:?}", def_id),
+ })
}
}
};
providers.lookup_stability = |tcx, id| {
- assert_eq!(id.krate, LOCAL_CRATE);
- let id = tcx.hir().definitions().def_index_to_hir_id(id.index);
+ let id = tcx.hir().local_def_id_to_hir_id(id.expect_local());
tcx.stability().local_stability(id)
};
providers.lookup_const_stability = |tcx, id| {
- assert_eq!(id.krate, LOCAL_CRATE);
- let id = tcx.hir().definitions().def_index_to_hir_id(id.index);
+ let id = tcx.hir().local_def_id_to_hir_id(id.expect_local());
tcx.stability().local_const_stability(id)
};
providers.lookup_deprecation_entry = |tcx, id| {
- assert_eq!(id.krate, LOCAL_CRATE);
- let id = tcx.hir().definitions().def_index_to_hir_id(id.index);
+ let id = tcx.hir().local_def_id_to_hir_id(id.expect_local());
tcx.stability().local_deprecation_entry(id)
};
providers.extern_mod_stmt_cnum = |tcx, id| {