diff --git a/Cargo.lock b/Cargo.lock index 45a1a169be446..a25f8dbc9186a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3091,6 +3091,7 @@ dependencies = [ "rustc_errors", "rustc_feature", "rustc_fs_util", + "rustc_hir", "rustc_index", "rustc_macros", "rustc_session", @@ -3368,6 +3369,7 @@ dependencies = [ "rustc_error_codes", "rustc_errors", "rustc_index", + "rustc_session", "rustc_span", "rustc_target", "smallvec 1.0.0", @@ -3562,6 +3564,22 @@ dependencies = [ name = "rustc_fs_util" version = "0.0.0" +[[package]] +name = "rustc_hir" +version = "0.0.0" +dependencies = [ + "rustc_data_structures", + "rustc_errors", + "rustc_index", + "rustc_macros", + "rustc_session", + "rustc_span", + "rustc_target", + "serialize", + "smallvec 1.0.0", + "syntax", +] + [[package]] name = "rustc_incremental" version = "0.0.0" @@ -3602,6 +3620,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_expand", + "rustc_hir", "rustc_incremental", "rustc_lint", "rustc_metadata", @@ -3808,6 +3827,7 @@ dependencies = [ "rustc_expand", "rustc_feature", "rustc_metadata", + "rustc_session", "rustc_span", "smallvec 1.0.0", "syntax", diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml index 973384bcf05aa..2e882cfdafdf3 100644 --- a/src/librustc/Cargo.toml +++ b/src/librustc/Cargo.toml @@ -23,6 +23,7 @@ rustc-rayon-core = "0.3.0" polonius-engine = "0.11.0" rustc_apfloat = { path = "../librustc_apfloat" } rustc_feature = { path = "../librustc_feature" } +rustc_hir = { path = "../librustc_hir" } rustc_target = { path = "../librustc_target" } rustc_macros = { path = "../librustc_macros" } rustc_data_structures = { path = "../librustc_data_structures" } diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index c576c5af31e6a..1c7d36b731225 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -41,10 +41,10 @@ macro_rules! arena_types { rustc::hir::def_id::DefId, rustc::ty::subst::SubstsRef<$tcx> )>, - [few, decode] mir_keys: rustc::util::nodemap::DefIdSet, + [few, decode] mir_keys: rustc::hir::def_id::DefIdSet, [decode] specialization_graph: rustc::traits::specialization_graph::Graph, [] region_scope_tree: rustc::middle::region::ScopeTree, - [] item_local_set: rustc::util::nodemap::ItemLocalSet, + [] item_local_set: rustc::hir::ItemLocalSet, [decode] mir_const_qualif: rustc_index::bit_set::BitSet, [] trait_impls_of: rustc::ty::trait_def::TraitImpls, [] dropck_outlives: @@ -87,7 +87,7 @@ macro_rules! arena_types { >, [few] crate_inherent_impls: rustc::ty::CrateInherentImpls, [few] upstream_monomorphizations: - rustc::util::nodemap::DefIdMap< + rustc::hir::def_id::DefIdMap< rustc_data_structures::fx::FxHashMap< rustc::ty::subst::SubstsRef<'tcx>, rustc::hir::def_id::CrateNum @@ -113,10 +113,10 @@ macro_rules! arena_types { >, [few] get_lib_features: rustc::middle::lib_features::LibFeatures, [few] defined_lib_features: rustc::middle::lang_items::LanguageItems, - [few] visible_parent_map: rustc::util::nodemap::DefIdMap, + [few] visible_parent_map: rustc::hir::def_id::DefIdMap, [few] foreign_module: rustc::middle::cstore::ForeignModule, [few] foreign_modules: Vec, - [few] reachable_non_generics: rustc::util::nodemap::DefIdMap< + [few] reachable_non_generics: rustc::hir::def_id::DefIdMap< rustc::middle::exported_symbols::SymbolExportLevel >, [few] crate_variances: rustc::ty::CrateVariancesMap<'tcx>, diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 8c68f7272c02c..0dae5d05066ef 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -396,12 +396,6 @@ impl DefPathHash { } } -impl DefId { - pub fn to_dep_node(self, tcx: TyCtxt<'_>, kind: DepKind) -> DepNode { - DepNode::from_def_path_hash(kind, tcx.def_path_hash(self)) - } -} - rustc_dep_node_append!([define_dep_nodes!][ <'tcx> // We use this for most things when incr. comp. is turned off. [] Null, diff --git a/src/librustc/hir.rs b/src/librustc/hir.rs new file mode 100644 index 0000000000000..62160fed1bc66 --- /dev/null +++ b/src/librustc/hir.rs @@ -0,0 +1,30 @@ +//! HIR datatypes. See the [rustc guide] for more info. +//! +//! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html + +pub mod check_attr; +pub use rustc_hir::def; +pub mod exports; +pub use rustc_hir::def_id; +pub use rustc_hir::hir_id::*; +pub mod intravisit; +pub use rustc_hir::itemlikevisit; +pub mod map; +pub use rustc_hir::pat_util; +pub use rustc_hir::print; +pub mod upvars; + +pub use rustc_hir::BlockCheckMode::*; +pub use rustc_hir::FunctionRetTy::*; +pub use rustc_hir::PrimTy::*; +pub use rustc_hir::UnOp::*; +pub use rustc_hir::UnsafeSource::*; +pub use rustc_hir::*; + +use crate::ty::query::Providers; + +pub fn provide(providers: &mut Providers<'_>) { + check_attr::provide(providers); + map::provide(providers); + upvars::provide(providers); +} diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index a7d7dddf580da..08d4163add732 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -7,7 +7,7 @@ use crate::hir::def_id::DefId; use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; use crate::hir::DUMMY_HIR_ID; -use crate::hir::{self, Attribute, HirId, Item, ItemKind, TraitItem, TraitItemKind}; +use crate::hir::{self, HirId, Item, ItemKind, TraitItem, TraitItemKind}; use crate::lint::builtin::UNUSED_ATTRIBUTES; use crate::ty::query::Providers; use crate::ty::TyCtxt; @@ -15,6 +15,7 @@ use crate::ty::TyCtxt; use rustc_error_codes::*; use rustc_span::symbol::sym; use rustc_span::Span; +use syntax::ast::Attribute; use syntax::attr; use std::fmt::{self, Display}; diff --git a/src/librustc/hir/exports.rs b/src/librustc/hir/exports.rs new file mode 100644 index 0000000000000..a2e885f2a6a7e --- /dev/null +++ b/src/librustc/hir/exports.rs @@ -0,0 +1,32 @@ +use crate::hir::def::Res; +use crate::hir::def_id::DefIdMap; +use crate::ty; + +use rustc_macros::HashStable; +use rustc_span::Span; +use syntax::ast; + +use std::fmt::Debug; + +/// This is the replacement export map. It maps a module to all of the exports +/// within. +pub type ExportMap = DefIdMap>>; + +#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] +pub struct Export { + /// The name of the target. + pub ident: ast::Ident, + /// The resolution of the target. + pub res: Res, + /// The span of the target. + pub span: Span, + /// The visibility of the export. + /// We include non-`pub` exports for hygienic macros that get used from extern crates. + pub vis: ty::Visibility, +} + +impl Export { + pub fn map_id(self, map: impl FnMut(Id) -> R) -> Export { + Export { ident: self.ident, res: self.res.map_id(map), span: self.span, vis: self.vis } + } +} diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 241febe0cf60c..780b0e36b5e4d 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -31,13 +31,66 @@ //! This order consistency is required in a few places in rustc, for //! example generator inference, and possibly also HIR borrowck. -use super::itemlikevisit::DeepVisitor; - +use crate::hir::itemlikevisit::{ItemLikeVisitor, ParItemLikeVisitor}; use crate::hir::map::Map; use crate::hir::*; use rustc_span::Span; -use syntax::ast::{Attribute, Ident, Name}; +use syntax::ast::{Attribute, Ident, Label, Name}; + +pub struct DeepVisitor<'v, V> { + visitor: &'v mut V, +} + +impl<'v, 'hir, V> DeepVisitor<'v, V> +where + V: Visitor<'hir> + 'v, +{ + pub fn new(base: &'v mut V) -> Self { + DeepVisitor { visitor: base } + } +} + +impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V> +where + V: Visitor<'hir>, +{ + fn visit_item(&mut self, item: &'hir Item<'hir>) { + self.visitor.visit_item(item); + } + + fn visit_trait_item(&mut self, trait_item: &'hir TraitItem<'hir>) { + self.visitor.visit_trait_item(trait_item); + } + + fn visit_impl_item(&mut self, impl_item: &'hir ImplItem<'hir>) { + self.visitor.visit_impl_item(impl_item); + } +} + +pub trait IntoVisitor<'hir> { + type Visitor: Visitor<'hir>; + fn into_visitor(&self) -> Self::Visitor; +} + +pub struct ParDeepVisitor(pub V); + +impl<'hir, V> ParItemLikeVisitor<'hir> for ParDeepVisitor +where + V: IntoVisitor<'hir>, +{ + fn visit_item(&self, item: &'hir Item<'hir>) { + self.0.into_visitor().visit_item(item); + } + + fn visit_trait_item(&self, trait_item: &'hir TraitItem<'hir>) { + self.0.into_visitor().visit_trait_item(trait_item); + } + + fn visit_impl_item(&self, impl_item: &'hir ImplItem<'hir>) { + self.0.into_visitor().visit_impl_item(impl_item); + } +} #[derive(Copy, Clone)] pub enum FnKind<'a> { diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 00026d6969bb5..25083281ce9d1 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -1,16 +1,15 @@ use super::*; use crate::dep_graph::{DepGraph, DepKind, DepNodeIndex}; use crate::hir; -use crate::hir::def_id::{CrateNum, LOCAL_CRATE}; +use crate::hir::def_id::{CrateNum, DefIndex, LOCAL_CRATE}; use crate::hir::intravisit::{NestedVisitorMap, Visitor}; use crate::hir::map::HirEntryMap; use crate::ich::Fingerprint; use crate::middle::cstore::CrateStore; -use crate::session::CrateDisambiguator; -use crate::session::Session; -use crate::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::svh::Svh; use rustc_index::vec::IndexVec; +use rustc_session::{CrateDisambiguator, Session}; use rustc_span::source_map::SourceMap; use rustc_span::Span; use std::iter::repeat; diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index 60bacfbe2df63..b04c3523662eb 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -7,12 +7,12 @@ use crate::hir; use crate::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE}; use crate::ich::Fingerprint; -use crate::session::CrateDisambiguator; -use crate::util::nodemap::NodeMap; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::StableHasher; use rustc_index::vec::IndexVec; +use rustc_session::node_id::NodeMap; +use rustc_session::CrateDisambiguator; use rustc_span::hygiene::ExpnId; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 9ea10d0c51591..b499ba20b8cf1 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -4,20 +4,21 @@ pub use self::definitions::{ }; use crate::dep_graph::{DepGraph, DepKind, DepNode, DepNodeIndex}; -use crate::hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX}; +use crate::hir::def::{DefKind, Res}; +use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX}; use crate::hir::itemlikevisit::ItemLikeVisitor; use crate::hir::print::Nested; -use crate::hir::DefKind; use crate::hir::*; use crate::middle::cstore::CrateStoreDyn; use crate::ty::query::Providers; use crate::util::common::time; -use crate::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::svh::Svh; use rustc_index::vec::IndexVec; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::Spanned; +use rustc_span::symbol::kw; use rustc_span::{Span, DUMMY_SP}; use rustc_target::spec::abi::Abi; use syntax::ast::{self, Name, NodeId}; @@ -1203,7 +1204,7 @@ impl Named for ImplItem<'_> { } pub fn map_crate<'hir>( - sess: &crate::session::Session, + sess: &rustc_session::Session, cstore: &CrateStoreDyn, forest: &'hir Forest<'hir>, definitions: Definitions, @@ -1265,45 +1266,6 @@ impl<'hir> print::PpAnn for Map<'hir> { } } -impl<'a> print::State<'a> { - pub fn print_node(&mut self, node: Node<'_>) { - match node { - Node::Param(a) => self.print_param(&a), - Node::Item(a) => self.print_item(&a), - Node::ForeignItem(a) => self.print_foreign_item(&a), - Node::TraitItem(a) => self.print_trait_item(a), - Node::ImplItem(a) => self.print_impl_item(a), - Node::Variant(a) => self.print_variant(&a), - Node::AnonConst(a) => self.print_anon_const(&a), - Node::Expr(a) => self.print_expr(&a), - Node::Stmt(a) => self.print_stmt(&a), - Node::PathSegment(a) => self.print_path_segment(&a), - Node::Ty(a) => self.print_type(&a), - Node::TraitRef(a) => self.print_trait_ref(&a), - Node::Binding(a) | Node::Pat(a) => self.print_pat(&a), - Node::Arm(a) => self.print_arm(&a), - Node::Block(a) => { - // Containing cbox, will be closed by print-block at `}`. - self.cbox(print::INDENT_UNIT); - // Head-ibox, will be closed by print-block after `{`. - self.ibox(0); - self.print_block(&a) - } - Node::Lifetime(a) => self.print_lifetime(&a), - Node::Visibility(a) => self.print_visibility(&a), - Node::GenericParam(_) => bug!("cannot print Node::GenericParam"), - Node::Field(_) => bug!("cannot print StructField"), - // These cases do not carry enough information in the - // `hir_map` to reconstruct their full structure for pretty - // printing. - Node::Ctor(..) => bug!("cannot print isolated Ctor"), - Node::Local(a) => self.print_local_decl(&a), - Node::MacroDef(_) => bug!("cannot print MacroDef"), - Node::Crate => bug!("cannot print Crate"), - } - } -} - fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String { let id_str = format!(" (hir_id={})", id); let id_str = if include_id { &id_str[..] } else { "" }; diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 44230fa0a44dc..86cad00af17a8 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -33,10 +33,10 @@ pub struct StableHashingContext<'a> { sess: &'a Session, definitions: &'a Definitions, cstore: &'a dyn CrateStore, - body_resolver: BodyResolver<'a>, + pub(super) body_resolver: BodyResolver<'a>, hash_spans: bool, hash_bodies: bool, - node_id_hashing_mode: NodeIdHashingMode, + pub(super) node_id_hashing_mode: NodeIdHashingMode, // Very often, we are hashing something that does not need the // `CachingSourceMapView`, so we initialize it lazily. @@ -54,12 +54,12 @@ pub enum NodeIdHashingMode { /// We could also just store a plain reference to the `hir::Crate` but we want /// to avoid that the crate is used to get untracked access to all of the HIR. #[derive(Clone, Copy)] -struct BodyResolver<'tcx>(&'tcx hir::Crate<'tcx>); +pub(super) struct BodyResolver<'tcx>(&'tcx hir::Crate<'tcx>); impl<'tcx> BodyResolver<'tcx> { /// Returns a reference to the `hir::Body` with the given `BodyId`. /// **Does not do any tracking**; use carefully. - fn body(self, id: hir::BodyId) -> &'tcx hir::Body<'tcx> { + pub(super) fn body(self, id: hir::BodyId) -> &'tcx hir::Body<'tcx> { self.0.body(id) } } @@ -207,31 +207,6 @@ impl<'a> StableHashingContextProvider<'a> for StableHashingContext<'a> { impl<'a> crate::dep_graph::DepGraphSafe for StableHashingContext<'a> {} -impl<'a> HashStable> for hir::BodyId { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - if hcx.hash_bodies() { - hcx.body_resolver.body(*self).hash_stable(hcx, hasher); - } - } -} - -impl<'a> HashStable> for hir::HirId { - #[inline] - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - match hcx.node_id_hashing_mode { - NodeIdHashingMode::Ignore => { - // Don't do anything. - } - NodeIdHashingMode::HashDefPath => { - let hir::HirId { owner, local_id } = *self; - - hcx.local_def_path_hash(owner).hash_stable(hcx, hasher); - local_id.hash_stable(hcx, hasher); - } - } - } -} - impl<'a> ToStableHashKey> for hir::HirId { type KeyType = (DefPathHash, hir::ItemLocalId); diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 214a50456d576..f69051fd85dd2 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -11,10 +11,132 @@ use smallvec::SmallVec; use std::mem; use syntax::attr; -impl<'a> HashStable> for DefId { +impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> { #[inline] - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - hcx.def_path_hash(*self).hash_stable(hcx, hasher); + fn hash_def_id(&mut self, def_id: DefId, hasher: &mut StableHasher) { + let hcx = self; + hcx.def_path_hash(def_id).hash_stable(hcx, hasher); + } + + #[inline] + fn hash_hir_id(&mut self, hir_id: hir::HirId, hasher: &mut StableHasher) { + let hcx = self; + match hcx.node_id_hashing_mode { + NodeIdHashingMode::Ignore => { + // Don't do anything. + } + NodeIdHashingMode::HashDefPath => { + let hir::HirId { owner, local_id } = hir_id; + + hcx.local_def_path_hash(owner).hash_stable(hcx, hasher); + local_id.hash_stable(hcx, hasher); + } + } + } + + fn hash_body_id(&mut self, id: hir::BodyId, hasher: &mut StableHasher) { + let hcx = self; + if hcx.hash_bodies() { + hcx.body_resolver.body(id).hash_stable(hcx, hasher); + } + } + + // The following implementations of HashStable for `ItemId`, `TraitItemId`, and + // `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within + // the HIR, since they just signify a HIR nodes own path. But `ItemId` et al + // are used when another item in the HIR is *referenced* and we certainly + // want to pick up on a reference changing its target, so we hash the NodeIds + // in "DefPath Mode". + + fn hash_item_id(&mut self, id: hir::ItemId, hasher: &mut StableHasher) { + let hcx = self; + let hir::ItemId { id } = id; + + hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { + id.hash_stable(hcx, hasher); + }) + } + + fn hash_impl_item_id(&mut self, id: hir::ImplItemId, hasher: &mut StableHasher) { + let hcx = self; + let hir::ImplItemId { hir_id } = id; + + hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { + hir_id.hash_stable(hcx, hasher); + }) + } + + fn hash_trait_item_id(&mut self, id: hir::TraitItemId, hasher: &mut StableHasher) { + let hcx = self; + let hir::TraitItemId { hir_id } = id; + + hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { + hir_id.hash_stable(hcx, hasher); + }) + } + + fn hash_hir_mod(&mut self, module: &hir::Mod<'_>, hasher: &mut StableHasher) { + let hcx = self; + let hir::Mod { inner: ref inner_span, ref item_ids } = *module; + + inner_span.hash_stable(hcx, hasher); + + // Combining the `DefPathHash`s directly is faster than feeding them + // into the hasher. Because we use a commutative combine, we also don't + // have to sort the array. + let item_ids_hash = item_ids + .iter() + .map(|id| { + let (def_path_hash, local_id) = id.id.to_stable_hash_key(hcx); + debug_assert_eq!(local_id, hir::ItemLocalId::from_u32(0)); + def_path_hash.0 + }) + .fold(Fingerprint::ZERO, |a, b| a.combine_commutative(b)); + + item_ids.len().hash_stable(hcx, hasher); + item_ids_hash.hash_stable(hcx, hasher); + } + + fn hash_hir_expr(&mut self, expr: &hir::Expr<'_>, hasher: &mut StableHasher) { + self.while_hashing_hir_bodies(true, |hcx| { + let hir::Expr { hir_id: _, ref span, ref kind, ref attrs } = *expr; + + span.hash_stable(hcx, hasher); + kind.hash_stable(hcx, hasher); + attrs.hash_stable(hcx, hasher); + }) + } + + fn hash_hir_ty(&mut self, ty: &hir::Ty<'_>, hasher: &mut StableHasher) { + self.while_hashing_hir_bodies(true, |hcx| { + let hir::Ty { hir_id: _, ref kind, ref span } = *ty; + + kind.hash_stable(hcx, hasher); + span.hash_stable(hcx, hasher); + }) + } + + fn hash_hir_visibility_kind( + &mut self, + vis: &hir::VisibilityKind<'_>, + hasher: &mut StableHasher, + ) { + let hcx = self; + mem::discriminant(vis).hash_stable(hcx, hasher); + match *vis { + hir::VisibilityKind::Public | hir::VisibilityKind::Inherited => { + // No fields to hash. + } + hir::VisibilityKind::Crate(sugar) => { + sugar.hash_stable(hcx, hasher); + } + hir::VisibilityKind::Restricted { ref path, hir_id } => { + hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { + hir_id.hash_stable(hcx, hasher); + }); + path.hash_stable(hcx, hasher); + } + } } } @@ -69,66 +191,6 @@ impl<'a> ToStableHashKey> for hir::ItemLocalId { } } -// The following implementations of HashStable for `ItemId`, `TraitItemId`, and -// `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within -// the HIR, since they just signify a HIR nodes own path. But `ItemId` et al -// are used when another item in the HIR is *referenced* and we certainly -// want to pick up on a reference changing its target, so we hash the NodeIds -// in "DefPath Mode". - -impl<'a> HashStable> for hir::ItemId { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - let hir::ItemId { id } = *self; - - hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { - id.hash_stable(hcx, hasher); - }) - } -} - -impl<'a> HashStable> for hir::TraitItemId { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - let hir::TraitItemId { hir_id } = *self; - - hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { - hir_id.hash_stable(hcx, hasher); - }) - } -} - -impl<'a> HashStable> for hir::ImplItemId { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - let hir::ImplItemId { hir_id } = *self; - - hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { - hir_id.hash_stable(hcx, hasher); - }) - } -} - -impl<'a> HashStable> for hir::Ty<'_> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - hcx.while_hashing_hir_bodies(true, |hcx| { - let hir::Ty { hir_id: _, ref kind, ref span } = *self; - - kind.hash_stable(hcx, hasher); - span.hash_stable(hcx, hasher); - }) - } -} - -impl<'a> HashStable> for hir::Expr<'_> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - hcx.while_hashing_hir_bodies(true, |hcx| { - let hir::Expr { hir_id: _, ref span, ref kind, ref attrs } = *self; - - span.hash_stable(hcx, hasher); - kind.hash_stable(hcx, hasher); - attrs.hash_stable(hcx, hasher); - }) - } -} - impl<'a> HashStable> for hir::TraitItem<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::TraitItem { hir_id: _, ident, ref attrs, ref generics, ref kind, span } = *self; @@ -168,49 +230,6 @@ impl<'a> HashStable> for hir::ImplItem<'_> { } } -impl<'a> HashStable> for hir::VisibilityKind<'_> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - hir::VisibilityKind::Public | hir::VisibilityKind::Inherited => { - // No fields to hash. - } - hir::VisibilityKind::Crate(sugar) => { - sugar.hash_stable(hcx, hasher); - } - hir::VisibilityKind::Restricted { ref path, hir_id } => { - hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { - hir_id.hash_stable(hcx, hasher); - }); - path.hash_stable(hcx, hasher); - } - } - } -} - -impl<'a> HashStable> for hir::Mod<'_> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - let hir::Mod { inner: ref inner_span, ref item_ids } = *self; - - inner_span.hash_stable(hcx, hasher); - - // Combining the `DefPathHash`s directly is faster than feeding them - // into the hasher. Because we use a commutative combine, we also don't - // have to sort the array. - let item_ids_hash = item_ids - .iter() - .map(|id| { - let (def_path_hash, local_id) = id.id.to_stable_hash_key(hcx); - debug_assert_eq!(local_id, hir::ItemLocalId::from_u32(0)); - def_path_hash.0 - }) - .fold(Fingerprint::ZERO, |a, b| a.combine_commutative(b)); - - item_ids.len().hash_stable(hcx, hasher); - item_ids_hash.hash_stable(hcx, hasher); - } -} - impl<'a> HashStable> for hir::Item<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::Item { ident, ref attrs, hir_id: _, ref kind, ref vis, span } = *self; diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 90e1cac211aa6..e72a5241fadb1 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -43,25 +43,23 @@ impl<'a> HashStable> for [ast::Attribute] { } } -impl<'a> HashStable> for ast::Attribute { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { +impl<'ctx> syntax::HashStableContext for StableHashingContext<'ctx> { + fn hash_attr(&mut self, attr: &ast::Attribute, hasher: &mut StableHasher) { // Make sure that these have been filtered out. - debug_assert!(!self.ident().map_or(false, |ident| hcx.is_ignored_attr(ident.name))); - debug_assert!(!self.is_doc_comment()); + debug_assert!(!attr.ident().map_or(false, |ident| self.is_ignored_attr(ident.name))); + debug_assert!(!attr.is_doc_comment()); - let ast::Attribute { kind, id: _, style, span } = self; + let ast::Attribute { kind, id: _, style, span } = attr; if let ast::AttrKind::Normal(item) = kind { - item.hash_stable(hcx, hasher); - style.hash_stable(hcx, hasher); - span.hash_stable(hcx, hasher); + item.hash_stable(self, hasher); + style.hash_stable(self, hasher); + span.hash_stable(self, hasher); } else { unreachable!(); } } } -impl<'ctx> syntax::HashStableContext for StableHashingContext<'ctx> {} - impl<'a> HashStable> for SourceFile { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let SourceFile { diff --git a/src/librustc/infer/freshen.rs b/src/librustc/infer/freshen.rs index f258968b2a31b..16087959972b7 100644 --- a/src/librustc/infer/freshen.rs +++ b/src/librustc/infer/freshen.rs @@ -33,7 +33,8 @@ use crate::ty::fold::TypeFolder; use crate::ty::{self, Ty, TyCtxt, TypeFoldable}; -use crate::util::nodemap::FxHashMap; + +use rustc_data_structures::fx::FxHashMap; use std::collections::hash_map::Entry; diff --git a/src/librustc/infer/lexical_region_resolve/graphviz.rs b/src/librustc/infer/lexical_region_resolve/graphviz.rs index 2a3187afd7100..b7a3ff6987cb5 100644 --- a/src/librustc/infer/lexical_region_resolve/graphviz.rs +++ b/src/librustc/infer/lexical_region_resolve/graphviz.rs @@ -15,7 +15,7 @@ use crate::infer::SubregionOrigin; use crate::middle::free_region::RegionRelations; use crate::middle::region; use crate::ty; -use crate::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use std::borrow::Cow; use std::collections::btree_map::BTreeMap; diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index f9bc9020f1633..5c11659b550ce 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -22,9 +22,9 @@ use crate::ty::relate::RelateResult; use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef}; use crate::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt}; use crate::ty::{ConstVid, FloatVid, IntVid, TyVid}; -use crate::util::nodemap::{FxHashMap, FxHashSet}; use errors::DiagnosticBuilder; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::Lrc; use rustc_data_structures::unify as ut; use rustc_span::symbol::Symbol; diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 8399737b3e610..638ab01baac70 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -1,5 +1,5 @@ use crate::hir; -use crate::hir::def_id::DefId; +use crate::hir::def_id::{DefId, DefIdMap}; use crate::hir::Node; use crate::infer::outlives::free_region_map::FreeRegionRelations; use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin, TypeVariableOriginKind}; @@ -8,7 +8,6 @@ use crate::traits::{self, PredicateObligation}; use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor}; use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef}; use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt}; -use crate::util::nodemap::DefIdMap; use errors::DiagnosticBuilder; use rustc::session::config::nightly_options; use rustc_data_structures::fx::FxHashMap; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 76588dfa5e25e..9882b021ff30e 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -105,7 +105,6 @@ pub mod util { pub mod bug; pub mod captures; pub mod common; - pub mod nodemap; } // Allows macros to refer to this crate as `::rustc` diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index e1350ad03a10f..ca6a7beb48ed4 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -27,9 +27,8 @@ use crate::middle::privacy::AccessLevels; use crate::session::Session; use crate::ty::layout::{LayoutError, LayoutOf, TyLayout}; use crate::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt}; -use crate::util::nodemap::FxHashMap; - use errors::DiagnosticBuilder; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync; use rustc_span::{symbol::Symbol, MultiSpan, Span}; use std::slice; diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index b1894a1f9ba25..40e6f22c25f3d 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -6,8 +6,8 @@ use crate::lint::builtin; use crate::lint::context::{CheckLintNameResult, LintStore}; use crate::lint::{self, Level, Lint, LintId, LintSource}; use crate::session::Session; -use crate::util::nodemap::FxHashMap; use errors::{Applicability, DiagnosticBuilder}; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_span::source_map::MultiSpan; use rustc_span::symbol::{sym, Symbol}; diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 680fb497e4014..3c55669231301 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -25,10 +25,10 @@ use rustc_data_structures::sync; use crate::hir; use crate::lint::builtin::BuiltinLintDiagnostics; -use crate::session::{DiagnosticMessageId, Session}; use crate::ty::TyCtxt; -use crate::util::nodemap::NodeMap; use errors::{DiagnosticBuilder, DiagnosticId}; +use rustc_session::node_id::NodeMap; +use rustc_session::{DiagnosticMessageId, Session}; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::{DesugaringKind, ExpnKind, MultiSpan}; use rustc_span::symbol::Symbol; diff --git a/src/librustc/middle/codegen_fn_attrs.rs b/src/librustc/middle/codegen_fn_attrs.rs new file mode 100644 index 0000000000000..3b109f2fea687 --- /dev/null +++ b/src/librustc/middle/codegen_fn_attrs.rs @@ -0,0 +1,116 @@ +use crate::mir::mono::Linkage; +use rustc_span::symbol::Symbol; +use syntax::attr::{InlineAttr, OptimizeAttr}; + +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] +pub struct CodegenFnAttrs { + pub flags: CodegenFnAttrFlags, + /// Parsed representation of the `#[inline]` attribute + pub inline: InlineAttr, + /// Parsed representation of the `#[optimize]` attribute + pub optimize: OptimizeAttr, + /// The `#[export_name = "..."]` attribute, indicating a custom symbol a + /// function should be exported under + pub export_name: Option, + /// The `#[link_name = "..."]` attribute, indicating a custom symbol an + /// imported function should be imported as. Note that `export_name` + /// probably isn't set when this is set, this is for foreign items while + /// `#[export_name]` is for Rust-defined functions. + pub link_name: Option, + /// The `#[link_ordinal = "..."]` attribute, indicating an ordinal an + /// imported function has in the dynamic library. Note that this must not + /// be set when `link_name` is set. This is for foreign items with the + /// "raw-dylib" kind. + pub link_ordinal: Option, + /// The `#[target_feature(enable = "...")]` attribute and the enabled + /// features (only enabled features are supported right now). + pub target_features: Vec, + /// The `#[linkage = "..."]` attribute and the value we found. + pub linkage: Option, + /// The `#[link_section = "..."]` attribute, or what executable section this + /// should be placed in. + pub link_section: Option, +} + +bitflags! { + #[derive(RustcEncodable, RustcDecodable, HashStable)] + pub struct CodegenFnAttrFlags: u32 { + /// `#[cold]`: a hint to LLVM that this function, when called, is never on + /// the hot path. + const COLD = 1 << 0; + /// `#[rustc_allocator]`: a hint to LLVM that the pointer returned from this + /// function is never null. + const ALLOCATOR = 1 << 1; + /// `#[unwind]`: an indicator that this function may unwind despite what + /// its ABI signature may otherwise imply. + const UNWIND = 1 << 2; + /// `#[rust_allocator_nounwind]`, an indicator that an imported FFI + /// function will never unwind. Probably obsolete by recent changes with + /// #[unwind], but hasn't been removed/migrated yet + const RUSTC_ALLOCATOR_NOUNWIND = 1 << 3; + /// `#[naked]`: an indicator to LLVM that no function prologue/epilogue + /// should be generated. + const NAKED = 1 << 4; + /// `#[no_mangle]`: an indicator that the function's name should be the same + /// as its symbol. + const NO_MANGLE = 1 << 5; + /// `#[rustc_std_internal_symbol]`: an indicator that this symbol is a + /// "weird symbol" for the standard library in that it has slightly + /// different linkage, visibility, and reachability rules. + const RUSTC_STD_INTERNAL_SYMBOL = 1 << 6; + /// `#[no_debug]`: an indicator that no debugging information should be + /// generated for this function by LLVM. + const NO_DEBUG = 1 << 7; + /// `#[thread_local]`: indicates a static is actually a thread local + /// piece of memory + const THREAD_LOCAL = 1 << 8; + /// `#[used]`: indicates that LLVM can't eliminate this function (but the + /// linker can!). + const USED = 1 << 9; + /// `#[ffi_returns_twice]`, indicates that an extern function can return + /// multiple times + const FFI_RETURNS_TWICE = 1 << 10; + /// `#[track_caller]`: allow access to the caller location + const TRACK_CALLER = 1 << 11; + } +} + +impl CodegenFnAttrs { + pub fn new() -> CodegenFnAttrs { + CodegenFnAttrs { + flags: CodegenFnAttrFlags::empty(), + inline: InlineAttr::None, + optimize: OptimizeAttr::None, + export_name: None, + link_name: None, + link_ordinal: None, + target_features: vec![], + linkage: None, + link_section: None, + } + } + + /// Returns `true` if `#[inline]` or `#[inline(always)]` is present. + pub fn requests_inline(&self) -> bool { + match self.inline { + InlineAttr::Hint | InlineAttr::Always => true, + InlineAttr::None | InlineAttr::Never => false, + } + } + + /// Returns `true` if it looks like this symbol needs to be exported, for example: + /// + /// * `#[no_mangle]` is present + /// * `#[export_name(...)]` is present + /// * `#[linkage]` is present + pub fn contains_extern_indicator(&self) -> bool { + self.flags.contains(CodegenFnAttrFlags::NO_MANGLE) + || self.export_name.is_some() + || match self.linkage { + // These are private, so make sure we don't try to consider + // them external. + None | Some(Linkage::Internal) | Some(Linkage::Private) => false, + Some(_) => true, + } + } +} diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 98e48ca0e4d94..0e9a2a39fd912 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -9,15 +9,15 @@ pub use self::LangItem::*; +use crate::hir; use crate::hir::check_attr::Target; use crate::hir::def_id::DefId; +use crate::hir::itemlikevisit::ItemLikeVisitor; use crate::middle::cstore::ExternCrate; use crate::middle::weak_lang_items; use crate::ty::{self, TyCtxt}; -use crate::util::nodemap::FxHashMap; -use crate::hir; -use crate::hir::itemlikevisit::ItemLikeVisitor; +use rustc_data_structures::fx::FxHashMap; use rustc_macros::HashStable; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; diff --git a/src/librustc/middle/mod.rs b/src/librustc/middle/mod.rs index 96b14eae8ea0e..c2959766c570a 100644 --- a/src/librustc/middle/mod.rs +++ b/src/librustc/middle/mod.rs @@ -1,3 +1,4 @@ +pub mod codegen_fn_attrs; pub mod cstore; pub mod dependency_format; pub mod exported_symbols; diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index fc48999115e86..c4da4d75f4de2 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -2,9 +2,10 @@ //! outside their scopes. This pass will also generate a set of exported items //! which are available for use externally when compiled as a library. +use crate::hir::def_id::DefIdSet; use crate::hir::HirId; -use crate::util::nodemap::{DefIdSet, FxHashMap}; +use rustc_data_structures::fx::FxHashMap; use rustc_macros::HashStable; use std::fmt; use std::hash::Hash; diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index dd03a703c8964..ee96b595f6fde 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -11,8 +11,8 @@ use crate::hir::def_id::DefId; use crate::hir::Node; use crate::ich::{NodeIdHashingMode, StableHashingContext}; use crate::ty::{self, DefIdTree, TyCtxt}; -use crate::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_index::vec::Idx; use rustc_macros::HashStable; diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 6926ed24afdfb..951181c8900ce 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -5,7 +5,7 @@ use crate::hir::{GenericParam, ItemLocalId}; use crate::hir::{GenericParamKind, LifetimeParamKind}; use crate::ty; -use crate::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_macros::HashStable; /// The origin of a named lifetime definition. diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index a6a49864a9564..0c756c71fbdf6 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -10,8 +10,9 @@ use crate::lint::builtin::BuiltinLintDiagnostics; use crate::lint::{self, in_derive_expansion, Lint}; use crate::session::{DiagnosticMessageId, Session}; use crate::ty::{self, TyCtxt}; -use crate::util::nodemap::{FxHashMap, FxHashSet}; + use errors::DiagnosticBuilder; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_feature::GateIssue; use rustc_span::symbol::{sym, Symbol}; use rustc_span::{MultiSpan, Span}; diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs index bec98221e5af3..2dbe1d4fa5c49 100644 --- a/src/librustc/mir/mono.rs +++ b/src/librustc/mir/mono.rs @@ -5,8 +5,8 @@ use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext}; use crate::session::config::OptLevel; use crate::ty::print::obsolete::DefPathBasedNames; use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt}; -use crate::util::nodemap::FxHashMap; use rustc_data_structures::base_n; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_span::source_map::Span; use rustc_span::symbol::Symbol; diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index 1534e922cddf0..e81497351cabb 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -16,6 +16,14 @@ use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt}; use rustc_span::symbol::Symbol; use std::borrow::Cow; +fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String { + if def_id.is_top_level_module() { + format!("top-level module") + } else { + format!("module `{}`", tcx.def_path_str(def_id)) + } +} + // Each of these queries corresponds to a function pointer field in the // `Providers` struct for requesting a value of that type, and a method // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way @@ -332,50 +340,50 @@ rustc_queries! { Other { query lint_mod(key: DefId) -> () { - desc { |tcx| "linting {}", key.describe_as_module(tcx) } + desc { |tcx| "linting {}", describe_as_module(key, tcx) } } /// Checks the attributes in the module. query check_mod_attrs(key: DefId) -> () { - desc { |tcx| "checking attributes in {}", key.describe_as_module(tcx) } + desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) } } query check_mod_unstable_api_usage(key: DefId) -> () { - desc { |tcx| "checking for unstable API usage in {}", key.describe_as_module(tcx) } + desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) } } /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`). query check_mod_const_bodies(key: DefId) -> () { - desc { |tcx| "checking consts in {}", key.describe_as_module(tcx) } + desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) } } /// Checks the loops in the module. query check_mod_loops(key: DefId) -> () { - desc { |tcx| "checking loops in {}", key.describe_as_module(tcx) } + desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) } } query check_mod_item_types(key: DefId) -> () { - desc { |tcx| "checking item types in {}", key.describe_as_module(tcx) } + desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) } } query check_mod_privacy(key: DefId) -> () { - desc { |tcx| "checking privacy in {}", key.describe_as_module(tcx) } + desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) } } query check_mod_intrinsics(key: DefId) -> () { - desc { |tcx| "checking intrinsics in {}", key.describe_as_module(tcx) } + desc { |tcx| "checking intrinsics in {}", describe_as_module(key, tcx) } } query check_mod_liveness(key: DefId) -> () { - desc { |tcx| "checking liveness of variables in {}", key.describe_as_module(tcx) } + desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) } } query check_mod_impl_wf(key: DefId) -> () { - desc { |tcx| "checking that impls are well-formed in {}", key.describe_as_module(tcx) } + desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) } } query collect_mod_item_types(key: DefId) -> () { - desc { |tcx| "collecting item types in {}", key.describe_as_module(tcx) } + desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) } } /// Caches `CoerceUnsized` kinds for impls on custom types. diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index dbc872a51bfbe..3fef1dd064edb 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -21,10 +21,10 @@ use crate::ty::GenericParamDefKind; use crate::ty::SubtypePredicate; use crate::ty::TypeckTables; use crate::ty::{self, AdtKind, DefIdTree, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable}; -use crate::util::nodemap::{FxHashMap, FxHashSet}; use errors::{pluralize, Applicability, DiagnosticBuilder, Style}; use rustc::hir::def_id::LOCAL_CRATE; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span::source_map::SourceMap; use rustc_span::symbol::{kw, sym}; use rustc_span::{ExpnKind, MultiSpan, Span, DUMMY_SP}; diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs index 9097cbf0c221a..f1a04da188ba0 100644 --- a/src/librustc/traits/on_unimplemented.rs +++ b/src/librustc/traits/on_unimplemented.rs @@ -3,8 +3,8 @@ use fmt_macros::{Parser, Piece, Position}; use crate::hir::def_id::DefId; use crate::ty::{self, GenericParamDefKind, TyCtxt}; use crate::util::common::ErrorReported; -use crate::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; use syntax::ast::{MetaItem, NestedMetaItem}; diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 7e412eb03038a..0d35ad2a4cdda 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -39,7 +39,7 @@ use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable}; use crate::hir; -use crate::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::Lock; use rustc_index::bit_set::GrowableBitSet; use rustc_span::symbol::sym; diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index 8d2dcee22f544..200c2188ac360 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -1,11 +1,11 @@ use super::OverlapError; -use crate::hir::def_id::DefId; +use crate::hir::def_id::{DefId, DefIdMap}; use crate::ich::{self, StableHashingContext}; use crate::traits; use crate::ty::fast_reject::{self, SimplifiedType}; use crate::ty::{self, TyCtxt, TypeFoldable}; -use crate::util::nodemap::{DefIdMap, FxHashMap}; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use syntax::ast::Ident; diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 99f6e933fb418..9951311782849 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -7,7 +7,7 @@ use crate::hir::def_id::DefId; use crate::ty::outlives::Component; use crate::ty::subst::{GenericArg, Subst, SubstsRef}; use crate::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt}; -use crate::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use super::{Normalized, Obligation, ObligationCause, PredicateObligation, SelectionContext}; diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index c26d68de181b6..86042d86b939c 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -3,11 +3,13 @@ use crate::arena::Arena; use crate::dep_graph::DepGraph; use crate::dep_graph::{self, DepConstructor, DepNode}; -use crate::hir::def::{DefKind, Export, Res}; -use crate::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE}; +use crate::hir::def::{DefKind, Res}; +use crate::hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex, LOCAL_CRATE}; +use crate::hir::exports::Export; use crate::hir::map as hir_map; use crate::hir::map::DefPathHash; -use crate::hir::{self, HirId, ItemKind, ItemLocalId, Node, TraitCandidate}; +use crate::hir::{self, HirId, Node, TraitCandidate}; +use crate::hir::{ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet}; use crate::ich::{NodeIdHashingMode, StableHashingContext}; use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos}; use crate::infer::outlives::free_region_map::FreeRegionMap; @@ -46,11 +48,10 @@ use crate::ty::{ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, Pr use crate::ty::{InferConst, ParamConst}; use crate::ty::{List, TyKind, TyS}; use crate::util::common::ErrorReported; -use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet, NodeMap}; -use crate::util::nodemap::{FxHashMap, FxHashSet}; use arena::SyncDroplessArena; use errors::DiagnosticBuilder; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::sharded::ShardedHashMap; use rustc_data_structures::stable_hasher::{ @@ -59,6 +60,7 @@ use rustc_data_structures::stable_hasher::{ use rustc_data_structures::sync::{Lock, Lrc, WorkerLocal}; use rustc_index::vec::{Idx, IndexVec}; use rustc_macros::HashStable; +use rustc_session::node_id::NodeMap; use rustc_span::source_map::MultiSpan; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index 53a1727d1cc13..7004cec8a31ce 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -34,7 +34,7 @@ use crate::hir::def_id::DefId; use crate::ty::{self, flags::FlagComputation, Binder, Ty, TyCtxt, TypeFlags}; -use crate::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use std::collections::BTreeMap; use std::fmt; diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index cfd1779c080ec..a7e716ad7b730 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -1,6 +1,6 @@ use crate::hir::def::Namespace; use crate::hir::def_id::DefId; -use crate::hir::CodegenFnAttrFlags; +use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::middle::lang_items::DropInPlaceFnLangItem; use crate::traits; use crate::ty::print::{FmtPrinter, Printer}; diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 2707d07633b2f..1ce74a61c0e42 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -6,8 +6,9 @@ pub use self::BorrowKind::*; pub use self::IntVarValue::*; pub use self::Variance::*; -use crate::hir::def::{CtorKind, CtorOf, DefKind, ExportMap, Res}; -use crate::hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use crate::hir::def::{CtorKind, CtorOf, DefKind, Res}; +use crate::hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use crate::hir::exports::ExportMap; use crate::hir::Node; use crate::hir::{map as hir_map, GlobMap, TraitMap}; use crate::ich::Fingerprint; @@ -28,10 +29,11 @@ use crate::ty::subst::{InternalSubsts, Subst, SubstsRef}; use crate::ty::util::{Discr, IntTypeExt}; use crate::ty::walk::TypeWalker; use crate::util::captures::Captures; -use crate::util::nodemap::{DefIdMap, FxHashMap, NodeMap, NodeSet}; use arena::SyncDroplessArena; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::svh::Svh; use rustc_macros::HashStable; +use rustc_session::node_id::{NodeMap, NodeSet}; use rustc_data_structures::sync::{self, par_iter, Lrc, ParallelIterator}; use rustc_serialize::{self, Encodable, Encoder}; diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index 1907e6c82c62a..0ec3874e6a117 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -1,9 +1,11 @@ use crate::dep_graph::{self, DepNode}; -use crate::hir::def::{DefKind, Export}; -use crate::hir::def_id::{CrateNum, DefId, DefIndex}; -use crate::hir::{self, CodegenFnAttrs, ItemLocalId, TraitCandidate}; +use crate::hir::def::DefKind; +use crate::hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex}; +use crate::hir::exports::Export; +use crate::hir::{self, HirIdSet, ItemLocalId, TraitCandidate}; use crate::infer::canonical::{self, Canonical}; use crate::lint; +use crate::middle::codegen_fn_attrs::CodegenFnAttrs; use crate::middle::cstore::{CrateSource, DepKind, NativeLibraryKind}; use crate::middle::cstore::{ExternCrate, ForeignModule, LinkagePreference, NativeLibrary}; use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; @@ -36,7 +38,6 @@ use crate::ty::subst::SubstsRef; use crate::ty::util::NeedsDrop; use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt}; use crate::util::common::ErrorReported; -use crate::util::nodemap::{DefIdMap, DefIdSet, HirIdSet}; use rustc_data_structures::profiling::ProfileCategory::*; use rustc_data_structures::fingerprint::Fingerprint; diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs deleted file mode 100644 index ce0f77e0b6d37..0000000000000 --- a/src/librustc/util/nodemap.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! An efficient hash map for `NodeId`s. - -use crate::hir::def_id::DefId; -use crate::hir::{HirId, ItemLocalId}; -use syntax::ast; - -pub use rustc_data_structures::fx::FxHashMap; -pub use rustc_data_structures::fx::FxHashSet; - -macro_rules! define_id_collections { - ($map_name:ident, $set_name:ident, $key:ty) => { - pub type $map_name = FxHashMap<$key, T>; - pub type $set_name = FxHashSet<$key>; - }; -} - -define_id_collections!(NodeMap, NodeSet, ast::NodeId); -define_id_collections!(DefIdMap, DefIdSet, DefId); -define_id_collections!(HirIdMap, HirIdSet, HirId); -define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId); diff --git a/src/librustc_ast_lowering/Cargo.toml b/src/librustc_ast_lowering/Cargo.toml index 664d41c45f2a2..76980dfa31db4 100644 --- a/src/librustc_ast_lowering/Cargo.toml +++ b/src/librustc_ast_lowering/Cargo.toml @@ -18,5 +18,6 @@ rustc_index = { path = "../librustc_index" } rustc_span = { path = "../librustc_span" } rustc_error_codes = { path = "../librustc_error_codes" } rustc_errors = { path = "../librustc_errors" } +rustc_session = { path = "../librustc_session" } syntax = { path = "../libsyntax" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/src/librustc_ast_lowering/item.rs b/src/librustc_ast_lowering/item.rs index c1eb8be0f8aad..7e7e2d1e10892 100644 --- a/src/librustc_ast_lowering/item.rs +++ b/src/librustc_ast_lowering/item.rs @@ -6,8 +6,8 @@ use rustc::bug; use rustc::hir; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::DefId; -use rustc::util::nodemap::NodeMap; use rustc_error_codes::*; +use rustc_session::node_id::NodeMap; use rustc_span::source_map::{respan, DesugaringKind}; use rustc_span::symbol::{kw, sym}; use rustc_span::Span; diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs index 3b06a6969acc0..5694bedb19937 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -37,7 +37,7 @@ use rustc::arena::Arena; use rustc::dep_graph::DepGraph; use rustc::hir::def::{DefKind, Namespace, PartialRes, PerNS, Res}; -use rustc::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX}; +use rustc::hir::def_id::{DefId, DefIdMap, DefIndex, CRATE_DEF_INDEX}; use rustc::hir::map::{DefKey, DefPathData, Definitions}; use rustc::hir::{self, ConstArg, GenericArg, ParamName}; use rustc::lint; @@ -47,13 +47,13 @@ use rustc::session::config::nightly_options; use rustc::session::Session; use rustc::util::captures::Captures; use rustc::util::common::FN_OUTPUT_NAME; -use rustc::util::nodemap::{DefIdMap, NodeMap}; use rustc::{bug, span_bug}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_error_codes::*; use rustc_errors::Applicability; use rustc_index::vec::IndexVec; +use rustc_session::node_id::NodeMap; use rustc_span::hygiene::ExpnId; use rustc_span::source_map::{respan, DesugaringKind, ExpnData, ExpnKind, Spanned}; use rustc_span::symbol::{kw, sym, Symbol}; diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index 942ba9f868c60..a7826282314eb 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -3,7 +3,7 @@ use std::ffi::CString; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; -use rustc::hir::CodegenFnAttrFlags; +use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::session::config::{OptLevel, Sanitizer}; use rustc::session::Session; use rustc::ty::layout::HasTyCtxt; diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index c757fb596b11d..cb44a56d07516 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -14,33 +14,32 @@ //! int)` and `rec(x=int, y=int, z=int)` will have the same `llvm::Type`. use super::{LlvmCodegenBackend, ModuleLlvm}; -use rustc_codegen_ssa::base::maybe_create_entry_wrapper; -use rustc_codegen_ssa::{ModuleCodegen, ModuleKind}; use crate::builder::Builder; use crate::common; use crate::context::CodegenCx; use crate::llvm; use crate::metadata; +use crate::value::Value; + use rustc::dep_graph; +use rustc::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc::middle::cstore::EncodedMetadata; use rustc::middle::exported_symbols; use rustc::mir::mono::{Linkage, Visibility}; use rustc::session::config::DebugInfo; use rustc::ty::TyCtxt; -use rustc_codegen_ssa::mono_item::MonoItemExt; -use rustc_data_structures::small_c_str::SmallCStr; - use rustc_codegen_ssa::back::write::submit_codegened_module_to_llvm; +use rustc_codegen_ssa::base::maybe_create_entry_wrapper; +use rustc_codegen_ssa::mono_item::MonoItemExt; use rustc_codegen_ssa::traits::*; - -use rustc::hir::CodegenFnAttrs; +use rustc_codegen_ssa::{ModuleCodegen, ModuleKind}; +use rustc_data_structures::small_c_str::SmallCStr; use rustc_span::symbol::Symbol; + use std::ffi::CString; use std::time::Instant; -use crate::value::Value; - pub fn write_compressed_metadata<'tcx>( tcx: TyCtxt<'tcx>, metadata: &EncodedMetadata, diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index 318037b5bd81d..4b4fbd0e1ad53 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -8,9 +8,11 @@ use crate::value::Value; use libc::c_uint; use log::debug; use rustc::hir::def_id::DefId; -use rustc::hir::Node; +use rustc::hir::{self, Node}; +use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc::mir::interpret::{read_target_uint, Allocation, ConstValue, ErrorHandled, Pointer}; use rustc::mir::mono::MonoItem; +use rustc::ty::layout::{self, Align, LayoutOf, Size}; use rustc::ty::{self, Instance, Ty}; use rustc::{bug, span_bug}; use rustc_codegen_ssa::traits::*; @@ -18,10 +20,6 @@ use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; use rustc_target::abi::HasDataLayout; -use rustc::ty::layout::{self, Align, LayoutOf, Size}; - -use rustc::hir::{self, CodegenFnAttrFlags, CodegenFnAttrs}; - use std::ffi::CStr; pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll Value { diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index c0a5e0089a955..746b76ad1c7d0 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -19,10 +19,10 @@ use rustc::ty::layout::{ FnAbiExt, HasParamEnv, LayoutError, LayoutOf, PointeeInfo, Size, TyLayout, VariantIdx, }; use rustc::ty::{self, Instance, Ty, TyCtxt}; -use rustc::util::nodemap::FxHashMap; use rustc_codegen_ssa::base::wants_msvc_seh; use rustc_data_structures::base_n; use rustc_data_structures::const_cstr; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_target::spec::{HasTargetSpec, Target}; diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 61ccd7820109a..88e692cb11747 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -22,8 +22,8 @@ use crate::value::Value; use log::debug; use rustc::hir::def::CtorKind; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; -use rustc::hir::CodegenFnAttrFlags; use rustc::ich::NodeIdHashingMode; +use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::mir::interpret::truncate; use rustc::mir::{self, Field, GeneratorLayout}; use rustc::session::config::{self, DebugInfo}; @@ -33,11 +33,11 @@ use rustc::ty::layout::{ use rustc::ty::subst::{GenericArgKind, SubstsRef}; use rustc::ty::Instance; use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt}; -use rustc::util::nodemap::FxHashMap; use rustc::{bug, span_bug}; use rustc_codegen_ssa::traits::*; use rustc_data_structures::const_cstr; use rustc_data_structures::fingerprint::Fingerprint; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_fs_util::path_to_c_string; diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 16ae3c9503052..0edfd3457746d 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -13,8 +13,8 @@ use crate::llvm; use crate::llvm::debuginfo::{ DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DISPFlags, DIScope, DIType, }; -use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; -use rustc::hir::CodegenFnAttrFlags; +use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE}; +use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::ty::subst::{GenericArgKind, SubstsRef}; use crate::abi::FnAbi; @@ -24,9 +24,9 @@ use crate::value::Value; use rustc::mir; use rustc::session::config::{self, DebugInfo}; use rustc::ty::{self, Instance, InstanceDef, ParamEnv, Ty}; -use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet}; use rustc_codegen_ssa::debuginfo::type_names; use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::small_c_str::SmallCStr; use rustc_index::vec::IndexVec; diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 5bdb310f9b546..0f54557eaed2d 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -2,17 +2,17 @@ use std::collections::hash_map::Entry::*; use std::sync::Arc; use rustc::hir; -use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; -use rustc::hir::CodegenFnAttrFlags; +use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::Node; +use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::middle::exported_symbols::{metadata_symbol_name, ExportedSymbol, SymbolExportLevel}; use rustc::session::config; use rustc::ty::query::Providers; use rustc::ty::subst::SubstsRef; use rustc::ty::Instance; use rustc::ty::{SymbolName, TyCtxt}; -use rustc::util::nodemap::{DefIdMap, FxHashMap}; use rustc_data_structures::fingerprint::Fingerprint; +use rustc_data_structures::fx::FxHashMap; use rustc_index::vec::IndexVec; use syntax::expand::allocator::ALLOCATOR_METHODS; diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index 4e49d4dda935d..f901a51ada805 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -19,7 +19,7 @@ use rustc::session::config::{ use rustc::session::Session; use rustc::ty::TyCtxt; use rustc::util::common::{print_time_passes_entry, set_time_depth, time_depth}; -use rustc::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::Lrc; diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index 27841d67c1a9a..b964fa1c182c9 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -27,6 +27,7 @@ use crate::{CachedModuleCodegen, CrateInfo, MemFlags, ModuleCodegen, ModuleKind} use rustc::hir; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; +use rustc::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc::middle::cstore::EncodedMetadata; use rustc::middle::cstore::{self, LinkagePreference}; use rustc::middle::lang_items::StartFnLangItem; @@ -39,8 +40,8 @@ use rustc::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA}; use rustc::ty::query::Providers; use rustc::ty::{self, Instance, Ty, TyCtxt}; use rustc::util::common::{print_time_passes_entry, set_time_depth, time, time_depth}; -use rustc::util::nodemap::FxHashMap; use rustc_codegen_utils::{check_for_rustc_errors_attr, symbol_names_test}; +use rustc_data_structures::fx::FxHashMap; use rustc_index::vec::Idx; use rustc_session::cgu_reuse_tracker::CguReuse; use rustc_span::Span; @@ -811,7 +812,7 @@ pub fn provide_both(providers: &mut Providers<'_>) { let (defids, _) = tcx.collect_and_partition_mono_items(cratenum); for id in &*defids { - let hir::CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id); + let CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id); match optimize { attr::OptimizeAttr::None => continue, attr::OptimizeAttr::Size => continue, diff --git a/src/librustc_codegen_ssa/traits/misc.rs b/src/librustc_codegen_ssa/traits/misc.rs index 658ddd0028076..691b94c2f9d48 100644 --- a/src/librustc_codegen_ssa/traits/misc.rs +++ b/src/librustc_codegen_ssa/traits/misc.rs @@ -2,7 +2,7 @@ use super::BackendTypes; use rustc::mir::mono::CodegenUnit; use rustc::session::Session; use rustc::ty::{self, Instance, Ty}; -use rustc::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use std::cell::RefCell; use std::sync::Arc; diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index 533ce620b678c..e479573038b73 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -88,8 +88,8 @@ //! DefPaths which are much more robust in the face of changes to the code base. use rustc::hir::def_id::LOCAL_CRATE; -use rustc::hir::CodegenFnAttrFlags; use rustc::hir::Node; +use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::mir::mono::{InstantiationMode, MonoItem}; use rustc::session::config::SymbolManglingVersion; use rustc::ty::query::Providers; diff --git a/src/librustc_data_structures/fx.rs b/src/librustc_data_structures/fx.rs index a9e8c2edbff9e..bbeb193dba32b 100644 --- a/src/librustc_data_structures/fx.rs +++ b/src/librustc_data_structures/fx.rs @@ -4,3 +4,11 @@ pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; pub type FxIndexMap = indexmap::IndexMap>; pub type FxIndexSet = indexmap::IndexSet>; + +#[macro_export] +macro_rules! define_id_collections { + ($map_name:ident, $set_name:ident, $key:ty) => { + pub type $map_name = $crate::fx::FxHashMap<$key, T>; + pub type $set_name = $crate::fx::FxHashSet<$key>; + }; +} diff --git a/src/librustc_hir/Cargo.toml b/src/librustc_hir/Cargo.toml new file mode 100644 index 0000000000000..f2e420dbae640 --- /dev/null +++ b/src/librustc_hir/Cargo.toml @@ -0,0 +1,22 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_hir" +version = "0.0.0" +edition = "2018" + +[lib] +name = "rustc_hir" +path = "lib.rs" +doctest = false + +[dependencies] +rustc_target = { path = "../librustc_target" } +rustc_macros = { path = "../librustc_macros" } +rustc_data_structures = { path = "../librustc_data_structures" } +rustc_index = { path = "../librustc_index" } +rustc_span = { path = "../librustc_span" } +rustc_errors = { path = "../librustc_errors" } +rustc_serialize = { path = "../libserialize", package = "serialize" } +rustc_session = { path = "../librustc_session" } +syntax = { path = "../libsyntax" } +smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/src/librustc/hir/def.rs b/src/librustc_hir/def.rs similarity index 88% rename from src/librustc/hir/def.rs rename to src/librustc_hir/def.rs index 6ba9a53799b9a..83e30d85c5a67 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc_hir/def.rs @@ -1,20 +1,16 @@ -use self::Namespace::*; - +use crate::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use crate::hir; -use crate::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; -use crate::ty; -use crate::util::nodemap::DefIdMap; -use rustc_macros::HashStable; +use rustc_macros::HashStable_Generic; use rustc_span::hygiene::MacroKind; -use rustc_span::Span; use syntax::ast; use syntax::ast::NodeId; use std::fmt::Debug; /// Encodes if a `DefKind::Ctor` is the constructor of an enum variant or a struct. -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(HashStable_Generic)] pub enum CtorOf { /// This `DefKind::Ctor` is a synthesized constructor of a tuple or unit struct. Struct, @@ -22,7 +18,8 @@ pub enum CtorOf { Variant, } -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(HashStable_Generic)] pub enum CtorKind { /// Constructor function automatically created by a tuple struct/variant. Fn, @@ -32,7 +29,8 @@ pub enum CtorKind { Fictive, } -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(HashStable_Generic)] pub enum NonMacroAttrKind { /// Single-segment attribute defined by the language (`#[inline]`) Builtin, @@ -44,7 +42,8 @@ pub enum NonMacroAttrKind { Registered, } -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(HashStable_Generic)] pub enum DefKind { // Type namespace Mod, @@ -98,7 +97,7 @@ impl DefKind { DefKind::Ctor(CtorOf::Struct, CtorKind::Fn) => "tuple struct", DefKind::Ctor(CtorOf::Struct, CtorKind::Const) => "unit struct", DefKind::Ctor(CtorOf::Struct, CtorKind::Fictive) => { - bug!("impossible struct constructor") + panic!("impossible struct constructor") } DefKind::OpaqueTy => "opaque type", DefKind::TyAlias => "type alias", @@ -159,7 +158,8 @@ impl DefKind { } } -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(HashStable_Generic)] pub enum Res { Def(DefKind, DefId), @@ -239,9 +239,9 @@ pub enum Namespace { impl Namespace { pub fn descr(self) -> &'static str { match self { - TypeNS => "type", - ValueNS => "value", - MacroNS => "macro", + Self::TypeNS => "type", + Self::ValueNS => "value", + Self::MacroNS => "macro", } } } @@ -265,9 +265,9 @@ impl ::std::ops::Index for PerNS { fn index(&self, ns: Namespace) -> &T { match ns { - ValueNS => &self.value_ns, - TypeNS => &self.type_ns, - MacroNS => &self.macro_ns, + Namespace::ValueNS => &self.value_ns, + Namespace::TypeNS => &self.type_ns, + Namespace::MacroNS => &self.macro_ns, } } } @@ -275,9 +275,9 @@ impl ::std::ops::Index for PerNS { impl ::std::ops::IndexMut for PerNS { fn index_mut(&mut self, ns: Namespace) -> &mut T { match ns { - ValueNS => &mut self.value_ns, - TypeNS => &mut self.type_ns, - MacroNS => &mut self.macro_ns, + Namespace::ValueNS => &mut self.value_ns, + Namespace::TypeNS => &mut self.type_ns, + Namespace::MacroNS => &mut self.macro_ns, } } } @@ -296,29 +296,6 @@ impl PerNS> { } } -/// This is the replacement export map. It maps a module to all of the exports -/// within. -pub type ExportMap = DefIdMap>>; - -#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] -pub struct Export { - /// The name of the target. - pub ident: ast::Ident, - /// The resolution of the target. - pub res: Res, - /// The span of the target. - pub span: Span, - /// The visibility of the export. - /// We include non-`pub` exports for hygienic macros that get used from extern crates. - pub vis: ty::Visibility, -} - -impl Export { - pub fn map_id(self, map: impl FnMut(Id) -> R) -> Export { - Export { ident: self.ident, res: self.res.map_id(map), span: self.span, vis: self.vis } - } -} - impl CtorKind { pub fn from_ast(vdata: &ast::VariantData) -> CtorKind { match *vdata { @@ -369,7 +346,8 @@ impl Res { where Id: Debug, { - self.opt_def_id().unwrap_or_else(|| bug!("attempted .def_id() on invalid res: {:?}", self)) + self.opt_def_id() + .unwrap_or_else(|| panic!("attempted .def_id() on invalid res: {:?}", self)) } /// Return `Some(..)` with the `DefId` of this `Res` if it has a ID, else `None`. diff --git a/src/librustc/hir/def_id.rs b/src/librustc_hir/def_id.rs similarity index 84% rename from src/librustc/hir/def_id.rs rename to src/librustc_hir/def_id.rs index b26617a57f475..f8cacdc6238e8 100644 --- a/src/librustc/hir/def_id.rs +++ b/src/librustc_hir/def_id.rs @@ -1,4 +1,4 @@ -use crate::ty::{self, TyCtxt}; +use rustc_data_structures::AtomicRef; use rustc_index::vec::Idx; use std::fmt; use std::u32; @@ -40,7 +40,7 @@ impl Idx for CrateNum { fn index(self) -> usize { match self { CrateNum::Index(idx) => Idx::index(idx), - _ => bug!("Tried to get crate index of {:?}", self), + _ => panic!("Tried to get crate index of {:?}", self), } } } @@ -61,14 +61,14 @@ impl CrateNum { pub fn as_usize(self) -> usize { match self { CrateNum::Index(id) => id.as_usize(), - _ => bug!("tried to get index of non-standard crate {:?}", self), + _ => panic!("tried to get index of non-standard crate {:?}", self), } } pub fn as_u32(self) -> u32 { match self { CrateNum::Index(id) => id.as_u32(), - _ => bug!("tried to get index of non-standard crate {:?}", self), + _ => panic!("tried to get index of non-standard crate {:?}", self), } } @@ -113,21 +113,6 @@ pub struct DefId { pub index: DefIndex, } -impl fmt::Debug for DefId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "DefId({}:{}", self.krate, self.index.index())?; - - ty::tls::with_opt(|opt_tcx| { - if let Some(tcx) = opt_tcx { - write!(f, " ~ {}", tcx.def_path_debug_str(*self))?; - } - Ok(()) - })?; - - write!(f, ")") - } -} - impl DefId { /// Makes a local `DefId` from the given `DefIndex`. #[inline] @@ -145,18 +130,29 @@ impl DefId { LocalDefId::from_def_id(self) } - pub fn describe_as_module(&self, tcx: TyCtxt<'_>) -> String { - if self.is_local() && self.index == CRATE_DEF_INDEX { - format!("top-level module") - } else { - format!("module `{}`", tcx.def_path_str(*self)) - } + pub fn is_top_level_module(self) -> bool { + self.is_local() && self.index == CRATE_DEF_INDEX } } impl rustc_serialize::UseSpecializedEncodable for DefId {} impl rustc_serialize::UseSpecializedDecodable for DefId {} +pub fn default_def_id_debug(def_id: DefId, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("DefId").field("krate", &def_id.krate).field("index", &def_id.index).finish() +} + +pub static DEF_ID_DEBUG: AtomicRef) -> fmt::Result> = + AtomicRef::new(&(default_def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); + +impl fmt::Debug for DefId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + (*DEF_ID_DEBUG)(*self, f) + } +} + +rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId); + /// A LocalDefId is equivalent to a DefId with `krate == LOCAL_CRATE`. Since /// we encode this information in the type, we can ensure at compile time that /// no DefIds from upstream crates get thrown into the mix. There are quite a diff --git a/src/librustc/hir/mod.rs b/src/librustc_hir/hir.rs similarity index 85% rename from src/librustc/hir/mod.rs rename to src/librustc_hir/hir.rs index d0cc87f7506a0..2303a85df4acf 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc_hir/hir.rs @@ -1,24 +1,18 @@ -//! HIR datatypes. See the [rustc guide] for more info. -//! -//! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html - -pub use self::BlockCheckMode::*; -pub use self::FunctionRetTy::*; -pub use self::PrimTy::*; -pub use self::UnOp::*; -pub use self::UnsafeSource::*; - -use crate::hir::def::{DefKind, Res}; -use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX}; -use crate::mir::mono::Linkage; -use crate::ty::query::Providers; -use crate::ty::AdtKind; -use crate::util::nodemap::{FxHashSet, NodeMap}; - -use errors::FatalError; +use crate::def::{DefKind, Res}; +use crate::def_id::DefId; +crate use crate::hir_id::HirId; +use crate::itemlikevisit; +use crate::print; + +crate use BlockCheckMode::*; +crate use FunctionRetTy::*; +crate use UnsafeSource::*; + +use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::{par_for_each_in, Send, Sync}; -use rustc_macros::HashStable; -use rustc_serialize::{self, Decodable, Decoder, Encodable, Encoder}; +use rustc_errors::FatalError; +use rustc_macros::HashStable_Generic; +use rustc_session::node_id::NodeMap; use rustc_span::source_map::{SourceMap, Spanned}; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::{MultiSpan, Span, DUMMY_SP}; @@ -30,101 +24,10 @@ use syntax::ast::{self, AsmDialect, CrateSugar, Ident, Name, NodeId}; use syntax::ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy}; pub use syntax::ast::{BorrowKind, ImplPolarity, IsAuto}; pub use syntax::ast::{CaptureBy, Constness, Movability, Mutability, Unsafety}; -use syntax::attr::{InlineAttr, OptimizeAttr}; use syntax::tokenstream::TokenStream; use syntax::util::parser::ExprPrecedence; -pub mod check_attr; -pub mod def; -pub mod def_id; -pub mod intravisit; -pub mod itemlikevisit; -pub mod map; -pub mod pat_util; -pub mod print; -pub mod upvars; - -/// Uniquely identifies a node in the HIR of the current crate. It is -/// composed of the `owner`, which is the `DefIndex` of the directly enclosing -/// `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e., the closest "item-like"), -/// and the `local_id` which is unique within the given owner. -/// -/// This two-level structure makes for more stable values: One can move an item -/// around within the source code, or add or remove stuff before it, without -/// 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, PartialOrd, Ord)] -pub struct HirId { - pub owner: DefIndex, - pub local_id: ItemLocalId, -} - -impl HirId { - pub fn owner_def_id(self) -> DefId { - DefId::local(self.owner) - } - - pub fn owner_local_def_id(self) -> LocalDefId { - LocalDefId::from_def_id(DefId::local(self.owner)) - } -} - -impl rustc_serialize::UseSpecializedEncodable for HirId { - fn default_encode(&self, s: &mut S) -> Result<(), S::Error> { - let HirId { owner, local_id } = *self; - - owner.encode(s)?; - local_id.encode(s)?; - Ok(()) - } -} - -impl rustc_serialize::UseSpecializedDecodable for HirId { - fn default_decode(d: &mut D) -> Result { - let owner = DefIndex::decode(d)?; - let local_id = ItemLocalId::decode(d)?; - - Ok(HirId { owner, local_id }) - } -} - -impl fmt::Display for HirId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self) - } -} - -// Hack to ensure that we don't try to access the private parts of `ItemLocalId` in this module. -mod item_local_id_inner { - use rustc_index::vec::Idx; - use rustc_macros::HashStable; - rustc_index::newtype_index! { - /// An `ItemLocalId` uniquely identifies something within a given "item-like"; - /// that is, within a `hir::Item`, `hir::TraitItem`, or `hir::ImplItem`. There is no - /// guarantee that the numerical value of a given `ItemLocalId` corresponds to - /// the node's position within the owning item in any way, but there is a - /// guarantee that the `LocalItemId`s within an owner occupy a dense range of - /// integers starting at zero, so a mapping that maps all or most nodes within - /// an "item-like" to something else can be implemented by a `Vec` instead of a - /// tree or hash map. - pub struct ItemLocalId { - derive [HashStable] - } - } -} - -pub use self::item_local_id_inner::ItemLocalId; - -/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`. -pub const CRATE_HIR_ID: HirId = - HirId { owner: CRATE_DEF_INDEX, local_id: ItemLocalId::from_u32_const(0) }; - -pub const DUMMY_HIR_ID: HirId = HirId { owner: CRATE_DEF_INDEX, local_id: DUMMY_ITEM_LOCAL_ID }; - -pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX; - -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable_Generic)] pub struct Lifetime { pub hir_id: HirId, pub span: Span, @@ -138,7 +41,8 @@ pub struct Lifetime { pub name: LifetimeName, } -#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy, HashStable)] +#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(HashStable_Generic)] pub enum ParamName { /// Some user-given name like `T` or `'x`. Plain(Ident), @@ -183,7 +87,8 @@ impl ParamName { } } -#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy, HashStable)] +#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(HashStable_Generic)] pub enum LifetimeName { /// User-given names or fresh (synthetic) names. Param(ParamName), @@ -284,7 +189,7 @@ impl Lifetime { /// A `Path` is essentially Rust's notion of a name; for instance, /// `std::cmp::PartialEq`. It's represented as a sequence of identifiers, /// along with a bunch of supporting information. -#[derive(RustcEncodable, RustcDecodable, HashStable)] +#[derive(RustcEncodable, RustcDecodable, HashStable_Generic)] pub struct Path<'hir> { pub span: Span, /// The resolution for the path. @@ -313,7 +218,7 @@ impl fmt::Display for Path<'_> { /// A segment of a path: an identifier, an optional lifetime, and a set of /// types. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct PathSegment<'hir> { /// The identifier portion of this path segment. #[stable_hasher(project(name))] @@ -356,13 +261,13 @@ impl<'hir> PathSegment<'hir> { } } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct ConstArg { pub value: AnonConst, pub span: Span, } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum GenericArg<'hir> { Lifetime(Lifetime), Type(Ty<'hir>), @@ -394,7 +299,7 @@ impl GenericArg<'_> { } } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct GenericArgs<'hir> { /// The generic arguments for this path segment. pub args: &'hir [GenericArg<'hir>], @@ -431,7 +336,7 @@ impl GenericArgs<'_> { } } } - bug!("GenericArgs::inputs: not a `Fn(T) -> U`"); + panic!("GenericArgs::inputs: not a `Fn(T) -> U`"); } pub fn own_counts(&self) -> GenericParamCount { @@ -454,7 +359,8 @@ impl GenericArgs<'_> { /// A modifier on a bound, currently this is only used for `?Sized`, where the /// modifier is `Maybe`. Negative bounds should also be handled here. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(HashStable_Generic)] pub enum TraitBoundModifier { None, Maybe, @@ -464,7 +370,7 @@ pub enum TraitBoundModifier { /// `typeck::collect::compute_bounds` matches these against /// the "special" built-in traits (see `middle::lang_items`) and /// detects `Copy`, `Send` and `Sync`. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum GenericBound<'hir> { Trait(PolyTraitRef<'hir>, TraitBoundModifier), Outlives(Lifetime), @@ -481,7 +387,7 @@ impl GenericBound<'_> { pub type GenericBounds<'hir> = &'hir [GenericBound<'hir>]; -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum LifetimeParamKind { // Indicates that the lifetime definition was explicitly declared (e.g., in // `fn foo<'a>(x: &'a u8) -> &'a u8 { x }`). @@ -500,7 +406,7 @@ pub enum LifetimeParamKind { Error, } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum GenericParamKind<'hir> { /// A lifetime definition (e.g., `'a: 'b + 'c + 'd`). Lifetime { @@ -515,7 +421,7 @@ pub enum GenericParamKind<'hir> { }, } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct GenericParam<'hir> { pub hir_id: HirId, pub name: ParamName, @@ -535,7 +441,7 @@ pub struct GenericParamCount { /// Represents lifetimes and type parameters attached to a declaration /// of a function, enum, trait, etc. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct Generics<'hir> { pub params: &'hir [GenericParam<'hir>], pub where_clause: WhereClause<'hir>, @@ -588,13 +494,14 @@ impl Generics<'hir> { /// Synthetic type parameters are converted to another form during lowering; this allows /// us to track the original form they had, and is useful for error messages. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(HashStable_Generic)] pub enum SyntheticTyParamKind { ImplTrait, } /// A where-clause in a definition. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct WhereClause<'hir> { pub predicates: &'hir [WherePredicate<'hir>], // Only valid if predicates isn't empty. @@ -614,7 +521,7 @@ impl WhereClause<'_> { } /// A single predicate in a where-clause. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum WherePredicate<'hir> { /// A type binding (e.g., `for<'c> Foo: Send + Clone + 'c`). BoundPredicate(WhereBoundPredicate<'hir>), @@ -635,7 +542,7 @@ impl WherePredicate<'_> { } /// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`). -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct WhereBoundPredicate<'hir> { pub span: Span, /// Any generics from a `for` binding. @@ -647,7 +554,7 @@ pub struct WhereBoundPredicate<'hir> { } /// A lifetime predicate (e.g., `'a: 'b + 'c`). -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct WhereRegionPredicate<'hir> { pub span: Span, pub lifetime: Lifetime, @@ -655,7 +562,7 @@ pub struct WhereRegionPredicate<'hir> { } /// An equality predicate (e.g., `T = int`); currently unsupported. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct WhereEqPredicate<'hir> { pub hir_id: HirId, pub span: Span, @@ -783,7 +690,7 @@ impl Crate<'_> { /// A macro definition, in this crate or imported from another. /// /// Not parsed directly, but created on macro import or `macro_rules!` expansion. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct MacroDef<'hir> { pub name: Name, pub vis: Visibility<'hir>, @@ -797,7 +704,7 @@ pub struct MacroDef<'hir> { /// A block of statements `{ .. }`, which may have a label (in this case the /// `targeted_by_break` field will be `true`) and may be `unsafe` by means of /// the `rules` being anything but `DefaultBlock`. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct Block<'hir> { /// Statements in a block. pub stmts: &'hir [Stmt<'hir>], @@ -815,7 +722,7 @@ pub struct Block<'hir> { pub targeted_by_break: bool, } -#[derive(RustcEncodable, RustcDecodable, HashStable)] +#[derive(RustcEncodable, RustcDecodable, HashStable_Generic)] pub struct Pat<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -904,7 +811,7 @@ impl Pat<'_> { /// Patterns like the fields of Foo `{ x, ref y, ref mut z }` /// are treated the same as` x: x, y: ref y, z: ref mut z`, /// except `is_shorthand` is true. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct FieldPat<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -920,7 +827,7 @@ pub struct FieldPat<'hir> { /// Explicit binding annotations given in the HIR for a binding. Note /// that this is not the final binding *mode* that we infer after type /// inference. -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum BindingAnnotation { /// No binding annotation given: this means that the final binding mode /// will depend on whether we have skipped through a `&` reference @@ -941,7 +848,7 @@ pub enum BindingAnnotation { RefMut, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum RangeEnd { Included, Excluded, @@ -956,7 +863,7 @@ impl fmt::Display for RangeEnd { } } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum PatKind<'hir> { /// Represents a wildcard pattern (i.e., `_`). Wild, @@ -1012,7 +919,7 @@ pub enum PatKind<'hir> { Slice(&'hir [&'hir Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [&'hir Pat<'hir>]), } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum BinOpKind { /// The `+` operator (addition). Add, @@ -1146,7 +1053,7 @@ impl Into for BinOpKind { pub type BinOp = Spanned; -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum UnOp { /// The `*` operator (deferencing). UnDeref, @@ -1159,23 +1066,23 @@ pub enum UnOp { impl UnOp { pub fn as_str(self) -> &'static str { match self { - UnDeref => "*", - UnNot => "!", - UnNeg => "-", + Self::UnDeref => "*", + Self::UnNot => "!", + Self::UnNeg => "-", } } /// Returns `true` if the unary operator takes its argument by value. pub fn is_by_value(self) -> bool { match self { - UnNeg | UnNot => true, + Self::UnNeg | Self::UnNot => true, _ => false, } } } /// A statement. -#[derive(RustcEncodable, RustcDecodable, HashStable)] +#[derive(RustcEncodable, RustcDecodable, HashStable_Generic)] pub struct Stmt<'hir> { pub hir_id: HirId, pub kind: StmtKind<'hir>, @@ -1194,7 +1101,7 @@ impl fmt::Debug for Stmt<'_> { } /// The contents of a statement. -#[derive(RustcEncodable, RustcDecodable, HashStable)] +#[derive(RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum StmtKind<'hir> { /// A local (`let`) binding. Local(&'hir Local<'hir>), @@ -1220,7 +1127,7 @@ impl StmtKind<'hir> { } /// Represents a `let` statement (i.e., `let : = ;`). -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct Local<'hir> { pub pat: &'hir Pat<'hir>, /// Type annotation, if any (otherwise the type will be inferred). @@ -1237,7 +1144,7 @@ pub struct Local<'hir> { /// Represents a single arm of a `match` expression, e.g. /// ` (if ) => `. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct Arm<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -1251,12 +1158,12 @@ pub struct Arm<'hir> { pub body: &'hir Expr<'hir>, } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum Guard<'hir> { If(&'hir Expr<'hir>), } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct Field<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -1266,7 +1173,7 @@ pub struct Field<'hir> { pub is_shorthand: bool, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum BlockCheckMode { DefaultBlock, UnsafeBlock(UnsafeSource), @@ -1274,7 +1181,7 @@ pub enum BlockCheckMode { PopUnsafeBlock(UnsafeSource), } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum UnsafeSource { CompilerGenerated, UserProvided, @@ -1324,7 +1231,7 @@ impl Body<'hir> { } /// The type of source expression that caused this generator to be created. -#[derive(Clone, PartialEq, Eq, HashStable, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Eq, HashStable_Generic, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum GeneratorKind { /// An explicit `async` block or the body of an async function. Async(AsyncGeneratorKind), @@ -1347,7 +1254,7 @@ impl fmt::Display for GeneratorKind { /// /// This helps error messages but is also used to drive coercions in /// type-checking (see #60424). -#[derive(Clone, PartialEq, Eq, HashStable, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Eq, HashStable_Generic, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum AsyncGeneratorKind { /// An explicit `async` block written by the user. Block, @@ -1401,7 +1308,7 @@ pub type Lit = Spanned; /// These are usually found nested inside types (e.g., array lengths) /// or expressions (e.g., repeat counts), and also used to define /// explicit discriminant values for enum variants. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct AnonConst { pub hir_id: HirId, pub body: BodyId, @@ -1418,7 +1325,7 @@ pub struct Expr<'hir> { // `Expr` is used a lot. Make sure it doesn't unintentionally get bigger. #[cfg(target_arch = "x86_64")] -static_assert_size!(Expr<'static>, 64); +rustc_data_structures::static_assert_size!(Expr<'static>, 64); impl Expr<'_> { pub fn precedence(&self) -> ExprPrecedence { @@ -1478,7 +1385,7 @@ impl Expr<'_> { // https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md#type-ascription-and-temporaries ExprKind::Type(ref e, _) => e.is_place_expr(allow_projections_from), - ExprKind::Unary(UnDeref, _) => true, + ExprKind::Unary(UnOp::UnDeref, _) => true, ExprKind::Field(ref base, _) | ExprKind::Index(ref base, _) => { allow_projections_from(base) || base.is_place_expr(allow_projections_from) @@ -1602,7 +1509,7 @@ pub fn is_range_literal(sm: &SourceMap, expr: &Expr<'_>) -> bool { false } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum ExprKind<'hir> { /// A `box x` expression. Box(&'hir Expr<'hir>), @@ -1715,7 +1622,7 @@ pub enum ExprKind<'hir> { /// To resolve the path to a `DefId`, call [`qpath_res`]. /// /// [`qpath_res`]: ../ty/struct.TypeckTables.html#method.qpath_res -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum QPath<'hir> { /// Path to a definition, optionally "fully-qualified" with a `Self` /// type, if the path points to an associated item in a trait. @@ -1735,7 +1642,7 @@ pub enum QPath<'hir> { } /// Hints at the original code for a let statement. -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum LocalSource { /// A `match _ { .. }`. Normal, @@ -1757,7 +1664,8 @@ pub enum LocalSource { } /// Hints at the original code for a `match _ { .. }`. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(HashStable_Generic)] pub enum MatchSource { /// A `match _ { .. }`. Normal, @@ -1793,7 +1701,7 @@ impl MatchSource { } /// The loop type that yielded an `ExprKind::Loop`. -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum LoopSource { /// A `loop { .. }` loop. Loop, @@ -1815,7 +1723,7 @@ impl LoopSource { } } -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum LoopIdError { OutsideLoopScope, UnlabeledCfInWhileCondition, @@ -1834,7 +1742,7 @@ impl fmt::Display for LoopIdError { } } -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct Destination { // This is `Some(_)` iff there is an explicit user-specified `label pub label: Option