From c19ed3bc5b281fa5e74e70e008a154204fbfd814 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 24 Dec 2019 05:12:01 +0100 Subject: [PATCH 01/20] fn adt_kind -> wfcheck --- src/librustc/hir/mod.rs | 10 ---------- src/librustc_typeck/check/wfcheck.rs | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index d0cc87f7506a0..b7609fa0898e9 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -12,7 +12,6 @@ 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; @@ -2550,15 +2549,6 @@ impl ItemKind<'_> { } } - pub fn adt_kind(&self) -> Option { - match *self { - ItemKind::Struct(..) => Some(AdtKind::Struct), - ItemKind::Union(..) => Some(AdtKind::Union), - ItemKind::Enum(..) => Some(AdtKind::Enum), - _ => None, - } - } - pub fn generics(&self) -> Option<&Generics<'_>> { Some(match *self { ItemKind::Fn(_, ref generics, _) diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index e0ce95aa46b8b..5e2178cf91060 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -1,12 +1,13 @@ use crate::check::{FnCtxt, Inherited}; use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter}; -use crate::hir::def_id::DefId; +use rustc::hir::def_id::DefId; +use rustc::hir::ItemKind; use rustc::infer::opaque_types::may_define_opaque_type; use rustc::middle::lang_items; use rustc::traits::{self, ObligationCause, ObligationCauseCode}; use rustc::ty::subst::{InternalSubsts, Subst}; -use rustc::ty::{self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable}; +use rustc::ty::{self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable}; use rustc::util::nodemap::{FxHashMap, FxHashSet}; use errors::DiagnosticBuilder; @@ -252,6 +253,15 @@ fn for_id(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) -> CheckWfFcxBuilder<'_> } } +fn item_adt_kind(kind: &ItemKind<'_>) -> Option { + match kind { + ItemKind::Struct(..) => Some(AdtKind::Struct), + ItemKind::Union(..) => Some(AdtKind::Union), + ItemKind::Enum(..) => Some(AdtKind::Enum), + _ => None, + } +} + /// In a type definition, we check that to ensure that the types of the fields are well-formed. fn check_type_defn<'tcx, F>( tcx: TyCtxt<'tcx>, @@ -297,7 +307,7 @@ fn check_type_defn<'tcx, F>( field.span, fcx.body_id, traits::FieldSized { - adt_kind: match item.kind.adt_kind() { + adt_kind: match item_adt_kind(&item.kind) { Some(i) => i, None => bug!(), }, From 66f5bf1b8b1e29afc15220d4753ffbcf0c5b5d91 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 24 Dec 2019 05:30:02 +0100 Subject: [PATCH 02/20] extract rustc::middle::codegen_fn_attrs --- src/librustc/hir/mod.rs | 115 ----------------- src/librustc/middle/codegen_fn_attrs.rs | 116 ++++++++++++++++++ src/librustc/middle/mod.rs | 1 + src/librustc/ty/instance.rs | 2 +- src/librustc/ty/query/mod.rs | 3 +- src/librustc_codegen_llvm/attributes.rs | 2 +- src/librustc_codegen_llvm/base.rs | 17 ++- src/librustc_codegen_llvm/consts.rs | 8 +- .../debuginfo/metadata.rs | 2 +- src/librustc_codegen_llvm/debuginfo/mod.rs | 2 +- .../back/symbol_export.rs | 2 +- src/librustc_codegen_ssa/base.rs | 3 +- src/librustc_codegen_utils/symbol_names.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 3 +- src/librustc_mir/monomorphize/partitioning.rs | 2 +- src/librustc_mir/transform/inline.rs | 2 +- src/librustc_passes/dead.rs | 2 +- src/librustc_passes/reachable.rs | 13 +- src/librustc_typeck/collect.rs | 3 +- 19 files changed, 151 insertions(+), 149 deletions(-) create mode 100644 src/librustc/middle/codegen_fn_attrs.rs diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index b7609fa0898e9..959a4a0a304f0 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -10,7 +10,6 @@ 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::util::nodemap::{FxHashSet, NodeMap}; @@ -29,7 +28,6 @@ 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; @@ -2668,119 +2666,6 @@ pub fn provide(providers: &mut Providers<'_>) { upvars::provide(providers); } -#[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, - } - } -} - #[derive(Copy, Clone, Debug)] pub enum Node<'hir> { Param(&'hir Param<'hir>), 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/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/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/query/mod.rs b/src/librustc/ty/query/mod.rs index 1907e6c82c62a..5f739c4e6e625 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -1,9 +1,10 @@ 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::{self, 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}; 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/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 61ccd7820109a..a03938082da5a 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}; diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 16ae3c9503052..143fa651a1516 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -14,7 +14,7 @@ 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::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::ty::subst::{GenericArgKind, SubstsRef}; use crate::abi::FnAbi; diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 5bdb310f9b546..fba221a80f709 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -3,8 +3,8 @@ 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::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; diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index 27841d67c1a9a..d340e0f25231b 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; @@ -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_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_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 6c8f8f6c2275c..16319d1ab370d 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -176,9 +176,10 @@ use crate::monomorphize; +use rustc::hir; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::hir::itemlikevisit::ItemLikeVisitor; -use rustc::hir::{self, CodegenFnAttrFlags}; +use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem}; use rustc::mir::interpret::{AllocId, ConstValue}; use rustc::mir::interpret::{ErrorHandled, GlobalAlloc, Scalar}; diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index 8011de19e78ed..afbae7676fdc2 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -98,7 +98,7 @@ use std::sync::Arc; use rustc::hir::def::DefKind; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; -use rustc::hir::CodegenFnAttrFlags; +use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::middle::exported_symbols::SymbolExportLevel; use rustc::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility}; use rustc::mir::mono::{InstantiationMode, MonoItem}; diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 3c9f8542e51d0..52a105658bdcd 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -1,11 +1,11 @@ //! Inlining pass for MIR functions use rustc::hir::def_id::DefId; -use rustc::hir::CodegenFnAttrFlags; use rustc_index::bit_set::BitSet; use rustc_index::vec::{Idx, IndexVec}; +use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::mir::visit::*; use rustc::mir::*; use rustc::ty::subst::{InternalSubsts, Subst, SubstsRef}; diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index 22f3533b1e4bc..8e813ec692e7a 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -9,8 +9,8 @@ use rustc::hir::{self, PatKind, TyKind}; use rustc::hir::def::{CtorOf, DefKind, Res}; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; -use rustc::hir::CodegenFnAttrFlags; use rustc::lint; +use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::middle::privacy; use rustc::ty::{self, DefIdTree, TyCtxt}; use rustc::util::nodemap::FxHashSet; diff --git a/src/librustc_passes/reachable.rs b/src/librustc_passes/reachable.rs index 5241d9ea43f13..c3ab595ad6826 100644 --- a/src/librustc_passes/reachable.rs +++ b/src/librustc_passes/reachable.rs @@ -5,22 +5,21 @@ // makes all other generics or inline functions that it references // reachable as well. +use rustc::hir; use rustc::hir::def::{DefKind, Res}; +use rustc::hir::def_id::LOCAL_CRATE; use rustc::hir::def_id::{CrateNum, DefId}; +use rustc::hir::intravisit; +use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; +use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::Node; -use rustc::hir::{CodegenFnAttrFlags, CodegenFnAttrs}; +use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc::middle::privacy; use rustc::session::config; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt}; use rustc::util::nodemap::{FxHashSet, HirIdSet}; use rustc_data_structures::sync::Lrc; - -use rustc::hir; -use rustc::hir::def_id::LOCAL_CRATE; -use rustc::hir::intravisit; -use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; -use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc_target::spec::abi::Abi; // Returns true if the given item must be inlined because it may be diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index d13ddb28bf937..1d20ef2fe0735 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -20,6 +20,7 @@ use crate::constrained_generic_params as cgp; use crate::lint; use crate::middle::resolve_lifetime as rl; use crate::middle::weak_lang_items; +use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc::mir::mono::Linkage; use rustc::ty::query::Providers; use rustc::ty::subst::GenericArgKind; @@ -44,7 +45,7 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::GenericParamKind; use rustc::hir::Node; -use rustc::hir::{self, CodegenFnAttrFlags, CodegenFnAttrs, Unsafety}; +use rustc::hir::{self, Unsafety}; use errors::{Applicability, StashKey}; From 7901c7f707fd84c4f57401dd13ac0c4fc7b693ee Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 24 Dec 2019 05:02:53 +0100 Subject: [PATCH 03/20] canonicalize FxHash{Map,Set} imports --- src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/map/mod.rs | 2 +- src/librustc/hir/mod.rs | 3 ++- src/librustc/infer/freshen.rs | 3 ++- .../infer/lexical_region_resolve/graphviz.rs | 2 +- src/librustc/infer/mod.rs | 2 +- src/librustc/lint/context.rs | 3 +-- src/librustc/lint/levels.rs | 2 +- src/librustc/middle/lang_items.rs | 6 +++--- src/librustc/middle/privacy.rs | 3 ++- src/librustc/middle/region.rs | 2 +- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc/middle/stability.rs | 3 ++- src/librustc/mir/mono.rs | 2 +- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/on_unimplemented.rs | 2 +- src/librustc/traits/select.rs | 2 +- .../traits/specialize/specialization_graph.rs | 3 ++- src/librustc/traits/util.rs | 2 +- src/librustc/ty/context.rs | 2 +- src/librustc/ty/fold.rs | 2 +- src/librustc/ty/mod.rs | 3 ++- src/librustc/util/nodemap.rs | 7 ++----- src/librustc_codegen_llvm/context.rs | 2 +- .../debuginfo/metadata.rs | 2 +- src/librustc_codegen_llvm/debuginfo/mod.rs | 3 ++- .../back/symbol_export.rs | 3 ++- src/librustc_codegen_ssa/back/write.rs | 2 +- src/librustc_codegen_ssa/base.rs | 2 +- src/librustc_codegen_ssa/traits/misc.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_lint/types.rs | 3 ++- src/librustc_metadata/dependency_format.rs | 2 +- src/librustc_metadata/locator.rs | 3 +-- src/librustc_metadata/native_libs.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 3 +-- src/librustc_mir/borrow_check/borrow_set.rs | 2 +- .../borrow_check/universal_regions.rs | 2 +- src/librustc_mir/dataflow/move_paths/mod.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 4 ++-- src/librustc_mir/monomorphize/partitioning.rs | 3 ++- src/librustc_mir/transform/elaborate_drops.rs | 2 +- src/librustc_mir/transform/instcombine.rs | 2 +- src/librustc_passes/dead.rs | 4 +--- src/librustc_passes/diagnostic_items.rs | 7 +++---- src/librustc_passes/hir_stats.rs | 2 +- src/librustc_passes/reachable.rs | 3 ++- src/librustc_passes/region.rs | 3 +-- src/librustc_passes/stability.rs | 2 +- src/librustc_resolve/diagnostics.rs | 2 +- src/librustc_resolve/imports.rs | 3 +-- src/librustc_resolve/late.rs | 2 +- src/librustc_resolve/late/diagnostics.rs | 2 +- src/librustc_resolve/lib.rs | 15 ++++++--------- src/librustc_resolve/lifetimes.rs | 19 +++++++++---------- src/librustc_resolve/macros.rs | 2 +- src/librustc_traits/dropck_outlives.rs | 2 +- src/librustc_typeck/astconv.rs | 4 +--- src/librustc_typeck/check/expr.rs | 2 +- .../check/generator_interior.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 3 ++- src/librustc_typeck/check/pat.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/collect.rs | 2 +- .../constrained_generic_params.rs | 2 +- src/librustc_typeck/impl_wf_check.rs | 2 +- src/librustc_typeck/outlives/explicit.rs | 2 +- .../outlives/implicit_infer.rs | 2 +- src/librustdoc/clean/auto_trait.rs | 2 +- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/clean/types.rs | 2 +- src/librustdoc/clean/utils.rs | 2 +- src/librustdoc/core.rs | 2 +- src/librustdoc/html/format.rs | 2 +- src/librustdoc/html/render.rs | 2 +- src/librustdoc/passes/collect_trait_impls.rs | 2 +- src/librustdoc/visit_ast.rs | 2 +- src/librustdoc/visit_lib.rs | 2 +- 81 files changed, 112 insertions(+), 117 deletions(-) diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 00026d6969bb5..ffb5610c2c3ea 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -8,7 +8,7 @@ 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_span::source_map::SourceMap; diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 9ea10d0c51591..15914809ba4c5 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -12,8 +12,8 @@ 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; diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 959a4a0a304f0..39c9866666c4b 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -11,9 +11,10 @@ pub use self::UnsafeSource::*; use crate::hir::def::{DefKind, Res}; use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX}; use crate::ty::query::Providers; -use crate::util::nodemap::{FxHashSet, NodeMap}; +use crate::util::nodemap::NodeMap; use errors::FatalError; +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}; 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/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/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/privacy.rs b/src/librustc/middle/privacy.rs index fc48999115e86..770a974da07f2 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -3,8 +3,9 @@ //! which are available for use externally when compiled as a library. use crate::hir::HirId; -use crate::util::nodemap::{DefIdSet, FxHashMap}; +use crate::util::nodemap::DefIdSet; +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/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..fe67598230824 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -5,7 +5,8 @@ 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 crate::util::nodemap::DefIdMap; +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..25db4f0f4ab1e 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -47,10 +47,10 @@ 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::{ 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/mod.rs b/src/librustc/ty/mod.rs index 2707d07633b2f..452ae073f1da7 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -28,8 +28,9 @@ 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 crate::util::nodemap::{DefIdMap, NodeMap, NodeSet}; use arena::SyncDroplessArena; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::svh::Svh; use rustc_macros::HashStable; diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs index ce0f77e0b6d37..c166a712d7b75 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -4,13 +4,10 @@ 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>; + pub type $map_name = rustc_data_structures::fx::FxHashMap<$key, T>; + pub type $set_name = rustc_data_structures::fx::FxHashSet<$key>; }; } 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 a03938082da5a..88e692cb11747 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -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 143fa651a1516..3fea27445a09e 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -24,9 +24,10 @@ 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::util::nodemap::DefIdMap; 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 fba221a80f709..44e9067a60a65 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -11,8 +11,9 @@ 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::util::nodemap::DefIdMap; 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 d340e0f25231b..b964fa1c182c9 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -40,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; 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_lint/builtin.rs b/src/librustc_lint/builtin.rs index 055b1f8b366d8..90d87e34e48da 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -33,7 +33,7 @@ use rustc::ty::{self, layout::VariantIdx, Ty, TyCtxt}; use rustc::{lint, util}; use util::nodemap::HirIdSet; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_feature::Stability; use rustc_feature::{deprecated_attributes, AttributeGate, AttributeTemplate, AttributeType}; diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 67eccda5eb7e8..7944c88c7cbd8 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -5,11 +5,12 @@ use lint::{LateContext, LintArray, LintContext}; use lint::{LateLintPass, LintPass}; use rustc::hir; use rustc::hir::{is_range_literal, ExprKind, Node}; +use rustc::lint; use rustc::mir::interpret::{sign_extend, truncate}; use rustc::ty::layout::{self, IntegerExt, LayoutOf, SizeSkeleton, VariantIdx}; use rustc::ty::subst::SubstsRef; use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt}; -use rustc::{lint, util::nodemap::FxHashSet}; +use rustc_data_structures::fx::FxHashSet; use rustc_index::vec::Idx; use rustc_span::source_map; use rustc_span::symbol::sym; diff --git a/src/librustc_metadata/dependency_format.rs b/src/librustc_metadata/dependency_format.rs index 191231a3d608f..f82579aba02ad 100644 --- a/src/librustc_metadata/dependency_format.rs +++ b/src/librustc_metadata/dependency_format.rs @@ -59,7 +59,7 @@ use rustc::middle::cstore::{self, DepKind}; use rustc::middle::dependency_format::{Dependencies, DependencyList, Linkage}; use rustc::session::config; use rustc::ty::TyCtxt; -use rustc::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use rustc_target::spec::PanicStrategy; crate fn calculate(tcx: TyCtxt<'_>) -> Dependencies { diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index a9adb6291c74d..59e769cabb7d4 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -219,8 +219,7 @@ use rustc::middle::cstore::{CrateSource, MetadataLoader}; use rustc::session::filesearch::{FileDoesntMatch, FileMatches, FileSearch}; use rustc::session::search_paths::PathKind; use rustc::session::{config, CrateDisambiguator, Session}; -use rustc::util::nodemap::FxHashMap; -use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::MetadataRef; diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index 3228c9f2ff435..bdd9eab71186d 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -3,7 +3,7 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::middle::cstore::{self, NativeLibrary}; use rustc::session::Session; use rustc::ty::TyCtxt; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_span::source_map::Span; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_target::spec::abi::Abi; diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 6d84bd6f26369..fc7eae1e6c7a1 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -18,8 +18,7 @@ use rustc_data_structures::fingerprint::Fingerprint; use rustc_index::vec::Idx; use rustc::session::config::{self, CrateType}; -use rustc::util::nodemap::FxHashMap; - +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::StableHasher; use rustc_data_structures::sync::Lrc; use rustc_serialize::{opaque, Encodable, Encoder, SpecializedEncoder}; diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs index 1423ff2ed417d..b66b2e4b1f7f5 100644 --- a/src/librustc_mir/borrow_check/borrow_set.rs +++ b/src/librustc_mir/borrow_check/borrow_set.rs @@ -7,7 +7,7 @@ use rustc::mir::traversal; use rustc::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor}; use rustc::mir::{self, Body, Local, Location, ReadOnlyBodyAndCache}; use rustc::ty::{RegionVid, TyCtxt}; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::bit_set::BitSet; use rustc_index::vec::IndexVec; use std::fmt; diff --git a/src/librustc_mir/borrow_check/universal_regions.rs b/src/librustc_mir/borrow_check/universal_regions.rs index 4e3aa4c65b6a8..c7ef017215e0c 100644 --- a/src/librustc_mir/borrow_check/universal_regions.rs +++ b/src/librustc_mir/borrow_check/universal_regions.rs @@ -20,7 +20,7 @@ use rustc::middle::lang_items; use rustc::ty::fold::TypeFoldable; use rustc::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc::ty::{self, RegionVid, Ty, TyCtxt}; -use rustc::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use rustc_errors::DiagnosticBuilder; use rustc_index::vec::{Idx, IndexVec}; use std::iter; diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index 6b711c37dae38..6450762d351b1 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -1,7 +1,7 @@ use core::slice::Iter; use rustc::mir::*; use rustc::ty::{ParamEnv, Ty, TyCtxt}; -use rustc::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use rustc_index::vec::{Enumerated, Idx, IndexVec}; use rustc_span::Span; use smallvec::SmallVec; diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 16319d1ab370d..d0775d10a2c7b 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -192,8 +192,8 @@ use rustc::ty::print::obsolete::DefPathBasedNames; use rustc::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc::ty::{self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable}; use rustc::util::common::time; -use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet}; - +use rustc::util::nodemap::DefIdMap; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator}; use rustc_index::bit_set::GrowableBitSet; diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index afbae7676fdc2..d6d174bef89f8 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -106,7 +106,8 @@ use rustc::ty::print::characteristic_def_id_of_type; use rustc::ty::query::Providers; use rustc::ty::{self, DefIdTree, InstanceDef, TyCtxt}; use rustc::util::common::time; -use rustc::util::nodemap::{DefIdSet, FxHashMap, FxHashSet}; +use rustc::util::nodemap::DefIdSet; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span::symbol::Symbol; use crate::monomorphize::collector::InliningMap; diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index 269465fb88b42..860a014c5173c 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -13,7 +13,7 @@ use rustc::hir; use rustc::mir::*; use rustc::ty::layout::VariantIdx; use rustc::ty::{self, TyCtxt}; -use rustc::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use rustc_index::bit_set::BitSet; use rustc_span::Span; use std::fmt; diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index 02022b7bbf1d1..a2f3fcea7569a 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -7,7 +7,7 @@ use rustc::mir::{ ProjectionElem, Rvalue, }; use rustc::ty::{self, TyCtxt}; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::vec::Idx; use std::mem; diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index 8e813ec692e7a..f9db1a21cc87d 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -13,9 +13,7 @@ use rustc::lint; use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::middle::privacy; use rustc::ty::{self, DefIdTree, TyCtxt}; -use rustc::util::nodemap::FxHashSet; - -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span; use rustc_span::symbol::sym; diff --git a/src/librustc_passes/diagnostic_items.rs b/src/librustc_passes/diagnostic_items.rs index 4e8b5c5f6b653..6b2c42602ff0b 100644 --- a/src/librustc_passes/diagnostic_items.rs +++ b/src/librustc_passes/diagnostic_items.rs @@ -9,13 +9,12 @@ //! //! * Compiler internal types like `Ty` and `TyCtxt` +use rustc::hir; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; +use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; -use rustc::util::nodemap::FxHashMap; - -use rustc::hir; -use rustc::hir::itemlikevisit::ItemLikeVisitor; +use rustc_data_structures::fx::FxHashMap; use rustc_span::symbol::{sym, Symbol}; use syntax::ast; diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index d52f31ceeeadf..4341ebfc45736 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -5,7 +5,7 @@ use rustc::hir::intravisit as hir_visit; use rustc::hir::{self, HirId}; use rustc::util::common::to_readable_str; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span::Span; use syntax::ast::{self, AttrId, NodeId}; use syntax::visit as ast_visit; diff --git a/src/librustc_passes/reachable.rs b/src/librustc_passes/reachable.rs index c3ab595ad6826..1c8733ab44db1 100644 --- a/src/librustc_passes/reachable.rs +++ b/src/librustc_passes/reachable.rs @@ -18,7 +18,8 @@ use rustc::middle::privacy; use rustc::session::config; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt}; -use rustc::util::nodemap::{FxHashSet, HirIdSet}; +use rustc::util::nodemap::HirIdSet; +use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_target::spec::abi::Abi; diff --git a/src/librustc_passes/region.rs b/src/librustc_passes/region.rs index 685e48e0f3558..7652d5a36ee19 100644 --- a/src/librustc_passes/region.rs +++ b/src/librustc_passes/region.rs @@ -14,8 +14,7 @@ use rustc::hir::{Arm, Block, Expr, Local, Pat, PatKind, Stmt}; use rustc::middle::region::*; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; -use rustc::util::nodemap::FxHashSet; - +use rustc_data_structures::fx::FxHashSet; use rustc_index::vec::Idx; use rustc_span::source_map; use rustc_span::Span; diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index 686ed6c1345bc..60f26625a2e87 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -11,7 +11,7 @@ use rustc::middle::stability::{DeprecationEntry, Index}; use rustc::session::Session; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; use syntax::ast::Attribute; diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index c4538ddc24226..1d45f1cd9124a 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -8,7 +8,7 @@ use rustc::hir::def::{self, DefKind, NonMacroAttrKind}; use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX}; use rustc::session::Session; use rustc::ty::{self, DefIdTree}; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_feature::BUILTIN_ATTRIBUTES; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::SourceMap; diff --git a/src/librustc_resolve/imports.rs b/src/librustc_resolve/imports.rs index eb2c4f79feff5..9b7cd2578f878 100644 --- a/src/librustc_resolve/imports.rs +++ b/src/librustc_resolve/imports.rs @@ -19,10 +19,9 @@ use rustc::lint::builtin::BuiltinLintDiagnostics; use rustc::lint::builtin::{PUB_USE_OF_PRIVATE_EXTERN_CRATE, UNUSED_IMPORTS}; use rustc::session::DiagnosticMessageId; use rustc::ty; -use rustc::util::nodemap::FxHashSet; use rustc::{bug, span_bug}; +use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::ptr_key::PtrKey; - use rustc_span::hygiene::ExpnId; use rustc_span::symbol::kw; use rustc_span::{MultiSpan, Span}; diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index cc9e617f430cd..84cb3f7181996 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -16,8 +16,8 @@ use rustc::hir::def::Namespace::{self, *}; use rustc::hir::def::{self, CtorKind, DefKind, PartialRes, PerNS}; use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX}; use rustc::hir::TraitCandidate; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; use rustc::{bug, lint, span_bug}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span::symbol::{kw, sym}; use rustc_span::Span; use smallvec::{smallvec, SmallVec}; diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 4a65b097e73bf..cd94229b0abc5 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -11,7 +11,7 @@ use rustc::hir::def::{self, CtorKind, DefKind}; use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX}; use rustc::hir::PrimTy; use rustc::session::config::nightly_options; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_span::hygiene::MacroKind; use rustc_span::symbol::kw; use rustc_span::Span; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 420e3d5c6de7a..708bf538bdbd5 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -20,6 +20,7 @@ pub use rustc::hir::def::{Namespace, PerNS}; use Determinacy::*; +use errors::{Applicability, DiagnosticBuilder}; use rustc::hir::def::Namespace::*; use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, ExportMap, NonMacroAttrKind, PartialRes}; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; @@ -32,12 +33,12 @@ use rustc::session::Session; use rustc::span_bug; use rustc::ty::query::Providers; use rustc::ty::{self, DefIdTree, ResolverOutputs}; -use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, NodeMap, NodeSet}; - -use rustc_metadata::creader::{CStore, CrateLoader}; - -use errors::{Applicability, DiagnosticBuilder}; +use rustc::util::nodemap::{DefIdMap, NodeMap, NodeSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; +use rustc_data_structures::ptr_key::PtrKey; +use rustc_data_structures::sync::Lrc; use rustc_expand::base::SyntaxExtension; +use rustc_metadata::creader::{CStore, CrateLoader}; use rustc_span::hygiene::{ExpnId, ExpnKind, MacroKind, SyntaxContext, Transparency}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym}; @@ -51,10 +52,6 @@ use syntax::visit::{self, Visitor}; use syntax::{struct_span_err, unwrap_or}; use log::debug; - -use rustc_data_structures::fx::FxIndexMap; -use rustc_data_structures::ptr_key::PtrKey; -use rustc_data_structures::sync::Lrc; use std::cell::{Cell, RefCell}; use std::collections::BTreeSet; use std::{cmp, fmt, iter, ptr}; diff --git a/src/librustc_resolve/lifetimes.rs b/src/librustc_resolve/lifetimes.rs index e7d6cd2709d73..96f1e069f9231 100644 --- a/src/librustc_resolve/lifetimes.rs +++ b/src/librustc_resolve/lifetimes.rs @@ -5,16 +5,20 @@ //! used between functions, and they operate in a purely top-down //! way. Therefore, we break lifetime name resolution into a separate pass. +use errors::{pluralize, Applicability, DiagnosticBuilder}; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; +use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; +use rustc::hir::{self, GenericParamKind, LifetimeParamKind}; use rustc::hir::{GenericArg, GenericParam, LifetimeName, Node, ParamName, QPath}; -use rustc::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt}; - -use errors::{pluralize, Applicability, DiagnosticBuilder}; use rustc::lint; +use rustc::middle::resolve_lifetime::*; use rustc::session::Session; -use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet}; +use rustc::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt}; +use rustc::util::nodemap::{DefIdMap, HirIdMap, HirIdSet}; +use rustc::{bug, span_bug}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span::symbol::{kw, sym}; use rustc_span::Span; use std::borrow::Cow; @@ -22,15 +26,10 @@ use std::cell::Cell; use std::mem::{replace, take}; use syntax::ast; use syntax::attr; - -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; -use rustc::hir::{self, GenericParamKind, LifetimeParamKind}; +use syntax::{help, span_err, struct_span_err, walk_list}; use log::debug; -use rustc::{bug, span_bug}; -use syntax::{help, span_err, struct_span_err, walk_list}; -use rustc::middle::resolve_lifetime::*; use rustc_error_codes::*; // This counts the no of times a lifetime is used diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 4c95607410bd7..a2ef6ad70f907 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -10,8 +10,8 @@ use rustc::hir::def::{self, DefKind, NonMacroAttrKind}; use rustc::hir::def_id; use rustc::middle::stability; use rustc::session::Session; -use rustc::util::nodemap::FxHashSet; use rustc::{lint, span_bug, ty}; +use rustc_data_structures::fx::FxHashSet; use rustc_expand::base::SyntaxExtension; use rustc_expand::base::{self, Indeterminate, InvocationRes}; use rustc_expand::compile_declarative_macro; diff --git a/src/librustc_traits/dropck_outlives.rs b/src/librustc_traits/dropck_outlives.rs index 46021f8b3991b..a0bbc2824336c 100644 --- a/src/librustc_traits/dropck_outlives.rs +++ b/src/librustc_traits/dropck_outlives.rs @@ -7,7 +7,7 @@ use rustc::traits::{Normalized, ObligationCause, TraitEngine, TraitEngineExt}; use rustc::ty::query::Providers; use rustc::ty::subst::{InternalSubsts, Subst}; use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt}; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_span::source_map::{Span, DUMMY_SP}; crate fn provide(p: &mut Providers<'_>) { diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 609ce70057d0d..601a46ad345c4 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -14,7 +14,6 @@ use crate::middle::resolve_lifetime as rl; use crate::namespace::Namespace; use crate::require_c_abi_if_c_variadic; use crate::util::common::ErrorReported; -use crate::util::nodemap::FxHashMap; use errors::{Applicability, DiagnosticId}; use rustc::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS; use rustc::traits; @@ -22,6 +21,7 @@ use rustc::ty::subst::{self, InternalSubsts, Subst, SubstsRef}; use rustc::ty::wf::object_region_bounds; use rustc::ty::{self, Const, DefIdTree, ToPredicate, Ty, TyCtxt, TypeFoldable}; use rustc::ty::{GenericParamDef, GenericParamDefKind}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span::symbol::sym; use rustc_span::{MultiSpan, Span, DUMMY_SP}; use rustc_target::spec::abi; @@ -35,8 +35,6 @@ use std::collections::BTreeSet; use std::iter; use std::slice; -use rustc_data_structures::fx::FxHashSet; - use rustc_error_codes::*; #[derive(Debug)] diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 773c9a2665992..743a2c6b54397 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -15,7 +15,6 @@ use crate::check::FnCtxt; use crate::check::Needs; use crate::check::TupleArgumentsFlag::DontTupleArguments; use crate::util::common::ErrorReported; -use crate::util::nodemap::FxHashMap; use errors::{pluralize, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc::hir; @@ -31,6 +30,7 @@ use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoB use rustc::ty::Ty; use rustc::ty::TypeFoldable; use rustc::ty::{AdtKind, Visibility}; +use rustc_data_structures::fx::FxHashMap; use rustc_span::hygiene::DesugaringKind; use rustc_span::source_map::Span; use rustc_span::symbol::{kw, sym, Symbol}; diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index f63971039bc5a..63aadd43a0949 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -4,13 +4,13 @@ //! types computed here. use super::FnCtxt; -use crate::util::nodemap::FxHashMap; use rustc::hir::def::{CtorKind, DefKind, Res}; use rustc::hir::def_id::DefId; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::{self, Expr, ExprKind, Pat, PatKind}; use rustc::middle::region::{self, YieldData}; use rustc::ty::{self, Ty}; +use rustc_data_structures::fx::FxHashMap; use rustc_span::Span; struct InteriorVisitor<'a, 'tcx> { diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index acf449d384cca..28c84c5c0d022 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -27,7 +27,7 @@ use rustc::ty::GenericParamDefKind; use rustc::ty::{ self, ParamEnvAnd, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeFoldable, }; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_span::{symbol::Symbol, Span, DUMMY_SP}; use std::cmp::max; diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 40ea27df4ffe2..fd92e376f61c1 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -4,7 +4,6 @@ use crate::check::FnCtxt; use crate::middle::lang_items::FnOnceTraitLangItem; use crate::namespace::Namespace; -use crate::util::nodemap::FxHashSet; use errors::{pluralize, Applicability, DiagnosticBuilder}; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; @@ -14,6 +13,7 @@ use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::traits::Obligation; use rustc::ty::print::with_crate_prefix; use rustc::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable}; +use rustc_data_structures::fx::FxHashSet; use rustc_span::{source_map, FileName, Span}; use syntax::ast; use syntax::util::lev_distance; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 43e0134ceda40..71a7a5dd69b1a 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -117,6 +117,7 @@ use rustc::ty::{ self, AdtKind, CanonicalUserType, Const, GenericParamDefKind, RegionKind, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, UserType, }; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::vec::Idx; use rustc_span::hygiene::DesugaringKind; use rustc_span::source_map::{original_sp, DUMMY_SP}; @@ -144,7 +145,7 @@ use crate::session::config::EntryFnType; use crate::session::Session; use crate::util::captures::Captures; use crate::util::common::{indenter, ErrorReported}; -use crate::util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, HirIdMap}; +use crate::util::nodemap::{DefIdMap, DefIdSet, HirIdMap}; use crate::TypeAndSubsts; use self::autoderef::Autoderef; diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 251c8427ffd54..8e5e5c39e67dc 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -1,5 +1,4 @@ use crate::check::FnCtxt; -use crate::util::nodemap::FxHashMap; use errors::{pluralize, Applicability, DiagnosticBuilder}; use rustc::hir::def::{CtorKind, DefKind, Res}; use rustc::hir::pat_util::EnumerateAndAdjustIterator; @@ -9,6 +8,7 @@ use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::traits::Pattern; use rustc::ty::subst::GenericArg; use rustc::ty::{self, BindingMode, Ty, TypeFoldable}; +use rustc_data_structures::fx::FxHashMap; use rustc_span::hygiene::DesugaringKind; use rustc_span::Span; use syntax::ast; diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 5e2178cf91060..e9df155c9b758 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -8,7 +8,7 @@ use rustc::middle::lang_items; use rustc::traits::{self, ObligationCause, ObligationCauseCode}; use rustc::ty::subst::{InternalSubsts, Subst}; use rustc::ty::{self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable}; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use errors::DiagnosticBuilder; use rustc_span::symbol::sym; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 1d20ef2fe0735..bc39856e14d73 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -30,7 +30,7 @@ use rustc::ty::util::IntTypeExt; use rustc::ty::{self, AdtKind, Const, DefIdTree, ToPolyTraitRef, Ty, TyCtxt}; use rustc::ty::{ReprOptions, ToPredicate}; use rustc::util::captures::Captures; -use rustc::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use rustc_target::spec::abi; use rustc_span::symbol::{kw, sym, Symbol}; diff --git a/src/librustc_typeck/constrained_generic_params.rs b/src/librustc_typeck/constrained_generic_params.rs index 706174041deac..a281c0ae67d24 100644 --- a/src/librustc_typeck/constrained_generic_params.rs +++ b/src/librustc_typeck/constrained_generic_params.rs @@ -1,6 +1,6 @@ use rustc::ty::fold::{TypeFoldable, TypeVisitor}; use rustc::ty::{self, Ty, TyCtxt}; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_span::source_map::Span; #[derive(Clone, PartialEq, Eq, Hash, Debug)] diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index 82632bbc17c05..770aeb6869a8a 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -14,7 +14,7 @@ use rustc::hir::def_id::DefId; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt, TypeFoldable}; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use std::collections::hash_map::Entry::{Occupied, Vacant}; use rustc_span::Span; diff --git a/src/librustc_typeck/outlives/explicit.rs b/src/librustc_typeck/outlives/explicit.rs index f549946a59a7b..a922846856db8 100644 --- a/src/librustc_typeck/outlives/explicit.rs +++ b/src/librustc_typeck/outlives/explicit.rs @@ -1,6 +1,6 @@ -use crate::util::nodemap::FxHashMap; use rustc::hir::def_id::DefId; use rustc::ty::{self, OutlivesPredicate, TyCtxt}; +use rustc_data_structures::fx::FxHashMap; use super::utils::*; diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index 9b96506b06e1b..b18f89c1a72d1 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -3,7 +3,7 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::{self, Node}; use rustc::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc::ty::{self, Ty, TyCtxt}; -use rustc::util::nodemap::FxHashMap; +use rustc_data_structures::fx::FxHashMap; use rustc_span::Span; use super::explicit::ExplicitPredicatesMap; diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index f3b0a6833098c..dec019711a012 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -1,7 +1,7 @@ use rustc::hir; use rustc::traits::auto_trait::{self, AutoTraitResult}; use rustc::ty::{self, Region, RegionVid, TypeFoldable}; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use std::fmt::Debug; diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 57ec985285d59..49baff065c873 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -11,7 +11,7 @@ use rustc::hir::def::{CtorKind, DefKind, Res}; use rustc::hir::def_id::DefId; use rustc::hir::{self, Mutability}; use rustc::ty; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_metadata::creader::LoadedMacro; use crate::clean::{self, GetDefId, ToSource, TypeKind}; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0ba7370f3ebe1..fad2bab43b990 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -19,7 +19,7 @@ use rustc::middle::stability; use rustc::ty::fold::TypeFolder; use rustc::ty::subst::InternalSubsts; use rustc::ty::{self, AdtKind, Lift, Ty, TyCtxt}; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::vec::{Idx, IndexVec}; use rustc_span::hygiene::MacroKind; use rustc_span::symbol::{kw, sym}; diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 6dd89dbd7f1ce..6bb1ef7d1261b 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -14,7 +14,7 @@ use rustc::hir::{self, Mutability}; use rustc::middle::lang_items; use rustc::middle::stability; use rustc::ty::layout::VariantIdx; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::vec::IndexVec; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::DUMMY_SP; diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index be4ae1c911975..d17b3ce0b1bc2 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -15,7 +15,7 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::mir::interpret::{sign_extend, ConstValue, Scalar}; use rustc::ty::subst::{GenericArgKind, SubstsRef}; use rustc::ty::{self, DefIdTree, Ty}; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_span; use rustc_span::symbol::{kw, sym, Symbol}; use std::mem; diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index cb22039327e07..8ac9e957d3e71 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -8,7 +8,7 @@ use rustc::session::config::ErrorOutputType; use rustc::session::DiagnosticOutput; use rustc::session::{self, config}; use rustc::ty::{Ty, TyCtxt}; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_driver::abort_on_err; use rustc_feature::UnstableFeatures; use rustc_interface::interface; diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 96b841046ff22..f84fef2761eca 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -11,7 +11,7 @@ use std::fmt; use rustc::hir; use rustc::hir::def_id::DefId; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_target::spec::abi::Abi; use crate::clean::{self, PrimitiveType}; diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ad059463aa43a..c315cefc1b88b 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -47,8 +47,8 @@ use rustc::hir::def_id::DefId; use rustc::hir::{self, Mutability}; use rustc::middle::privacy::AccessLevels; use rustc::middle::stability; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; use rustc_data_structures::flock; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_feature::UnstableFeatures; use rustc_span::edition::Edition; use rustc_span::hygiene::MacroKind; diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 63ad9a66a482d..d9360f24a787c 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -4,7 +4,7 @@ use crate::core::DocContext; use crate::fold::DocFolder; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_span::symbol::sym; pub const COLLECT_TRAIT_IMPLS: Pass = Pass { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 959f61644d60d..707d9a999e529 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -6,7 +6,7 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::hir::{self, Node}; use rustc::middle::privacy::AccessLevel; use rustc::ty::TyCtxt; -use rustc::util::nodemap::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::Spanned; use rustc_span::symbol::sym; diff --git a/src/librustdoc/visit_lib.rs b/src/librustdoc/visit_lib.rs index f8f82e17e8f4c..d157a0ca03fd0 100644 --- a/src/librustdoc/visit_lib.rs +++ b/src/librustdoc/visit_lib.rs @@ -2,7 +2,7 @@ use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX}; use rustc::middle::privacy::{AccessLevel, AccessLevels}; use rustc::ty::{TyCtxt, Visibility}; -use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::fx::FxHashSet; use rustc_span::symbol::sym; use crate::clean::{AttributesExt, NestedAttributesExt}; From f507403517299765b6d628fd677c6d880899b83c Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 24 Dec 2019 22:32:36 +0100 Subject: [PATCH 04/20] define_id_collections -> rustc_data_structures --- src/librustc/util/nodemap.rs | 7 +------ src/librustc_data_structures/fx.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs index c166a712d7b75..7a5c2780f3c01 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -4,12 +4,7 @@ use crate::hir::def_id::DefId; use crate::hir::{HirId, ItemLocalId}; use syntax::ast; -macro_rules! define_id_collections { - ($map_name:ident, $set_name:ident, $key:ty) => { - pub type $map_name = rustc_data_structures::fx::FxHashMap<$key, T>; - pub type $set_name = rustc_data_structures::fx::FxHashSet<$key>; - }; -} +use rustc_data_structures::define_id_collections; define_id_collections!(NodeMap, NodeSet, ast::NodeId); define_id_collections!(DefIdMap, DefIdSet, DefId); 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>; + }; +} From 5ccc1e45bd39f05d960d8e9ed610f7ade527720e Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 24 Dec 2019 22:42:56 +0100 Subject: [PATCH 05/20] move Node{Map,Set} -> rustc_session::node_id --- Cargo.lock | 2 ++ src/librustc/hir/map/definitions.rs | 4 ++-- src/librustc/hir/mod.rs | 2 +- src/librustc/lint/mod.rs | 4 ++-- src/librustc/ty/context.rs | 3 ++- src/librustc/ty/mod.rs | 3 ++- src/librustc/util/nodemap.rs | 2 -- src/librustc_ast_lowering/Cargo.toml | 1 + src/librustc_ast_lowering/item.rs | 2 +- src/librustc_ast_lowering/lib.rs | 3 ++- src/librustc_resolve/Cargo.toml | 1 + src/librustc_resolve/check_unused.rs | 3 +-- src/librustc_resolve/lib.rs | 3 ++- src/librustc_session/node_id.rs | 2 ++ 14 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45a1a169be446..aff2d7e65af1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3368,6 +3368,7 @@ dependencies = [ "rustc_error_codes", "rustc_errors", "rustc_index", + "rustc_session", "rustc_span", "rustc_target", "smallvec 1.0.0", @@ -3808,6 +3809,7 @@ dependencies = [ "rustc_expand", "rustc_feature", "rustc_metadata", + "rustc_session", "rustc_span", "smallvec 1.0.0", "syntax", 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/mod.rs b/src/librustc/hir/mod.rs index 39c9866666c4b..ff025f48dc44f 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -11,13 +11,13 @@ pub use self::UnsafeSource::*; use crate::hir::def::{DefKind, Res}; use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX}; use crate::ty::query::Providers; -use crate::util::nodemap::NodeMap; use errors::FatalError; 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_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}; 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/ty/context.rs b/src/librustc/ty/context.rs index 25db4f0f4ab1e..88fbed32729da 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -46,7 +46,7 @@ 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::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet}; use arena::SyncDroplessArena; use errors::DiagnosticBuilder; @@ -59,6 +59,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/mod.rs b/src/librustc/ty/mod.rs index 452ae073f1da7..73020b8bc6689 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -28,11 +28,12 @@ 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, NodeMap, NodeSet}; +use crate::util::nodemap::DefIdMap; 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/util/nodemap.rs b/src/librustc/util/nodemap.rs index 7a5c2780f3c01..ed69e9002b6ba 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -2,11 +2,9 @@ use crate::hir::def_id::DefId; use crate::hir::{HirId, ItemLocalId}; -use syntax::ast; use rustc_data_structures::define_id_collections; -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..ba27e79dff517 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -47,13 +47,14 @@ 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::util::nodemap::DefIdMap; 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_resolve/Cargo.toml b/src/librustc_resolve/Cargo.toml index a7ad0db99cfe0..593662c1180db 100644 --- a/src/librustc_resolve/Cargo.toml +++ b/src/librustc_resolve/Cargo.toml @@ -24,4 +24,5 @@ rustc_data_structures = { path = "../librustc_data_structures" } rustc_feature = { path = "../librustc_feature" } rustc_metadata = { path = "../librustc_metadata" } rustc_error_codes = { path = "../librustc_error_codes" } +rustc_session = { path = "../librustc_session" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index 4f25d55db3610..6561072a21bce 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -27,10 +27,9 @@ use crate::imports::ImportDirectiveSubclass; use crate::Resolver; use errors::pluralize; - -use rustc::util::nodemap::NodeMap; use rustc::{lint, ty}; use rustc_data_structures::fx::FxHashSet; +use rustc_session::node_id::NodeMap; use rustc_span::{MultiSpan, Span, DUMMY_SP}; use syntax::ast; use syntax::visit::{self, Visitor}; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 708bf538bdbd5..a822c0fa51885 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -33,12 +33,13 @@ use rustc::session::Session; use rustc::span_bug; use rustc::ty::query::Providers; use rustc::ty::{self, DefIdTree, ResolverOutputs}; -use rustc::util::nodemap::{DefIdMap, NodeMap, NodeSet}; +use rustc::util::nodemap::DefIdMap; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::ptr_key::PtrKey; use rustc_data_structures::sync::Lrc; use rustc_expand::base::SyntaxExtension; use rustc_metadata::creader::{CStore, CrateLoader}; +use rustc_session::node_id::{NodeMap, NodeSet}; use rustc_span::hygiene::{ExpnId, ExpnKind, MacroKind, SyntaxContext, Transparency}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym}; diff --git a/src/librustc_session/node_id.rs b/src/librustc_session/node_id.rs index b94c11391ebac..5e51c5a92ccc4 100644 --- a/src/librustc_session/node_id.rs +++ b/src/librustc_session/node_id.rs @@ -10,6 +10,8 @@ rustc_index::newtype_index! { } } +rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId); + impl NodeId { pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self { NodeId::from_u32(expn_id.as_u32()) From 8e15bb6546955e9d2369abe4adad6acc0bbecf6e Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 24 Dec 2019 23:43:44 +0100 Subject: [PATCH 06/20] canonicalize rustc_session imports --- src/librustc/hir/map/collector.rs | 3 +-- src/librustc/hir/map/mod.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index ffb5610c2c3ea..21cafb4270f75 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -6,11 +6,10 @@ 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 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/mod.rs b/src/librustc/hir/map/mod.rs index 15914809ba4c5..abaa9fa9ae622 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -1203,7 +1203,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, From ca297f8cf45b98c65e090528da97bf873f2bec2b Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 25 Dec 2019 00:10:10 +0100 Subject: [PATCH 07/20] DefId{Map,Set} -> rustc::hir::def_id --- src/librustc/arena.rs | 8 ++++---- src/librustc/hir/def.rs | 3 +-- src/librustc/hir/def_id.rs | 2 ++ src/librustc/infer/opaque_types/mod.rs | 3 +-- src/librustc/middle/privacy.rs | 2 +- src/librustc/traits/specialize/specialization_graph.rs | 3 +-- src/librustc/ty/context.rs | 4 ++-- src/librustc/ty/mod.rs | 3 +-- src/librustc/ty/query/mod.rs | 4 ++-- src/librustc/util/nodemap.rs | 2 -- src/librustc_ast_lowering/lib.rs | 3 +-- src/librustc_codegen_llvm/debuginfo/mod.rs | 3 +-- src/librustc_codegen_ssa/back/symbol_export.rs | 3 +-- src/librustc_metadata/rmeta/decoder/cstore_impl.rs | 3 +-- src/librustc_mir/monomorphize/collector.rs | 3 +-- src/librustc_mir/monomorphize/partitioning.rs | 3 +-- src/librustc_mir/transform/mod.rs | 3 +-- src/librustc_resolve/lib.rs | 3 +-- src/librustc_resolve/lifetimes.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 4 ++-- src/librustc_typeck/check/writeback.rs | 3 +-- src/librustc_typeck/check_unused.rs | 4 +--- src/librustdoc/passes/mod.rs | 3 +-- src/librustdoc/passes/strip_hidden.rs | 2 +- src/librustdoc/passes/strip_private.rs | 2 +- 25 files changed, 32 insertions(+), 48 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index c576c5af31e6a..0ec8863fa6965 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -41,7 +41,7 @@ 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, @@ -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/hir/def.rs b/src/librustc/hir/def.rs index 6ba9a53799b9a..ebe9fc82f1b41 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -1,9 +1,8 @@ use self::Namespace::*; use crate::hir; -use crate::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use crate::hir::def_id::{DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; use crate::ty; -use crate::util::nodemap::DefIdMap; use rustc_macros::HashStable; use rustc_span::hygiene::MacroKind; diff --git a/src/librustc/hir/def_id.rs b/src/librustc/hir/def_id.rs index b26617a57f475..9c2046a45547c 100644 --- a/src/librustc/hir/def_id.rs +++ b/src/librustc/hir/def_id.rs @@ -157,6 +157,8 @@ impl DefId { impl rustc_serialize::UseSpecializedEncodable for DefId {} impl rustc_serialize::UseSpecializedDecodable for DefId {} +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/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/middle/privacy.rs b/src/librustc/middle/privacy.rs index 770a974da07f2..c4da4d75f4de2 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -2,8 +2,8 @@ //! 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; use rustc_data_structures::fx::FxHashMap; use rustc_macros::HashStable; diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index fe67598230824..200c2188ac360 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -1,11 +1,10 @@ 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; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use syntax::ast::Ident; diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 88fbed32729da..5bac49ca492ec 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -4,7 +4,7 @@ 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_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex, LOCAL_CRATE}; use crate::hir::map as hir_map; use crate::hir::map::DefPathHash; use crate::hir::{self, HirId, ItemKind, ItemLocalId, Node, TraitCandidate}; @@ -46,7 +46,7 @@ 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}; +use crate::util::nodemap::{ItemLocalMap, ItemLocalSet}; use arena::SyncDroplessArena; use errors::DiagnosticBuilder; diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 73020b8bc6689..9f2df16f376af 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -7,7 +7,7 @@ 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_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use crate::hir::Node; use crate::hir::{map as hir_map, GlobMap, TraitMap}; use crate::ich::Fingerprint; @@ -28,7 +28,6 @@ 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; use arena::SyncDroplessArena; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::svh::Svh; diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index 5f739c4e6e625..f8cad3437b4bc 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -1,6 +1,6 @@ use crate::dep_graph::{self, DepNode}; use crate::hir::def::{DefKind, Export}; -use crate::hir::def_id::{CrateNum, DefId, DefIndex}; +use crate::hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex}; use crate::hir::{self, ItemLocalId, TraitCandidate}; use crate::infer::canonical::{self, Canonical}; use crate::lint; @@ -37,7 +37,7 @@ 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 crate::util::nodemap::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 index ed69e9002b6ba..a7d79b9f3414c 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -1,10 +1,8 @@ //! An efficient hash map for `NodeId`s. -use crate::hir::def_id::DefId; use crate::hir::{HirId, ItemLocalId}; use rustc_data_structures::define_id_collections; -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/lib.rs b/src/librustc_ast_lowering/lib.rs index ba27e79dff517..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,7 +47,6 @@ 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; use rustc::{bug, span_bug}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 3fea27445a09e..0edfd3457746d 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -13,7 +13,7 @@ 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::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE}; use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::ty::subst::{GenericArgKind, SubstsRef}; @@ -24,7 +24,6 @@ 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; use rustc_codegen_ssa::debuginfo::type_names; use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 44e9067a60a65..0f54557eaed2d 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -2,7 +2,7 @@ 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::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}; @@ -11,7 +11,6 @@ use rustc::ty::query::Providers; use rustc::ty::subst::SubstsRef; use rustc::ty::Instance; use rustc::ty::{SymbolName, TyCtxt}; -use rustc::util::nodemap::DefIdMap; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_index::vec::IndexVec; diff --git a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs index 00d5b4321cb7e..7de829edfc860 100644 --- a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs +++ b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs @@ -6,7 +6,7 @@ use crate::rmeta::{self, encoder}; use rustc::hir; use rustc::hir::def; -use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::map::definitions::DefPathTable; use rustc::hir::map::{DefKey, DefPath, DefPathHash}; use rustc::middle::cstore::{CrateSource, CrateStore, DepKind, EncodedMetadata, NativeLibraryKind}; @@ -16,7 +16,6 @@ use rustc::session::{CrateDisambiguator, Session}; use rustc::ty::query::Providers; use rustc::ty::query::QueryConfig; use rustc::ty::{self, TyCtxt}; -use rustc::util::nodemap::DefIdMap; use rustc_data_structures::svh::Svh; use rustc_parse::parser::emit_unclosed_delims; use rustc_parse::source_file_to_stream; diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index d0775d10a2c7b..43d57e0e85fb3 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -177,7 +177,7 @@ use crate::monomorphize; use rustc::hir; -use rustc::hir::def_id::{DefId, LOCAL_CRATE}; +use rustc::hir::def_id::{DefId, DefIdMap, LOCAL_CRATE}; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem}; @@ -192,7 +192,6 @@ use rustc::ty::print::obsolete::DefPathBasedNames; use rustc::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc::ty::{self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable}; use rustc::util::common::time; -use rustc::util::nodemap::DefIdMap; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator}; use rustc_index::bit_set::GrowableBitSet; diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index d6d174bef89f8..9c8bcfad6da17 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -97,7 +97,7 @@ use std::collections::hash_map::Entry; use std::sync::Arc; use rustc::hir::def::DefKind; -use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc::hir::def_id::{CrateNum, DefId, DefIdSet, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::middle::exported_symbols::SymbolExportLevel; use rustc::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility}; @@ -106,7 +106,6 @@ use rustc::ty::print::characteristic_def_id_of_type; use rustc::ty::query::Providers; use rustc::ty::{self, DefIdTree, InstanceDef, TyCtxt}; use rustc::util::common::time; -use rustc::util::nodemap::DefIdSet; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span::symbol::Symbol; diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 62f7a3f539acb..7cf94f7260fd4 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -1,12 +1,11 @@ use crate::{build, shim}; use rustc::hir; -use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; +use rustc::hir::def_id::{CrateNum, DefId, DefIdSet, LOCAL_CRATE}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::mir::{BodyAndCache, ConstQualifs, MirPhase, Promoted}; use rustc::ty::query::Providers; use rustc::ty::steal::Steal; use rustc::ty::{InstanceDef, TyCtxt, TypeFoldable}; -use rustc::util::nodemap::DefIdSet; use rustc_index::vec::IndexVec; use rustc_span::Span; use std::borrow::Cow; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index a822c0fa51885..0d08313ae730c 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -23,7 +23,7 @@ use Determinacy::*; use errors::{Applicability, DiagnosticBuilder}; use rustc::hir::def::Namespace::*; use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, ExportMap, NonMacroAttrKind, PartialRes}; -use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::map::Definitions; use rustc::hir::{Bool, Char, Float, Int, PrimTy, Str, Uint}; use rustc::hir::{GlobMap, TraitMap}; @@ -33,7 +33,6 @@ use rustc::session::Session; use rustc::span_bug; use rustc::ty::query::Providers; use rustc::ty::{self, DefIdTree, ResolverOutputs}; -use rustc::util::nodemap::DefIdMap; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::ptr_key::PtrKey; use rustc_data_structures::sync::Lrc; diff --git a/src/librustc_resolve/lifetimes.rs b/src/librustc_resolve/lifetimes.rs index 96f1e069f9231..a5afd73c28b68 100644 --- a/src/librustc_resolve/lifetimes.rs +++ b/src/librustc_resolve/lifetimes.rs @@ -7,7 +7,7 @@ use errors::{pluralize, Applicability, DiagnosticBuilder}; use rustc::hir::def::{DefKind, Res}; -use rustc::hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; +use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::hir::{self, GenericParamKind, LifetimeParamKind}; @@ -16,7 +16,7 @@ use rustc::lint; use rustc::middle::resolve_lifetime::*; use rustc::session::Session; use rustc::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt}; -use rustc::util::nodemap::{DefIdMap, HirIdMap, HirIdSet}; +use rustc::util::nodemap::{HirIdMap, HirIdSet}; use rustc::{bug, span_bug}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span::symbol::{kw, sym}; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 71a7a5dd69b1a..5157406309348 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -92,7 +92,7 @@ use crate::middle::lang_items; use crate::namespace::Namespace; use errors::{pluralize, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc::hir::def::{CtorOf, DefKind, Res}; -use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; +use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LOCAL_CRATE}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::{self, ExprKind, GenericArg, ItemKind, Node, PatKind, QPath}; @@ -145,7 +145,7 @@ use crate::session::config::EntryFnType; use crate::session::Session; use crate::util::captures::Captures; use crate::util::common::{indenter, ErrorReported}; -use crate::util::nodemap::{DefIdMap, DefIdSet, HirIdMap}; +use crate::util::nodemap::HirIdMap; use crate::TypeAndSubsts; use self::autoderef::Autoderef; diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index ecf5aa576f54d..0fbc14a717374 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -5,14 +5,13 @@ use crate::check::FnCtxt; use rustc::hir; -use rustc::hir::def_id::{DefId, DefIndex}; +use rustc::hir::def_id::{DefId, DefIdSet, DefIndex}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::infer::error_reporting::TypeAnnotationNeeded::E0282; use rustc::infer::InferCtxt; use rustc::ty::adjustment::{Adjust, Adjustment, PointerCast}; use rustc::ty::fold::{TypeFoldable, TypeFolder}; use rustc::ty::{self, Ty, TyCtxt}; -use rustc::util::nodemap::DefIdSet; use rustc_data_structures::sync::Lrc; use rustc_span::symbol::sym; use rustc_span::Span; diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 9b88345a2117a..b0cbabd195853 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -6,11 +6,9 @@ use rustc_span::Span; use syntax::ast; use rustc::hir; -use rustc::hir::def_id::{DefId, LOCAL_CRATE}; +use rustc::hir::def_id::{DefId, DefIdSet, LOCAL_CRATE}; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::print::visibility_qualified; -use rustc::util::nodemap::DefIdSet; - use rustc_data_structures::fx::FxHashMap; pub fn check_crate(tcx: TyCtxt<'_>) { diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index 7ac3009d8271d..784d967017db0 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -1,10 +1,9 @@ //! Contains information about "passes", used to modify crate information during the documentation //! process. -use rustc::hir::def_id::DefId; +use rustc::hir::def_id::{DefId, DefIdSet}; use rustc::lint; use rustc::middle::privacy::AccessLevels; -use rustc::util::nodemap::DefIdSet; use rustc_span::{InnerSpan, Span, DUMMY_SP}; use std::mem; use std::ops::Range; diff --git a/src/librustdoc/passes/strip_hidden.rs b/src/librustdoc/passes/strip_hidden.rs index 9698ad1d2312d..5fd97d1685ac6 100644 --- a/src/librustdoc/passes/strip_hidden.rs +++ b/src/librustdoc/passes/strip_hidden.rs @@ -1,4 +1,4 @@ -use rustc::util::nodemap::DefIdSet; +use rustc::hir::def_id::DefIdSet; use rustc_span::symbol::sym; use std::mem; diff --git a/src/librustdoc/passes/strip_private.rs b/src/librustdoc/passes/strip_private.rs index 5113afa48402c..167aa2ca7d230 100644 --- a/src/librustdoc/passes/strip_private.rs +++ b/src/librustdoc/passes/strip_private.rs @@ -1,4 +1,4 @@ -use rustc::util::nodemap::DefIdSet; +use rustc::hir::def_id::DefIdSet; use crate::clean; use crate::core::DocContext; From 2f64ab66339405ae4d5636a238268e2cd4a309ff Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 25 Dec 2019 00:22:24 +0100 Subject: [PATCH 08/20] {HirId,ItemLocal}{Map,Set} -> rustc::hir & nix rustc::nodemap --- src/librustc/arena.rs | 2 +- src/librustc/hir/mod.rs | 3 +++ src/librustc/lib.rs | 1 - src/librustc/ty/context.rs | 4 ++-- src/librustc/ty/query/mod.rs | 3 +-- src/librustc/util/nodemap.rs | 8 -------- src/librustc_lint/builtin.rs | 5 ++--- src/librustc_mir/build/mod.rs | 4 +--- src/librustc_passes/liveness.rs | 5 +---- src/librustc_passes/reachable.rs | 3 +-- src/librustc_privacy/lib.rs | 3 +-- src/librustc_resolve/lifetimes.rs | 3 +-- src/librustc_typeck/check/mod.rs | 3 +-- src/librustc_typeck/variance/terms.rs | 3 +-- 14 files changed, 16 insertions(+), 34 deletions(-) delete mode 100644 src/librustc/util/nodemap.rs diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index 0ec8863fa6965..1c7d36b731225 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -44,7 +44,7 @@ macro_rules! arena_types { [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: diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index ff025f48dc44f..ce1b8ca2f8862 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -93,6 +93,9 @@ impl fmt::Display for HirId { } } +rustc_data_structures::define_id_collections!(HirIdMap, HirIdSet, HirId); +rustc_data_structures::define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId); + // 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; 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/ty/context.rs b/src/librustc/ty/context.rs index 5bac49ca492ec..842728e5a9f00 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -7,7 +7,8 @@ use crate::hir::def::{DefKind, Export, Res}; use crate::hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex, LOCAL_CRATE}; 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,7 +47,6 @@ 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::{ItemLocalMap, ItemLocalSet}; use arena::SyncDroplessArena; use errors::DiagnosticBuilder; diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index f8cad3437b4bc..a29d78318a065 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -1,7 +1,7 @@ use crate::dep_graph::{self, DepNode}; use crate::hir::def::{DefKind, Export}; use crate::hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex}; -use crate::hir::{self, ItemLocalId, TraitCandidate}; +use crate::hir::{self, HirIdSet, ItemLocalId, TraitCandidate}; use crate::infer::canonical::{self, Canonical}; use crate::lint; use crate::middle::codegen_fn_attrs::CodegenFnAttrs; @@ -37,7 +37,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::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 a7d79b9f3414c..0000000000000 --- a/src/librustc/util/nodemap.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! An efficient hash map for `NodeId`s. - -use crate::hir::{HirId, ItemLocalId}; - -use rustc_data_structures::define_id_collections; - -define_id_collections!(HirIdMap, HirIdSet, HirId); -define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId); diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 90d87e34e48da..5e107b2f72d62 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -23,15 +23,14 @@ use std::fmt::Write; -use hir::Node; use lint::{EarlyContext, EarlyLintPass, LateLintPass, LintPass}; use lint::{LateContext, LintArray, LintContext}; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::DefId; +use rustc::hir::{HirIdSet, Node}; +use rustc::lint; use rustc::lint::FutureIncompatibleInfo; use rustc::ty::{self, layout::VariantIdx, Ty, TyCtxt}; -use rustc::{lint, util}; -use util::nodemap::HirIdSet; use rustc_data_structures::fx::FxHashSet; use rustc_feature::Stability; diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index b265ab6b7becb..39edcc981a005 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -4,15 +4,13 @@ use crate::hair::cx::Cx; use crate::hair::{BindingMode, LintLevel, PatKind}; use crate::transform::MirSource; use crate::util as mir_util; -use rustc::hir; use rustc::hir::def_id::DefId; -use rustc::hir::{GeneratorKind, Node}; +use rustc::hir::{self, GeneratorKind, HirIdMap, Node}; use rustc::middle::lang_items; use rustc::middle::region; use rustc::mir::*; use rustc::ty::subst::Subst; use rustc::ty::{self, Ty, TyCtxt}; -use rustc::util::nodemap::HirIdMap; use rustc_index::vec::{Idx, IndexVec}; use rustc_span::symbol::kw; use rustc_span::Span; diff --git a/src/librustc_passes/liveness.rs b/src/librustc_passes/liveness.rs index 49664be9c7758..6a38524720e27 100644 --- a/src/librustc_passes/liveness.rs +++ b/src/librustc_passes/liveness.rs @@ -96,16 +96,13 @@ use self::LiveNodeKind::*; use self::VarKind::*; -use rustc::hir; use rustc::hir::def::*; use rustc::hir::def_id::DefId; use rustc::hir::intravisit::{self, FnKind, NestedVisitorMap, Visitor}; -use rustc::hir::Node; -use rustc::hir::{Expr, HirId}; +use rustc::hir::{self, Expr, HirId, HirIdMap, HirIdSet, Node}; use rustc::lint; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt}; -use rustc::util::nodemap::{HirIdMap, HirIdSet}; use errors::Applicability; use rustc_data_structures::fx::FxIndexMap; diff --git a/src/librustc_passes/reachable.rs b/src/librustc_passes/reachable.rs index 1c8733ab44db1..4bcba96910bde 100644 --- a/src/librustc_passes/reachable.rs +++ b/src/librustc_passes/reachable.rs @@ -5,7 +5,6 @@ // makes all other generics or inline functions that it references // reachable as well. -use rustc::hir; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::LOCAL_CRATE; use rustc::hir::def_id::{CrateNum, DefId}; @@ -13,12 +12,12 @@ use rustc::hir::intravisit; use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::Node; +use rustc::hir::{self, HirIdSet}; use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc::middle::privacy; use rustc::session::config; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt}; -use rustc::util::nodemap::HirIdSet; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_target::spec::abi::Abi; diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index c4b113d7a935c..1b91f48d78f2c 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -11,14 +11,13 @@ use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::itemlikevisit::DeepVisitor; -use rustc::hir::{self, AssocItemKind, Node, PatKind}; +use rustc::hir::{self, AssocItemKind, HirIdSet, Node, PatKind}; use rustc::lint; use rustc::middle::privacy::{AccessLevel, AccessLevels}; use rustc::ty::fold::TypeVisitor; use rustc::ty::query::Providers; use rustc::ty::subst::InternalSubsts; use rustc::ty::{self, GenericParamDefKind, TraitRef, Ty, TyCtxt, TypeFoldable}; -use rustc::util::nodemap::HirIdSet; use rustc_data_structures::fx::FxHashSet; use rustc_span::hygiene::Transparency; use rustc_span::symbol::{kw, sym}; diff --git a/src/librustc_resolve/lifetimes.rs b/src/librustc_resolve/lifetimes.rs index a5afd73c28b68..5d82c17725944 100644 --- a/src/librustc_resolve/lifetimes.rs +++ b/src/librustc_resolve/lifetimes.rs @@ -10,13 +10,12 @@ use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; -use rustc::hir::{self, GenericParamKind, LifetimeParamKind}; +use rustc::hir::{self, GenericParamKind, HirIdMap, HirIdSet, LifetimeParamKind}; use rustc::hir::{GenericArg, GenericParam, LifetimeName, Node, ParamName, QPath}; use rustc::lint; use rustc::middle::resolve_lifetime::*; use rustc::session::Session; use rustc::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt}; -use rustc::util::nodemap::{HirIdMap, HirIdSet}; use rustc::{bug, span_bug}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_span::symbol::{kw, sym}; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 5157406309348..312208626cf2d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -95,7 +95,7 @@ use rustc::hir::def::{CtorOf, DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LOCAL_CRATE}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::itemlikevisit::ItemLikeVisitor; -use rustc::hir::{self, ExprKind, GenericArg, ItemKind, Node, PatKind, QPath}; +use rustc::hir::{self, ExprKind, GenericArg, HirIdMap, ItemKind, Node, PatKind, QPath}; use rustc::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse}; use rustc::infer::error_reporting::TypeAnnotationNeeded::E0282; use rustc::infer::opaque_types::OpaqueTypeDecl; @@ -145,7 +145,6 @@ use crate::session::config::EntryFnType; use crate::session::Session; use crate::util::captures::Captures; use crate::util::common::{indenter, ErrorReported}; -use crate::util::nodemap::HirIdMap; use crate::TypeAndSubsts; use self::autoderef::Autoderef; diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index 090c4ed759026..db3e7a2b13428 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -9,10 +9,9 @@ // `InferredIndex` is a newtype'd int representing the index of such // a variable. -use crate::util::nodemap::HirIdMap; use arena::TypedArena; -use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; +use rustc::hir::{self, HirIdMap}; use rustc::ty::{self, TyCtxt}; use std::fmt; From e0e9ff06af899b12d263b6e84af348615d65701f Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 25 Dec 2019 00:31:55 +0100 Subject: [PATCH 09/20] remove DefId::to_dep_node (dead code) --- src/librustc/dep_graph/dep_node.rs | 6 ------ 1 file changed, 6 deletions(-) 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, From 7eb7b23b2a46bda8ee31d37731ecdf99793e2b91 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 25 Dec 2019 01:27:51 +0100 Subject: [PATCH 10/20] move describe_as_module to where it's used --- src/librustc/hir/def_id.rs | 10 +++------- src/librustc/query/mod.rs | 30 +++++++++++++++++++----------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/librustc/hir/def_id.rs b/src/librustc/hir/def_id.rs index 9c2046a45547c..150fa5e8bf51c 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 crate::ty; use rustc_index::vec::Idx; use std::fmt; use std::u32; @@ -145,12 +145,8 @@ 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 } } 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. From 7a1407387567beb0f300ddc3ae98e274259e2b78 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 25 Dec 2019 03:51:27 +0100 Subject: [PATCH 11/20] move def_id to new rustc_hir crate --- Cargo.lock | 38 ++++++++++++++++++ src/librustc/Cargo.toml | 1 + src/librustc/hir/mod.rs | 2 +- src/librustc_hir/Cargo.toml | 42 ++++++++++++++++++++ src/{librustc/hir => librustc_hir}/def_id.rs | 36 ++++++++--------- src/librustc_hir/lib.rs | 3 ++ src/librustc_interface/Cargo.toml | 1 + src/librustc_interface/callbacks.rs | 14 +++++++ 8 files changed, 117 insertions(+), 20 deletions(-) create mode 100644 src/librustc_hir/Cargo.toml rename src/{librustc/hir => librustc_hir}/def_id.rs (88%) create mode 100644 src/librustc_hir/lib.rs diff --git a/Cargo.lock b/Cargo.lock index aff2d7e65af1b..6c14056bdba52 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", @@ -3563,6 +3564,42 @@ dependencies = [ name = "rustc_fs_util" version = "0.0.0" +[[package]] +name = "rustc_hir" +version = "0.0.0" +dependencies = [ + "arena", + "backtrace", + "bitflags", + "byteorder", + "chalk-engine", + "fmt_macros", + "graphviz", + "jobserver", + "log", + "measureme", + "num_cpus", + "parking_lot", + "polonius-engine", + "rustc-rayon", + "rustc-rayon-core", + "rustc_apfloat", + "rustc_data_structures", + "rustc_error_codes", + "rustc_errors", + "rustc_feature", + "rustc_fs_util", + "rustc_index", + "rustc_macros", + "rustc_session", + "rustc_span", + "rustc_target", + "scoped-tls", + "serialize", + "smallvec 1.0.0", + "syntax", +] + [[package]] name = "rustc_incremental" version = "0.0.0" @@ -3603,6 +3640,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_expand", + "rustc_hir", "rustc_incremental", "rustc_lint", "rustc_metadata", 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/hir/mod.rs b/src/librustc/hir/mod.rs index ce1b8ca2f8862..d7d9990bb8828 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -34,7 +34,7 @@ use syntax::util::parser::ExprPrecedence; pub mod check_attr; pub mod def; -pub mod def_id; +pub use rustc_hir::def_id; pub mod intravisit; pub mod itemlikevisit; pub mod map; diff --git a/src/librustc_hir/Cargo.toml b/src/librustc_hir/Cargo.toml new file mode 100644 index 0000000000000..24df1130368c9 --- /dev/null +++ b/src/librustc_hir/Cargo.toml @@ -0,0 +1,42 @@ +[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] +arena = { path = "../libarena" } +bitflags = "1.2.1" +fmt_macros = { path = "../libfmt_macros" } +graphviz = { path = "../libgraphviz" } +jobserver = "0.1" +num_cpus = "1.0" +scoped-tls = "1.0" +log = { version = "0.4", features = ["release_max_level_info", "std"] } +rustc-rayon = "0.3.0" +rustc-rayon-core = "0.3.0" +polonius-engine = "0.11.0" +rustc_apfloat = { path = "../librustc_apfloat" } +rustc_feature = { path = "../librustc_feature" } +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" } +errors = { path = "../librustc_errors", package = "rustc_errors" } +rustc_serialize = { path = "../libserialize", package = "serialize" } +syntax = { path = "../libsyntax" } +backtrace = "0.3.40" +parking_lot = "0.9" +byteorder = { version = "1.3" } +chalk-engine = { version = "0.9.0", default-features=false } +rustc_fs_util = { path = "../librustc_fs_util" } +smallvec = { version = "1.0", features = ["union", "may_dangle"] } +measureme = "0.5" +rustc_error_codes = { path = "../librustc_error_codes" } +rustc_session = { path = "../librustc_session" } diff --git a/src/librustc/hir/def_id.rs b/src/librustc_hir/def_id.rs similarity index 88% rename from src/librustc/hir/def_id.rs rename to src/librustc_hir/def_id.rs index 150fa5e8bf51c..f8cacdc6238e8 100644 --- a/src/librustc/hir/def_id.rs +++ b/src/librustc_hir/def_id.rs @@ -1,4 +1,4 @@ -use crate::ty; +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] @@ -153,6 +138,19 @@ impl DefId { 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 diff --git a/src/librustc_hir/lib.rs b/src/librustc_hir/lib.rs new file mode 100644 index 0000000000000..1ef1694c32018 --- /dev/null +++ b/src/librustc_hir/lib.rs @@ -0,0 +1,3 @@ +#![feature(specialization)] + +pub mod def_id; diff --git a/src/librustc_interface/Cargo.toml b/src/librustc_interface/Cargo.toml index 9e2fae178d552..be60b75bc47eb 100644 --- a/src/librustc_interface/Cargo.toml +++ b/src/librustc_interface/Cargo.toml @@ -27,6 +27,7 @@ rustc_data_structures = { path = "../librustc_data_structures" } rustc_codegen_ssa = { path = "../librustc_codegen_ssa" } rustc_codegen_utils = { path = "../librustc_codegen_utils" } rustc_codegen_llvm = { path = "../librustc_codegen_llvm", optional = true } +rustc_hir = { path = "../librustc_hir" } rustc_metadata = { path = "../librustc_metadata" } rustc_mir = { path = "../librustc_mir" } rustc_passes = { path = "../librustc_passes" } diff --git a/src/librustc_interface/callbacks.rs b/src/librustc_interface/callbacks.rs index 1ed8d66863c81..eb9c118bb0100 100644 --- a/src/librustc_interface/callbacks.rs +++ b/src/librustc_interface/callbacks.rs @@ -40,9 +40,23 @@ fn track_diagnostic(diagnostic: &Diagnostic) { }) } +/// This is a callback from librustc_hir as it cannot access the implicit state +/// in librustc otherwise. +fn def_id_debug(def_id: rustc_hir::def_id::DefId, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "DefId({}:{}", def_id.krate, def_id.index.index())?; + tls::with_opt(|opt_tcx| { + if let Some(tcx) = opt_tcx { + write!(f, " ~ {}", tcx.def_path_debug_str(def_id))?; + } + Ok(()) + })?; + write!(f, ")") +} + /// Sets up the callbacks in prior crates which we want to refer to the /// TyCtxt in. pub fn setup_callbacks() { rustc_span::SPAN_DEBUG.swap(&(span_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); + rustc_hir::def_id::DEF_ID_DEBUG.swap(&(def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); TRACK_DIAGNOSTICS.swap(&(track_diagnostic as fn(&_))); } From 72241ad348442b44e115bbb8657b5514ff61c39b Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 25 Dec 2019 15:26:30 +0100 Subject: [PATCH 12/20] move `HirId` to librustc_hir::hir_id --- src/librustc/hir/mod.rs | 87 +------------------------------------- src/librustc_hir/hir_id.rs | 79 ++++++++++++++++++++++++++++++++++ src/librustc_hir/lib.rs | 2 + 3 files changed, 83 insertions(+), 85 deletions(-) create mode 100644 src/librustc_hir/hir_id.rs diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index d7d9990bb8828..f6085c5f87301 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -9,14 +9,13 @@ 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::hir::def_id::{DefId, DefIndex}; use crate::ty::query::Providers; use errors::FatalError; 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_session::node_id::NodeMap; use rustc_span::source_map::{SourceMap, Spanned}; use rustc_span::symbol::{kw, sym, Symbol}; @@ -35,6 +34,7 @@ use syntax::util::parser::ExprPrecedence; pub mod check_attr; pub mod def; pub use rustc_hir::def_id; +pub use rustc_hir::hir_id::*; pub mod intravisit; pub mod itemlikevisit; pub mod map; @@ -42,89 +42,6 @@ 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) - } -} - -rustc_data_structures::define_id_collections!(HirIdMap, HirIdSet, HirId); -rustc_data_structures::define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId); - -// 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)] pub struct Lifetime { pub hir_id: HirId, diff --git a/src/librustc_hir/hir_id.rs b/src/librustc_hir/hir_id.rs new file mode 100644 index 0000000000000..462946411718b --- /dev/null +++ b/src/librustc_hir/hir_id.rs @@ -0,0 +1,79 @@ +use crate::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX}; +use rustc_serialize::{self, Decodable, Decoder, Encodable, Encoder}; +use std::fmt; + +/// 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) + } +} + +rustc_data_structures::define_id_collections!(HirIdMap, HirIdSet, HirId); +rustc_data_structures::define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId); + +use rustc_index::vec::Idx; +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 { .. } +} +rustc_data_structures::impl_stable_hash_via_hash!(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; diff --git a/src/librustc_hir/lib.rs b/src/librustc_hir/lib.rs index 1ef1694c32018..7e778736634d3 100644 --- a/src/librustc_hir/lib.rs +++ b/src/librustc_hir/lib.rs @@ -1,3 +1,5 @@ #![feature(specialization)] pub mod def_id; +pub mod hir_id; +pub use hir_id::*; From 3b66f4e79244bdc3749177ca679a29cd878a315c Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 2 Jan 2020 03:39:11 +0100 Subject: [PATCH 13/20] split hir/mod.rs -> hir.rs & hir/hir.rs --- src/librustc/hir.rs | 30 +++++++++++++++++++++++++++++ src/librustc/hir/check_attr.rs | 3 ++- src/librustc/hir/{mod.rs => hir.rs} | 23 ++++------------------ src/librustc/hir/intravisit.rs | 2 +- src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/map/mod.rs | 5 +++-- 6 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 src/librustc/hir.rs rename src/librustc/hir/{mod.rs => hir.rs} (99%) diff --git a/src/librustc/hir.rs b/src/librustc/hir.rs new file mode 100644 index 0000000000000..149f6ca10c5ec --- /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 mod def; +pub use rustc_hir::def_id; +pub use rustc_hir::hir_id::*; +pub mod intravisit; +pub mod itemlikevisit; +pub mod map; +pub mod pat_util; +pub mod print; +pub mod upvars; + +mod hir; +pub use hir::BlockCheckMode::*; +pub use hir::FunctionRetTy::*; +pub use hir::PrimTy::*; +pub use hir::UnOp::*; +pub use hir::UnsafeSource::*; +pub use 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/mod.rs b/src/librustc/hir/hir.rs similarity index 99% rename from src/librustc/hir/mod.rs rename to src/librustc/hir/hir.rs index f6085c5f87301..0c719c3db8271 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/hir.rs @@ -9,12 +9,14 @@ pub use self::UnOp::*; pub use self::UnsafeSource::*; use crate::hir::def::{DefKind, Res}; -use crate::hir::def_id::{DefId, DefIndex}; -use crate::ty::query::Providers; +use crate::hir::def_id::DefId; +use crate::hir::itemlikevisit; +use crate::hir::print; use errors::FatalError; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::{par_for_each_in, Send, Sync}; +use rustc_hir::hir_id::*; use rustc_macros::HashStable; use rustc_session::node_id::NodeMap; use rustc_span::source_map::{SourceMap, Spanned}; @@ -31,17 +33,6 @@ pub use syntax::ast::{CaptureBy, Constness, Movability, Mutability, Unsafety}; use syntax::tokenstream::TokenStream; use syntax::util::parser::ExprPrecedence; -pub mod check_attr; -pub mod def; -pub use rustc_hir::def_id; -pub use rustc_hir::hir_id::*; -pub mod intravisit; -pub mod itemlikevisit; -pub mod map; -pub mod pat_util; -pub mod print; -pub mod upvars; - #[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable)] pub struct Lifetime { pub hir_id: HirId, @@ -2581,12 +2572,6 @@ pub type TraitMap = NodeMap>; // imported. pub type GlobMap = NodeMap>; -pub fn provide(providers: &mut Providers<'_>) { - check_attr::provide(providers); - map::provide(providers); - upvars::provide(providers); -} - #[derive(Copy, Clone, Debug)] pub enum Node<'hir> { Param(&'hir Param<'hir>), diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 241febe0cf60c..12fe1f7037069 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -37,7 +37,7 @@ 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}; #[derive(Copy, Clone)] pub enum FnKind<'a> { diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 21cafb4270f75..25083281ce9d1 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -1,7 +1,7 @@ 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; diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index abaa9fa9ae622..92547bbe038dd 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -4,10 +4,10 @@ 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; @@ -18,6 +18,7 @@ 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}; From e1087213efc4a7b2101f9fabb9ee907dd45cb0c0 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 2 Jan 2020 03:48:12 +0100 Subject: [PATCH 14/20] hir::hir: simplify some imports --- src/librustc/hir/hir.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/librustc/hir/hir.rs b/src/librustc/hir/hir.rs index 0c719c3db8271..da67cf3ccba22 100644 --- a/src/librustc/hir/hir.rs +++ b/src/librustc/hir/hir.rs @@ -2,21 +2,15 @@ //! //! [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; use crate::hir::itemlikevisit; use crate::hir::print; +use rustc_hir::hir_id::HirId; use errors::FatalError; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::{par_for_each_in, Send, Sync}; -use rustc_hir::hir_id::*; use rustc_macros::HashStable; use rustc_session::node_id::NodeMap; use rustc_span::source_map::{SourceMap, Spanned}; @@ -1068,16 +1062,16 @@ 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, } } @@ -1387,7 +1381,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) @@ -2145,8 +2139,8 @@ pub enum FunctionRetTy<'hir> { impl fmt::Display for FunctionRetTy<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Return(ref ty) => print::to_string(print::NO_ANN, |s| s.print_type(ty)).fmt(f), - DefaultReturn(_) => "()".fmt(f), + Self::Return(ref ty) => print::to_string(print::NO_ANN, |s| s.print_type(ty)).fmt(f), + Self::DefaultReturn(_) => "()".fmt(f), } } } @@ -2154,8 +2148,8 @@ impl fmt::Display for FunctionRetTy<'_> { impl FunctionRetTy<'_> { pub fn span(&self) -> Span { match *self { - DefaultReturn(span) => span, - Return(ref ty) => ty.span, + Self::DefaultReturn(span) => span, + Self::Return(ref ty) => ty.span, } } } From 60d5d36370612c8553d0363e1b56048998705754 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 2 Jan 2020 04:18:51 +0100 Subject: [PATCH 15/20] move {Par}DeepVisitor to intravisit --- src/librustc/hir/intravisit.rs | 57 +++++++++++++++++++++++++++++-- src/librustc/hir/itemlikevisit.rs | 55 ----------------------------- src/librustc_privacy/lib.rs | 3 +- 3 files changed, 56 insertions(+), 59 deletions(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 12fe1f7037069..780b0e36b5e4d 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -31,14 +31,67 @@ //! 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, 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> { /// `#[xxx] pub async/const/extern "Abi" fn foo()` diff --git a/src/librustc/hir/itemlikevisit.rs b/src/librustc/hir/itemlikevisit.rs index 56dcf91a134ce..369cd49621b2d 100644 --- a/src/librustc/hir/itemlikevisit.rs +++ b/src/librustc/hir/itemlikevisit.rs @@ -1,4 +1,3 @@ -use super::intravisit::Visitor; use super::{ImplItem, Item, TraitItem}; /// The "item-like visitor" defines only the top-level methods @@ -50,63 +49,9 @@ pub trait ItemLikeVisitor<'hir> { fn visit_impl_item(&mut self, impl_item: &'hir ImplItem<'hir>); } -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); - } -} - /// A parallel variant of `ItemLikeVisitor`. pub trait ParItemLikeVisitor<'hir> { fn visit_item(&self, item: &'hir Item<'hir>); fn visit_trait_item(&self, trait_item: &'hir TraitItem<'hir>); fn visit_impl_item(&self, impl_item: &'hir ImplItem<'hir>); } - -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); - } -} diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 1b91f48d78f2c..68e5e6d2543a6 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -9,8 +9,7 @@ extern crate syntax; use rustc::bug; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; -use rustc::hir::itemlikevisit::DeepVisitor; +use rustc::hir::intravisit::{self, DeepVisitor, NestedVisitorMap, Visitor}; use rustc::hir::{self, AssocItemKind, HirIdSet, Node, PatKind}; use rustc::lint; use rustc::middle::privacy::{AccessLevel, AccessLevels}; From 702b2d736a8c6235bdf8a3a3db86f64b566049b9 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 2 Jan 2020 04:24:17 +0100 Subject: [PATCH 16/20] simplify self::Namespace::* import --- src/librustc/hir/def.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index ebe9fc82f1b41..392f3cc07f394 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -1,5 +1,3 @@ -use self::Namespace::*; - use crate::hir; use crate::hir::def_id::{DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; use crate::ty; @@ -238,9 +236,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", } } } @@ -264,9 +262,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, } } } @@ -274,9 +272,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, } } } From 1f7b4e9a59ccb3e5d819900f45de81882e959c72 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 2 Jan 2020 04:53:12 +0100 Subject: [PATCH 17/20] extract Export, ExportMap from hir::def --- src/librustc/hir.rs | 1 + src/librustc/hir/def.rs | 27 +------------ src/librustc/hir/exports.rs | 32 +++++++++++++++ src/librustc/ty/context.rs | 3 +- src/librustc/ty/mod.rs | 3 +- src/librustc/ty/query/mod.rs | 3 +- src/librustc_metadata/rmeta/decoder.rs | 20 ++++------ .../rmeta/decoder/cstore_impl.rs | 39 +++++++++---------- src/librustc_metadata/rmeta/mod.rs | 5 ++- src/librustc_resolve/build_reduced_graph.rs | 1 + src/librustc_resolve/imports.rs | 3 +- src/librustc_resolve/lib.rs | 3 +- 12 files changed, 75 insertions(+), 65 deletions(-) create mode 100644 src/librustc/hir/exports.rs diff --git a/src/librustc/hir.rs b/src/librustc/hir.rs index 149f6ca10c5ec..ae19d82387d49 100644 --- a/src/librustc/hir.rs +++ b/src/librustc/hir.rs @@ -4,6 +4,7 @@ pub mod check_attr; pub mod def; +pub mod exports; pub use rustc_hir::def_id; pub use rustc_hir::hir_id::*; pub mod intravisit; diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index 392f3cc07f394..71ece0aadd34f 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -1,10 +1,8 @@ use crate::hir; -use crate::hir::def_id::{DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; -use crate::ty; +use crate::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_macros::HashStable; use rustc_span::hygiene::MacroKind; -use rustc_span::Span; use syntax::ast; use syntax::ast::NodeId; @@ -293,29 +291,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 { 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/ty/context.rs b/src/librustc/ty/context.rs index 842728e5a9f00..86042d86b939c 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -3,8 +3,9 @@ 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::{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, Node, TraitCandidate}; diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 9f2df16f376af..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::{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; diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index a29d78318a065..0ec3874e6a117 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -1,6 +1,7 @@ use crate::dep_graph::{self, DepNode}; -use crate::hir::def::{DefKind, Export}; +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; diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs index 2e133bdbf8898..1ed6b748d873a 100644 --- a/src/librustc_metadata/rmeta/decoder.rs +++ b/src/librustc_metadata/rmeta/decoder.rs @@ -5,8 +5,9 @@ use crate::rmeta::*; use rustc::dep_graph::{self, DepNodeIndex}; use rustc::hir; -use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, Res}; +use rustc::hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc::hir::exports::Export; use rustc::hir::map::definitions::DefPathTable; use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash}; use rustc::middle::cstore::{CrateSource, ExternCrate}; @@ -930,7 +931,7 @@ impl<'a, 'tcx> CrateMetadata { /// Iterates over each child of the given item. fn each_child_of_item(&self, id: DefIndex, mut callback: F, sess: &Session) where - F: FnMut(def::Export), + F: FnMut(Export), { if let Some(proc_macros_ids) = self.root.proc_macro_data.map(|d| d.decode(self)) { /* If we are loading as a proc macro, we want to return the view of this crate @@ -944,12 +945,7 @@ impl<'a, 'tcx> CrateMetadata { self.local_def_id(def_index), ); let ident = Ident::from_str(raw_macro.name()); - callback(def::Export { - ident: ident, - res: res, - vis: ty::Visibility::Public, - span: DUMMY_SP, - }); + callback(Export { ident, res, vis: ty::Visibility::Public, span: DUMMY_SP }); } } return; @@ -989,7 +985,7 @@ impl<'a, 'tcx> CrateMetadata { .unwrap_or(Lazy::empty()); for child_index in child_children.decode((self, sess)) { if let Some(kind) = self.def_kind(child_index) { - callback(def::Export { + callback(Export { res: Res::Def(kind, self.local_def_id(child_index)), ident: Ident::with_dummy_span(self.item_name(child_index)), vis: self.get_visibility(child_index), @@ -1019,7 +1015,7 @@ impl<'a, 'tcx> CrateMetadata { let vis = self.get_visibility(child_index); let def_id = self.local_def_id(child_index); let res = Res::Def(kind, def_id); - callback(def::Export { res, ident, vis, span }); + callback(Export { res, ident, vis, span }); // For non-re-export structs and variants add their constructors to children. // Re-export lists automatically contain constructors when necessary. match kind { @@ -1029,7 +1025,7 @@ impl<'a, 'tcx> CrateMetadata { let ctor_res = Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id); let vis = self.get_visibility(ctor_def_id.index); - callback(def::Export { res: ctor_res, vis, ident, span }); + callback(Export { res: ctor_res, vis, ident, span }); } } DefKind::Variant => { @@ -1053,7 +1049,7 @@ impl<'a, 'tcx> CrateMetadata { vis = ty::Visibility::Restricted(crate_def_id); } } - callback(def::Export { res: ctor_res, ident, vis, span }); + callback(Export { res: ctor_res, ident, vis, span }); } _ => {} } diff --git a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs index 7de829edfc860..5d5fcf4068987 100644 --- a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs +++ b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs @@ -5,8 +5,8 @@ use crate::native_libs; use crate::rmeta::{self, encoder}; use rustc::hir; -use rustc::hir::def; use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc::hir::exports::Export; use rustc::hir::map::definitions::DefPathTable; use rustc::hir::map::{DefKey, DefPath, DefPathHash}; use rustc::middle::cstore::{CrateSource, CrateStore, DepKind, EncodedMetadata, NativeLibraryKind}; @@ -342,29 +342,28 @@ pub fn provide(providers: &mut Providers<'_>) { // (restrict scope of mutable-borrow of `visible_parent_map`) { let visible_parent_map = &mut visible_parent_map; - let mut add_child = |bfs_queue: &mut VecDeque<_>, - child: &def::Export, - parent: DefId| { - if child.vis != ty::Visibility::Public { - return; - } + let mut add_child = + |bfs_queue: &mut VecDeque<_>, child: &Export, parent: DefId| { + if child.vis != ty::Visibility::Public { + return; + } - if let Some(child) = child.res.opt_def_id() { - match visible_parent_map.entry(child) { - Entry::Occupied(mut entry) => { - // If `child` is defined in crate `cnum`, ensure - // that it is mapped to a parent in `cnum`. - if child.krate == cnum && entry.get().krate != cnum { + if let Some(child) = child.res.opt_def_id() { + match visible_parent_map.entry(child) { + Entry::Occupied(mut entry) => { + // If `child` is defined in crate `cnum`, ensure + // that it is mapped to a parent in `cnum`. + if child.krate == cnum && entry.get().krate != cnum { + entry.insert(parent); + } + } + Entry::Vacant(entry) => { entry.insert(parent); + bfs_queue.push_back(child); } } - Entry::Vacant(entry) => { - entry.insert(parent); - bfs_queue.push_back(child); - } } - } - }; + }; while let Some(def) = bfs_queue.pop_front() { for child in tcx.item_children(def).iter() { @@ -410,7 +409,7 @@ impl CStore { &self, def_id: DefId, sess: &Session, - ) -> Vec> { + ) -> Vec> { let mut result = vec![]; self.get_crate_data(def_id.krate).each_child_of_item( def_id.index, diff --git a/src/librustc_metadata/rmeta/mod.rs b/src/librustc_metadata/rmeta/mod.rs index 40b0ec74a4a33..4ef978c21e06d 100644 --- a/src/librustc_metadata/rmeta/mod.rs +++ b/src/librustc_metadata/rmeta/mod.rs @@ -2,8 +2,9 @@ use decoder::Metadata; use table::{Table, TableBuilder}; use rustc::hir; -use rustc::hir::def::{self, CtorKind}; +use rustc::hir::def::CtorKind; use rustc::hir::def_id::{DefId, DefIndex}; +use rustc::hir::exports::Export; use rustc::middle::cstore::{DepKind, ForeignModule, LinkagePreference, NativeLibrary}; use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use rustc::middle::lang_items; @@ -317,7 +318,7 @@ struct RenderedConst(String); #[derive(RustcEncodable, RustcDecodable)] struct ModData { - reexports: Lazy<[def::Export]>, + reexports: Lazy<[Export]>, } #[derive(RustcEncodable, RustcDecodable)] diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 5304aced69fbf..0ed4aab6b3e21 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -19,6 +19,7 @@ use crate::{Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, Segmen use rustc::bug; use rustc::hir::def::{self, *}; use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc::hir::exports::Export; use rustc::middle::cstore::CrateStore; use rustc::ty; use rustc_metadata::creader::LoadedMacro; diff --git a/src/librustc_resolve/imports.rs b/src/librustc_resolve/imports.rs index 9b7cd2578f878..cc35b7748ef44 100644 --- a/src/librustc_resolve/imports.rs +++ b/src/librustc_resolve/imports.rs @@ -13,8 +13,9 @@ use crate::{NameBinding, NameBindingKind, PathResult, PrivacyError, ToNameBindin use errors::{pluralize, Applicability}; -use rustc::hir::def::{self, Export, PartialRes}; +use rustc::hir::def::{self, PartialRes}; use rustc::hir::def_id::DefId; +use rustc::hir::exports::Export; use rustc::lint::builtin::BuiltinLintDiagnostics; use rustc::lint::builtin::{PUB_USE_OF_PRIVATE_EXTERN_CRATE, UNUSED_IMPORTS}; use rustc::session::DiagnosticMessageId; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 0d08313ae730c..72e0dc32c2103 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -22,8 +22,9 @@ use Determinacy::*; use errors::{Applicability, DiagnosticBuilder}; use rustc::hir::def::Namespace::*; -use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, ExportMap, NonMacroAttrKind, PartialRes}; +use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PartialRes}; use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc::hir::exports::ExportMap; use rustc::hir::map::Definitions; use rustc::hir::{Bool, Char, Float, Int, PrimTy, Str, Uint}; use rustc::hir::{GlobMap, TraitMap}; From ef08662613ae80983dff32efda0c6275d1f86dda Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 2 Jan 2020 05:18:45 +0100 Subject: [PATCH 18/20] hir::{hir,def,itemlikevisit,pat_util,print} -> rustc_hir Also fix fallout wrt. HashStable. --- src/librustc/hir.rs | 21 +- src/librustc/hir/map/mod.rs | 39 --- src/librustc/ich/hcx.rs | 33 +-- src/librustc/ich/impls_hir.rs | 231 ++++++++++-------- src/librustc/ich/impls_syntax.rs | 18 +- src/{librustc/hir => librustc_hir}/def.rs | 24 +- src/{librustc/hir => librustc_hir}/hir.rs | 204 ++++++++-------- .../hir => librustc_hir}/itemlikevisit.rs | 0 src/librustc_hir/lib.rs | 15 ++ .../hir => librustc_hir}/pat_util.rs | 4 +- src/{librustc/hir => librustc_hir}/print.rs | 49 +++- src/librustc_hir/stable_hash_impls.rs | 81 ++++++ src/libsyntax/lib.rs | 12 +- 13 files changed, 420 insertions(+), 311 deletions(-) rename src/{librustc/hir => librustc_hir}/def.rs (96%) rename src/{librustc/hir => librustc_hir}/hir.rs (93%) rename src/{librustc/hir => librustc_hir}/itemlikevisit.rs (100%) rename src/{librustc/hir => librustc_hir}/pat_util.rs (98%) rename src/{librustc/hir => librustc_hir}/print.rs (97%) create mode 100644 src/librustc_hir/stable_hash_impls.rs diff --git a/src/librustc/hir.rs b/src/librustc/hir.rs index ae19d82387d49..62160fed1bc66 100644 --- a/src/librustc/hir.rs +++ b/src/librustc/hir.rs @@ -3,24 +3,23 @@ //! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html pub mod check_attr; -pub mod def; +pub use rustc_hir::def; pub mod exports; pub use rustc_hir::def_id; pub use rustc_hir::hir_id::*; pub mod intravisit; -pub mod itemlikevisit; +pub use rustc_hir::itemlikevisit; pub mod map; -pub mod pat_util; -pub mod print; +pub use rustc_hir::pat_util; +pub use rustc_hir::print; pub mod upvars; -mod hir; -pub use hir::BlockCheckMode::*; -pub use hir::FunctionRetTy::*; -pub use hir::PrimTy::*; -pub use hir::UnOp::*; -pub use hir::UnsafeSource::*; -pub use hir::*; +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; diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 92547bbe038dd..b499ba20b8cf1 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -1266,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/hir/def.rs b/src/librustc_hir/def.rs similarity index 96% rename from src/librustc/hir/def.rs rename to src/librustc_hir/def.rs index 71ece0aadd34f..83e30d85c5a67 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc_hir/def.rs @@ -1,7 +1,7 @@ +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 rustc_macros::HashStable; +use rustc_macros::HashStable_Generic; use rustc_span::hygiene::MacroKind; use syntax::ast; use syntax::ast::NodeId; @@ -9,7 +9,8 @@ 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, @@ -17,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, @@ -27,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, @@ -39,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, @@ -93,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", @@ -154,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), @@ -341,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/hir.rs b/src/librustc_hir/hir.rs similarity index 93% rename from src/librustc/hir/hir.rs rename to src/librustc_hir/hir.rs index da67cf3ccba22..1fea05306b6d5 100644 --- a/src/librustc/hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -1,17 +1,17 @@ -//! HIR datatypes. See the [rustc guide] for more info. -//! -//! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html +use crate::def::{DefKind, Res}; +use crate::def_id::DefId; +crate use crate::hir_id::HirId; +use crate::itemlikevisit; +use crate::print; -use crate::hir::def::{DefKind, Res}; -use crate::hir::def_id::DefId; -use crate::hir::itemlikevisit; -use crate::hir::print; -use rustc_hir::hir_id::HirId; +crate use BlockCheckMode::*; +crate use FunctionRetTy::*; +crate use UnsafeSource::*; use errors::FatalError; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::{par_for_each_in, Send, Sync}; -use rustc_macros::HashStable; +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}; @@ -27,7 +27,7 @@ pub use syntax::ast::{CaptureBy, Constness, Movability, Mutability, Unsafety}; use syntax::tokenstream::TokenStream; use syntax::util::parser::ExprPrecedence; -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable_Generic)] pub struct Lifetime { pub hir_id: HirId, pub span: Span, @@ -41,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), @@ -86,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), @@ -187,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. @@ -216,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))] @@ -259,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>), @@ -297,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>], @@ -334,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 { @@ -357,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, @@ -367,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), @@ -384,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 }`). @@ -403,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 { @@ -418,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, @@ -438,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>, @@ -491,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. @@ -517,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>), @@ -538,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. @@ -550,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, @@ -558,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, @@ -663,7 +667,7 @@ impl Crate<'_> { where V: itemlikevisit::ParItemLikeVisitor<'hir> + Sync + Send, { - parallel!( + rustc_data_structures::parallel!( { par_for_each_in(&self.items, |(_, item)| { visitor.visit_item(item); @@ -686,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>, @@ -700,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>], @@ -718,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, @@ -807,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, @@ -823,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 @@ -844,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, @@ -859,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, @@ -915,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, @@ -1049,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, @@ -1078,7 +1082,7 @@ impl UnOp { } /// A statement. -#[derive(RustcEncodable, RustcDecodable, HashStable)] +#[derive(RustcEncodable, RustcDecodable, HashStable_Generic)] pub struct Stmt<'hir> { pub hir_id: HirId, pub kind: StmtKind<'hir>, @@ -1097,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>), @@ -1123,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). @@ -1140,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, @@ -1154,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, @@ -1169,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), @@ -1177,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, @@ -1227,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), @@ -1250,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, @@ -1304,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, @@ -1321,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 { @@ -1505,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>), @@ -1618,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. @@ -1638,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, @@ -1660,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, @@ -1696,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, @@ -1718,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, @@ -1737,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